mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
accounts/abi: tests for array/slices of structs
Signed-off-by: VoR0220 <catalanor0220@gmail.com>
This commit is contained in:
parent
29c1074140
commit
beda0c0e89
1 changed files with 80 additions and 9 deletions
|
|
@ -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"}}}}},
|
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(
|
Type{
|
||||||
struct {
|
Kind: reflect.Struct,
|
||||||
A *big.Int `json:"a"`
|
T: StructTy,
|
||||||
B []*big.Int `json:"b"`
|
stringKind: "(uint256,uint256[],(uint256,uint256)[])",
|
||||||
C []struct {
|
Type: reflect.TypeOf(
|
||||||
X *big.Int `json:"x"`
|
struct {
|
||||||
Y *big.Int `json:"y"`
|
A *big.Int `json:"a"`
|
||||||
} `json:"c"`
|
B []*big.Int `json:"b"`
|
||||||
}{}), stringKind: "(uint256,uint256[],(uint256,uint256)[])"},
|
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...)
|
newStruct, err := ParseStructType(test.input.Name, test.input.Components...)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue