github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/network/payload/mptinventory_test.go (about) 1 package payload 2 3 import ( 4 "testing" 5 6 "github.com/nspcc-dev/neo-go/internal/testserdes" 7 "github.com/nspcc-dev/neo-go/pkg/util" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestMPTInventory_EncodeDecodeBinary(t *testing.T) { 12 t.Run("empty", func(t *testing.T) { 13 testserdes.EncodeDecodeBinary(t, NewMPTInventory([]util.Uint256{}), new(MPTInventory)) 14 }) 15 16 t.Run("good", func(t *testing.T) { 17 inv := NewMPTInventory([]util.Uint256{{1, 2, 3}, {2, 3, 4}}) 18 testserdes.EncodeDecodeBinary(t, inv, new(MPTInventory)) 19 }) 20 21 t.Run("too large", func(t *testing.T) { 22 check := func(t *testing.T, count int, fail bool) { 23 h := make([]util.Uint256, count) 24 for i := range h { 25 h[i] = util.Uint256{1, 2, 3} 26 } 27 if fail { 28 bytes, err := testserdes.EncodeBinary(NewMPTInventory(h)) 29 require.NoError(t, err) 30 require.Error(t, testserdes.DecodeBinary(bytes, new(MPTInventory))) 31 } else { 32 testserdes.EncodeDecodeBinary(t, NewMPTInventory(h), new(MPTInventory)) 33 } 34 } 35 check(t, MaxMPTHashesCount, false) 36 check(t, MaxMPTHashesCount+1, true) 37 }) 38 }