test(memorypack): mock @solana/web3.js for the on-chain verifiers - #117
Open
sebbsssss wants to merge 1 commit into
Open
test(memorypack): mock @solana/web3.js for the on-chain verifiers#117sebbsssss wants to merge 1 commit into
sebbsssss wants to merge 1 commit into
Conversation
…yRevocationAnchors
Closes the longstanding "untested with mocks" gap on the on-chain
verifier code. Both verifyChainAnchors (v0.2) and
verifyRevocationAnchors (v0.6) now have unit coverage that exercises
their full security surface without hitting a real RPC.
Mock strategy
- vi.hoisted carries mutable mock state into the vi.mock factory.
- MockConnection captures construction count, getTransaction call
count, and looks up canned tx responses by signature.
- MockPublicKey wraps a string and returns it from toBase58().
- beforeEach resets state — each test sets up its own fixture.
Coverage (23 new tests, 115 total)
Per verifier:
- Happy path: compiledInstructions (Uint8Array data)
- Happy path: legacy instructions (bs58 string data)
- Legacy memo program ID (Memo1Uhk...) accepted alongside v3
- getTransaction returning null → unverified, warning
- Tx exists but no SPL Memo instruction → unverified
- Memo bytes don't match expected → unverified
- expectedSigner not in tx signers → unverified (signer-binding)
- Cluster cross-check pass via getGenesisHash
- Cluster mismatch → all anchors rejected, no per-tx fetch
- Cluster mismatch + strict → throws
- Per-anchor failure + strict → throws on first
- Empty input → no Connection constructed
- Unsupported anchor_format → caught, warning
- Multiple anchors: partial verified set when some fail
Revocation anchors specifically:
- Memo with wrong revoked_at → unverified (timestamp pinning
verified to work as intended; producer can't backdate by
editing revocations.jsonl)
Pure helpers:
- expectedMemoForRecordHash format bound
- expectedRevocationMemo format bound
What this does NOT cover
- Versioned-tx with address-lookup-table path. Tests use legacy
accountKeys + (compiled or instructions) which is the security
surface that matters. ALT coverage is a future addition.
Public API: NO CHANGE.
Tests-only release. dist/cli.js, dist/index.js, type signatures,
and runtime behaviour are unchanged.
Version
- @clude/memorypack: 0.7.0 → 0.7.1 (patch — tests-only).
Stacked on feat/memorypack-tarball-appends (PR #116). Seventh in
the chain.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the longstanding untested-with-mocks gap on the on-chain verifier code. Both `verifyChainAnchors` (v0.2) and `verifyRevocationAnchors` (v0.6) now have unit coverage that exercises their full security surface without hitting a real RPC.
Stacked on #116. Seventh in the chain. Tests-only — no public API change.
Mock strategy
`vi.hoisted` carries mutable mock state into the `vi.mock` factory:
```ts
const { mockState } = vi.hoisted(() => ({
mockState: {
genesisHash: '...',
transactions: new Map<string, any>(),
failNextGenesis: false,
connectionCount: 0,
getTransactionCalls: 0,
},
}));
vi.mock('@solana/web3.js', () => ({
Connection: class { /* uses mockState / },
PublicKey: class { / string-wrapping shim */ },
}));
```
Each test populates canned `getTransaction` / `getGenesisHash` responses; `beforeEach` resets state.
Coverage (23 new tests, 115 total)
For both verifiers:
For revocation anchors specifically:
What this does NOT cover
Versioned-tx with address-lookup-table (ALT) path. Tests use legacy `accountKeys` + (compiled or instructions) which is the security surface that matters in the spec. ALT coverage is a future addition.
Test plan
Version
`@clude/memorypack`: 0.7.0 → 0.7.1 (patch — tests-only).
🤖 Generated with Claude Code