github.com/neatlab/neatio@v1.7.3-0.20220425043230-d903e92fcc75/chain/accounts/abi/type_test.go (about) 1 package abi 2 3 import ( 4 "math/big" 5 "reflect" 6 "testing" 7 8 "github.com/davecgh/go-spew/spew" 9 "github.com/neatlab/neatio/utilities/common" 10 ) 11 12 type typeWithoutStringer Type 13 14 func TestTypeRegexp(t *testing.T) { 15 tests := []struct { 16 blob string 17 components []ArgumentMarshaling 18 kind Type 19 }{ 20 {"bool", nil, Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}}, 21 {"bool[]", nil, Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([]bool(nil)), Elem: &Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}, stringKind: "bool[]"}}, 22 {"bool[2]", nil, Type{Size: 2, Kind: reflect.Array, T: ArrayTy, Type: reflect.TypeOf([2]bool{}), Elem: &Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}, stringKind: "bool[2]"}}, 23 {"bool[2][]", nil, Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([][2]bool{}), Elem: &Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]bool{}), Elem: &Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}, stringKind: "bool[2]"}, stringKind: "bool[2][]"}}, 24 {"bool[][]", nil, Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([][]bool{}), Elem: &Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([]bool{}), Elem: &Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}, stringKind: "bool[]"}, stringKind: "bool[][]"}}, 25 {"bool[][2]", nil, Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2][]bool{}), Elem: &Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([]bool{}), Elem: &Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}, stringKind: "bool[]"}, stringKind: "bool[][2]"}}, 26 {"bool[2][2]", nil, Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2][2]bool{}), Elem: &Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]bool{}), Elem: &Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}, stringKind: "bool[2]"}, stringKind: "bool[2][2]"}}, 27 {"bool[2][][2]", nil, Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2][][2]bool{}), Elem: &Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([][2]bool{}), Elem: &Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]bool{}), Elem: &Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}, stringKind: "bool[2]"}, stringKind: "bool[2][]"}, stringKind: "bool[2][][2]"}}, 28 {"bool[2][2][2]", nil, Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2][2][2]bool{}), Elem: &Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2][2]bool{}), Elem: &Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]bool{}), Elem: &Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}, stringKind: "bool[2]"}, stringKind: "bool[2][2]"}, stringKind: "bool[2][2][2]"}}, 29 {"bool[][][]", nil, Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([][][]bool{}), Elem: &Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([][]bool{}), Elem: &Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([]bool{}), Elem: &Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}, stringKind: "bool[]"}, stringKind: "bool[][]"}, stringKind: "bool[][][]"}}, 30 {"bool[][2][]", nil, Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([][2][]bool{}), Elem: &Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2][]bool{}), Elem: &Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([]bool{}), Elem: &Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}, stringKind: "bool[]"}, stringKind: "bool[][2]"}, stringKind: "bool[][2][]"}}, 31 {"int8", nil, Type{Kind: reflect.Int8, Type: int8T, Size: 8, T: IntTy, stringKind: "int8"}}, 32 {"int16", nil, Type{Kind: reflect.Int16, Type: int16T, Size: 16, T: IntTy, stringKind: "int16"}}, 33 {"int32", nil, Type{Kind: reflect.Int32, Type: int32T, Size: 32, T: IntTy, stringKind: "int32"}}, 34 {"int64", nil, Type{Kind: reflect.Int64, Type: int64T, Size: 64, T: IntTy, stringKind: "int64"}}, 35 {"int256", nil, Type{Kind: reflect.Ptr, Type: bigT, Size: 256, T: IntTy, stringKind: "int256"}}, 36 {"int8[]", nil, Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([]int8{}), Elem: &Type{Kind: reflect.Int8, Type: int8T, Size: 8, T: IntTy, stringKind: "int8"}, stringKind: "int8[]"}}, 37 {"int8[2]", nil, Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]int8{}), Elem: &Type{Kind: reflect.Int8, Type: int8T, Size: 8, T: IntTy, stringKind: "int8"}, stringKind: "int8[2]"}}, 38 {"int16[]", nil, Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([]int16{}), Elem: &Type{Kind: reflect.Int16, Type: int16T, Size: 16, T: IntTy, stringKind: "int16"}, stringKind: "int16[]"}}, 39 {"int16[2]", nil, Type{Size: 2, Kind: reflect.Array, T: ArrayTy, Type: reflect.TypeOf([2]int16{}), Elem: &Type{Kind: reflect.Int16, Type: int16T, Size: 16, T: IntTy, stringKind: "int16"}, stringKind: "int16[2]"}}, 40 {"int32[]", nil, Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([]int32{}), Elem: &Type{Kind: reflect.Int32, Type: int32T, Size: 32, T: IntTy, stringKind: "int32"}, stringKind: "int32[]"}}, 41 {"int32[2]", nil, Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]int32{}), Elem: &Type{Kind: reflect.Int32, Type: int32T, Size: 32, T: IntTy, stringKind: "int32"}, stringKind: "int32[2]"}}, 42 {"int64[]", nil, Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([]int64{}), Elem: &Type{Kind: reflect.Int64, Type: int64T, Size: 64, T: IntTy, stringKind: "int64"}, stringKind: "int64[]"}}, 43 {"int64[2]", nil, Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]int64{}), Elem: &Type{Kind: reflect.Int64, Type: int64T, Size: 64, T: IntTy, stringKind: "int64"}, stringKind: "int64[2]"}}, 44 {"int256[]", nil, Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([]*big.Int{}), Elem: &Type{Kind: reflect.Ptr, Type: bigT, Size: 256, T: IntTy, stringKind: "int256"}, stringKind: "int256[]"}}, 45 {"int256[2]", nil, Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]*big.Int{}), Elem: &Type{Kind: reflect.Ptr, Type: bigT, Size: 256, T: IntTy, stringKind: "int256"}, stringKind: "int256[2]"}}, 46 {"uint8", nil, Type{Kind: reflect.Uint8, Type: uint8T, Size: 8, T: UintTy, stringKind: "uint8"}}, 47 {"uint16", nil, Type{Kind: reflect.Uint16, Type: uint16T, Size: 16, T: UintTy, stringKind: "uint16"}}, 48 {"uint32", nil, Type{Kind: reflect.Uint32, Type: uint32T, Size: 32, T: UintTy, stringKind: "uint32"}}, 49 {"uint64", nil, Type{Kind: reflect.Uint64, Type: uint64T, Size: 64, T: UintTy, stringKind: "uint64"}}, 50 {"uint256", nil, Type{Kind: reflect.Ptr, Type: bigT, Size: 256, T: UintTy, stringKind: "uint256"}}, 51 {"uint8[]", nil, Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([]uint8{}), Elem: &Type{Kind: reflect.Uint8, Type: uint8T, Size: 8, T: UintTy, stringKind: "uint8"}, stringKind: "uint8[]"}}, 52 {"uint8[2]", nil, Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]uint8{}), Elem: &Type{Kind: reflect.Uint8, Type: uint8T, Size: 8, T: UintTy, stringKind: "uint8"}, stringKind: "uint8[2]"}}, 53 {"uint16[]", nil, Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([]uint16{}), Elem: &Type{Kind: reflect.Uint16, Type: uint16T, Size: 16, T: UintTy, stringKind: "uint16"}, stringKind: "uint16[]"}}, 54 {"uint16[2]", nil, Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]uint16{}), Elem: &Type{Kind: reflect.Uint16, Type: uint16T, Size: 16, T: UintTy, stringKind: "uint16"}, stringKind: "uint16[2]"}}, 55 {"uint32[]", nil, Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([]uint32{}), Elem: &Type{Kind: reflect.Uint32, Type: uint32T, Size: 32, T: UintTy, stringKind: "uint32"}, stringKind: "uint32[]"}}, 56 {"uint32[2]", nil, Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]uint32{}), Elem: &Type{Kind: reflect.Uint32, Type: uint32T, Size: 32, T: UintTy, stringKind: "uint32"}, stringKind: "uint32[2]"}}, 57 {"uint64[]", nil, Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([]uint64{}), Elem: &Type{Kind: reflect.Uint64, Type: uint64T, Size: 64, T: UintTy, stringKind: "uint64"}, stringKind: "uint64[]"}}, 58 {"uint64[2]", nil, Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]uint64{}), Elem: &Type{Kind: reflect.Uint64, Type: uint64T, Size: 64, T: UintTy, stringKind: "uint64"}, stringKind: "uint64[2]"}}, 59 {"uint256[]", nil, Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([]*big.Int{}), Elem: &Type{Kind: reflect.Ptr, Type: bigT, Size: 256, T: UintTy, stringKind: "uint256"}, stringKind: "uint256[]"}}, 60 {"uint256[2]", nil, Type{Kind: reflect.Array, T: ArrayTy, Type: reflect.TypeOf([2]*big.Int{}), Size: 2, Elem: &Type{Kind: reflect.Ptr, Type: bigT, Size: 256, T: UintTy, stringKind: "uint256"}, stringKind: "uint256[2]"}}, 61 {"bytes32", nil, Type{Kind: reflect.Array, T: FixedBytesTy, Size: 32, Type: reflect.TypeOf([32]byte{}), stringKind: "bytes32"}}, 62 {"bytes[]", nil, Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([][]byte{}), Elem: &Type{Kind: reflect.Slice, Type: reflect.TypeOf([]byte{}), T: BytesTy, stringKind: "bytes"}, stringKind: "bytes[]"}}, 63 {"bytes[2]", nil, Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2][]byte{}), Elem: &Type{T: BytesTy, Type: reflect.TypeOf([]byte{}), Kind: reflect.Slice, stringKind: "bytes"}, stringKind: "bytes[2]"}}, 64 {"bytes32[]", nil, Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([][32]byte{}), Elem: &Type{Kind: reflect.Array, Type: reflect.TypeOf([32]byte{}), T: FixedBytesTy, Size: 32, stringKind: "bytes32"}, stringKind: "bytes32[]"}}, 65 {"bytes32[2]", nil, Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2][32]byte{}), Elem: &Type{Kind: reflect.Array, T: FixedBytesTy, Size: 32, Type: reflect.TypeOf([32]byte{}), stringKind: "bytes32"}, stringKind: "bytes32[2]"}}, 66 {"string", nil, Type{Kind: reflect.String, T: StringTy, Type: reflect.TypeOf(""), stringKind: "string"}}, 67 {"string[]", nil, Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([]string{}), Elem: &Type{Kind: reflect.String, Type: reflect.TypeOf(""), T: StringTy, stringKind: "string"}, stringKind: "string[]"}}, 68 {"string[2]", nil, Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]string{}), Elem: &Type{Kind: reflect.String, T: StringTy, Type: reflect.TypeOf(""), stringKind: "string"}, stringKind: "string[2]"}}, 69 {"address", nil, Type{Kind: reflect.Array, Type: addressT, Size: 20, T: AddressTy, stringKind: "address"}}, 70 {"address[]", nil, Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([]common.Address{}), Elem: &Type{Kind: reflect.Array, Type: addressT, Size: 20, T: AddressTy, stringKind: "address"}, stringKind: "address[]"}}, 71 {"address[2]", nil, Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]common.Address{}), Elem: &Type{Kind: reflect.Array, Type: addressT, Size: 20, T: AddressTy, stringKind: "address"}, stringKind: "address[2]"}}, 72 73 {"tuple", []ArgumentMarshaling{{Name: "a", Type: "int64"}}, Type{Kind: reflect.Struct, T: TupleTy, Type: reflect.TypeOf(struct { 74 A int64 `json:"a"` 75 }{}), stringKind: "(int64)", 76 TupleElems: []*Type{{Kind: reflect.Int64, T: IntTy, Type: reflect.TypeOf(int64(0)), Size: 64, stringKind: "int64"}}, TupleRawNames: []string{"a"}}}, 77 {"tuple with long name", []ArgumentMarshaling{{Name: "aTypicalParamName", Type: "int64"}}, Type{Kind: reflect.Struct, T: TupleTy, Type: reflect.TypeOf(struct { 78 ATypicalParamName int64 `json:"aTypicalParamName"` 79 }{}), stringKind: "(int64)", 80 TupleElems: []*Type{{Kind: reflect.Int64, T: IntTy, Type: reflect.TypeOf(int64(0)), Size: 64, stringKind: "int64"}}, TupleRawNames: []string{"aTypicalParamName"}}}, 81 } 82 83 for _, tt := range tests { 84 typ, err := NewType(tt.blob, "", tt.components) 85 if err != nil { 86 t.Errorf("type %q: failed to parse type string: %v", tt.blob, err) 87 } 88 if !reflect.DeepEqual(typ, tt.kind) { 89 t.Errorf("type %q: parsed type mismatch:\nGOT %s\nWANT %s ", tt.blob, spew.Sdump(typeWithoutStringer(typ)), spew.Sdump(typeWithoutStringer(tt.kind))) 90 } 91 } 92 } 93 94 func TestTypeCheck(t *testing.T) { 95 for i, test := range []struct { 96 typ string 97 components []ArgumentMarshaling 98 input interface{} 99 err string 100 }{ 101 {"uint", nil, big.NewInt(1), "unsupported arg type: uint"}, 102 {"int", nil, big.NewInt(1), "unsupported arg type: int"}, 103 {"uint256", nil, big.NewInt(1), ""}, 104 {"uint256[][3][]", nil, [][3][]*big.Int{{{}}}, ""}, 105 {"uint256[][][3]", nil, [3][][]*big.Int{{{}}}, ""}, 106 {"uint256[3][][]", nil, [][][3]*big.Int{{{}}}, ""}, 107 {"uint256[3][3][3]", nil, [3][3][3]*big.Int{{{}}}, ""}, 108 {"uint8[][]", nil, [][]uint8{}, ""}, 109 {"int256", nil, big.NewInt(1), ""}, 110 {"uint8", nil, uint8(1), ""}, 111 {"uint16", nil, uint16(1), ""}, 112 {"uint32", nil, uint32(1), ""}, 113 {"uint64", nil, uint64(1), ""}, 114 {"int8", nil, int8(1), ""}, 115 {"int16", nil, int16(1), ""}, 116 {"int32", nil, int32(1), ""}, 117 {"int64", nil, int64(1), ""}, 118 {"uint24", nil, big.NewInt(1), ""}, 119 {"uint40", nil, big.NewInt(1), ""}, 120 {"uint48", nil, big.NewInt(1), ""}, 121 {"uint56", nil, big.NewInt(1), ""}, 122 {"uint72", nil, big.NewInt(1), ""}, 123 {"uint80", nil, big.NewInt(1), ""}, 124 {"uint88", nil, big.NewInt(1), ""}, 125 {"uint96", nil, big.NewInt(1), ""}, 126 {"uint104", nil, big.NewInt(1), ""}, 127 {"uint112", nil, big.NewInt(1), ""}, 128 {"uint120", nil, big.NewInt(1), ""}, 129 {"uint128", nil, big.NewInt(1), ""}, 130 {"uint136", nil, big.NewInt(1), ""}, 131 {"uint144", nil, big.NewInt(1), ""}, 132 {"uint152", nil, big.NewInt(1), ""}, 133 {"uint160", nil, big.NewInt(1), ""}, 134 {"uint168", nil, big.NewInt(1), ""}, 135 {"uint176", nil, big.NewInt(1), ""}, 136 {"uint184", nil, big.NewInt(1), ""}, 137 {"uint192", nil, big.NewInt(1), ""}, 138 {"uint200", nil, big.NewInt(1), ""}, 139 {"uint208", nil, big.NewInt(1), ""}, 140 {"uint216", nil, big.NewInt(1), ""}, 141 {"uint224", nil, big.NewInt(1), ""}, 142 {"uint232", nil, big.NewInt(1), ""}, 143 {"uint240", nil, big.NewInt(1), ""}, 144 {"uint248", nil, big.NewInt(1), ""}, 145 {"int24", nil, big.NewInt(1), ""}, 146 {"int40", nil, big.NewInt(1), ""}, 147 {"int48", nil, big.NewInt(1), ""}, 148 {"int56", nil, big.NewInt(1), ""}, 149 {"int72", nil, big.NewInt(1), ""}, 150 {"int80", nil, big.NewInt(1), ""}, 151 {"int88", nil, big.NewInt(1), ""}, 152 {"int96", nil, big.NewInt(1), ""}, 153 {"int104", nil, big.NewInt(1), ""}, 154 {"int112", nil, big.NewInt(1), ""}, 155 {"int120", nil, big.NewInt(1), ""}, 156 {"int128", nil, big.NewInt(1), ""}, 157 {"int136", nil, big.NewInt(1), ""}, 158 {"int144", nil, big.NewInt(1), ""}, 159 {"int152", nil, big.NewInt(1), ""}, 160 {"int160", nil, big.NewInt(1), ""}, 161 {"int168", nil, big.NewInt(1), ""}, 162 {"int176", nil, big.NewInt(1), ""}, 163 {"int184", nil, big.NewInt(1), ""}, 164 {"int192", nil, big.NewInt(1), ""}, 165 {"int200", nil, big.NewInt(1), ""}, 166 {"int208", nil, big.NewInt(1), ""}, 167 {"int216", nil, big.NewInt(1), ""}, 168 {"int224", nil, big.NewInt(1), ""}, 169 {"int232", nil, big.NewInt(1), ""}, 170 {"int240", nil, big.NewInt(1), ""}, 171 {"int248", nil, big.NewInt(1), ""}, 172 {"uint30", nil, uint8(1), "abi: cannot use uint8 as type ptr as argument"}, 173 {"uint8", nil, uint16(1), "abi: cannot use uint16 as type uint8 as argument"}, 174 {"uint8", nil, uint32(1), "abi: cannot use uint32 as type uint8 as argument"}, 175 {"uint8", nil, uint64(1), "abi: cannot use uint64 as type uint8 as argument"}, 176 {"uint8", nil, int8(1), "abi: cannot use int8 as type uint8 as argument"}, 177 {"uint8", nil, int16(1), "abi: cannot use int16 as type uint8 as argument"}, 178 {"uint8", nil, int32(1), "abi: cannot use int32 as type uint8 as argument"}, 179 {"uint8", nil, int64(1), "abi: cannot use int64 as type uint8 as argument"}, 180 {"uint16", nil, uint16(1), ""}, 181 {"uint16", nil, uint8(1), "abi: cannot use uint8 as type uint16 as argument"}, 182 {"uint16[]", nil, []uint16{1, 2, 3}, ""}, 183 {"uint16[]", nil, [3]uint16{1, 2, 3}, ""}, 184 {"uint16[]", nil, []uint32{1, 2, 3}, "abi: cannot use []uint32 as type [0]uint16 as argument"}, 185 {"uint16[3]", nil, [3]uint32{1, 2, 3}, "abi: cannot use [3]uint32 as type [3]uint16 as argument"}, 186 {"uint16[3]", nil, [4]uint16{1, 2, 3}, "abi: cannot use [4]uint16 as type [3]uint16 as argument"}, 187 {"uint16[3]", nil, []uint16{1, 2, 3}, ""}, 188 {"uint16[3]", nil, []uint16{1, 2, 3, 4}, "abi: cannot use [4]uint16 as type [3]uint16 as argument"}, 189 {"address[]", nil, []common.Address{{1}}, ""}, 190 {"address[1]", nil, []common.Address{{1}}, ""}, 191 {"address[1]", nil, [1]common.Address{{1}}, ""}, 192 {"address[2]", nil, [1]common.Address{{1}}, "abi: cannot use [1]array as type [2]array as argument"}, 193 {"bytes32", nil, [32]byte{}, ""}, 194 {"bytes31", nil, [31]byte{}, ""}, 195 {"bytes30", nil, [30]byte{}, ""}, 196 {"bytes29", nil, [29]byte{}, ""}, 197 {"bytes28", nil, [28]byte{}, ""}, 198 {"bytes27", nil, [27]byte{}, ""}, 199 {"bytes26", nil, [26]byte{}, ""}, 200 {"bytes25", nil, [25]byte{}, ""}, 201 {"bytes24", nil, [24]byte{}, ""}, 202 {"bytes23", nil, [23]byte{}, ""}, 203 {"bytes22", nil, [22]byte{}, ""}, 204 {"bytes21", nil, [21]byte{}, ""}, 205 {"bytes20", nil, [20]byte{}, ""}, 206 {"bytes19", nil, [19]byte{}, ""}, 207 {"bytes18", nil, [18]byte{}, ""}, 208 {"bytes17", nil, [17]byte{}, ""}, 209 {"bytes16", nil, [16]byte{}, ""}, 210 {"bytes15", nil, [15]byte{}, ""}, 211 {"bytes14", nil, [14]byte{}, ""}, 212 {"bytes13", nil, [13]byte{}, ""}, 213 {"bytes12", nil, [12]byte{}, ""}, 214 {"bytes11", nil, [11]byte{}, ""}, 215 {"bytes10", nil, [10]byte{}, ""}, 216 {"bytes9", nil, [9]byte{}, ""}, 217 {"bytes8", nil, [8]byte{}, ""}, 218 {"bytes7", nil, [7]byte{}, ""}, 219 {"bytes6", nil, [6]byte{}, ""}, 220 {"bytes5", nil, [5]byte{}, ""}, 221 {"bytes4", nil, [4]byte{}, ""}, 222 {"bytes3", nil, [3]byte{}, ""}, 223 {"bytes2", nil, [2]byte{}, ""}, 224 {"bytes1", nil, [1]byte{}, ""}, 225 {"bytes32", nil, [33]byte{}, "abi: cannot use [33]uint8 as type [32]uint8 as argument"}, 226 {"bytes32", nil, common.Hash{1}, ""}, 227 {"bytes31", nil, common.Hash{1}, "abi: cannot use common.Hash as type [31]uint8 as argument"}, 228 {"bytes31", nil, [32]byte{}, "abi: cannot use [32]uint8 as type [31]uint8 as argument"}, 229 {"bytes", nil, []byte{0, 1}, ""}, 230 {"bytes", nil, [2]byte{0, 1}, "abi: cannot use array as type slice as argument"}, 231 {"bytes", nil, common.Hash{1}, "abi: cannot use array as type slice as argument"}, 232 {"string", nil, "hello world", ""}, 233 {"string", nil, string(""), ""}, 234 {"string", nil, []byte{}, "abi: cannot use slice as type string as argument"}, 235 {"bytes32[]", nil, [][32]byte{{}}, ""}, 236 {"function", nil, [24]byte{}, ""}, 237 {"bytes20", nil, common.Address{}, ""}, 238 {"address", nil, [20]byte{}, ""}, 239 {"address", nil, common.Address{}, ""}, 240 {"bytes32[]]", nil, "", "invalid arg type in abi"}, 241 {"invalidType", nil, "", "unsupported arg type: invalidType"}, 242 {"invalidSlice[]", nil, "", "unsupported arg type: invalidSlice"}, 243 244 {"tuple", []ArgumentMarshaling{{Name: "a", Type: "uint256"}, {Name: "b", Type: "uint256"}}, struct { 245 A *big.Int 246 B *big.Int 247 }{}, ""}, 248 249 {"tuple[]", []ArgumentMarshaling{{Name: "a", Type: "uint256"}, {Name: "b", Type: "uint256"}}, []struct { 250 A *big.Int 251 B *big.Int 252 }{}, ""}, 253 254 {"tuple[2]", []ArgumentMarshaling{{Name: "a", Type: "uint256"}, {Name: "b", Type: "uint256"}}, []struct { 255 A *big.Int 256 B *big.Int 257 }{{big.NewInt(0), big.NewInt(0)}, {big.NewInt(0), big.NewInt(0)}}, ""}, 258 } { 259 typ, err := NewType(test.typ, "", test.components) 260 if err != nil && len(test.err) == 0 { 261 t.Fatal("unexpected parse error:", err) 262 } else if err != nil && len(test.err) != 0 { 263 if err.Error() != test.err { 264 t.Errorf("%d failed. Expected err: '%v' got err: '%v'", i, test.err, err) 265 } 266 continue 267 } 268 269 err = typeCheck(typ, reflect.ValueOf(test.input)) 270 if err != nil && len(test.err) == 0 { 271 t.Errorf("%d failed. Expected no err but got: %v", i, err) 272 continue 273 } 274 if err == nil && len(test.err) != 0 { 275 t.Errorf("%d failed. Expected err: %v but got none", i, test.err) 276 continue 277 } 278 279 if err != nil && len(test.err) != 0 && err.Error() != test.err { 280 t.Errorf("%d failed. Expected err: '%v' got err: '%v'", i, test.err, err) 281 } 282 } 283 }