mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-11 14:33:52 +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) {
|
if input.Name == "" || isKeyWord(input.Name) {
|
||||||
normalizedArguments[i].Name = fmt.Sprintf("arg%d", i)
|
normalizedArguments[i].Name = fmt.Sprintf("arg%d", i)
|
||||||
}
|
}
|
||||||
|
normalizedArguments[i].Name = capitalise(normalizedArguments[i].Name)
|
||||||
for index := 0; ; index++ {
|
for index := 0; ; index++ {
|
||||||
if !used[capitalise(normalizedArguments[i].Name)] {
|
if !used[normalizedArguments[i].Name] {
|
||||||
used[capitalise(normalizedArguments[i].Name)] = true
|
used[normalizedArguments[i].Name] = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
normalizedArguments[i].Name = fmt.Sprintf("%s%d", normalizedArguments[i].Name, index)
|
normalizedArguments[i].Name = fmt.Sprintf("%s%d", normalizedArguments[i].Name, index)
|
||||||
|
|
|
||||||
|
|
@ -360,8 +360,10 @@ func TestNormalizeArgs(t *testing.T) {
|
||||||
inp []string
|
inp []string
|
||||||
expected []string
|
expected []string
|
||||||
}
|
}
|
||||||
for _, tc := range []normalizeArgsTc{
|
for i, tc := range []normalizeArgsTc{
|
||||||
{[]string{"arg1", "Arg1"}, []string{"Arg1", "Arg1"}}} {
|
{[]string{"arg1", "Arg1"}, []string{"Arg1", "Arg10"}},
|
||||||
|
{[]string{"", ""}, []string{"Arg0", "Arg1"}},
|
||||||
|
{[]string{"var", "const"}, []string{"Arg0", "Arg1"}}} {
|
||||||
var inpArgs abi.Arguments
|
var inpArgs abi.Arguments
|
||||||
for _, inpArgName := range tc.inp {
|
for _, inpArgName := range tc.inp {
|
||||||
inpArgs = append(inpArgs, abi.Argument{
|
inpArgs = append(inpArgs, abi.Argument{
|
||||||
|
|
@ -369,11 +371,9 @@ func TestNormalizeArgs(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
res := normalizeArgs(inpArgs)
|
res := normalizeArgs(inpArgs)
|
||||||
for i, resArg := range res {
|
for j, resArg := range res {
|
||||||
if resArg.Name != tc.expected[i] {
|
if resArg.Name != tc.expected[j] {
|
||||||
fmt.Println(resArg.Name)
|
t.Fatalf("mismatch for test index %d, arg index %d: expected %v. got %v", i, j, resArg.Name, tc.expected[j])
|
||||||
fmt.Println(tc.expected[i])
|
|
||||||
t.Fatalf("mismatch!!!")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue