-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
a2c404d
6ac4d9e
4f8b32d
d6715a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please create a script file and run it instead e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
- uses: ./.github/actions/git-diff/ | ||
|
||
test-programs: | ||
needs: setup-anchor-cli | ||
name: Test ${{ matrix.node.path }} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
.anchor | ||
.DS_Store | ||
target | ||
node_modules | ||
dist | ||
build | ||
test-ledger |
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" |
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 |
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. | ||
}; |
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Can we rename There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've renamed the package to |
||
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), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think people started passing That way, the incompatibility of the lifetimes is not an issue and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the context! Done! |
||
); | ||
} |
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 | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
"cfo", | ||
"chat", | ||
"composite", | ||
"compatibility-testing", | ||
"custom-coder", | ||
"errors", | ||
"escrow", | ||
|
There was a problem hiding this comment.
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!