2016-12-14 01:59:48 +03:00
|
|
|
package shachain
|
|
|
|
|
|
|
|
import (
|
2017-02-23 06:13:56 +03:00
|
|
|
"bytes"
|
2016-12-14 01:59:48 +03:00
|
|
|
"testing"
|
2017-02-23 06:13:56 +03:00
|
|
|
|
2016-12-14 01:59:48 +03:00
|
|
|
"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
|
|
|
|
|
2017-02-23 06:13:56 +03:00
|
|
|
seed := chainhash.DoubleHashH([]byte("shachaintest"))
|
2016-12-14 01:59:48 +03:00
|
|
|
sender := NewRevocationProducer(seed)
|
|
|
|
|
|
|
|
s1, err := sender.AtIndex(0)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2017-02-23 06:13:56 +03:00
|
|
|
var b bytes.Buffer
|
|
|
|
if err := sender.Encode(&b); err != nil {
|
2016-12-14 01:59:48 +03:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2017-02-23 06:13:56 +03:00
|
|
|
sender, err = NewRevocationProducerFromBytes(b.Bytes())
|
2016-12-14 01:59:48 +03:00
|
|
|
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())
|
|
|
|
}
|
|
|
|
}
|