Skip to content

Conversation

@ARR4N
Copy link
Contributor

@ARR4N ARR4N commented Jul 12, 2024

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

  1. The new evmsim package wraps geth's SimulatedBackend to provide a real EVM with an interface allowing use with contract bindings generated with abigen. It provides some additional convenience functions that make using the simulator easier. Most importantly, enabling individual precompiles is trivial.

  2. The new dstest parses transaction receipts to find events emitted by Solidity-based tests inheriting from DSTest; the existing precompile tests use this, as do Forge tests. All failing DSTest assertions emit such events.

  3. The existing Solidity contracts for testing the allowlist precompile are run through solc | abigen to produce Go bindings that are used with evmsim to mirror the behaviour of the equivalent Hardhat test. Failures are detected (and reported) with the dstest package. Unlike the Hardhat tests, these are run in the same process and on the subnet-evm VM implementation.

Tip

Review the code in the order described above: testing/evmsim, then testing/dstest, then contracts/*_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 an evmsim backend running a Solidity contract that emits DSTest 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

  • Abstract //go:generate solc | abigen into script
  • Pre-merge check that generated files are up to date
  • Move precompile configuration into evmsim.New()

ARR4N added 12 commits July 16, 2024 15:40
…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>`.
@ARR4N ARR4N marked this pull request as ready for review July 17, 2024 15:19
@ARR4N ARR4N requested review from ceyonur and darioush as code owners July 17, 2024 15:19
@ARR4N ARR4N requested a review from richardpringle July 17, 2024 15:20
ceyonur added a commit that referenced this pull request Oct 8, 2025
ceyonur added a commit that referenced this pull request Oct 8, 2025
github-merge-queue bot pushed a commit that referenced this pull request Oct 8, 2025
@JonathanOppenheimer
Copy link
Member

@ARR4N - the abigen scripting and backend wrapping (evmsim) are super interesting and may be worth revisiting in light of #1830. I think the ds-test approach now though has been decided against.

Should we incorporate some of this code? You put hard work into this!

@JonathanOppenheimer JonathanOppenheimer requested review from a team and maru-ava as code owners November 4, 2025 20:53
@JonathanOppenheimer JonathanOppenheimer added testing This primarly focuses on testing ci labels Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci testing This primarly focuses on testing

Projects

Status: In Progress 🏗️

Development

Successfully merging this pull request may close these issues.

3 participants