accounts/abi: fix type tests

Signed-off-by: VoR0220 <catalanor0220@gmail.com>
This commit is contained in:
VoR0220 2017-11-16 15:43:32 -05:00
parent b7583393da
commit 29c1074140

View file

@ -107,19 +107,6 @@ func TestTypeRegexp(t *testing.T) {
} }
} }
// Sample structs for struct parsing test
type (
S struct {
A *big.Int
B []*big.Int
C []struct {
X *big.Int
Y *big.Int
}
}
)
func TestStructParse(t *testing.T) { func TestStructParse(t *testing.T) {
for i, test := range []struct { for i, test := range []struct {
@ -128,7 +115,15 @@ 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(S{}), stringKind: "(uint256,uint256[],(uint256,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)[])"},
}, },
} { } {
newStruct, err := ParseStructType(test.input.Name, test.input.Components...) newStruct, err := ParseStructType(test.input.Name, test.input.Components...)
@ -136,7 +131,7 @@ func TestStructParse(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if !reflect.DeepEqual(newStruct, test.expectedOutput) { if !reflect.DeepEqual(newStruct, test.expectedOutput) {
t.Errorf("test %v: parsed type mismatch:\nGOT %v\nWANT %v ", i, newStruct, test.expectedOutput) t.Errorf("test %v: parsed type mismatch:\nGOT %v\nWANT %v ", i, spew.Sdump(typeWithoutStringer(newStruct)), spew.Sdump(typeWithoutStringer(test.expectedOutput)))
} }
} }
} }