lnd.xprv/elkrem/elkrem_test.go
Olaoluwa Osuntokun 102a0f6689
elkrem: sync with upstream onehop branch
This commit syncs the version of elkrem currently checked into master
with the version that has been developed in the upstream master branch.
2016-06-29 16:55:49 -07:00

72 lines
1.5 KiB
Go

package elkrem
import (
"testing"
"github.com/roasbeef/btcd/wire"
)
// TestElkremBig tries 10K hashes
func TestElkremBig(t *testing.T) {
sndr := NewElkremSender(wire.DoubleSha256SH([]byte("elktest")))
var rcv ElkremReceiver
// SenderSerdesTest(t, sndr)
for n := uint64(0); n < 10000; n++ {
sha, err := sndr.AtIndex(n)
if err != nil {
t.Fatal(err)
}
err = rcv.AddNext(sha)
if err != nil {
t.Fatal(err)
}
if n%1000 == 999 {
t.Logf("stack with %d received hashes\n", n+1)
for i, n := range rcv.s {
t.Logf("Stack element %d: index %d height %d %s\n",
i, n.i, n.h, n.sha.String())
}
}
}
// SenderSerdesTest(t, sndr)
ReceiverSerdesTest(t, &rcv)
for n := uint64(0); n < 10000; n += 500 {
sha, err := rcv.AtIndex(n)
if err != nil {
t.Fatal(err)
}
t.Logf("Retreived index %d %s\n", n, sha.String())
}
}
// TestElkremLess tries 10K hashes
func TestElkremLess(t *testing.T) {
sndr := NewElkremSender(wire.DoubleSha256SH([]byte("elktest2")))
var rcv ElkremReceiver
for n := uint64(0); n < 5000; n++ {
sha, err := sndr.AtIndex(n)
if err != nil {
t.Fatal(err)
}
err = rcv.AddNext(sha)
if err != nil {
t.Fatal(err)
}
if n%1000 == 999 {
t.Logf("stack with %d received hashes\n", n+1)
for i, n := range rcv.s {
t.Logf("Stack element %d: index %d height %d %s\n",
i, n.i, n.h, n.sha.String())
}
}
}
for n := uint64(0); n < 5000; n += 500 {
sha, err := rcv.AtIndex(n)
if err != nil {
t.Fatal(err)
}
t.Logf("Retreived index %d %s\n",
n, sha.String())
}
}