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
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/reusable-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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!

needs: setup-anchor-cli
name: Test Anchor Compatibility
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup/
- uses: ./.github/actions/setup-ts/
- uses: ./.github/actions/setup-solana/
- uses: actions/cache@v3
if: ${{ env.CACHE != 'false' }}
name: Cache Cargo registry + index
id: cache-anchor
with:
path: ${{ env.CARGO_CACHE_PATH }}
key: cargo-${{ runner.os }}-${{ env.CARGO_PROFILE }}-anchor-${{ hashFiles('**/Cargo.lock') }}
- uses: actions/download-artifact@v3
with:
name: ${{ env.ANCHOR_BINARY_NAME }}
path: ~/.cargo/bin/
- run: chmod +x ~/.cargo/bin/anchor
- name: Run Compatibility Tests
# TODO: Remove continue-on-error once https://github.com/coral-xyz/anchor/pull/2711 is resolved
continue-on-error: true
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.

- uses: ./.github/actions/git-diff/

test-programs:
needs: setup-anchor-cli
name: Test ${{ matrix.node.path }}
Expand Down
8 changes: 8 additions & 0 deletions tests/compatibility-testing/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

.anchor
.DS_Store
target
node_modules
dist
build
test-ledger
18 changes: 18 additions & 0 deletions tests/compatibility-testing/Anchor.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[toolchain]

[features]
seeds = false
skip-lint = false

[programs.localnet]
compatibility_testing = "DhFkMBzU3BqvcWuUZkFQR8QajQsiGYLPrhCh5BQBgmkg"

[registry]
url = "https://api.apr.dev"

[provider]
cluster = "Localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
14 changes: 14 additions & 0 deletions tests/compatibility-testing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[workspace]
members = [
"programs/*"
]
resolver = "2"

[profile.release]
overflow-checks = true
lto = "fat"
codegen-units = 1
[profile.release.build-override]
opt-level = 3
incremental = false
codegen-units = 1
12 changes: 12 additions & 0 deletions tests/compatibility-testing/migrations/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Migrations are an early feature. Currently, they're nothing more than this
// single deploy script that's invoked from the CLI, injecting a provider
// configured from the workspace's Anchor.toml.

const anchor = require("@coral-xyz/anchor");

module.exports = async function (provider) {
// Configure client to use the provider.
anchor.setProvider(provider);

// Add your deploy script here.
};
19 changes: 19 additions & 0 deletions tests/compatibility-testing/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"scripts": {
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
},
"dependencies": {
"@coral-xyz/anchor": "^0.29.0"
},
"devDependencies": {
"chai": "^4.3.4",
"mocha": "^9.0.3",
"ts-mocha": "^10.0.0",
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.0.0",
"typescript": "^4.3.5",
"prettier": "^2.6.2"
}
}
Original file line number Diff line number Diff line change
@@ -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

version = "0.1.0"
description = "Created with Anchor"
edition = "2021"

[lib]
crate-type = ["cdylib", "lib"]
name = "compatibility_testing"

[features]
no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
default = []

[dependencies]
anchor-lang = { path = "../../../../lang" }
solana-program-test = ">=1.16, <1.18"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.bpfel-unknown-unknown.dependencies.std]
features = []
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use anchor_lang::prelude::*;

declare_id!("DhFkMBzU3BqvcWuUZkFQR8QajQsiGYLPrhCh5BQBgmkg");

#[program]
pub mod compatibility_testing {
use super::*;

pub fn initialize(_ctx: Context<Initialize>) -> Result<()> {
Ok(())
}
}

#[derive(Accounts)]
pub struct Initialize {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use solana_program_test::{processor, ProgramTest};

#[test]
fn entrypoint_lifetime() {
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!

);
}
11 changes: 11 additions & 0 deletions tests/compatibility-testing/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"types": ["mocha", "chai"],
"typeRoots": ["./node_modules/@types"],
"lib": ["es2015"],
"module": "commonjs",
"target": "es6",
"esModuleInterop": true
}
}

1 change: 1 addition & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"cfo",
"chat",
"composite",
"compatibility-testing",
"custom-coder",
"errors",
"escrow",
Expand Down