diff --git a/abi/encode.go b/abi/encode.go index 30f86f09..41afb960 100644 --- a/abi/encode.go +++ b/abi/encode.go @@ -294,12 +294,10 @@ func mapFromStruct(v reflect.Value) (reflect.Value, error) { continue } - name := f.Name + name := strings.ToLower(f.Name) if tagValue != "" { name = tagValue } - - name = strings.ToLower(name) if _, ok := res[name]; !ok { res[name] = v.Field(i).Interface() } diff --git a/abi/encoding_test.go b/abi/encoding_test.go index b655209c..90e28462 100644 --- a/abi/encoding_test.go +++ b/abi/encoding_test.go @@ -706,3 +706,29 @@ func TestEncodingStruct(t *testing.T) { t.Fatal("bad") } } + +func TestEncodingStruct_camcelCase(t *testing.T) { + typ := MustNewType("tuple(address aA, uint256 b)") + + type Obj struct { + A ethgo.Address `abi:"aA"` + B *big.Int + } + obj := Obj{ + A: ethgo.Address{0x1}, + B: big.NewInt(1), + } + + encoded, err := typ.Encode(&obj) + if err != nil { + t.Fatal(err) + } + + var obj2 Obj + if err := typ.DecodeStruct(encoded, &obj2); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(obj, obj2) { + t.Fatal("bad") + } +}