Skip to content

test: add descriptive stub helpers to TestCanisterRuntime#188

Draft
lpahlavi wants to merge 1 commit intomainfrom
lpahlavi/defi-2780-test-runtime-stub-helpers
Draft

test: add descriptive stub helpers to TestCanisterRuntime#188
lpahlavi wants to merge 1 commit intomainfrom
lpahlavi/defi-2780-test-runtime-stub-helpers

Conversation

@lpahlavi
Copy link
Copy Markdown
Contributor

Summary

  • Replaces the DepositRuntimeExt trait with direct methods on TestCanisterRuntime, one per RPC/ledger call type
  • Each method has a doc comment identifying the call it stubs (e.g. /// Stubs the next \getTransaction` JSON-RPC call...`)
  • Adds helpers: add_get_transaction_response, add_get_transaction_not_found, add_n_get_transaction_not_found, add_get_signatures_for_address_response, add_get_signatures_for_address_error, add_get_slot_response, add_get_slot_error, add_n_get_slot_error, add_get_block_response, add_send_transaction_response, add_get_signature_statuses_response, add_get_signature_statuses_error, add_icrc1_transfer_response, add_icrc2_transfer_from_response
  • Updates withdraw/tests.rs, consolidate/tests.rs, monitor/tests.rs, and deposit/manual/tests.rs to use these helpers, eliminating MultiRpcResult::Consistent(Ok(...)) boilerplate and local type aliases

Test plan

  • cargo test -p cksol_minter passes (164 tests)
  • No new warnings

🤖 Generated with Claude Code

Replaces the DepositRuntimeExt trait with direct methods on
TestCanisterRuntime, and adds stub helpers for all RPC and ledger calls:
getTransaction, getSignaturesForAddress, getSlot, getBlock,
sendTransaction, getSignatureStatuses, icrc1_transfer, icrc2_transfer_from.

Each helper has a doc comment identifying the RPC call it stubs.
Updates all test files to use these methods, eliminating verbose
MultiRpcResult::Consistent(...) boilerplate and local type aliases.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 28, 2026 07:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the cksol_minter test suite to reduce Solana JSON-RPC and ledger stubbing boilerplate by introducing descriptive stub helper methods on TestCanisterRuntime.

Changes:

  • Adds per-RPC / per-ledger-call stub helper methods to TestCanisterRuntime (e.g., add_get_slot_response, add_send_transaction_response, add_icrc1_transfer_response).
  • Updates withdraw/consolidate/monitor/manual-deposit tests to use the new helpers and removes local type aliases/boilerplate.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
minter/src/test_fixtures/runtime.rs Introduces new TestCanisterRuntime helper methods for stubbing specific RPC/ledger calls.
minter/src/withdraw/tests.rs Migrates withdrawal tests to use the new runtime stub helpers.
minter/src/consolidate/tests.rs Migrates consolidation tests to use the new runtime stub helpers and removes local result aliases.
minter/src/monitor/tests.rs Migrates monitor tests to use the new runtime stub helpers and removes local result aliases.
minter/src/deposit/manual/tests.rs Removes a local extension trait and switches manual deposit tests to runtime stub helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +166 to +168
self.add_stub_response(MultiRpcResult::<ConfirmedBlock>::Consistent(Ok(block)))
}

Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

add_get_block_response currently stubs MultiRpcResult<ConfirmedBlock>, but other tests in the repo stub getBlock as MultiRpcResult<Option<ConfirmedBlock>> (e.g. minter/src/rpc/tests.rs), which suggests the underlying RPC call returns an Option. Consider changing this helper to stub MultiRpcResult<Option<ConfirmedBlock>>::Consistent(Ok(Some(block))) (and optionally add a ..._not_found helper for Ok(None)) so the helper matches the actual call type and is reusable everywhere without relying on Candid subtyping quirks.

Suggested change
self.add_stub_response(MultiRpcResult::<ConfirmedBlock>::Consistent(Ok(block)))
}
self.add_stub_response(MultiRpcResult::<Option<ConfirmedBlock>>::Consistent(
Ok(Some(block)),
))
}
/// Stubs the next `getBlock` JSON-RPC call to return no block.
pub fn add_get_block_not_found_response(self) -> Self {
self.add_stub_response(MultiRpcResult::<Option<ConfirmedBlock>>::Consistent(Ok(None)))
}

Copilot uses AI. Check for mistakes.
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