-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathfixtures.mjs
61 lines (51 loc) · 1.67 KB
/
fixtures.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env zx
import 'zx/globals';
import { existsSync } from 'fs';
import { cliArguments, workingDirectory } from '../utils.mjs';
// Directory where the fixtures are generated.
const FIXTURES_DIR = path.join(workingDirectory, 'target', 'fixtures');
// Directory of the SPL Token program.
const SPL_TOKEN_DIR = path.join(workingDirectory, 'program');
// Directory of the SBF program.
const SBF_OUTPUT_DIR = path.join(workingDirectory, 'target', 'deploy');
const [command, ...args] = cliArguments();
switch (command) {
case 'clean':
await clean();
break;
case 'generate':
await generate();
break;
case 'run':
await run(args);
break;
default:
throw new Error(`Unknown command: ${command}`);
}
async function clean() {
await $`rm -rf ${FIXTURES_DIR}`;
}
async function generate() {
if (existsSync(FIXTURES_DIR)) {
echo(chalk.yellow('[ WARNING ]'), `Fixtures directory already exists.`);
} else {
await $`mkdir ${FIXTURES_DIR}`;
// Fixtures are generated from the SPL Token program.
cd(SPL_TOKEN_DIR);
await $`RUST_LOG=error EJECT_FUZZ_FIXTURES=${FIXTURES_DIR} cargo test-sbf --features mollusk-svm/fuzz`;
}
}
async function run(args) {
if (!existsSync(FIXTURES_DIR)) {
throw new Error(`Fixtures directory does not exist: ${FIXTURES_DIR}`);
}
const [programName] = args;
if (!programName) {
throw new Error('The name of the program file must be provided.');
}
await $`mollusk execute-fixture \
${path.join(SBF_OUTPUT_DIR, programName + '.so')} \
${FIXTURES_DIR} \
TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA \
--ignore-compute-units`;
}