Skip to content

test: extract wallet setup into TestWalletContext#539

Open
xdustinface wants to merge 1 commit intov0.42-devfrom
test/wallet-context
Open

test: extract wallet setup into TestWalletContext#539
xdustinface wants to merge 1 commit intov0.42-devfrom
test/wallet-context

Conversation

@xdustinface
Copy link
Collaborator

@xdustinface xdustinface commented Mar 15, 2026

Add TestWalletContext struct to test_utils::wallet providing a pre-built testnet wallet with BIP44 account, receive address, and xpub. Replace duplicated wallet setup code across wallet_checker, routing, coinbase, and asset_unlock test modules.

Summary by CodeRabbit

  • Tests
    • Enhanced test infrastructure with improved wallet setup utilities to support more consistent and maintainable testing across transaction validation modules.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 15, 2026

📝 Walkthrough

Walkthrough

A new TestWalletContext utility struct is introduced in the test utilities module to consolidate wallet initialization and address derivation. Multiple test files are refactored to use this shared utility instead of manually creating wallets, managed wallet info, and deriving addresses individually.

Changes

Cohort / File(s) Summary
Test Utilities Infrastructure
key-wallet/src/test_utils/mod.rs, key-wallet/src/test_utils/wallet.rs
Introduces new TestWalletContext struct with managed_wallet, wallet, receive_address, and xpub fields, plus new_random() constructor that initializes a testnet wallet with address derivation. Public re-export added to module.
Asset Unlock Tests
key-wallet/src/transaction_checking/transaction_router/tests/asset_unlock.rs
Refactors test setup to use TestWalletContext::new_random(), replacing manual Wallet creation and address derivation with context-provided values.
Coinbase Tests
key-wallet/src/transaction_checking/transaction_router/tests/coinbase.rs
Consolidates multiple coinbase test cases to use shared TestWalletContext for wallet and address setup, eliminating per-test wallet initialization and reducing direct wallet/account manipulation.
Routing Tests
key-wallet/src/transaction_checking/transaction_router/tests/routing.rs
Replaces manual BIP44 setup with TestWalletContext::new_random() to simplify wallet initialization and address derivation.
Wallet Checker Tests
key-wallet/src/transaction_checking/wallet_checker.rs
Refactors numerous test cases across multiple scenarios (coinbase, spend detection, mempool) to use TestWalletContext for standardized wallet and address setup, removing redundant initialization logic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A context born from test dust fine,
No more addresses to derive or design!
Five tests now dance in harmony,
With wallet magic, tested spree—
Refactored paths, at last they shine! 🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: extracting wallet setup logic into a new TestWalletContext struct for reuse across tests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/wallet-context
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@xdustinface xdustinface changed the title refactor: extract wallet setup into TestWalletContext test: extract wallet setup into TestWalletContext Mar 15, 2026
@codecov
Copy link

codecov bot commented Mar 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.85%. Comparing base (b946271) to head (c9e13c1).

Additional details and impacted files
@@              Coverage Diff              @@
##           v0.42-dev     #539      +/-   ##
=============================================
- Coverage      66.89%   66.85%   -0.05%     
=============================================
  Files            313      313              
  Lines          64753    64701      -52     
=============================================
- Hits           43317    43254      -63     
- Misses         21436    21447      +11     
Flag Coverage Δ *Carryforward flag
core 75.02% <ø> (ø)
dash-network 75.00% <ø> (ø) Carriedforward from b946271
dash-network-ffi 34.76% <ø> (ø) Carriedforward from b946271
dash-spv 68.26% <ø> (ø) Carriedforward from b946271
dash-spv-ffi 34.76% <ø> (ø) Carriedforward from b946271
dashcore 75.00% <ø> (ø) Carriedforward from b946271
dashcore-private 75.00% <ø> (ø) Carriedforward from b946271
dashcore-rpc 19.92% <ø> (ø) Carriedforward from b946271
dashcore-rpc-json 19.92% <ø> (ø) Carriedforward from b946271
dashcore_hashes 75.00% <ø> (ø) Carriedforward from b946271
ffi 37.14% <ø> (+0.54%) ⬆️
key-wallet 65.49% <ø> (-0.16%) ⬇️ Carriedforward from b946271
key-wallet-ffi 34.76% <ø> (ø) Carriedforward from b946271
key-wallet-manager 65.49% <ø> (-0.16%) ⬇️ Carriedforward from b946271
rpc 19.92% <ø> (ø)
spv 81.09% <ø> (+<0.01%) ⬆️
wallet 65.57% <100.00%> (-0.11%) ⬇️

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
...-wallet/src/transaction_checking/wallet_checker.rs 93.44% <100.00%> (-0.67%) ⬇️

