2018-01-30 10:56:36 +00:00
|
|
|
package payload
|
|
|
|
|
|
|
|
import (
|
2020-12-04 12:26:14 +00:00
|
|
|
"strings"
|
2018-01-30 10:56:36 +00:00
|
|
|
"testing"
|
|
|
|
|
2020-11-23 11:09:00 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/internal/testserdes"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
2023-10-20 14:23:35 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2019-08-29 14:33:53 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-12-04 12:26:14 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-01-30 10:56:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestInventoryEncodeDecode(t *testing.T) {
|
2023-10-20 14:23:35 +00:00
|
|
|
hashes := []util.Uint256{
|
2019-08-23 15:50:45 +00:00
|
|
|
hash.Sha256([]byte("a")),
|
|
|
|
hash.Sha256([]byte("b")),
|
2018-01-30 10:56:36 +00:00
|
|
|
}
|
|
|
|
inv := NewInventory(BlockType, hashes)
|
|
|
|
|
2020-03-26 14:43:24 +00:00
|
|
|
testserdes.EncodeDecodeBinary(t, inv, new(Inventory))
|
2018-01-30 10:56:36 +00:00
|
|
|
}
|
2019-08-29 17:27:16 +00:00
|
|
|
|
|
|
|
func TestEmptyInv(t *testing.T) {
|
2023-10-20 14:23:35 +00:00
|
|
|
msgInv := NewInventory(TXType, []util.Uint256{})
|
2019-08-29 17:27:16 +00:00
|
|
|
|
2020-03-26 14:43:24 +00:00
|
|
|
data, err := testserdes.EncodeBinary(msgInv)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, []byte{byte(TXType), 0}, data)
|
2019-08-29 17:27:16 +00:00
|
|
|
assert.Equal(t, 0, len(msgInv.Hashes))
|
|
|
|
}
|
2020-12-04 12:26:14 +00:00
|
|
|
|
|
|
|
func TestValid(t *testing.T) {
|
2020-11-27 10:55:48 +00:00
|
|
|
require.True(t, TXType.Valid(false))
|
|
|
|
require.True(t, TXType.Valid(true))
|
|
|
|
require.True(t, BlockType.Valid(false))
|
|
|
|
require.True(t, BlockType.Valid(true))
|
2021-01-14 13:38:40 +00:00
|
|
|
require.True(t, ExtensibleType.Valid(false))
|
|
|
|
require.True(t, ExtensibleType.Valid(true))
|
2020-11-27 10:55:48 +00:00
|
|
|
require.False(t, P2PNotaryRequestType.Valid(false))
|
|
|
|
require.True(t, P2PNotaryRequestType.Valid(true))
|
|
|
|
require.False(t, InventoryType(0xFF).Valid(false))
|
|
|
|
require.False(t, InventoryType(0xFF).Valid(true))
|
2020-12-04 12:26:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestString(t *testing.T) {
|
|
|
|
require.Equal(t, "TX", TXType.String())
|
|
|
|
require.Equal(t, "block", BlockType.String())
|
2021-01-14 13:38:40 +00:00
|
|
|
require.Equal(t, "extensible", ExtensibleType.String())
|
2020-11-27 10:55:48 +00:00
|
|
|
require.Equal(t, "p2pNotaryRequest", P2PNotaryRequestType.String())
|
2020-12-04 12:26:14 +00:00
|
|
|
require.True(t, strings.Contains(InventoryType(0xFF).String(), "unknown"))
|
|
|
|
}
|