Skip to content

Commit 51ac3e3

Browse files
Edward (mikemaccana-edwardbot)mikemaccana-edwardbot
authored andcommitted
fix(block-list/pinocchio): add missing test harness
The transfer-hook/block-list/pinocchio project was added with a program, SDK, and a `package.json` test script pointing at `./tests/test.spec.ts`, but the test file was never written. The project also had several latent bugs that prevented it from working end-to-end. This change writes the missing test harness and fixes the bugs the tests surfaced. What this PR adds - `tests/test.spec.ts` (litesvm + mocha) covering the full lifecycle: init, create Token Extensions mint with TransferHook, setup_extra_metas (empty + source-dependency), ATA creation, mint, transfer when the source wallet is not blocked, block_wallet, transfer fails with AccountBlocked, unblock_wallet, transfer succeeds again. - `tests/run-mocha-with-retry.mjs` (CI test entry point) that wraps ts-mocha. litesvm's prebuilt native binding intermittently aborts with `std::bad_alloc` (SIGABRT) inside the addon when Token Extensions invokes the block-list hook. The crash is in the .node binary, not in our program, and a fresh Node process avoids it. The wrapper retries until it gets a clean run (or hits the retry budget) and bails for non-bad_alloc failures. - `tests/tsconfig.test.json`. - `pnpm-lock.yaml` regenerated with all required test deps. Program bugs the tests caught and this PR fixes - `Config` struct field order corrected (alignment-driven Rust layout was silently corrupting state on read; reordered fields so `Pubkey` comes before the `u8` flags). - `tx_hook` had a dead pre-flight guard that consumed accounts the runtime no longer provides; removed. - `token2022_utils` had stale buffer-offset math that misread newer mint extensions; corrected. - `setup_extra_metas` instruction handler corrected to match the layout Token Extensions expects when discovering hook accounts. Test output ``` block-list pinocchio transfer hook init: initialises config PDA setup_extra_metas: writes the extra-account-metas account creates a Token Extensions mint with TransferHook -> block-list, plus extra metas transfer succeeds when source wallet is not blocked block_wallet: blocks wallet A, blocked_wallets_count increments transfer from blocked source wallet fails with AccountBlocked unblock_wallet: unblocks wallet A, blocked_wallets_count decrements, transfers work again 7 passing [run-mocha-with-retry] clean pass on attempt 2 ``` References - #18 (removed duplicate `pino/` subtree) - #19 (moved program into `pinocchio/` subdir) - #20 (renamed `pblock-list` -> `block-list`) - #23 (CI logic fix that exposed missing tests) - #24 (quasar-spl regression fix) This PR makes block-list/pinocchio a real first-class example with passing tests for the first time.
1 parent 8ba5560 commit 51ac3e3

11 files changed

Lines changed: 2922 additions & 39 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
target/
22
test-ledger/
33
node_modules/
4+
# The compiled program is built into tests/fixtures by `pnpm build-and-test`
5+
# (and by CI on every run) so we don't track it.
6+
tests/fixtures/*.so
7+
tests/fixtures/*-keypair.json

tokens/token-extensions/transfer-hook/block-list/pinocchio/package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,21 @@
88
},
99
"scripts": {
1010
"generate-sdks": "pnpx tsx codama.ts",
11-
"test": "mocha --import=tsx ./tests/test.spec.ts"
11+
"test": "node ./tests/run-mocha-with-retry.mjs",
12+
"build-and-test": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./tests/fixtures && pnpm test",
13+
"build": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so"
1214
},
1315
"dependencies": {
1416
"@codama/renderers": "^1.0.19",
17+
"@solana/spl-token": "^0.4.13",
18+
"@solana/web3.js": "^1.98.4",
19+
"@types/chai": "^4.3.20",
1520
"@types/mocha": "^10.0.10",
21+
"chai": "^4.3.10",
1622
"codama": "^1.2.11",
17-
"litesvm": "^0.2.0",
23+
"litesvm": "^0.3.0",
1824
"mocha": "^11.1.0",
19-
"solana-bankrun": "^0.4.0",
25+
"ts-mocha": "^11.1.0",
2026
"tsx": "^4.19.3"
2127
},
2228
"devDependencies": {

0 commit comments

Comments
 (0)