Skip to content

Sourcify Tests#1305

Merged
mjoerussell merged 77 commits intoNomicFoundation:mainfrom
manastech:feature/sourcify
May 6, 2025
Merged

Sourcify Tests#1305
mjoerussell merged 77 commits intoNomicFoundation:mainfrom
manastech:feature/sourcify

Conversation

@mjoerussell
Copy link
Contributor

@mjoerussell mjoerussell commented Apr 15, 2025

Run e2e tests on real-world contracts using the Sourcify dataset. This will eventually replace the Sanctuary tests.

Still to-do:

  • Better diagnostic messages when parsing fails (restore messages that we get in Sanctuary tests)
  • Test for more import resolution corner cases
  • CI Job

github-actions added 18 commits March 31, 2025 08:12
The test runner checks the sourcify manifest for a list of all shards for a particular chain, then downloads each sequentially, unpacks, and finally tests each source file.

This is a very basic runner and there are a lot of improvements that can be made, plus a lot of missing features. But this is a pretty good start.
…imports

* Reuse a buffer when reading source files for efficiency
* Reorganize code
…e parallelized. Now they are using proper iterators, and `Contract::Item` is a struct which contains a file handle instead of the file contents. This means that we can still use a shared buffer to read all of the files, improving performance, without having to borrow the string through several layers of iterators. This was what prompted me to move away from "real" iterators previously.

Like the sanctuary tests, I'm using `rayon` to parallize the runner. Here, contracts are processed in parallel, but the source files within a single contract are processed sequentially. Most contracts don't have a large number of source files and trying to parallelize them as well would be unnecessary complexity.
…t them "in the background". This means less time waiting in-between shards, which matters more now that processing each shard is internally parallelized.

There could still be some improvements here, specifically with making the fetches truly async. Right now we're using `reqwest`, which requires `tokio` to be used as the async runtime. It's possible that we could find a different library that would allow us to make async calls using only the `futures` crate, which would be much better suited to our use case.
…of how imports/files are resolved when building a compilation unit, since the previous way wasn't working in practice.
* Allow the user to not include partial_match contracts. They are still included by default
* Categorize contracts between full_match and partial_match
…ning up confusing code.

* Fetch archives in the main thread, and process them in a separate thread. This means that the thread doesn't have to take ownership of the `Repository` instance, and so that will get dropped at the correct time.
* Following that change, moved the fetching logic into a closure that we invoke immediately. This is all so that `tx` (Sender) can be dropped before calling `process_thread.join()`. Otherwise, the processing thread will get stuck waiting for a new message forever and will never be joined.
* Removing all of the custom iterators that I built for `ContractArchive` and `Contract`. The `Contract` iterators were no longer being used since I started building compilation units by traversing the import tree. The `ContractArchive` iterator was replaced by a function `ContractArchive::contracts`, which returns an `impl Iterator`. I thought that this would be a much simpler way to express this logic, especially since the other custom iterator was removed.
* Adding additional terminal output to inform the user about the progress of the test runner.
* Emit events report after testing is complete
@changeset-bot
Copy link

changeset-bot bot commented Apr 15, 2025

⚠️ No Changeset found

Latest commit: 2d889f8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@mjoerussell
Copy link
Contributor Author

Just ran a parsing test locally on the entire Ethereum mainnet. Here are the high-level stats:

Source Files3,149,211
Contracts Passed820,565
Contracts Failed4
Unresolved Imports0
  • 2 of the parse failures were related to multi-line comments. Example:
Error: Expected ContractKeyword or ImportKeyword or InterfaceKeyword or LibraryKeyword or PragmaKeyword.
     ╭─[Presscoins.sol:335:1]
     │
 335 │ ╭─▶ /** PressOnDemand is the first decentralized ondemand platform with in-Dapp store,
     ┆ ┆
 341 │ ├─▶   /*
     │ │
     │ ╰───────── Error occurred here.
─────╯
  • 2 of the parse failures were on function arguments which used the indexed keyword twice. Example:
Error: Expected CloseParen or Comma.
     ╭─[MEXPToken.sol:207:32]
     │
 207 │     event Burn(address indexed indexed from, uint256 value);
     │                                ─────────────┬─────────────
     │                                             ╰─────────────── Error occurred here.
─────╯

@mjoerussell mjoerussell marked this pull request as ready for review April 16, 2025 22:16
@mjoerussell mjoerussell requested a review from a team as a code owner April 16, 2025 22:16
Copy link
Contributor

@OmarTawfik OmarTawfik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

@mjoerussell mjoerussell requested a review from OmarTawfik April 30, 2025 15:34
mjoerussell and others added 2 commits May 5, 2025 08:53
Co-authored-by: Omar Tawfik <15987992+OmarTawfik@users.noreply.github.com>
…o try to test the workflow. This trigger should be removed before merging because we don't actually want it to run on every PR.
Copy link
Contributor

@OmarTawfik OmarTawfik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of comments. But otherwise LGTM.
Thanks!

@mjoerussell mjoerussell added this pull request to the merge queue May 6, 2025
Merged via the queue into NomicFoundation:main with commit 8d1cde7 May 6, 2025
2 checks passed
@mjoerussell mjoerussell deleted the feature/sourcify branch May 6, 2025 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants