|
| 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