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
|
|
|
)
|
|
|
|
|
2016-06-30 02:54:24 +03:00
|
|
|
// TestElkremBig tries 10K hashes
|
2016-01-19 07:43:02 +03:00
|
|
|
func TestElkremBig(t *testing.T) {
|
2016-06-30 02:54:24 +03:00
|
|
|
sndr := NewElkremSender(wire.DoubleSha256SH([]byte("elktest")))
|
|
|
|
var rcv ElkremReceiver
|
|
|
|
// SenderSerdesTest(t, sndr)
|
2016-01-19 07:43:02 +03:00
|
|
|
for n := uint64(0); n < 10000; n++ {
|
2016-06-30 02:54:24 +03:00
|
|
|
sha, err := sndr.AtIndex(n)
|
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-06-30 02:54:24 +03:00
|
|
|
// SenderSerdesTest(t, sndr)
|
2016-01-19 10:28:14 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-30 02:54:24 +03:00
|
|
|
// TestElkremLess tries 10K hashes
|
|
|
|
func TestElkremLess(t *testing.T) {
|
|
|
|
sndr := NewElkremSender(wire.DoubleSha256SH([]byte("elktest2")))
|
|
|
|
var rcv ElkremReceiver
|
2016-01-19 07:43:02 +03:00
|
|
|
for n := uint64(0); n < 5000; n++ {
|
2016-06-30 02:54:24 +03:00
|
|
|
sha, err := sndr.AtIndex(n)
|
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())
|
|
|
|
}
|
|
|
|
}
|