Skip to content

test(minter): replace the stubbed runtime with a mockall mock of inter-canister calls - #238

Draft
gregorydemay wants to merge 4 commits into
mainfrom
refactor/mock-runtime
Draft

gregorydemay wants to merge 4 commits into
mainfrom
refactor/mock-runtime

Conversation

@gregorydemay

@gregorydemay gregorydemay commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

TestCanisterRuntime answered inter-canister calls with a StubRuntime: an ordered queue of Candid-encoded responses that ignored which method was called and with which arguments. To assert what was sent, the mint tests additionally wrapped it in a RecordingStubRuntime and compared the recorded arguments after the fact.

Both are replaced by a mockall mock. Every test registers the calls it expects upfront, stating the canister, the method, the arguments, the attached cycles and the response — e.g. which signature a getTransaction call queries, which address a getBalance call reads, or the full icrc1_transfer arguments of a pending mint, including the created_at_time the ledger deduplicates retries on. A sendTransaction expectation matches the submitted transaction by its first signature, i.e. by the fee payer's signature. Each expectation answers exactly one matching call: a call without a matching expectation and an expectation that goes unused both fail the test, which already uncovered one test that queued a recent block the code under test never fetches.

The mockall mock is written against a Candid-erased copy of the Runtime trait because mockall cannot mock its generic methods directly (expectations need 'static generic parameters, which the trait does not require). Failure messages still print the arguments as readable Candid text. The builder style of TestCanisterRuntime (add_recent_block, transaction_builder, ...) is kept, so tests keep reading as a list of expected calls.

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings October 2, 2026 14:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The test-only migration is internally consistent and adds strict verification without identified regressions.

Review effort: Balanced
Findings: None

What changed in this PR

Replaces queue-based inter-canister stubs with argument-aware mockall expectations, making minter tests validate canisters, methods, arguments, cycles, and call counts.

Changes:

  • Adds a Candid-erased mock implementation of Runtime.
  • Migrates RPC and ledger tests to explicit call expectations.
  • Adds tests for matched, unexpected, and unused expectations.
File Description
minter/​src/​test_fixtures/​runtime.rs Implements inter-canister call mocking and expectation builders.
minter/​src/​test_fixtures/​tests.rs Tests expectation matching and failure behavior.
minter/​src/​test_fixtures/​mod.rs Updates fixture terminology.
minter/​src/​withdraw/​tests.rs Validates withdrawal ledger and RPC calls.
minter/​src/​rpc/​tests.rs Validates RPC arguments and submitted signatures.
minter/​src/​monitor/​tests.rs Adds exact status-check and resubmission expectations.
minter/​src/​deposit/​sweep/​timer/​tests.rs Validates failed sweep submission calls.
minter/​src/​deposit/​sweep/​tests.rs Validates deposit-address balance queries.
minter/​src/​deposit/​sweep/​finalize/​tests.rs Validates transaction lookup signatures.
minter/​src/​deposit/​manual/​tests.rs Validates transaction lookups and ledger mint arguments.
minter/​src/​consolidate/​tests.rs Migrates consolidation tests to transaction expectations.
minter/​Cargo.toml Adds the test-only async trait dependency.
Cargo.lock Records the minter dependency update.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI balanced review requested due to automatic review settings October 2, 2026 14:33
@gregorydemay
gregorydemay force-pushed the refactor/mock-runtime branch from 5018b47 to 54f231e Compare October 2, 2026 14:33
@gregorydemay
gregorydemay changed the base branch from main to refactor/remove-process-deposit October 2, 2026 14:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The mock replacement is coherent, comprehensively exercised, and all migrated tests use expectations consistent with production call construction.

Review effort: Balanced
Findings: None

@gregorydemay
gregorydemay force-pushed the refactor/remove-process-deposit branch from 0ada0d1 to c892b3a Compare October 5, 2026 08:37
@gregorydemay
gregorydemay force-pushed the refactor/remove-process-deposit branch from c892b3a to 1df12a5 Compare October 5, 2026 09:49
@gregorydemay
gregorydemay force-pushed the refactor/mock-runtime branch from 54f231e to f13d4dd Compare October 5, 2026 09:53
@gregorydemay
gregorydemay force-pushed the refactor/remove-process-deposit branch from 1df12a5 to 71a59cf Compare October 6, 2026 07:36
Base automatically changed from refactor/remove-process-deposit to main October 6, 2026 10:11
Copilot AI balanced review requested due to automatic review settings October 6, 2026 11:21
@gregorydemay
gregorydemay force-pushed the refactor/mock-runtime branch from f13d4dd to 91e9b86 Compare October 6, 2026 11:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The mock migration is consistent across affected tests and introduces strict validation without identified unresolved issues.

Review effort: Balanced
Findings: None

…r-canister calls

TestCanisterRuntime answered inter-canister calls from an ordered queue of
Candid-encoded responses that ignored the arguments of a call. Back it by a
mockall mock instead: every test now registers the calls it expects, stating
the canister, the method, the arguments, the attached cycles and the response.
A call without a matching expectation and an expectation that goes unused both
fail the test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 6, 2026 13:19
@gregorydemay
gregorydemay force-pushed the refactor/mock-runtime branch from 91e9b86 to 7660386 Compare October 6, 2026 13:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The test-only migration is coherent, complete, and preserves behavior while strengthening call validation.

Review effort: Balanced
Findings: None

@gregorydemay
gregorydemay marked this pull request as ready for review October 7, 2026 09:16
@gregorydemay
gregorydemay requested a review from a team as a code owner October 7, 2026 09:16
@zeropath-ai

zeropath-ai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

✅ No security or compliance issues detected. Reviewed everything up to d5208e0.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► minter/src/deposit/sweep/finalize/tests.rs
       Improve test stubs and expectations for transactions and balances
► minter/src/deposit/sweep/mint/tests.rs
       Adjust minting tests to use richer runtime expectations and balance checks
► minter/src/deposit/sweep/tests.rs
       Enhance deposit sweep tests with updated balance reads and address handling
► minter/src/deposit/sweep/timer/tests.rs
       Update timer tests to expect specific transaction behavior
► minter/src/monitor/tests.rs
       Refactor to use explicit expectations for balance/transaction status checks
► minter/src/rpc/tests.rs
       Update RPC tests to use explicit get_balance/get_transaction expectations and remove some stub responses
► minter/src/rpc/tests.rs
       Improve test scaffolding for balance/transaction RPC interactions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 8, 2026 14:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The mock update calls do not yield, preventing concurrent tests from modeling inter-canister await boundaries.

1 open finding

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread minter/src/test_fixtures/runtime.rs Outdated
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 8, 2026 14:48
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gregorydemay
gregorydemay marked this pull request as draft October 8, 2026 14:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The mock replacement is consistently applied and preserves asynchronous call behavior while strengthening request verification.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Copilot AI balanced review requested due to automatic review settings October 8, 2026 14:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The test-only refactor consistently replaces ordered stubs with precise expectations and preserves asynchronous call behavior.

0 open findings

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

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