Skip to content

Commit

Permalink
fix events/error args normalization capitalization. add unit test tha…
Browse files Browse the repository at this point in the history
…t fails before the fix, and also also a few more test cases for args normalization.
  • Loading branch information
jwasinger committed Dec 23, 2024
1 parent b5862df commit 7a9259e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions accounts/abi/bind/bindv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ func normalizeArgs(inp abi.Arguments) abi.Arguments {
if input.Name == "" || isKeyWord(input.Name) {
normalizedArguments[i].Name = fmt.Sprintf("arg%d", i)
}
normalizedArguments[i].Name = capitalise(normalizedArguments[i].Name)
for index := 0; ; index++ {
if !used[capitalise(normalizedArguments[i].Name)] {
used[capitalise(normalizedArguments[i].Name)] = true
if !used[normalizedArguments[i].Name] {
used[normalizedArguments[i].Name] = true
break
}
normalizedArguments[i].Name = fmt.Sprintf("%s%d", normalizedArguments[i].Name, index)
Expand Down
14 changes: 7 additions & 7 deletions accounts/abi/bind/bindv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,20 +360,20 @@ func TestNormalizeArgs(t *testing.T) {
inp []string
expected []string
}
for _, tc := range []normalizeArgsTc{
{[]string{"arg1", "Arg1"}, []string{"Arg1", "Arg1"}}} {
for i, tc := range []normalizeArgsTc{
{[]string{"arg1", "Arg1"}, []string{"Arg1", "Arg10"}},
{[]string{"", ""}, []string{"Arg0", "Arg1"}},
{[]string{"var", "const"}, []string{"Arg0", "Arg1"}}} {
var inpArgs abi.Arguments
for _, inpArgName := range tc.inp {
inpArgs = append(inpArgs, abi.Argument{
Name: inpArgName,
})
}
res := normalizeArgs(inpArgs)
for i, resArg := range res {
if resArg.Name != tc.expected[i] {
fmt.Println(resArg.Name)
fmt.Println(tc.expected[i])
t.Fatalf("mismatch!!!")
for j, resArg := range res {
if resArg.Name != tc.expected[j] {
t.Fatalf("mismatch for test index %d, arg index %d: expected %v. got %v", i, j, resArg.Name, tc.expected[j])
}
}
}
Expand Down

0 comments on commit 7a9259e

Please sign in to comment.