b6d8271b8d
* headers can now sync till infinity * fixed empty hashStop getBlock payload + test * added more test + more binary decoding/encoding * bump version
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package payload
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/sha256"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
|
)
|
|
|
|
func TestGetBlockEncodeDecode(t *testing.T) {
|
|
start := []util.Uint256{
|
|
sha256.Sum256([]byte("a")),
|
|
sha256.Sum256([]byte("b")),
|
|
sha256.Sum256([]byte("c")),
|
|
sha256.Sum256([]byte("d")),
|
|
}
|
|
|
|
p := NewGetBlocks(start, util.Uint256{})
|
|
buf := new(bytes.Buffer)
|
|
if err := p.EncodeBinary(buf); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
pDecode := &GetBlocks{}
|
|
if err := pDecode.DecodeBinary(buf); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if !reflect.DeepEqual(p, pDecode) {
|
|
t.Fatalf("expected to have equal block payload %v and %v", p, pDecode)
|
|
}
|
|
}
|
|
|
|
func TestGetBlockEncodeDecodeWithHashStop(t *testing.T) {
|
|
var (
|
|
start = []util.Uint256{
|
|
sha256.Sum256([]byte("a")),
|
|
sha256.Sum256([]byte("b")),
|
|
sha256.Sum256([]byte("c")),
|
|
sha256.Sum256([]byte("d")),
|
|
}
|
|
stop = sha256.Sum256([]byte("e"))
|
|
)
|
|
p := NewGetBlocks(start, stop)
|
|
buf := new(bytes.Buffer)
|
|
if err := p.EncodeBinary(buf); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
pDecode := &GetBlocks{}
|
|
if err := pDecode.DecodeBinary(buf); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if !reflect.DeepEqual(p, pDecode) {
|
|
t.Fatalf("expected to have equal block payload %v and %v", p, pDecode)
|
|
}
|
|
}
|