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