Skip to content
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

[WIP] Add spl-token tests #4

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

[WIP] Add spl-token tests #4

wants to merge 2 commits into from

Conversation

febo
Copy link
Owner

@febo febo commented Jan 9, 2025

Problem

Currently the tests are limited to only test if instructions can execute.

Solution

Expand the tests by adding the same test suite as spl-token program.

@buffalojoec
Copy link
Collaborator

buffalojoec commented Jan 9, 2025

Before going too far with porting tests over from spl-token, might I suggest a simpler method.

We're already in the process of refactoring all of the spl-token tests with Mollusk.
solana-program/token#16

Once that's done, what we can do is the following:

  1. Export all spl-token tests as fixtures.
  2. Move that directory of fixture here in p-token.
  3. Set up the Mollusk fixture entrypoint here in p-token (only a few lines of code).
  4. Run all of the fixtures from spl-token against p-token.

Any unit test that invokes Mollusk's process_instruction or process_instruction_chain can generate a fixture.

cd spl-token
EJECT_FUZZ_FIXTURES=fixtures-dir cargo test-sbf

Then you can move those fixtures into the p-token repository here, and set up a simple Mollusk entrypoint to accept those fixtures.

for fix in fixtures_dir {
    let fixture = Fixture::load_from_blob_file(fix);
    Mollusk::process_and_validate_fixture(&fixture);
}

https://github.com/buffalojoec/mollusk/blob/c01523016195c315870bd9e4bfa3a64a6cffa659/harness/src/lib.rs#L356

And boom, that's it, you ran the whole spl-token suite against p-token.

@febo
Copy link
Owner Author

febo commented Jan 11, 2025

Before going too far with porting tests over from spl-token, might I suggest a simpler method.

We're already in the process of refactoring all of the spl-token tests with Mollusk. solana-program/token#16

Once that's done, what we can do is the following:

  1. Export all spl-token tests as fixtures.
  2. Move that directory of fixture here in p-token.
  3. Set up the Mollusk fixture entrypoint here in p-token (only a few lines of code).
  4. Run all of the fixtures from spl-token against p-token.

Any unit test that invokes Mollusk's process_instruction or process_instruction_chain can generate a fixture.

cd spl-token
EJECT_FUZZ_FIXTURES=fixtures-dir cargo test-sbf

Then you can move those fixtures into the p-token repository here, and set up a simple Mollusk entrypoint to accept those fixtures.

for fix in fixtures_dir {
    let fixture = Fixture::load_from_blob_file(fix);
    Mollusk::process_and_validate_fixture(&fixture);
}

https://github.com/buffalojoec/mollusk/blob/c01523016195c315870bd9e4bfa3a64a6cffa659/harness/src/lib.rs#L356

And boom, that's it, you ran the whole spl-token suite against p-token.

Amazing!

The tests here are literally a copy-paste from spl-token and just needed to change the program id constant. At the moment it is more just a quick way to check that they work. ☺️

I will definitely follow your suggestion when adding the final tests.

@febo
Copy link
Owner Author

febo commented Jan 12, 2025

@buffalojoec Given the way that we ended up doing the spl-token tests, I think we can't use the fixtures – if I understood how mollusk fixtures work. We don't pass the checks to mollusk since we rely on "external" assert!s so we don't have that information on the fixtures.

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.

2 participants