mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-29 23:33:37 +00:00
ec7e17ffa6
Simplifies a lot of code and removes some duplication. Unfortunately I had to move test_util random functions in same commit to avoid cycle dependencies. One of these random functions was also used in core/transaction testing, to simplify things I've just dropped it there and used a static string (which is nice to have for a test anyway). There is still sha256 left in wallet (but it needs to pass Hash structure into the signing function).
56 lines
1.1 KiB
Go
56 lines
1.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)
|
|
if err := p.EncodeBinary(buf); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
pDecode := &GetBlocks{}
|
|
if err := pDecode.DecodeBinary(buf); err != nil {
|
|
t.Fatal(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)
|
|
if err := p.EncodeBinary(buf); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
pDecode := &GetBlocks{}
|
|
if err := pDecode.DecodeBinary(buf); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
assert.Equal(t, p, pDecode)
|
|
}
|