github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/accounts/abi/type_test.go (about)

     1  
     2  //此源码被清华学神尹成大魔王专业翻译分析并修改
     3  //尹成QQ77025077
     4  //尹成微信18510341407
     5  //尹成所在QQ群721929980
     6  //尹成邮箱 yinc13@mails.tsinghua.edu.cn
     7  //尹成毕业于清华大学,微软区块链领域全球最有价值专家
     8  //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620
     9  //版权所有2016 Go Ethereum作者
    10  //此文件是Go以太坊库的一部分。
    11  //
    12  //Go-Ethereum库是免费软件:您可以重新分发它和/或修改
    13  //根据GNU发布的较低通用公共许可证的条款
    14  //自由软件基金会,或者许可证的第3版,或者
    15  //(由您选择)任何更高版本。
    16  //
    17  //Go以太坊图书馆的发行目的是希望它会有用,
    18  //但没有任何保证;甚至没有
    19  //适销性或特定用途的适用性。见
    20  //GNU较低的通用公共许可证,了解更多详细信息。
    21  //
    22  //你应该收到一份GNU较低级别的公共许可证副本
    23  //以及Go以太坊图书馆。如果没有,请参见<http://www.gnu.org/licenses/>。
    24  
    25  package abi
    26  
    27  import (
    28  	"math/big"
    29  	"reflect"
    30  	"testing"
    31  
    32  	"github.com/davecgh/go-spew/spew"
    33  	"github.com/ethereum/go-ethereum/common"
    34  )
    35  
    36  //typewithoutStringer是类型类型类型的别名,该类型只是不实现
    37  //Stringer接口允许在下面的测试中打印类型详细信息。
    38  type typeWithoutStringer Type
    39  
    40  //测试类型分析器识别所有允许的类型。
    41  func TestTypeRegexp(t *testing.T) {
    42  	tests := []struct {
    43  		blob string
    44  		kind Type
    45  	}{
    46  		{"bool", Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}},
    47  		{"bool[]", 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[]"}},
    48  		{"bool[2]", 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]"}},
    49  		{"bool[2][]", 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][]"}},
    50  		{"bool[][]", 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[][]"}},
    51  		{"bool[][2]", 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]"}},
    52  		{"bool[2][2]", 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]"}},
    53  		{"bool[2][][2]", 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]"}},
    54  		{"bool[2][2][2]", 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]"}},
    55  		{"bool[][][]", 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[][][]"}},
    56  		{"bool[][2][]", 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][]"}},
    57  		{"int8", Type{Kind: reflect.Int8, Type: int8T, Size: 8, T: IntTy, stringKind: "int8"}},
    58  		{"int16", Type{Kind: reflect.Int16, Type: int16T, Size: 16, T: IntTy, stringKind: "int16"}},
    59  		{"int32", Type{Kind: reflect.Int32, Type: int32T, Size: 32, T: IntTy, stringKind: "int32"}},
    60  		{"int64", Type{Kind: reflect.Int64, Type: int64T, Size: 64, T: IntTy, stringKind: "int64"}},
    61  		{"int256", Type{Kind: reflect.Ptr, Type: bigT, Size: 256, T: IntTy, stringKind: "int256"}},
    62  		{"int8[]", 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[]"}},
    63  		{"int8[2]", 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]"}},
    64  		{"int16[]", 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[]"}},
    65  		{"int16[2]", 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]"}},
    66  		{"int32[]", 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[]"}},
    67  		{"int32[2]", 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]"}},
    68  		{"int64[]", 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[]"}},
    69  		{"int64[2]", 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]"}},
    70  		{"int256[]", 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[]"}},
    71  		{"int256[2]", 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]"}},
    72  		{"uint8", Type{Kind: reflect.Uint8, Type: uint8T, Size: 8, T: UintTy, stringKind: "uint8"}},
    73  		{"uint16", Type{Kind: reflect.Uint16, Type: uint16T, Size: 16, T: UintTy, stringKind: "uint16"}},
    74  		{"uint32", Type{Kind: reflect.Uint32, Type: uint32T, Size: 32, T: UintTy, stringKind: "uint32"}},
    75  		{"uint64", Type{Kind: reflect.Uint64, Type: uint64T, Size: 64, T: UintTy, stringKind: "uint64"}},
    76  		{"uint256", Type{Kind: reflect.Ptr, Type: bigT, Size: 256, T: UintTy, stringKind: "uint256"}},
    77  		{"uint8[]", 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[]"}},
    78  		{"uint8[2]", 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]"}},
    79  		{"uint16[]", 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[]"}},
    80  		{"uint16[2]", 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]"}},
    81  		{"uint32[]", 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[]"}},
    82  		{"uint32[2]", 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]"}},
    83  		{"uint64[]", 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[]"}},
    84  		{"uint64[2]", 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]"}},
    85  		{"uint256[]", 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[]"}},
    86  		{"uint256[2]", 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]"}},
    87  		{"bytes32", Type{Kind: reflect.Array, T: FixedBytesTy, Size: 32, Type: reflect.TypeOf([32]byte{}), stringKind: "bytes32"}},
    88  		{"bytes[]", 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[]"}},
    89  		{"bytes[2]", 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]"}},
    90  		{"bytes32[]", 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[]"}},
    91  		{"bytes32[2]", 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]"}},
    92  		{"string", Type{Kind: reflect.String, T: StringTy, Type: reflect.TypeOf(""), stringKind: "string"}},
    93  		{"string[]", Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([]string{}), Elem: &Type{Kind: reflect.String, Type: reflect.TypeOf(""), T: StringTy, stringKind: "string"}, stringKind: "string[]"}},
    94  		{"string[2]", 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]"}},
    95  		{"address", Type{Kind: reflect.Array, Type: addressT, Size: 20, T: AddressTy, stringKind: "address"}},
    96  		{"address[]", 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[]"}},
    97  		{"address[2]", 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]"}},
    98  //正确实现固定类型时的TODO
    99  //“固定”,类型,
   100  //“Fixed128x128”,类型,
   101  //“Fixed[]”,类型,
   102  //“Fixed[2]”,类型,
   103  //“Fixed128x128[]”,类型,
   104  //“Fixed128x128[2]”,类型,
   105  	}
   106  
   107  	for _, tt := range tests {
   108  		typ, err := NewType(tt.blob)
   109  		if err != nil {
   110  			t.Errorf("type %q: failed to parse type string: %v", tt.blob, err)
   111  		}
   112  		if !reflect.DeepEqual(typ, tt.kind) {
   113  			t.Errorf("type %q: parsed type mismatch:\nGOT %s\nWANT %s ", tt.blob, spew.Sdump(typeWithoutStringer(typ)), spew.Sdump(typeWithoutStringer(tt.kind)))
   114  		}
   115  	}
   116  }
   117  
   118  func TestTypeCheck(t *testing.T) {
   119  	for i, test := range []struct {
   120  		typ   string
   121  		input interface{}
   122  		err   string
   123  	}{
   124  		{"uint", big.NewInt(1), "unsupported arg type: uint"},
   125  		{"int", big.NewInt(1), "unsupported arg type: int"},
   126  		{"uint256", big.NewInt(1), ""},
   127  		{"uint256[][3][]", [][3][]*big.Int{{{}}}, ""},
   128  		{"uint256[][][3]", [3][][]*big.Int{{{}}}, ""},
   129  		{"uint256[3][][]", [][][3]*big.Int{{{}}}, ""},
   130  		{"uint256[3][3][3]", [3][3][3]*big.Int{{{}}}, ""},
   131  		{"uint8[][]", [][]uint8{}, ""},
   132  		{"int256", big.NewInt(1), ""},
   133  		{"uint8", uint8(1), ""},
   134  		{"uint16", uint16(1), ""},
   135  		{"uint32", uint32(1), ""},
   136  		{"uint64", uint64(1), ""},
   137  		{"int8", int8(1), ""},
   138  		{"int16", int16(1), ""},
   139  		{"int32", int32(1), ""},
   140  		{"int64", int64(1), ""},
   141  		{"uint24", big.NewInt(1), ""},
   142  		{"uint40", big.NewInt(1), ""},
   143  		{"uint48", big.NewInt(1), ""},
   144  		{"uint56", big.NewInt(1), ""},
   145  		{"uint72", big.NewInt(1), ""},
   146  		{"uint80", big.NewInt(1), ""},
   147  		{"uint88", big.NewInt(1), ""},
   148  		{"uint96", big.NewInt(1), ""},
   149  		{"uint104", big.NewInt(1), ""},
   150  		{"uint112", big.NewInt(1), ""},
   151  		{"uint120", big.NewInt(1), ""},
   152  		{"uint128", big.NewInt(1), ""},
   153  		{"uint136", big.NewInt(1), ""},
   154  		{"uint144", big.NewInt(1), ""},
   155  		{"uint152", big.NewInt(1), ""},
   156  		{"uint160", big.NewInt(1), ""},
   157  		{"uint168", big.NewInt(1), ""},
   158  		{"uint176", big.NewInt(1), ""},
   159  		{"uint184", big.NewInt(1), ""},
   160  		{"uint192", big.NewInt(1), ""},
   161  		{"uint200", big.NewInt(1), ""},
   162  		{"uint208", big.NewInt(1), ""},
   163  		{"uint216", big.NewInt(1), ""},
   164  		{"uint224", big.NewInt(1), ""},
   165  		{"uint232", big.NewInt(1), ""},
   166  		{"uint240", big.NewInt(1), ""},
   167  		{"uint248", big.NewInt(1), ""},
   168  		{"int24", big.NewInt(1), ""},
   169  		{"int40", big.NewInt(1), ""},
   170  		{"int48", big.NewInt(1), ""},
   171  		{"int56", big.NewInt(1), ""},
   172  		{"int72", big.NewInt(1), ""},
   173  		{"int80", big.NewInt(1), ""},
   174  		{"int88", big.NewInt(1), ""},
   175  		{"int96", big.NewInt(1), ""},
   176  		{"int104", big.NewInt(1), ""},
   177  		{"int112", big.NewInt(1), ""},
   178  		{"int120", big.NewInt(1), ""},
   179  		{"int128", big.NewInt(1), ""},
   180  		{"int136", big.NewInt(1), ""},
   181  		{"int144", big.NewInt(1), ""},
   182  		{"int152", big.NewInt(1), ""},
   183  		{"int160", big.NewInt(1), ""},
   184  		{"int168", big.NewInt(1), ""},
   185  		{"int176", big.NewInt(1), ""},
   186  		{"int184", big.NewInt(1), ""},
   187  		{"int192", big.NewInt(1), ""},
   188  		{"int200", big.NewInt(1), ""},
   189  		{"int208", big.NewInt(1), ""},
   190  		{"int216", big.NewInt(1), ""},
   191  		{"int224", big.NewInt(1), ""},
   192  		{"int232", big.NewInt(1), ""},
   193  		{"int240", big.NewInt(1), ""},
   194  		{"int248", big.NewInt(1), ""},
   195  		{"uint30", uint8(1), "abi: cannot use uint8 as type ptr as argument"},
   196  		{"uint8", uint16(1), "abi: cannot use uint16 as type uint8 as argument"},
   197  		{"uint8", uint32(1), "abi: cannot use uint32 as type uint8 as argument"},
   198  		{"uint8", uint64(1), "abi: cannot use uint64 as type uint8 as argument"},
   199  		{"uint8", int8(1), "abi: cannot use int8 as type uint8 as argument"},
   200  		{"uint8", int16(1), "abi: cannot use int16 as type uint8 as argument"},
   201  		{"uint8", int32(1), "abi: cannot use int32 as type uint8 as argument"},
   202  		{"uint8", int64(1), "abi: cannot use int64 as type uint8 as argument"},
   203  		{"uint16", uint16(1), ""},
   204  		{"uint16", uint8(1), "abi: cannot use uint8 as type uint16 as argument"},
   205  		{"uint16[]", []uint16{1, 2, 3}, ""},
   206  		{"uint16[]", [3]uint16{1, 2, 3}, ""},
   207  		{"uint16[]", []uint32{1, 2, 3}, "abi: cannot use []uint32 as type [0]uint16 as argument"},
   208  		{"uint16[3]", [3]uint32{1, 2, 3}, "abi: cannot use [3]uint32 as type [3]uint16 as argument"},
   209  		{"uint16[3]", [4]uint16{1, 2, 3}, "abi: cannot use [4]uint16 as type [3]uint16 as argument"},
   210  		{"uint16[3]", []uint16{1, 2, 3}, ""},
   211  		{"uint16[3]", []uint16{1, 2, 3, 4}, "abi: cannot use [4]uint16 as type [3]uint16 as argument"},
   212  		{"address[]", []common.Address{{1}}, ""},
   213  		{"address[1]", []common.Address{{1}}, ""},
   214  		{"address[1]", [1]common.Address{{1}}, ""},
   215  		{"address[2]", [1]common.Address{{1}}, "abi: cannot use [1]array as type [2]array as argument"},
   216  		{"bytes32", [32]byte{}, ""},
   217  		{"bytes31", [31]byte{}, ""},
   218  		{"bytes30", [30]byte{}, ""},
   219  		{"bytes29", [29]byte{}, ""},
   220  		{"bytes28", [28]byte{}, ""},
   221  		{"bytes27", [27]byte{}, ""},
   222  		{"bytes26", [26]byte{}, ""},
   223  		{"bytes25", [25]byte{}, ""},
   224  		{"bytes24", [24]byte{}, ""},
   225  		{"bytes23", [23]byte{}, ""},
   226  		{"bytes22", [22]byte{}, ""},
   227  		{"bytes21", [21]byte{}, ""},
   228  		{"bytes20", [20]byte{}, ""},
   229  		{"bytes19", [19]byte{}, ""},
   230  		{"bytes18", [18]byte{}, ""},
   231  		{"bytes17", [17]byte{}, ""},
   232  		{"bytes16", [16]byte{}, ""},
   233  		{"bytes15", [15]byte{}, ""},
   234  		{"bytes14", [14]byte{}, ""},
   235  		{"bytes13", [13]byte{}, ""},
   236  		{"bytes12", [12]byte{}, ""},
   237  		{"bytes11", [11]byte{}, ""},
   238  		{"bytes10", [10]byte{}, ""},
   239  		{"bytes9", [9]byte{}, ""},
   240  		{"bytes8", [8]byte{}, ""},
   241  		{"bytes7", [7]byte{}, ""},
   242  		{"bytes6", [6]byte{}, ""},
   243  		{"bytes5", [5]byte{}, ""},
   244  		{"bytes4", [4]byte{}, ""},
   245  		{"bytes3", [3]byte{}, ""},
   246  		{"bytes2", [2]byte{}, ""},
   247  		{"bytes1", [1]byte{}, ""},
   248  		{"bytes32", [33]byte{}, "abi: cannot use [33]uint8 as type [32]uint8 as argument"},
   249  		{"bytes32", common.Hash{1}, ""},
   250  		{"bytes31", common.Hash{1}, "abi: cannot use common.Hash as type [31]uint8 as argument"},
   251  		{"bytes31", [32]byte{}, "abi: cannot use [32]uint8 as type [31]uint8 as argument"},
   252  		{"bytes", []byte{0, 1}, ""},
   253  		{"bytes", [2]byte{0, 1}, "abi: cannot use array as type slice as argument"},
   254  		{"bytes", common.Hash{1}, "abi: cannot use array as type slice as argument"},
   255  		{"string", "hello world", ""},
   256  		{"string", string(""), ""},
   257  		{"string", []byte{}, "abi: cannot use slice as type string as argument"},
   258  		{"bytes32[]", [][32]byte{{}}, ""},
   259  		{"function", [24]byte{}, ""},
   260  		{"bytes20", common.Address{}, ""},
   261  		{"address", [20]byte{}, ""},
   262  		{"address", common.Address{}, ""},
   263  		{"bytes32[]]", "", "invalid arg type in abi"},
   264  		{"invalidType", "", "unsupported arg type: invalidType"},
   265  		{"invalidSlice[]", "", "unsupported arg type: invalidSlice"},
   266  	} {
   267  		typ, err := NewType(test.typ)
   268  		if err != nil && len(test.err) == 0 {
   269  			t.Fatal("unexpected parse error:", err)
   270  		} else if err != nil && len(test.err) != 0 {
   271  			if err.Error() != test.err {
   272  				t.Errorf("%d failed. Expected err: '%v' got err: '%v'", i, test.err, err)
   273  			}
   274  			continue
   275  		}
   276  
   277  		err = typeCheck(typ, reflect.ValueOf(test.input))
   278  		if err != nil && len(test.err) == 0 {
   279  			t.Errorf("%d failed. Expected no err but got: %v", i, err)
   280  			continue
   281  		}
   282  		if err == nil && len(test.err) != 0 {
   283  			t.Errorf("%d failed. Expected err: %v but got none", i, test.err)
   284  			continue
   285  		}
   286  
   287  		if err != nil && len(test.err) != 0 && err.Error() != test.err {
   288  			t.Errorf("%d failed. Expected err: '%v' got err: '%v'", i, test.err, err)
   289  		}
   290  	}
   291  }