Skip to content

Commit 1305207

Browse files
authored
add pinocchio cross-program-invocation example (#584)
Ports the hand+lever CPI example from anchor/native to Pinocchio. - Two-program workspace: hand (caller) and lever (callee). - Lever exposes initialize and switch_power instructions via a 1-byte discriminator; uses pinocchio-system::CreateAccount for account allocation under its own program id. - Hand forwards switch_power(name) over CPI to lever, building the cross-program Instruction on the stack (no_std, no allocator). - Bankrun TS test exercises the full init -> pull -> pull-again flow plus an invalid-discriminator rejection case.
1 parent 63c36fe commit 1305207

11 files changed

Lines changed: 1655 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ members = [
2020
"basics/create-account/anchor/programs/create-system-account",
2121
"basics/create-account/asm",
2222
"basics/cross-program-invocation/anchor/programs/*",
23+
"basics/cross-program-invocation/pinocchio/programs/*",
2324
"basics/hello-solana/native/program",
2425
"basics/hello-solana/anchor/programs/*",
2526
"basics/hello-solana/pinocchio/program",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
# Quick build script for the pinocchio CPI example.
4+
# Builds both programs and emits .so files into tests/fixtures so bankrun can pick them up.
5+
6+
cargo build-sbf --manifest-path=./programs/hand/Cargo.toml --sbf-out-dir=./tests/fixtures
7+
cargo build-sbf --manifest-path=./programs/lever/Cargo.toml --sbf-out-dir=./tests/fixtures
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"type": "module",
3+
"scripts": {
4+
"test": "pnpm ts-mocha -p ./tsconfig.json -t 1000000 ./tests/test.ts",
5+
"build": "cargo build-sbf --manifest-path=./programs/hand/Cargo.toml --sbf-out-dir=./tests/fixtures && cargo build-sbf --manifest-path=./programs/lever/Cargo.toml --sbf-out-dir=./tests/fixtures",
6+
"build-and-test": "pnpm build && pnpm test"
7+
},
8+
"dependencies": {
9+
"@solana/web3.js": "^1.98.4"
10+
},
11+
"devDependencies": {
12+
"@types/chai": "^4.3.1",
13+
"@types/mocha": "^9.1.1",
14+
"chai": "^4.3.4",
15+
"mocha": "^9.0.3",
16+
"solana-bankrun": "^0.3.1",
17+
"ts-mocha": "^10.0.0",
18+
"typescript": "^4.3.5"
19+
}
20+
}

0 commit comments

Comments
 (0)