... and 17 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xdustinface xdustinface force-pushed the test/create-transaction branch from 0c394c7 to 0077e89 Compare March 15, 2026 08:08
@github-actions github-actions bot added the merge-conflict The PR conflicts with the target branch. label Mar 15, 2026
@github-actions
Copy link

This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them.

Add `TestWalletContext` struct to `test_utils::wallet` providing a
pre-built testnet wallet with BIP44 account, receive address, and xpub.
Replace duplicated wallet setup code across `wallet_checker`, `routing`,
`coinbase`, and `asset_unlock` test modules.
@xdustinface xdustinface force-pushed the test/wallet-context branch from f60fae9 to c9e13c1 Compare March 15, 2026 08:12
@xdustinface xdustinface changed the base branch from test/create-transaction to v0.42-dev March 15, 2026 08:17
@xdustinface xdustinface marked this pull request as ready for review March 15, 2026 08:17
@xdustinface xdustinface reopened this Mar 15, 2026
@github-actions github-actions bot removed the merge-conflict The PR conflicts with the target branch. label Mar 15, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
key-wallet/src/test_utils/wallet.rs (1)

24-44: Make this helper's BIP44-only contract explicit.

new_random() hardcodes WalletAccountCreationOptions::Default and then immediately binds to standard_bip44_accounts.get(&0), so this is not a general wallet fixture. That ambiguity already let test_asset_unlock_routing_to_bip32_account switch to a BIP44 address. A more specific name, or separate builders for BIP44/BIP32/CoinJoin contexts, would make that kind of coverage loss much harder to introduce.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@key-wallet/src/test_utils/wallet.rs` around lines 24 - 44, The helper
TestWalletContext::new_random() currently creates a wallet with
WalletAccountCreationOptions::Default and immediately uses
standard_bip44_accounts.get(&0), implying it is BIP44-only; rename or split it
to make that explicit (e.g., new_random_bip44) or add an explicit parameter for
WalletAccountCreationOptions so callers request BIP44 vs BIP32/CoinJoin, and
update the function body to assert/use the chosen option (references:
TestWalletContext::new_random, WalletAccountCreationOptions::Default,
standard_bip44_accounts.get(&0), ManagedWalletInfo::from_wallet_with_name,
first_bip44_managed_account_mut); ensure tests adjust to call the new
BIP44-specific helper or pass the BIP44 option.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@key-wallet/src/transaction_checking/transaction_router/tests/asset_unlock.rs`:
- Around line 141-146: The test no longer covers BIP32 because it calls
TestWalletContext::new_random() which provisions a BIP44 receive address and the
assertion expects AccountTypeToCheck::StandardBIP44; restore explicit BIP32
setup by replacing the new_random() call with a helper that provisions a BIP32
receive address (or extend TestWalletContext to expose a BIP32 address), ensure
the test variables (managed_wallet_info, wallet, receive_address) refer to that
BIP32 account, and update the later assertion in
test_asset_unlock_routing_to_bip32_account to expect the BIP32
AccountTypeToCheck variant instead of StandardBIP44.

---

Nitpick comments:
In `@key-wallet/src/test_utils/wallet.rs`:
- Around line 24-44: The helper TestWalletContext::new_random() currently
creates a wallet with WalletAccountCreationOptions::Default and immediately uses
standard_bip44_accounts.get(&0), implying it is BIP44-only; rename or split it
to make that explicit (e.g., new_random_bip44) or add an explicit parameter for
WalletAccountCreationOptions so callers request BIP44 vs BIP32/CoinJoin, and
update the function body to assert/use the chosen option (references:
TestWalletContext::new_random, WalletAccountCreationOptions::Default,
standard_bip44_accounts.get(&0), ManagedWalletInfo::from_wallet_with_name,
first_bip44_managed_account_mut); ensure tests adjust to call the new
BIP44-specific helper or pass the BIP44 option.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 995f992f-ca10-43c9-8c78-5b86b489ea82

📥 Commits

Reviewing files that changed from the base of the PR and between b946271 and c9e13c1.

📒 Files selected for processing (6)
  • key-wallet/src/test_utils/mod.rs
  • key-wallet/src/test_utils/wallet.rs
  • key-wallet/src/transaction_checking/transaction_router/tests/asset_unlock.rs
  • key-wallet/src/transaction_checking/transaction_router/tests/coinbase.rs
  • key-wallet/src/transaction_checking/transaction_router/tests/routing.rs
  • key-wallet/src/transaction_checking/wallet_checker.rs

@xdustinface xdustinface reopened this Mar 15, 2026
@xdustinface xdustinface requested a review from ZocoLini March 15, 2026 09:33
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.

1 participant