shachain: complete shachain implementation

This commit is contained in:
Andrey Samokhvalov authored and Olaoluwa Osuntokun committed 2017-02-22 16:49:29 -08:00
1 parent 3a647869b6
commit b40afeaa08
9 files changed
+1279 -182

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
package shachain
import (
"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
hash := chainhash.DoubleHashH([]byte("shachaintest"))
seed := &hash
sender := NewRevocationProducer(seed)
s1, err := sender.AtIndex(0)
if err != nil {
t.Fatal(err)
}
data, err := sender.ToBytes()
if err != nil {
t.Fatal(err)
}
sender, err = NewRevocationProducerFromBytes(data)
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())
}
}