test: add descriptive stub helpers to TestCanisterRuntime#188
test: add descriptive stub helpers to TestCanisterRuntime#188
Conversation
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>
There was a problem hiding this comment.
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.
| self.add_stub_response(MultiRpcResult::<ConfirmedBlock>::Consistent(Ok(block))) | ||
| } | ||
|
|
There was a problem hiding this comment.
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.
| 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))) | |
| } |
Summary
DepositRuntimeExttrait with direct methods onTestCanisterRuntime, one per RPC/ledger call type/// Stubs the next \getTransaction` JSON-RPC call...`)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_responsewithdraw/tests.rs,consolidate/tests.rs,monitor/tests.rs, anddeposit/manual/tests.rsto use these helpers, eliminatingMultiRpcResult::Consistent(Ok(...))boilerplate and local type aliasesTest plan
cargo test -p cksol_minterpasses (164 tests)🤖 Generated with Claude Code