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

Add solana-program-test compatibility test in CI #2841

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

dfy313
Copy link

@dfy313 dfy313 commented Mar 14, 2024

Closes #2738

This PR adds the tests/solana-program-test-compatibility package which contains a simple test that checks entrypoint compatibility between anchor-lang and solana-program-test.

Executing compatibility tests

  1. clone repo and switch to this branch
  2. cd tests/solana-program-test-compatibility
  3. cargo test-sbf --package solana-program-test-compatibility --test compatibility_test check_entrypoint_lifetime

Verifying entrypoint lifetime compatibility before #2656

  1. clone repo and switch to this branch
  2. git checkout -b temp-branch
  3. git log --since="2023-10-9" --until="2023-10-12"
  4. git checkout 243ab7573865a7296dd2af1153f44bffbf488458
  5. git checkout temp-branch -- tests/solana-program-test-compatibility
  6. cd tests/solana-program-test-compatibility
  7. Update entry function to use processor! macro
  8. cargo test-sbf --package solana-program-test-compatibility --test compatibility_test check_entrypoint_lifetime

Code walkthrough (old):
https://www.loom.com/share/533e36b7a6594dcdac3b7add900eec97

The compatibility-testing package contains a simple compatibility test defined in compatibility-testing/programs/compatibility-testing/tests/solana_program_test.rs that checks for entrypoint lifetime compatibility
This CI job executes the newly added solana_program_test entrypoint_lifetime test. “continue-on-error: true” is included as the compatibility test is currently expected to fail
Copy link

vercel bot commented Mar 14, 2024

@dfy313 is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Collaborator

@acheroncrypto acheroncrypto left a comment

Choose a reason for hiding this comment

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

Thank you for starting on this!

The lifetimes of the entry function are not compatible with what processor! macro from solana-program-test expects, and it's quite challenging to fix it from Anchor side.

If more people start reporting about it, we might PR to solana-program-test crate to include an anchor feature with Anchor's expected lifetimes, but for now, passing None to the builtin_function argument and letting the programs get resolved from workspace/fixtures seem to be the easier option.

@@ -365,6 +365,49 @@ jobs:
# - run: cd "$(mktemp -d)" && anchor init hello-anchor && cd hello-anchor && yarn link @coral-xyz/anchor && yarn && anchor test && yarn lint:fix
# - uses: ./.github/actions/git-diff/

test-anchor-compatibility:
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be better to add this in the test-programs section as it's much shorter and requires less duplication for CI code.

Copy link
Author

Choose a reason for hiding this comment

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

Done!

Comment on lines 393 to 408
run: |
cd tests/compatibility-testing
test_output=$(cargo test --package compatibility-testing --test solana_program_test entrypoint_lifetime 2>&1) || test_exit_code=$?
echo "$test_output"

# Success exit code
if [ "$test_exit_code" -eq 0 ]; then
echo "solana_program_test entrypoint_lifetime compatibility test passed with exit code: $test_exit_code"
# Unrecoverable error exit code
elif [ "$test_exit_code" -eq 101 ]; then
echo "solana_program_test entrypoint_lifetime compatibility test failed with exit code: $test_exit_code"
exit 1
else
echo "Unexpected exit code: $test_exit_code"
exit 1
fi
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please create a script file and run it instead e.g. test.sh.

Copy link
Author

Choose a reason for hiding this comment

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

I had originally expected the compatibility test to fail so it made sense to use a script in conjunction with continue-on-error.
With the updated test case logic (passing None to the builtin_function argument and removing the processor! macro), the test case should pass, so this is no longer needed.

@@ -0,0 +1,20 @@
[package]
name = "compatibility-testing"
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Can we rename compatibility-test to something that indicates solana-program-test compatibility?

Copy link
Author

Choose a reason for hiding this comment

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

I've renamed the package to solana-program-test-compatibility. Additionally, I renamed the test file to compatibility_test.rs and the test case to check_entrypoint

let _pt = ProgramTest::new(
"compatibility_testing",
compatibility_testing::id(),
processor!(compatibility_testing::entry),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think people started passing None to the builtin_function argument, and let cargo test-sbf load the programs:

https://github.com/anza-xyz/agave/blob/a2579d484efd78099ba67db5911b2ba12c77b711/program-test/src/lib.rs#L617-L621

That way, the incompatibility of the lifetimes is not an issue and solana-program-test can be used with the generated entry function.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the context! Done!

dfy313 and others added 2 commits March 19, 2024 10:44
This commit renames the compatibility-testing package, test file, and test case to: solana-program-test-compatibility, compatibility-test.rs, and check_entrypoint. This commit also updates the compatibility test by passing None to the builtin_function argument, and letting cargo test-sbf load the programs. Finally, this commit updates the CI job in reusable-tests to take advantage of existing structure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add solana-program-test compatibility test in CI
2 participants