mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-25 13:56:35 +00:00
2e3172f8a5
Like in 483b875f4a
.
50 lines
1 KiB
Go
50 lines
1 KiB
Go
package payload
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetBlockEncodeDecode(t *testing.T) {
|
|
start := []util.Uint256{
|
|
hash.Sha256([]byte("a")),
|
|
hash.Sha256([]byte("b")),
|
|
hash.Sha256([]byte("c")),
|
|
hash.Sha256([]byte("d")),
|
|
}
|
|
|
|
p := NewGetBlocks(start, util.Uint256{})
|
|
buf := new(bytes.Buffer)
|
|
err := p.EncodeBinary(buf)
|
|
assert.Nil(t, err)
|
|
|
|
pDecode := &GetBlocks{}
|
|
err = pDecode.DecodeBinary(buf)
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, p, pDecode)
|
|
}
|
|
|
|
func TestGetBlockEncodeDecodeWithHashStop(t *testing.T) {
|
|
var (
|
|
start = []util.Uint256{
|
|
hash.Sha256([]byte("a")),
|
|
hash.Sha256([]byte("b")),
|
|
hash.Sha256([]byte("c")),
|
|
hash.Sha256([]byte("d")),
|
|
}
|
|
stop = hash.Sha256([]byte("e"))
|
|
)
|
|
p := NewGetBlocks(start, stop)
|
|
buf := new(bytes.Buffer)
|
|
err := p.EncodeBinary(buf)
|
|
assert.Nil(t, err)
|
|
|
|
pDecode := &GetBlocks{}
|
|
err = pDecode.DecodeBinary(buf)
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, p, pDecode)
|
|
}
|