Skip to content

refactor: share common code and test the precompiles end to end - #69

Open
sphamjoli wants to merge 4 commits into
mainfrom
spha/scarcity-precompiles
Open

refactor: share common code and test the precompiles end to end#69
sphamjoli wants to merge 4 commits into
mainfrom
spha/scarcity-precompiles

Conversation

@sphamjoli

@sphamjoli sphamjoli commented Aug 26, 2026

Copy link
Copy Markdown
Member

The scarcity and NFT-claims precompiles are already in place, but each had its own copy of the same guards and test scaffolding, revert reasons written out inline at each site, and the collection interface holding two contracts in one file. Nothing exercised them the way a real caller does, through a compiled contract running inside the virtual machine, so the behaviour that only shows up across that boundary was never tested.

This shares the common parts and adds that coverage. The guards and mock helpers move to a single support crate; both precompiles reuse, so they cannot drift apart. Small example contracts are now compiled at test time and run against the precompiles, covering a plain read, the delegate-call and value refusals, a contract that owns and gates its own collection, and a proxy that owns a collection under its own address, on both the EVM and PolkaVM backends. Revert reasons become named constants shared by the code and the tests, the collection interface is split so each file holds one interface, and the standard interface identifiers are checked against the compiler's own computation of them rather than trusted by hand.

Changes

  • Extract the shared guards and mock helpers into a common support crate that both precompiles depend on, so the rules stay identical.
  • Add a fixtures crate that compiles small Solidity examples to EVM and PolkaVM at test time, fetching the compilers on demand so no toolchain has to be installed by hand.
  • Add end-to-end tests: a normal read, the delegate-call and value guards, a contract that owns and mints from its own collection, an OpenZeppelin-based proxy that owns a collection, and the same read verified on both backends.
  • Cover native operations as tests: a native force transfer registers its destination so balanceOf and ownerOf agree, and native transfers and burns emit no ERC-721 log.
  • Turn every revert reason into a named public constant shared by callers and tests.
  • Split the collection interface so each file holds a single interface, and verify the ERC-165 and ERC-721 interface identifiers against a vendored OpenZeppelin fixture computed by the compiler.

@sphamjoli
sphamjoli requested a review from a team August 26, 2026 20:33
@sphamjoli sphamjoli added enhancement New feature or request bug Something isn't working labels Aug 26, 2026
@sphamjoli
sphamjoli enabled auto-merge (squash) August 27, 2026 13:54
@sphamjoli sphamjoli added D2-no audit No audit is needed D9-needs audit audit is needed and removed D2-no audit No audit is needed labels Aug 27, 2026
@sphamjoli sphamjoli added C0-non-breaking This PR is not a breaking change for any runtime consuming it. D5-nice to have audit optional to have, meant to express "audit it if there is bandwidth" and removed D9-needs audit audit is needed labels Sep 1, 2026
@sphamjoli

Copy link
Copy Markdown
Member Author

Hello @tindzk can you please have a look when you get time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working C0-non-breaking This PR is not a breaking change for any runtime consuming it. D5-nice to have audit optional to have, meant to express "audit it if there is bandwidth" enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants