2018-02-01 09:25:34 +00:00
|
|
|
package payload
|
|
|
|
|
2018-02-07 14:16:50 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-08-23 15:50:45 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
|
2019-09-16 09:18:13 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/io"
|
2018-02-07 14:16:50 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
2018-03-14 09:36:59 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2018-02-07 14:16:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetBlockEncodeDecode(t *testing.T) {
|
|
|
|
start := []util.Uint256{
|
2019-08-23 15:50:45 +00:00
|
|
|
hash.Sha256([]byte("a")),
|
|
|
|
hash.Sha256([]byte("b")),
|
|
|
|
hash.Sha256([]byte("c")),
|
|
|
|
hash.Sha256([]byte("d")),
|
2018-02-07 14:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p := NewGetBlocks(start, util.Uint256{})
|
2019-09-16 09:18:13 +00:00
|
|
|
buf := io.NewBufBinWriter()
|
2019-09-16 16:31:49 +00:00
|
|
|
p.EncodeBinary(buf.BinWriter)
|
|
|
|
assert.Nil(t, buf.Err)
|
2018-02-07 14:16:50 +00:00
|
|
|
|
2019-09-16 09:18:13 +00:00
|
|
|
b := buf.Bytes()
|
|
|
|
r := io.NewBinReaderFromBuf(b)
|
2018-02-07 14:16:50 +00:00
|
|
|
pDecode := &GetBlocks{}
|
2019-09-16 16:31:49 +00:00
|
|
|
pDecode.DecodeBinary(r)
|
|
|
|
assert.Nil(t, r.Err)
|
2018-03-14 09:36:59 +00:00
|
|
|
assert.Equal(t, p, pDecode)
|
2018-02-07 14:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetBlockEncodeDecodeWithHashStop(t *testing.T) {
|
|
|
|
var (
|
|
|
|
start = []util.Uint256{
|
2019-08-23 15:50:45 +00:00
|
|
|
hash.Sha256([]byte("a")),
|
|
|
|
hash.Sha256([]byte("b")),
|
|
|
|
hash.Sha256([]byte("c")),
|
|
|
|
hash.Sha256([]byte("d")),
|
2018-02-07 14:16:50 +00:00
|
|
|
}
|
2019-08-23 15:50:45 +00:00
|
|
|
stop = hash.Sha256([]byte("e"))
|
2018-02-07 14:16:50 +00:00
|
|
|
)
|
|
|
|
p := NewGetBlocks(start, stop)
|
2019-09-16 09:18:13 +00:00
|
|
|
buf := io.NewBufBinWriter()
|
2019-09-16 16:31:49 +00:00
|
|
|
p.EncodeBinary(buf.BinWriter)
|
|
|
|
assert.Nil(t, buf.Err)
|
2018-02-07 14:16:50 +00:00
|
|
|
|
2019-09-16 09:18:13 +00:00
|
|
|
b := buf.Bytes()
|
|
|
|
r := io.NewBinReaderFromBuf(b)
|
2018-02-07 14:16:50 +00:00
|
|
|
pDecode := &GetBlocks{}
|
2019-09-16 16:31:49 +00:00
|
|
|
pDecode.DecodeBinary(r)
|
|
|
|
assert.Nil(t, r.Err)
|
2018-03-14 09:36:59 +00:00
|
|
|
assert.Equal(t, p, pDecode)
|
2018-02-07 14:16:50 +00:00
|
|
|
}
|