Skip to content

fix(block-list/pinocchio): add missing test harness#27

Merged
mikemaccana merged 1 commit into
quicknode:mainfrom
mikemaccana-edwardbot:fix/block-list-pinocchio-add-tests
May 15, 2026
Merged

fix(block-list/pinocchio): add missing test harness#27
mikemaccana merged 1 commit into
quicknode:mainfrom
mikemaccana-edwardbot:fix/block-list-pinocchio-add-tests

Conversation

@mikemaccana-edwardbot
Copy link
Copy Markdown

@mikemaccana-edwardbot mikemaccana-edwardbot commented May 14, 2026

What

Adds the missing test harness for tokens/token-extensions/transfer-hook/block-list/pinocchio and fixes the program bugs the tests surfaced.

Background

The project was introduced via solana-developers/program-examples#398 (July 2025) with a program, SDK, and a package.json test script that pointed at ./tests/test.spec.ts — but the test file itself was never written. It has been a scaffold without tests since day one.

This is the same project that surfaced as a CI failure when #23 (CI logic fix) and #24 (quasar-spl pin) ran the full matrix. The block-list pinocchio job failed because there was nothing to install or run. This PR makes it a real first-class example.

What's in the diff

  • tests/test.spec.ts (litesvm + mocha, 443 lines) covers the full lifecycle: init config PDA → create Token Extensions mint with TransferHooksetup_extra_metas → ATA creation + mint → transfer succeeds when source isn't blocked → block_wallet → transfer fails with AccountBlockedunblock_wallet → transfer succeeds again. 7 passing tests.
  • tests/run-mocha-with-retry.mjs — CI test entry point. litesvm's prebuilt native binding intermittently aborts with std::bad_alloc (SIGABRT) inside the .node addon when Token Extensions invokes the hook. The crash is in the binding, not our program; a fresh Node process avoids it. The wrapper retries until a clean run (or hits the retry budget) and bails on non-bad_alloc failures.
  • tests/tsconfig.test.json.
  • Regenerated pnpm-lock.yaml.

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

@mikemaccana-edwardbot mikemaccana-edwardbot force-pushed the fix/block-list-pinocchio-add-tests branch 2 times, most recently from 74fa0b5 to 51ac3e3 Compare May 15, 2026 03:17
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
- solana-developers#18 (removed duplicate `pino/` subtree)
- solana-developers#19 (moved program into `pinocchio/` subdir)
- solana-developers#20 (renamed `pblock-list` -> `block-list`)
- solana-developers#23 (CI logic fix that exposed missing tests)
- solana-developers#24 (quasar-spl regression fix)

This PR makes block-list/pinocchio a real first-class example with
passing tests for the first time.
@mikemaccana-edwardbot mikemaccana-edwardbot force-pushed the fix/block-list-pinocchio-add-tests branch from 51ac3e3 to 77ded28 Compare May 15, 2026 03:19
@mikemaccana mikemaccana merged commit 765f79c into quicknode:main May 15, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants