git.frostfs.info/TrueCloudLab/frostfs-sdk-go@v0.0.0-20241022124111-5361f0ecebd3/netmap/network_info_decode_test.go (about) 1 package netmap 2 3 import ( 4 "math/big" 5 "testing" 6 7 "github.com/nspcc-dev/neo-go/pkg/encoding/bigint" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestDecodeUint64(t *testing.T) { 12 testCases := []uint64{ 13 0, 14 12, 15 129, 16 0x1234, 17 0x12345678, 18 0x1234567891011, 19 } 20 21 for _, expected := range testCases { 22 val := bigint.ToBytes(big.NewInt(int64(expected))) 23 24 actual, err := decodeConfigValueUint64(val) 25 require.NoError(t, err) 26 require.Equal(t, expected, actual) 27 } 28 } 29 30 func TestDecodeBool(t *testing.T) { 31 testCases := []struct { 32 expected bool 33 raw []byte 34 }{ 35 { 36 false, 37 []byte{0}, 38 }, 39 { 40 false, 41 []byte{0, 0, 0, 0}, 42 }, 43 { 44 true, 45 []byte{1}, 46 }, 47 { 48 true, 49 []byte{1, 1, 1, 1, 1}, 50 }, 51 { 52 true, 53 []byte{0, 0, 0, 0, 1}, // neo-go casts any value that does not consist of zeroes as `true` 54 }, 55 } 56 57 for _, test := range testCases { 58 actual, err := decodeConfigValueBool(test.raw) 59 require.NoError(t, err) 60 61 require.Equal(t, test.expected, actual) 62 } 63 }