Skip to content

Commit

Permalink
fix strings.ToLower wrong replacement in abi encoding, was lower casi…
Browse files Browse the repository at this point in the history
…ng tag names (#224)
  • Loading branch information
cyberhorsey committed Oct 31, 2022
1 parent 18cb320 commit f671bdb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 1 addition & 3 deletions abi/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
26 changes: 26 additions & 0 deletions abi/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit f671bdb

Please sign in to comment.