Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 7994bb8

Browse files
committed
Add fixtures runner
1 parent a24c759 commit 7994bb8

File tree

3 files changed

+92
-38
lines changed

3 files changed

+92
-38
lines changed

.github/workflows/main.yml

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,41 +26,6 @@ jobs:
2626
- name: Lint Programs
2727
run: pnpm programs:lint
2828

29-
format_and_lint_client_js:
30-
name: Format & Lint Client JS
31-
runs-on: ubuntu-latest
32-
steps:
33-
- name: Git Checkout
34-
uses: actions/checkout@v4
35-
36-
- name: Setup Environment
37-
uses: ./.github/actions/setup
38-
39-
- name: Format Client JS
40-
run: pnpm clients:js:format
41-
42-
- name: Lint Client JS
43-
run: pnpm clients:js:lint
44-
45-
# format_and_lint_client_rust:
46-
# name: Format & Lint Client Rust
47-
# runs-on: ubuntu-latest
48-
# steps:
49-
# - name: Git Checkout
50-
# uses: actions/checkout@v4
51-
52-
# - name: Setup Environment
53-
# uses: ./.github/actions/setup
54-
# with:
55-
# clippy: true
56-
# rustfmt: true
57-
58-
# - name: Format Client Rust
59-
# run: pnpm clients:rust:format
60-
61-
# - name: Lint Client Rust
62-
# run: pnpm clients:rust:lint
63-
6429
build_programs:
6530
name: Build programs
6631
runs-on: ubuntu-latest
@@ -85,7 +50,7 @@ jobs:
8550
path: ./target/deploy/*.so
8651
if-no-files-found: error
8752

88-
- name: Save Program Builds For Client Jobs
53+
- name: Save Program Builds For Fixtures Job
8954
uses: actions/cache/save@v4
9055
with:
9156
path: ./**/*.so
@@ -110,4 +75,31 @@ jobs:
11075
solana: true
11176

11277
- name: Test Programs
113-
run: pnpm programs:test
78+
run: RUST_LOG=error pnpm programs:test
79+
80+
run_fixtures:
81+
name: Run Fixtures
82+
runs-on: ubuntu-latest
83+
needs: build_programs
84+
steps:
85+
- name: Git Checkout
86+
uses: actions/checkout@v4
87+
88+
- name: Purge environment
89+
uses: ./.github/actions/purge
90+
91+
- name: Setup Environment
92+
uses: ./.github/actions/setup
93+
with:
94+
cargo-cache-key: cargo-program-tests
95+
cargo-cache-fallback-key: cargo-programs
96+
solana: true
97+
98+
- name: Restore Program Builds
99+
uses: actions/cache/restore@v4
100+
with:
101+
path: ./**/*.so
102+
key: ${{ runner.os }}-builds-${{ github.sha }}
103+
104+
- name: Run Fixtures
105+
run: RUST_LOG=error pnpm fixtures:run

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"clients:rust:format": "zx ./scripts/client/format-rust.mjs",
2222
"clients:rust:lint": "zx ./scripts/client/lint-rust.mjs",
2323
"clients:rust:publish": "zx ./scripts/client/publish-rust.mjs",
24-
"clients:rust:test": "zx ./scripts/client/test-rust.mjs"
24+
"clients:rust:test": "zx ./scripts/client/test-rust.mjs",
25+
"fixtures:run": "zx ./scripts/fixtures.mjs run",
26+
"fixtures:clean": "zx ./scripts/fixtures.mjs clean"
2527
},
2628
"devDependencies": {
2729
"@iarna/toml": "^2.2.5",

scripts/fixtures.mjs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env zx
2+
import 'zx/globals';
3+
import { existsSync } from 'fs';
4+
import { cliArguments, workingDirectory } from './utils.mjs';
5+
6+
// Git repository for the SPL Token program.
7+
const SPL_TOKEN_GIT = "https://github.com/solana-program/token.git";
8+
// Directory where the SPL Token program is cloned. Since it is not meant to be
9+
// checked in, it is cloned in the target directory.
10+
const SPL_TOKEN_DIR = path.join(workingDirectory, 'target', 'spl-token');
11+
// Directory where the fixtures are generated. They get generated everytime the
12+
// `SPL_TOKEN_GIT` repository is cloned to make sure they are up to date.
13+
const FIXTURES_DIR = path.join(workingDirectory, 'target', 'spl-token', 'fixtures');
14+
// Path to the Cargo.toml file of the fixtures CLI program.
15+
const FIXTURES_MANIFEST = path.join(workingDirectory, 'fixtures', 'Cargo.toml');
16+
// Directory where the program binary is found.
17+
const OUTPUT_DIR = path.join(workingDirectory, 'target', 'deploy');
18+
// Directory where the CLI executale is found.
19+
const CLI_OUTPUT_DIR = path.join(workingDirectory, 'target', 'release');
20+
21+
const [command, ...args] = cliArguments();
22+
23+
switch (command) {
24+
case 'clean':
25+
await clean();
26+
break;
27+
case 'run':
28+
await run(args);
29+
break;
30+
default:
31+
throw new Error(`Unknown command: ${command}`);
32+
}
33+
34+
async function clean() {
35+
await $`rm -rf ${SPL_TOKEN_DIR}`;
36+
}
37+
38+
async function run(args) {
39+
// On first run (or CI), clone the SPL Token program and generate the fixtures.
40+
// This allows re-runing the fixtures without having to run the tests again. To
41+
// force re-generating the fixtures, delete the `SPL_TOKEN_DIR` directory.
42+
if (!existsSync(SPL_TOKEN_DIR)) {
43+
await $`mkdir ${SPL_TOKEN_DIR}`;
44+
await $`git clone ${SPL_TOKEN_GIT} ${SPL_TOKEN_DIR}`;
45+
46+
cd(SPL_TOKEN_DIR);
47+
// TODO: this can be removed once the mollusk checks PR is merged.
48+
await $`git switch febo/mollusk-checks`;
49+
50+
await $`EJECT_FUZZ_FIXTURES=${FIXTURES_DIR} cargo test-sbf --features mollusk-svm/fuzz --test processor`;
51+
}
52+
53+
cd(workingDirectory);
54+
// Make sure that the program is up to date.
55+
await $`pnpm programs:build`;
56+
// Builds the fixtures CLI program.
57+
await $`cargo build --manifest-path ${FIXTURES_MANIFEST} --release`;
58+
// Run the fixtures.
59+
await $`SBF_OUT_DIR="${OUTPUT_DIR}" ${CLI_OUTPUT_DIR}/fixtures --directory ${FIXTURES_DIR} ${args ? args.join(' ') : ''}`;
60+
}

0 commit comments

Comments
 (0)