From beda0c0e89a365f3f3f5f2a06f2e5dfefa2c6431 Mon Sep 17 00:00:00 2001 From: VoR0220 Date: Thu, 16 Nov 2017 15:21:35 -0600 Subject: [PATCH] accounts/abi: tests for array/slices of structs Signed-off-by: VoR0220 --- accounts/abi/type_test.go | 89 +++++++++++++++++++++++++++++++++++---- 1 file changed, 80 insertions(+), 9 deletions(-) diff --git a/accounts/abi/type_test.go b/accounts/abi/type_test.go index 4e95ec97e5..8ca2513aab 100644 --- a/accounts/abi/type_test.go +++ b/accounts/abi/type_test.go @@ -115,15 +115,86 @@ func TestStructParse(t *testing.T) { }{ { unmarshalArg{Name: "s", Type: "tuple", Components: []unmarshalArg{unmarshalArg{Name: "a", Type: "uint256"}, unmarshalArg{Name: "b", Type: "uint256[]"}, unmarshalArg{Name: "c", Type: "tuple[]", Components: []unmarshalArg{unmarshalArg{Name: "x", Type: "uint256"}, unmarshalArg{Name: "y", Type: "uint256"}}}}}, - Type{Kind: reflect.Struct, T: StructTy, Type: reflect.TypeOf( - struct { - A *big.Int `json:"a"` - B []*big.Int `json:"b"` - C []struct { - X *big.Int `json:"x"` - Y *big.Int `json:"y"` - } `json:"c"` - }{}), stringKind: "(uint256,uint256[],(uint256,uint256)[])"}, + Type{ + Kind: reflect.Struct, + T: StructTy, + stringKind: "(uint256,uint256[],(uint256,uint256)[])", + Type: reflect.TypeOf( + struct { + A *big.Int `json:"a"` + B []*big.Int `json:"b"` + C []struct { + X *big.Int `json:"x"` + Y *big.Int `json:"y"` + } `json:"c"` + }{}, + ), + }, + }, + { + unmarshalArg{Name: "s", Type: "tuple[]", Components: []unmarshalArg{unmarshalArg{Name: "a", Type: "string"}, unmarshalArg{Name: "b", Type: "bytes32"}, unmarshalArg{Name: "c", Type: "tuple[]", Components: []unmarshalArg{unmarshalArg{Name: "x", Type: "string"}, unmarshalArg{Name: "y", Type: "string"}}}}}, + Type{ + Kind: reflect.Slice, + T: SliceTy, + stringKind: "(string,bytes32,(string,string)[])[]", + Type: reflect.TypeOf( + []struct { + A string `json:"a"` + B [32]byte `json:"b"` + C []struct { + X string `json:"x"` + Y string `json:"y"` + } `json:"c"` + }{}, + ), + Elem: &Type{ + Kind: reflect.Struct, + T: StructTy, + stringKind: "(string,bytes32,(string,string)[])", + Type: reflect.TypeOf( + struct { + A string `json:"a"` + B [32]byte `json:"b"` + C []struct { + X string `json:"x"` + Y string `json:"y"` + } `json:"c"` + }{}), + }, + }, + }, + { + unmarshalArg{Name: "s", Type: "tuple[3]", Components: []unmarshalArg{unmarshalArg{Name: "a", Type: "string"}, unmarshalArg{Name: "b", Type: "bytes32"}, unmarshalArg{Name: "c", Type: "tuple[]", Components: []unmarshalArg{unmarshalArg{Name: "x", Type: "string"}, unmarshalArg{Name: "y", Type: "string"}}}}}, + Type{ + Kind: reflect.Array, + T: ArrayTy, + Size: 3, + stringKind: "(string,bytes32,(string,string)[])[3]", + Type: reflect.TypeOf( + [3]struct { + A string `json:"a"` + B [32]byte `json:"b"` + C []struct { + X string `json:"x"` + Y string `json:"y"` + } `json:"c"` + }{}, + ), + Elem: &Type{ + Kind: reflect.Struct, + T: StructTy, + stringKind: "(string,bytes32,(string,string)[])", + Type: reflect.TypeOf( + struct { + A string `json:"a"` + B [32]byte `json:"b"` + C []struct { + X string `json:"x"` + Y string `json:"y"` + } `json:"c"` + }{}), + }, + }, }, } { newStruct, err := ParseStructType(test.input.Name, test.input.Components...)