Skip to content

Commit bda5e4c

Browse files
jwasingerfjl
authored andcommitted
fix test 'BindingV2ConvertedV1Tests'. add more comprehensive output checking to solc errors test.
1 parent 8d3fc41 commit bda5e4c

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

accounts/abi/bind/bindv2_test.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package bind
33
import (
44
_ "embed"
55
"fmt"
6-
"os"
7-
"strings"
86
"testing"
97

108
"github.com/ethereum/go-ethereum/accounts/abi"
@@ -331,8 +329,9 @@ var bindTests2 = []bindV2Test{
331329
},
332330
}
333331

332+
// TestBindingV2ConvertedV1Tests regenerates contracts from the v1 binding test cases (using v2 binding mode) and ensures
333+
// that no mutations occurred compared to the expected output included under internal/convertedv1bindtests.
334334
func TestBindingV2ConvertedV1Tests(t *testing.T) {
335-
os.Mkdir("convertedv1bindtests", 0777)
336335
for _, tc := range bindTests2 {
337336
t.Run(tc.name, func(t *testing.T) {
338337
if tc.types == nil {
@@ -344,21 +343,9 @@ func TestBindingV2ConvertedV1Tests(t *testing.T) {
344343
t.Fatalf("got error from bind: %v", err)
345344
}
346345

347-
// TODO: remove these before merging abigen2 PR. these are for convenience if I need to regenerate the converted bindings or add a new one.
348-
if err := os.WriteFile(fmt.Sprintf("convertedv1bindtests/%s.go", strings.ToLower(tc.name)), []byte(code), 0666); err != nil {
349-
t.Fatalf("err writing expected output to file: %v\n", err)
346+
if code != tc.expectedBindings {
347+
t.Fatalf("regenerating binding %s resulted in a mutation.", tc.name)
350348
}
351-
/*
352-
fmt.Printf("//go:embed v2/internal/convertedv1bindtests/%s.go\n", strings.ToLower(tc.name))
353-
fmt.Printf("var v1TestBinding%s string\n", tc.name)
354-
fmt.Println()
355-
*/
356-
/*
357-
if code != tc.expectedBindings {
358-
//t.Fatalf("name mismatch for %s", tc.name)
359-
t.Fatalf("'%s'\n!=\n'%s'\n", code, tc.expectedBindings)
360-
}
361-
*/
362349
})
363350
}
364351
}

accounts/abi/bind/v2/lib_test.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,27 @@ func TestErrors(t *testing.T) {
402402
if !hasRevertErrorData {
403403
t.Fatalf("expected call error to contain revert error data.")
404404
}
405-
unpackedErr := ctrct.UnpackError(raw)
406-
if unpackedErr == nil {
405+
rawUnpackedErr := ctrct.UnpackError(raw)
406+
if rawUnpackedErr == nil {
407407
t.Fatalf("expected to unpack error")
408408
}
409-
// TODO: check anything about the error?
409+
410+
unpackedErr, ok := rawUnpackedErr.(*solc_errors.CBadThing)
411+
if !ok {
412+
t.Fatalf("unexpected type for error")
413+
}
414+
if unpackedErr.Arg1.Cmp(big.NewInt(0)) != 0 {
415+
t.Fatalf("bad unpacked error result: expected Arg1 field to be 0. got %s", unpackedErr.Arg1.String())
416+
}
417+
if unpackedErr.Arg2.Cmp(big.NewInt(1)) != 0 {
418+
t.Fatalf("bad unpacked error result: expected Arg2 field to be 1. got %s", unpackedErr.Arg2.String())
419+
}
420+
if unpackedErr.Arg3.Cmp(big.NewInt(2)) != 0 {
421+
t.Fatalf("bad unpacked error result: expected Arg3 to be 2. got %s", unpackedErr.Arg3.String())
422+
}
423+
if unpackedErr.Arg4 != false {
424+
t.Fatalf("bad unpacked error result: expected Arg4 to be false. got true")
425+
}
410426
}
411427

412428
// TestBindingGeneration tests that re-running generation of bindings does not result in mutations to the binding code

0 commit comments

Comments
 (0)