2018-02-01 09:25:34 +00:00
|
|
|
package payload
|
|
|
|
|
2018-02-07 14:16:50 +00:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
|
2019-08-23 15:50:45 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
|
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{})
|
|
|
|
buf := new(bytes.Buffer)
|
2019-08-29 14:33:53 +00:00
|
|
|
err := p.EncodeBinary(buf)
|
|
|
|
assert.Nil(t, err)
|
2018-02-07 14:16:50 +00:00
|
|
|
|
|
|
|
pDecode := &GetBlocks{}
|
2019-08-29 14:33:53 +00:00
|
|
|
err = pDecode.DecodeBinary(buf)
|
|
|
|
assert.Nil(t, 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)
|
|
|
|
buf := new(bytes.Buffer)
|
2019-08-29 14:33:53 +00:00
|
|
|
err := p.EncodeBinary(buf)
|
|
|
|
assert.Nil(t, err)
|
2018-02-07 14:16:50 +00:00
|
|
|
|
|
|
|
pDecode := &GetBlocks{}
|
2019-08-29 14:33:53 +00:00
|
|
|
err = pDecode.DecodeBinary(buf)
|
|
|
|
assert.Nil(t, err)
|
2018-03-14 09:36:59 +00:00
|
|
|
assert.Equal(t, p, pDecode)
|
2018-02-07 14:16:50 +00:00
|
|
|
}
|