-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sketch out approach to testing abigen v2 #11
base: abigen2
Are you sure you want to change the base?
Conversation
Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
I am using unnamed parameters. It might be slightly more maintainable to use named parameters, but I get an error when trying to use {{.Type}} inside a struct literal.
accounts/abi/bind/bind_test.go
Outdated
if b, err := NewToken(common.Address{}, nil); b == nil || err != nil { | ||
t.Fatalf("binding (%v) nil or error (%v) not nil", b, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is currently failing:
bind_test.go:2204: test 1: failed to generate v2 binding: 77:39: expected ')', found ','
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because the output from abigen v2 is
func (_Token *Token) PackConstructor(, initialSupply *big.Int , tokenName string , decimalUnits uint8 , tokenSymbol string ) ([]byte, error) {
return _Token.abi.Pack("" , initialSupply, tokenName, decimalUnits, tokenSymbol)
}
and we are trying to format the output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed here ea664d0
The existing template prints a leading comma before each entry in the range. This works with the old template because there was a preceding variable printed. Here, we opt for a multilne function definition and use trailing commas.
Includes #10 .
The philosophy here is to mirror the existing test suite, so that the abigen v2 is run against all of the sam inputs, but with a custom set of assertions as to what to expect.
Overall the testing approach is pretty indirect / involved (writing to a temporary directory, building test files by editing raw strings,...). I don't love it, but it matches what is there and isn't too hard to modify.
An alternative I had considered is simply asserting on the output of
Bind
. If we find exactly what we want in the output, then probably there aren't any bugs. The existing testing system is better because it will check to see if the resulting package is free of bugs, too.Keen to get feedback before finishing off the test (it still has some notes in the margin / mess from development)