2016-01-19 07:43:02 +03:00
|
|
|
package elkrem
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2016-05-15 17:17:44 +03:00
|
|
|
"github.com/roasbeef/btcd/wire"
|
2016-01-19 07:43:02 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// TestElkremBig makes a height 63 (max size possible) tree and tries 10K hashes
|
|
|
|
func TestElkremBig(t *testing.T) {
|
2016-01-19 08:04:53 +03:00
|
|
|
sndr := NewElkremSender(63, wire.DoubleSha256SH([]byte("elktest")))
|
2016-01-19 07:43:02 +03:00
|
|
|
rcv := NewElkremReceiver(63)
|
2016-01-19 10:28:14 +03:00
|
|
|
SenderSerdesTest(t, &sndr)
|
2016-01-19 07:43:02 +03:00
|
|
|
for n := uint64(0); n < 10000; n++ {
|
2016-01-19 08:04:53 +03:00
|
|
|
sha, err := sndr.Next()
|
2016-01-19 07:43:02 +03:00
|
|
|
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())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-19 10:28:14 +03:00
|
|
|
SenderSerdesTest(t, &sndr)
|
|
|
|
ReceiverSerdesTest(t, &rcv)
|
2016-01-19 07:43:02 +03:00
|
|
|
for n := uint64(0); n < 10000; n += 500 {
|
|
|
|
sha, err := rcv.AtIndex(n)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-01-19 08:04:53 +03:00
|
|
|
t.Logf("Retreived index %d %s\n", n, sha.String())
|
2016-01-19 07:43:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestElkremSmall makes a height 15 (65534 size) tree and tries 10K hashes
|
|
|
|
func TestElkremSmall(t *testing.T) {
|
2016-01-19 08:04:53 +03:00
|
|
|
sndr := NewElkremSender(15, wire.DoubleSha256SH([]byte("elktest")))
|
2016-01-19 07:43:02 +03:00
|
|
|
rcv := NewElkremReceiver(15)
|
|
|
|
for n := uint64(0); n < 5000; n++ {
|
2016-01-19 08:04:53 +03:00
|
|
|
sha, err := sndr.Next()
|
2016-01-19 07:43:02 +03:00
|
|
|
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())
|
|
|
|
}
|
|
|
|
}
|