-
Notifications
You must be signed in to change notification settings - Fork 223
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
feat: precompile Solidity testing in pure Go #1234
base: master
Are you sure you want to change the base?
Conversation
scripts/abigen/abigen.go
Outdated
return fmt.Errorf("abigen: %w", err) | ||
} | ||
|
||
re := regexp.MustCompile(`github.com/ethereum/go-ethereum/(accounts|core)/`) |
Check failure
Code scanning / CodeQL
Missing regular expression anchor High
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
scripts/abigen/abigen.go
Outdated
return fmt.Errorf("abigen: %w", err) | ||
} | ||
|
||
re := regexp.MustCompile(`github.com/ethereum/go-ethereum/(accounts|core)/`) |
Check failure
Code scanning / CodeQL
Incomplete regular expression for hostnames High
the regular expression is used
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
…le `contract Empty` Repeated runs of `go generate ./contracts/...` could result in different outputs. I suspect that it's because of a Solidity bug (they call it a feature though) that appends a hash of the complete source file from which a contract was compiled. In this case it would have been from the different context in which the otherwise same `Example` contracts were defined; in the worst case a single-character change in a comment results in different addresses (i.e. a bug) `</rant>`.
…n` as assumed to be available
Why this should be merged
Prerequisite for #1228. Also paves the way for pure-Solidity (similar to Forge) testing of contracts intended to be deployed with custom precompiles.
How this works
The new
evmsim
package wraps geth'sSimulatedBackend
to provide a real EVM with an interface allowing use with contract bindings generated withabigen
. It provides some additional convenience functions that make using the simulator easier. Most importantly, enabling individual precompiles is trivial.The new
dstest
parses transaction receipts to find events emitted by Solidity-based tests inheriting fromDSTest
; the existing precompile tests use this, as do Forge tests. All failingDSTest
assertions emit such events.The existing Solidity contracts for testing the allowlist precompile are run through
solc | abigen
to produce Go bindings that are used withevmsim
to mirror the behaviour of the equivalent Hardhat test. Failures are detected (and reported) with thedstest
package. Unlike the Hardhat tests, these are run in the same process and on thesubnet-evm
VM implementation.Tip
Review the code in the order described above:
testing/evmsim
, thentesting/dstest
, thencontracts/*_test.go
. Apologies for adding so much functionality in one PR! It started as (3) but that necessitated (2) and then (1).How this was tested
Unit testing of
dstest
against anevmsim
backend running a Solidity contract that emitsDSTest
events. The allowlist tests were also deliberately broken (and then reverted) to confirm that the Go tests fail.How is this documented
Full godoc commentary.
TODO Before review
//go:generate solc | abigen
into scriptevmsim.New()