lnd.xprv/shachain/producer_test.go
Olaoluwa Osuntokun 2e25787a74
shachain: grammer fixes, gofmt conformance, slight interface changes
This commit contains a series of post-merge fixes which include:
  * ToBytes -> Encode
    * As the former version doesn’t _require_ allocation of new slices *
  * Store -> AddNextEntry
    * To communicate to the caller that entries MUST be added
      in order
  * Several grammar, spacing, spelling and gofmt fixes.
2017-02-24 16:31:37 -08:00

42 lines
787 B
Go

package shachain
import (
"bytes"
"testing"
"github.com/roasbeef/btcd/chaincfg/chainhash"
)
// TestShaChainProducerRestore checks the ability of shachain producer to be
// properly recreated from binary representation.
func TestShaChainProducerRestore(t *testing.T) {
var err error
seed := chainhash.DoubleHashH([]byte("shachaintest"))
sender := NewRevocationProducer(seed)
s1, err := sender.AtIndex(0)
if err != nil {
t.Fatal(err)
}
var b bytes.Buffer
if err := sender.Encode(&b); err != nil {
t.Fatal(err)
}
sender, err = NewRevocationProducerFromBytes(b.Bytes())
if err != nil {
t.Fatal(err)
}
s3, err := sender.AtIndex(0)
if err != nil {
t.Fatal(err)
}
if !s1.IsEqual(s3) {
t.Fatalf("secrets should match: %v:%v", s1.String(), s3.String())
}
}