github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/consensus/prepare_request_test.go (about) 1 package consensus 2 3 import ( 4 "testing" 5 6 "github.com/nspcc-dev/neo-go/internal/random" 7 "github.com/nspcc-dev/neo-go/internal/testserdes" 8 "github.com/nspcc-dev/neo-go/pkg/core/block" 9 "github.com/nspcc-dev/neo-go/pkg/util" 10 "github.com/stretchr/testify/require" 11 ) 12 13 func TestPrepareRequest_Getters(t *testing.T) { 14 hashes := []util.Uint256{random.Uint256(), random.Uint256()} 15 var p = &prepareRequest{ 16 version: 123, 17 prevHash: util.Uint256{1, 2, 3}, 18 timestamp: 123, 19 transactionHashes: hashes, 20 } 21 22 require.EqualValues(t, 123000000, p.Timestamp()) 23 require.Equal(t, hashes, p.TransactionHashes()) 24 } 25 26 func TestPrepareRequest_EncodeDecodeBinary(t *testing.T) { 27 t.Run("positive", func(t *testing.T) { 28 expected := &prepareRequest{ 29 timestamp: 112, 30 transactionHashes: []util.Uint256{ 31 random.Uint256(), 32 random.Uint256(), 33 }, 34 } 35 testserdes.EncodeDecodeBinary(t, expected, new(prepareRequest)) 36 }) 37 38 t.Run("bad hashes count", func(t *testing.T) { 39 hashes := make([]util.Uint256, block.MaxTransactionsPerBlock+1) 40 for i := range hashes { 41 hashes[i] = random.Uint256() 42 } 43 expected := &prepareRequest{ 44 timestamp: 112, 45 transactionHashes: hashes, 46 } 47 data, err := testserdes.EncodeBinary(expected) 48 require.NoError(t, err) 49 require.Error(t, testserdes.DecodeBinary(data, new(prepareRequest))) 50 }) 51 }