Skip to content

Commit f671bdb

Browse files
authored
fix strings.ToLower wrong replacement in abi encoding, was lower casing tag names (#224)
1 parent 18cb320 commit f671bdb

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

abi/encode.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,10 @@ func mapFromStruct(v reflect.Value) (reflect.Value, error) {
294294
continue
295295
}
296296

297-
name := f.Name
297+
name := strings.ToLower(f.Name)
298298
if tagValue != "" {
299299
name = tagValue
300300
}
301-
302-
name = strings.ToLower(name)
303301
if _, ok := res[name]; !ok {
304302
res[name] = v.Field(i).Interface()
305303
}

abi/encoding_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,3 +706,29 @@ func TestEncodingStruct(t *testing.T) {
706706
t.Fatal("bad")
707707
}
708708
}
709+
710+
func TestEncodingStruct_camcelCase(t *testing.T) {
711+
typ := MustNewType("tuple(address aA, uint256 b)")
712+
713+
type Obj struct {
714+
A ethgo.Address `abi:"aA"`
715+
B *big.Int
716+
}
717+
obj := Obj{
718+
A: ethgo.Address{0x1},
719+
B: big.NewInt(1),
720+
}
721+
722+
encoded, err := typ.Encode(&obj)
723+
if err != nil {
724+
t.Fatal(err)
725+
}
726+
727+
var obj2 Obj
728+
if err := typ.DecodeStruct(encoded, &obj2); err != nil {
729+
t.Fatal(err)
730+
}
731+
if !reflect.DeepEqual(obj, obj2) {
732+
t.Fatal("bad")
733+
}
734+
}

0 commit comments

Comments
 (0)