mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-28 15:46:43 +00:00
fix events/error args normalization capitalization. add unit test that fails before the fix, and also also a few more test cases for args normalization.
This commit is contained in:
parent
6a007cac18
commit
ec0b3e52fe
2 changed files with 10 additions and 9 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -360,8 +360,10 @@ 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{
|
||||
|
|
@ -369,11 +371,9 @@ func TestNormalizeArgs(t *testing.T) {
|
|||
})
|
||||
}
|
||||
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])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue