Commit d0499a6
authored
feat: add cli command to run the solana-test-validator with ER setup (#567)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
Updated On: 2025-10-09 15:30:44 UTC
<h3>Summary</h3>
This PR adds a new CLI command `mb-test-validator` that provides a
convenient way to run `solana-test-validator` with MagicBlock's
Ephemeral Rollup (ER) setup. The implementation includes several key
components:
**Core Functionality**: The PR introduces `mbTestValidator.ts`, which
wraps `solana-test-validator` with predefined BPF programs and accounts
necessary for MagicBlock's ER infrastructure. This eliminates the need
for users to manually specify numerous `--bpf-program` and `--account`
flags when setting up a local test environment.
**Code Refactoring**: The existing `ephemeralValidator.ts` was
refactored to extract process management logic into a reusable
`runWithForwardedExit` function. This promotes code reuse between the
ephemeral validator and the new test validator implementations,
following DRY principles while maintaining consistent process handling.
**Build Integration**: The package.json was updated to include the new
`mb-test-validator` binary and modified the build script to
automatically fetch required program binaries and account dumps from
MagicBlock's devnet RPC during compilation.
**Asset Management**: A new bash script `fetch-local-dumps.sh` was added
to handle downloading of Solana program binaries (.so files) and account
data (.json files) from MagicBlock's devnet, ensuring the test validator
has access to the correct program and account states for local
development.
This change integrates well with the existing codebase by following
established patterns from `ephemeralValidator.ts` and maintaining
consistency in CLI tool implementation. The solution addresses the
practical need for developers to quickly spin up a properly configured
test validator without manual setup of MagicBlock-specific
infrastructure components.
<h3>Important Files Changed</h3>
<details>
<summary>Changed Files</summary>
| Filename | Score | Overview |
|----------|-------|----------|
| .github/packages/npm-package/ephemeralValidator.ts | 5/5 | Refactored
to extract reusable process management logic into `runWithForwardedExit`
function |
| .github/packages/npm-package/mbTestValidator.ts | 2/5 | New CLI tool
for running solana-test-validator with ER setup, but contains duplicate
program entries and potential process handling issues |
| .github/packages/npm-package/package.json | 4/5 | Added new CLI binary
and build script modification to fetch local dumps during compilation |
| .github/packages/npm-package/scripts/fetch-local-dumps.sh | 4/5 | New
script to fetch program binaries and account data from MagicBlock devnet
with proper error handling |
</details>
<h3>Confidence score: 3/5</h3>
- This PR requires careful review due to several implementation issues
that could cause runtime problems
- Score reflects concerns about duplicate program entries, process exit
handling logic, and missing error handling in critical paths
- Pay close attention to mbTestValidator.ts which contains the most
problematic code patterns
<h3>Sequence Diagram</h3>
```mermaid
sequenceDiagram
participant User
participant "npm/yarn"
participant mbTestValidator.ts
participant "fetch-local-dumps.sh"
participant "Solana CLI"
participant "MagicBlock RPC"
participant "solana-test-validator"
participant "Local Filesystem"
User->>npm/yarn: "npm run build" or "yarn build"
npm/yarn->>mbTestValidator.ts: "tsc" (compile TypeScript)
npm/yarn->>fetch-local-dumps.sh: "bash scripts/fetch-local-dumps.sh"
fetch-local-dumps.sh->>Local Filesystem: "mkdir -p local-dumps"
loop For each account
fetch-local-dumps.sh->>Solana CLI: "solana account <pubkey> --output json --url <RPC_URL>"
Solana CLI->>MagicBlock RPC: "GET account data"
MagicBlock RPC-->>Solana CLI: "Account JSON data"
Solana CLI-->>fetch-local-dumps.sh: "Account data"
fetch-local-dumps.sh->>Local Filesystem: "Write <pubkey>.json"
end
loop For each program
fetch-local-dumps.sh->>Solana CLI: "solana program dump <pubkey> <output.so> --url <RPC_URL>"
Solana CLI->>MagicBlock RPC: "GET program binary"
MagicBlock RPC-->>Solana CLI: "Program .so binary"
Solana CLI-->>fetch-local-dumps.sh: "Program binary"
fetch-local-dumps.sh->>Local Filesystem: "Write <pubkey>.so"
end
User->>npm/yarn: "mb-test-validator [args]"
npm/yarn->>mbTestValidator.ts: "Execute mb-test-validator command"
mbTestValidator.ts->>Local Filesystem: "Check for required .so and .json files"
Local Filesystem-->>mbTestValidator.ts: "File existence status"
alt Missing files
mbTestValidator.ts->>User: "Warning: missing local dumps files"
end
mbTestValidator.ts->>solana-test-validator: "spawn with --bpf-program and --account flags"
loop Process lifecycle management
solana-test-validator->>mbTestValidator.ts: "Process events (exit, signals)"
mbTestValidator.ts->>User: "Forward exit codes and signals"
end
User->>mbTestValidator.ts: "SIGINT (Ctrl+C)"
mbTestValidator.ts->>solana-test-validator: "Kill SIGINT/SIGTERM"
```
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->1 parent d259367 commit d0499a6
File tree
4 files changed
+156
-8
lines changed- .github/packages/npm-package
- scripts
4 files changed
+156
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 36 | + | |
| 37 | + | |
40 | 38 | | |
41 | 39 | | |
42 | 40 | | |
| |||
47 | 45 | | |
48 | 46 | | |
49 | 47 | | |
50 | | - | |
51 | | - | |
| 48 | + | |
| 49 | + | |
52 | 50 | | |
53 | 51 | | |
54 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
55 | 59 | | |
56 | 60 | | |
57 | 61 | | |
| |||
101 | 105 | | |
102 | 106 | | |
103 | 107 | | |
| 108 | + | |
| 109 | + | |
104 | 110 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | | - | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
Lines changed: 48 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments