github.com/lmittmann/w3@v0.20.0/internal/abi/arguments_test.go (about)

     1  package abi
     2  
     3  import (
     4  	"bytes"
     5  	"math/big"
     6  	"reflect"
     7  	"strconv"
     8  	"testing"
     9  
    10  	"github.com/ethereum/go-ethereum/accounts/abi"
    11  	"github.com/ethereum/go-ethereum/common"
    12  	"github.com/google/go-cmp/cmp"
    13  )
    14  
    15  func TestSignature(t *testing.T) {
    16  	tests := []struct {
    17  		Args          Arguments
    18  		WantSignature string
    19  	}{
    20  		{
    21  			Args:          Arguments{},
    22  			WantSignature: "",
    23  		},
    24  		{
    25  			Args:          Arguments{{Type: typeUint256}},
    26  			WantSignature: "uint256",
    27  		},
    28  		{
    29  			Args:          Arguments{{Type: abi.Type{Elem: &typeUint256, T: abi.SliceTy}}},
    30  			WantSignature: "uint256[]",
    31  		},
    32  		{
    33  			Args:          Arguments{{Type: abi.Type{Elem: &typeUint256, T: abi.ArrayTy, Size: 3}}},
    34  			WantSignature: "uint256[3]",
    35  		},
    36  		{
    37  			Args: Arguments{{
    38  				Type: abi.Type{
    39  					T:             abi.TupleTy,
    40  					TupleElems:    []*abi.Type{&typeUint256},
    41  					TupleRawNames: []string{"arg0"},
    42  				},
    43  			}},
    44  			WantSignature: "(uint256)",
    45  		},
    46  	}
    47  
    48  	for i, test := range tests {
    49  		t.Run(strconv.Itoa(i), func(t *testing.T) {
    50  			gotSignature := test.Args.Signature()
    51  			if test.WantSignature != gotSignature {
    52  				t.Fatalf("want %q, got %q", test.WantSignature, gotSignature)
    53  			}
    54  		})
    55  	}
    56  }
    57  
    58  func TestSignatureWithName(t *testing.T) {
    59  	tests := []struct {
    60  		Arguments     Arguments
    61  		Name          string
    62  		WantSignature string
    63  	}{
    64  		{
    65  			Arguments:     Arguments{},
    66  			Name:          "func",
    67  			WantSignature: "func()",
    68  		},
    69  		{
    70  			Arguments:     Arguments{{Type: typeUint256}},
    71  			Name:          "func",
    72  			WantSignature: "func(uint256)",
    73  		},
    74  	}
    75  
    76  	for i, test := range tests {
    77  		t.Run(strconv.Itoa(i), func(t *testing.T) {
    78  			gotSignature := test.Arguments.SignatureWithName(test.Name)
    79  			if test.WantSignature != gotSignature {
    80  				t.Fatalf("want %q, got %q", test.WantSignature, gotSignature)
    81  			}
    82  		})
    83  	}
    84  }
    85  
    86  func TestEncode(t *testing.T) {
    87  	tests := []struct {
    88  		Arguments Arguments
    89  		Args      []any
    90  		WantData  []byte
    91  	}{
    92  		{
    93  			Arguments: Arguments{{Type: typeUint256}},
    94  			Args:      []any{big.NewInt(1)},
    95  			WantData:  common.FromHex("0x0000000000000000000000000000000000000000000000000000000000000001"),
    96  		},
    97  	}
    98  
    99  	for i, test := range tests {
   100  		t.Run(strconv.Itoa(i), func(t *testing.T) {
   101  			gotData, err := test.Arguments.Encode(test.Args...)
   102  			if err != nil {
   103  				t.Fatalf("Failed to encode args: %v", err)
   104  			}
   105  			if !bytes.Equal(test.WantData, gotData) {
   106  				t.Fatalf("\nwant 0x%x\ngot  0x%x", test.WantData, gotData)
   107  			}
   108  		})
   109  	}
   110  }
   111  
   112  func TestEncodeWithSelector(t *testing.T) {
   113  	tests := []struct {
   114  		Arguments Arguments
   115  		Selector  [4]byte
   116  		Args      []any
   117  		WantData  []byte
   118  	}{
   119  		{
   120  			Arguments: Arguments{{Type: typeUint256}},
   121  			Selector:  [4]byte{0x12, 0x34, 0x56, 0x78},
   122  			Args:      []any{big.NewInt(1)},
   123  			WantData:  common.FromHex("0x123456780000000000000000000000000000000000000000000000000000000000000001"),
   124  		},
   125  	}
   126  
   127  	for i, test := range tests {
   128  		t.Run(strconv.Itoa(i), func(t *testing.T) {
   129  			gotData, err := test.Arguments.EncodeWithSelector(test.Selector, test.Args...)
   130  			if err != nil {
   131  				t.Fatalf("Failed to encode args: %v", err)
   132  			}
   133  
   134  			if !bytes.Equal(test.WantData, gotData) {
   135  				t.Fatalf("\nwant 0x%x\ngot  0x%x", test.WantData, gotData)
   136  			}
   137  		})
   138  	}
   139  }
   140  
   141  func TestEncodeWithSignature(t *testing.T) {
   142  	tests := []struct {
   143  		Arguments Arguments
   144  		Args      []any
   145  		Signature string
   146  		WantData  []byte
   147  	}{
   148  		{
   149  			Arguments: Arguments{{Type: typeUint256}},
   150  			Args:      []any{big.NewInt(1)},
   151  			Signature: "func(uint256)",
   152  			WantData:  common.FromHex("0x7f98a45e0000000000000000000000000000000000000000000000000000000000000001"),
   153  		},
   154  	}
   155  
   156  	for i, test := range tests {
   157  		t.Run(strconv.Itoa(i), func(t *testing.T) {
   158  			gotData, err := test.Arguments.EncodeWithSignature(test.Signature, test.Args...)
   159  			if err != nil {
   160  				t.Fatalf("Failed to encode args: %v", err)
   161  			}
   162  			if !bytes.Equal(test.WantData, gotData) {
   163  				t.Fatalf("\nwant 0x%x\ngot  0x%x", test.WantData, gotData)
   164  			}
   165  		})
   166  	}
   167  }
   168  
   169  func TestDecode(t *testing.T) {
   170  	type tuple struct {
   171  		A bool
   172  		B *big.Int
   173  	}
   174  
   175  	var (
   176  		dataUintBool = common.FromHex("0x0000000000000000000000000000000000000000000000000000000000000001")
   177  		argsUint     = Arguments{{Type: typeUint256}}
   178  		argsBool     = Arguments{{Type: typeBool}}
   179  
   180  		dataTuple = common.FromHex("0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000007")
   181  		argsTuple = Arguments{{Type: abi.Type{
   182  			T:             abi.TupleTy,
   183  			TupleElems:    []*abi.Type{&typeBool, &typeUint256},
   184  			TupleRawNames: []string{"A", "_a"},
   185  			TupleType: reflect.TypeFor[struct {
   186  				A bool     `abi:"a"`
   187  				B *big.Int `abi:"b"`
   188  			}](),
   189  		}}}
   190  
   191  		dataBytes2 = common.FromHex("0xc0fe000000000000000000000000000000000000000000000000000000000000")
   192  		argsBytes2 = Arguments{{Type: abi.Type{T: abi.FixedBytesTy, Size: 2}}}
   193  
   194  		dataSlice = common.FromHex("0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000007")
   195  		argsSlice = Arguments{{Type: abi.Type{T: abi.SliceTy, Size: 1, Elem: &typeUint256}}}
   196  	)
   197  
   198  	t.Run("set-ptr", func(t *testing.T) {
   199  		var arg big.Int
   200  		err := argsUint.Decode(dataUintBool, &arg)
   201  		if err != nil {
   202  			t.Fatalf("Failed to decode args: %v", err)
   203  		}
   204  		if want := big.NewInt(1); arg.Cmp(want) != 0 {
   205  			t.Fatalf("want %v, got %v", want, arg)
   206  		}
   207  	})
   208  
   209  	t.Run("set-ptr-of-ptr", func(t *testing.T) {
   210  		var arg *big.Int
   211  		err := argsUint.Decode(dataUintBool, &arg)
   212  		if err != nil {
   213  			t.Fatalf("Failed to decode args: %v", err)
   214  		}
   215  		if want := big.NewInt(1); arg.Cmp(want) != 0 {
   216  			t.Fatalf("want %v, got %v", want, arg)
   217  		}
   218  	})
   219  
   220  	t.Run("nil-val", func(t *testing.T) {
   221  		var arg *big.Int
   222  		err := argsUint.Decode(dataUintBool, arg)
   223  		if want := "abi: decode nil *big.Int"; err == nil || want != err.Error() {
   224  			t.Fatalf("want %v, got %v", want, err)
   225  		}
   226  	})
   227  
   228  	t.Run("nil", func(t *testing.T) {
   229  		if err := argsUint.Decode(dataUintBool, nil); err != nil {
   230  			t.Fatalf("want nil, got %v", err)
   231  		}
   232  	})
   233  
   234  	t.Run("non-ptr", func(t *testing.T) {
   235  		var arg bool
   236  		err := argsBool.Decode(dataUintBool, arg)
   237  		if want := "abi: decode non-pointer bool"; err == nil || want != err.Error() {
   238  			t.Fatalf("want %v, got %v", want, err)
   239  		}
   240  	})
   241  
   242  	t.Run("set-bool-ptr", func(t *testing.T) {
   243  		var arg bool
   244  		err := argsBool.Decode(dataUintBool, &arg)
   245  		if err != nil {
   246  			t.Fatalf("Failed to decode args: %v", err)
   247  		}
   248  		if want := true; arg != want {
   249  			t.Fatalf("want %v, got %v", want, arg)
   250  		}
   251  	})
   252  
   253  	t.Run("set-bool-ptr-of-ptr", func(t *testing.T) {
   254  		var arg *bool
   255  		err := argsBool.Decode(dataUintBool, &arg)
   256  		if err != nil {
   257  			t.Fatalf("Failed to decode args: %v", err)
   258  		}
   259  		if want := true; *arg != want {
   260  			t.Fatalf("want %v, got %v", want, arg)
   261  		}
   262  	})
   263  
   264  	t.Run("set-bytes2", func(t *testing.T) {
   265  		var arg [2]byte
   266  		err := argsBytes2.Decode(dataBytes2, &arg)
   267  		if err != nil {
   268  			t.Fatalf("Failed to decode args: %v", err)
   269  		}
   270  		want := [2]byte{0xc0, 0xfe}
   271  		if diff := cmp.Diff(want, arg); diff != "" {
   272  			t.Fatalf("(-want, +got)\n%s", diff)
   273  		}
   274  	})
   275  
   276  	t.Run("set-tuple-ptr", func(t *testing.T) {
   277  		var arg tuple
   278  		err := argsTuple.Decode(dataTuple, &arg)
   279  		if err != nil {
   280  			t.Fatalf("Failed to decode args: %v", err)
   281  		}
   282  		want := tuple{A: true, B: big.NewInt(7)}
   283  		if diff := cmp.Diff(want, arg, cmp.AllowUnexported(big.Int{})); diff != "" {
   284  			t.Fatalf("(-want, +got)\n%s", diff)
   285  		}
   286  	})
   287  
   288  	t.Run("set-tuple-ptr-of-ptr", func(t *testing.T) {
   289  		var arg *tuple
   290  		err := argsTuple.Decode(dataTuple, &arg)
   291  		if err != nil {
   292  			t.Fatalf("Failed to decode args: %v", err)
   293  		}
   294  		want := &tuple{A: true, B: big.NewInt(7)}
   295  		if diff := cmp.Diff(want, arg, cmp.AllowUnexported(big.Int{})); diff != "" {
   296  			t.Fatalf("(-want, +got)\n%s", diff)
   297  		}
   298  	})
   299  
   300  	t.Run("set-slice", func(t *testing.T) {
   301  		var arg []*big.Int
   302  		err := argsSlice.Decode(dataSlice, &arg)
   303  		if err != nil {
   304  			t.Fatalf("Failed to decode args: %v", err)
   305  		}
   306  		want := []*big.Int{big.NewInt(7)}
   307  		if diff := cmp.Diff(want, arg, cmp.AllowUnexported(big.Int{})); diff != "" {
   308  			t.Fatalf("(-want, +got)\n%s", diff)
   309  		}
   310  	})
   311  }
   312  
   313  func TestTypeToString(t *testing.T) {
   314  	tests := []struct {
   315  		Type *abi.Type
   316  		Want string
   317  	}{
   318  		{Type: &abi.Type{T: abi.BoolTy}, Want: "bool"},
   319  		{Type: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{T: abi.BoolTy}}, Want: "bool[]"},
   320  		{Type: &abi.Type{Size: 2, T: abi.ArrayTy, Elem: &abi.Type{T: abi.BoolTy}}, Want: "bool[2]"},
   321  		{Type: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{T: abi.BoolTy}}}, Want: "bool[2][]"},
   322  		{Type: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{T: abi.BoolTy}}}, Want: "bool[][]"},
   323  		{Type: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{T: abi.BoolTy}}}, Want: "bool[][2]"},
   324  		{Type: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{T: abi.BoolTy}}}, Want: "bool[2][2]"},
   325  		{Type: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{T: abi.BoolTy}}}}, Want: "bool[2][][2]"},
   326  		{Type: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{T: abi.BoolTy}}}}, Want: "bool[2][2][2]"},
   327  		{Type: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{T: abi.BoolTy}}}}, Want: "bool[][][]"},
   328  		{Type: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{T: abi.BoolTy}}}}, Want: "bool[][2][]"},
   329  		{Type: &abi.Type{Size: 8, T: abi.IntTy}, Want: "int8"},
   330  		{Type: &abi.Type{Size: 16, T: abi.IntTy}, Want: "int16"},
   331  		{Type: &abi.Type{Size: 32, T: abi.IntTy}, Want: "int32"},
   332  		{Type: &abi.Type{Size: 64, T: abi.IntTy}, Want: "int64"},
   333  		{Type: &abi.Type{Size: 256, T: abi.IntTy}, Want: "int256"},
   334  		{Type: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{Size: 8, T: abi.IntTy}}, Want: "int8[]"},
   335  		{Type: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{Size: 8, T: abi.IntTy}}, Want: "int8[2]"},
   336  		{Type: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{Size: 16, T: abi.IntTy}}, Want: "int16[]"},
   337  		{Type: &abi.Type{Size: 2, T: abi.ArrayTy, Elem: &abi.Type{Size: 16, T: abi.IntTy}}, Want: "int16[2]"},
   338  		{Type: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{Size: 32, T: abi.IntTy}}, Want: "int32[]"},
   339  		{Type: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{Size: 32, T: abi.IntTy}}, Want: "int32[2]"},
   340  		{Type: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{Size: 64, T: abi.IntTy}}, Want: "int64[]"},
   341  		{Type: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{Size: 64, T: abi.IntTy}}, Want: "int64[2]"},
   342  		{Type: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{Size: 256, T: abi.IntTy}}, Want: "int256[]"},
   343  		{Type: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{Size: 256, T: abi.IntTy}}, Want: "int256[2]"},
   344  		{Type: &abi.Type{Size: 8, T: abi.UintTy}, Want: "uint8"},
   345  		{Type: &abi.Type{Size: 16, T: abi.UintTy}, Want: "uint16"},
   346  		{Type: &abi.Type{Size: 32, T: abi.UintTy}, Want: "uint32"},
   347  		{Type: &abi.Type{Size: 64, T: abi.UintTy}, Want: "uint64"},
   348  		{Type: &abi.Type{Size: 256, T: abi.UintTy}, Want: "uint256"},
   349  		{Type: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{Size: 8, T: abi.UintTy}}, Want: "uint8[]"},
   350  		{Type: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{Size: 8, T: abi.UintTy}}, Want: "uint8[2]"},
   351  		{Type: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{Size: 16, T: abi.UintTy}}, Want: "uint16[]"},
   352  		{Type: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{Size: 16, T: abi.UintTy}}, Want: "uint16[2]"},
   353  		{Type: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{Size: 32, T: abi.UintTy}}, Want: "uint32[]"},
   354  		{Type: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{Size: 32, T: abi.UintTy}}, Want: "uint32[2]"},
   355  		{Type: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{Size: 64, T: abi.UintTy}}, Want: "uint64[]"},
   356  		{Type: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{Size: 64, T: abi.UintTy}}, Want: "uint64[2]"},
   357  		{Type: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{Size: 256, T: abi.UintTy}}, Want: "uint256[]"},
   358  		{Type: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{Size: 256, T: abi.UintTy}}, Want: "uint256[2]"},
   359  		{Type: &abi.Type{T: abi.FixedBytesTy, Size: 32}, Want: "bytes32"},
   360  		{Type: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{T: abi.BytesTy}}, Want: "bytes[]"},
   361  		{Type: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{T: abi.BytesTy}}, Want: "bytes[2]"},
   362  		{Type: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{T: abi.FixedBytesTy, Size: 32}}, Want: "bytes32[]"},
   363  		{Type: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{T: abi.FixedBytesTy, Size: 32}}, Want: "bytes32[2]"},
   364  		{Type: &abi.Type{T: abi.HashTy, Size: 20}, Want: "hash"},
   365  		{Type: &abi.Type{T: abi.StringTy}, Want: "string"},
   366  		{Type: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{T: abi.StringTy}}, Want: "string[]"},
   367  		{Type: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{T: abi.StringTy}}, Want: "string[2]"},
   368  		{Type: &abi.Type{Size: 20, T: abi.AddressTy}, Want: "address"},
   369  		{Type: &abi.Type{T: abi.SliceTy, Elem: &abi.Type{Size: 20, T: abi.AddressTy}}, Want: "address[]"},
   370  		{Type: &abi.Type{T: abi.ArrayTy, Size: 2, Elem: &abi.Type{Size: 20, T: abi.AddressTy}}, Want: "address[2]"},
   371  		{Type: &abi.Type{T: abi.TupleTy, TupleElems: []*abi.Type{&typeUint256, &typeUint256}}, Want: "(uint256,uint256)"},
   372  		{Type: &abi.Type{T: abi.TupleTy, TupleElems: []*abi.Type{{T: abi.TupleTy, TupleElems: []*abi.Type{&typeUint256, &typeUint256}}, &typeUint256}}, Want: "((uint256,uint256),uint256)"},
   373  	}
   374  
   375  	for i, test := range tests {
   376  		t.Run(strconv.Itoa(i), func(t *testing.T) {
   377  			got := typeToString(test.Type)
   378  			if test.Want != got {
   379  				t.Fatalf("want %q, got %q", test.Want, got)
   380  			}
   381  		})
   382  	}
   383  }
   384  
   385  var (
   386  	big1 = big.NewInt(1)
   387  	hex1 = common.FromHex("0x0000000000000000000000000000000000000000000000000000000000000001")
   388  )
   389  
   390  func TestTypeMapping(t *testing.T) {
   391  	tests := []struct {
   392  		RAWType string
   393  		Data    []byte
   394  		Arg     any
   395  		Want    any
   396  	}{
   397  		{RAWType: "bool", Data: hex1, Arg: new(bool), Want: ptr(true)},
   398  
   399  		{RAWType: "int8", Data: hex1, Arg: new(int8), Want: ptr[int8](1)},
   400  		{RAWType: "int16", Data: hex1, Arg: new(int16), Want: ptr[int16](1)},
   401  		{RAWType: "int24", Data: hex1, Arg: new(big.Int), Want: big1},
   402  		{RAWType: "int32", Data: hex1, Arg: new(int32), Want: ptr[int32](1)},
   403  		{RAWType: "int40", Data: hex1, Arg: new(big.Int), Want: big1},
   404  		{RAWType: "int48", Data: hex1, Arg: new(big.Int), Want: big1},
   405  		{RAWType: "int56", Data: hex1, Arg: new(big.Int), Want: big1},
   406  		{RAWType: "int64", Data: hex1, Arg: new(int64), Want: ptr[int64](1)},
   407  		{RAWType: "int72", Data: hex1, Arg: new(big.Int), Want: big1},
   408  		{RAWType: "int80", Data: hex1, Arg: new(big.Int), Want: big1},
   409  		{RAWType: "int88", Data: hex1, Arg: new(big.Int), Want: big1},
   410  		{RAWType: "int96", Data: hex1, Arg: new(big.Int), Want: big1},
   411  		{RAWType: "int104", Data: hex1, Arg: new(big.Int), Want: big1},
   412  		{RAWType: "int112", Data: hex1, Arg: new(big.Int), Want: big1},
   413  		{RAWType: "int120", Data: hex1, Arg: new(big.Int), Want: big1},
   414  		{RAWType: "int128", Data: hex1, Arg: new(big.Int), Want: big1},
   415  		{RAWType: "int136", Data: hex1, Arg: new(big.Int), Want: big1},
   416  		{RAWType: "int144", Data: hex1, Arg: new(big.Int), Want: big1},
   417  		{RAWType: "int152", Data: hex1, Arg: new(big.Int), Want: big1},
   418  		{RAWType: "int160", Data: hex1, Arg: new(big.Int), Want: big1},
   419  		{RAWType: "int168", Data: hex1, Arg: new(big.Int), Want: big1},
   420  		{RAWType: "int176", Data: hex1, Arg: new(big.Int), Want: big1},
   421  		{RAWType: "int184", Data: hex1, Arg: new(big.Int), Want: big1},
   422  		{RAWType: "int192", Data: hex1, Arg: new(big.Int), Want: big1},
   423  		{RAWType: "int200", Data: hex1, Arg: new(big.Int), Want: big1},
   424  		{RAWType: "int208", Data: hex1, Arg: new(big.Int), Want: big1},
   425  		{RAWType: "int216", Data: hex1, Arg: new(big.Int), Want: big1},
   426  		{RAWType: "int224", Data: hex1, Arg: new(big.Int), Want: big1},
   427  		{RAWType: "int232", Data: hex1, Arg: new(big.Int), Want: big1},
   428  		{RAWType: "int240", Data: hex1, Arg: new(big.Int), Want: big1},
   429  		{RAWType: "int248", Data: hex1, Arg: new(big.Int), Want: big1},
   430  		{RAWType: "int256", Data: hex1, Arg: new(big.Int), Want: big1},
   431  		{RAWType: "int", Data: hex1, Arg: new(big.Int), Want: big1},
   432  
   433  		{RAWType: "uint8", Data: hex1, Arg: new(uint8), Want: ptr[uint8](1)},
   434  		{RAWType: "uint16", Data: hex1, Arg: new(uint16), Want: ptr[uint16](1)},
   435  		{RAWType: "uint24", Data: hex1, Arg: new(big.Int), Want: big1},
   436  		{RAWType: "uint32", Data: hex1, Arg: new(uint32), Want: ptr[uint32](1)},
   437  		{RAWType: "uint40", Data: hex1, Arg: new(big.Int), Want: big1},
   438  		{RAWType: "uint48", Data: hex1, Arg: new(big.Int), Want: big1},
   439  		{RAWType: "uint56", Data: hex1, Arg: new(big.Int), Want: big1},
   440  		{RAWType: "uint64", Data: hex1, Arg: new(uint64), Want: ptr[uint64](1)},
   441  		{RAWType: "uint72", Data: hex1, Arg: new(big.Int), Want: big1},
   442  		{RAWType: "uint80", Data: hex1, Arg: new(big.Int), Want: big1},
   443  		{RAWType: "uint88", Data: hex1, Arg: new(big.Int), Want: big1},
   444  		{RAWType: "uint96", Data: hex1, Arg: new(big.Int), Want: big1},
   445  		{RAWType: "uint104", Data: hex1, Arg: new(big.Int), Want: big1},
   446  		{RAWType: "uint112", Data: hex1, Arg: new(big.Int), Want: big1},
   447  		{RAWType: "uint120", Data: hex1, Arg: new(big.Int), Want: big1},
   448  		{RAWType: "uint128", Data: hex1, Arg: new(big.Int), Want: big1},
   449  		{RAWType: "uint136", Data: hex1, Arg: new(big.Int), Want: big1},
   450  		{RAWType: "uint144", Data: hex1, Arg: new(big.Int), Want: big1},
   451  		{RAWType: "uint152", Data: hex1, Arg: new(big.Int), Want: big1},
   452  		{RAWType: "uint160", Data: hex1, Arg: new(big.Int), Want: big1},
   453  		{RAWType: "uint168", Data: hex1, Arg: new(big.Int), Want: big1},
   454  		{RAWType: "uint176", Data: hex1, Arg: new(big.Int), Want: big1},
   455  		{RAWType: "uint184", Data: hex1, Arg: new(big.Int), Want: big1},
   456  		{RAWType: "uint192", Data: hex1, Arg: new(big.Int), Want: big1},
   457  		{RAWType: "uint200", Data: hex1, Arg: new(big.Int), Want: big1},
   458  		{RAWType: "uint208", Data: hex1, Arg: new(big.Int), Want: big1},
   459  		{RAWType: "uint216", Data: hex1, Arg: new(big.Int), Want: big1},
   460  		{RAWType: "uint224", Data: hex1, Arg: new(big.Int), Want: big1},
   461  		{RAWType: "uint232", Data: hex1, Arg: new(big.Int), Want: big1},
   462  		{RAWType: "uint240", Data: hex1, Arg: new(big.Int), Want: big1},
   463  		{RAWType: "uint248", Data: hex1, Arg: new(big.Int), Want: big1},
   464  		{RAWType: "uint256", Data: hex1, Arg: new(big.Int), Want: big1},
   465  		{RAWType: "uint", Data: hex1, Arg: new(big.Int), Want: big1},
   466  
   467  		{RAWType: "bytes1", Data: hex1, Arg: new([1]byte), Want: &[1]byte{}},
   468  		{RAWType: "bytes2", Data: hex1, Arg: new([2]byte), Want: &[2]byte{}},
   469  		{RAWType: "bytes3", Data: hex1, Arg: new([3]byte), Want: &[3]byte{}},
   470  		{RAWType: "bytes4", Data: hex1, Arg: new([4]byte), Want: &[4]byte{}},
   471  		{RAWType: "bytes5", Data: hex1, Arg: new([5]byte), Want: &[5]byte{}},
   472  		{RAWType: "bytes6", Data: hex1, Arg: new([6]byte), Want: &[6]byte{}},
   473  		{RAWType: "bytes7", Data: hex1, Arg: new([7]byte), Want: &[7]byte{}},
   474  		{RAWType: "bytes8", Data: hex1, Arg: new([8]byte), Want: &[8]byte{}},
   475  		{RAWType: "bytes9", Data: hex1, Arg: new([9]byte), Want: &[9]byte{}},
   476  		{RAWType: "bytes10", Data: hex1, Arg: new([10]byte), Want: &[10]byte{}},
   477  		{RAWType: "bytes11", Data: hex1, Arg: new([11]byte), Want: &[11]byte{}},
   478  		{RAWType: "bytes12", Data: hex1, Arg: new([12]byte), Want: &[12]byte{}},
   479  		{RAWType: "bytes13", Data: hex1, Arg: new([13]byte), Want: &[13]byte{}},
   480  		{RAWType: "bytes14", Data: hex1, Arg: new([14]byte), Want: &[14]byte{}},
   481  		{RAWType: "bytes15", Data: hex1, Arg: new([15]byte), Want: &[15]byte{}},
   482  		{RAWType: "bytes16", Data: hex1, Arg: new([16]byte), Want: &[16]byte{}},
   483  		{RAWType: "bytes17", Data: hex1, Arg: new([17]byte), Want: &[17]byte{}},
   484  		{RAWType: "bytes18", Data: hex1, Arg: new([18]byte), Want: &[18]byte{}},
   485  		{RAWType: "bytes19", Data: hex1, Arg: new([19]byte), Want: &[19]byte{}},
   486  		{RAWType: "bytes20", Data: hex1, Arg: new([20]byte), Want: &[20]byte{}},
   487  		{RAWType: "address", Data: hex1, Arg: new(common.Address), Want: &common.Address{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}},
   488  		{RAWType: "bytes21", Data: hex1, Arg: new([21]byte), Want: &[21]byte{}},
   489  		{RAWType: "bytes22", Data: hex1, Arg: new([22]byte), Want: &[22]byte{}},
   490  		{RAWType: "bytes23", Data: hex1, Arg: new([23]byte), Want: &[23]byte{}},
   491  		{RAWType: "bytes24", Data: hex1, Arg: new([24]byte), Want: &[24]byte{}},
   492  		{RAWType: "bytes25", Data: hex1, Arg: new([25]byte), Want: &[25]byte{}},
   493  		{RAWType: "bytes26", Data: hex1, Arg: new([26]byte), Want: &[26]byte{}},
   494  		{RAWType: "bytes27", Data: hex1, Arg: new([27]byte), Want: &[27]byte{}},
   495  		{RAWType: "bytes28", Data: hex1, Arg: new([28]byte), Want: &[28]byte{}},
   496  		{RAWType: "bytes29", Data: hex1, Arg: new([29]byte), Want: &[29]byte{}},
   497  		{RAWType: "bytes30", Data: hex1, Arg: new([30]byte), Want: &[30]byte{}},
   498  		{RAWType: "bytes31", Data: hex1, Arg: new([31]byte), Want: &[31]byte{}},
   499  		{RAWType: "bytes32", Data: hex1, Arg: new([32]byte), Want: &[32]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}},
   500  		{RAWType: "bytes32", Data: hex1, Arg: new(common.Hash), Want: &common.Hash{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}},
   501  	}
   502  
   503  	for i, test := range tests {
   504  		t.Run(strconv.Itoa(i), func(t *testing.T) {
   505  			args, err := Parse(test.RAWType)
   506  			if err != nil {
   507  				t.Fatalf("Failed to parse type: %v", err)
   508  			}
   509  
   510  			if err := args.Decode(test.Data, test.Arg); err != nil {
   511  				t.Fatalf("Failed to decode args: %v", err)
   512  			}
   513  
   514  			if diff := cmp.Diff(test.Want, test.Arg, cmp.AllowUnexported(big.Int{})); diff != "" {
   515  				t.Fatalf("(-want, +got)\n%s", diff)
   516  			}
   517  		})
   518  	}
   519  }