test: consolidate test transaction creation#538
test: consolidate test transaction creation#538xdustinface wants to merge 1 commit intov0.42-devfrom
Conversation
📝 WalkthroughWalkthroughTests across the wallet repo replace bespoke local transaction builders with a shared dummy/address-based approach: tests now use Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v0.42-dev #538 +/- ##
=============================================
- Coverage 66.89% 66.84% -0.05%
=============================================
Files 313 313
Lines 64753 64724 -29
=============================================
- Hits 43317 43267 -50
- Misses 21436 21457 +21
*This pull request uses carry forward flags. Click here to find out more.
🚀 New features to boost your workflow:
|
- Add `Transaction::empty()` for creating transactions with no inputs/outputs, replacing the private `create_test_transaction()` in `transaction_record.rs` - Remove `create_transaction_to_address` from `key-wallet/src/test_utils/wallet.rs` and replace all call sites in `wallet_checker` tests with `Transaction::dummy` - Remove `create_test_transaction` from router test helpers and replace all call sites across all router test files with `Transaction::dummy` - Add `test_addr()` helper in router test helpers to reduce verbosity
0c394c7 to
0077e89
Compare
helpers::create_test_transaction()There was a problem hiding this comment.
🧹 Nitpick comments (2)
key-wallet/src/transaction_checking/transaction_router/tests/helpers.rs (1)
9-10: Parameterize the test network instead of hardcodingRegtest.
test_addr()is shared across router tests; making the network explicit avoids accidental cross-network coupling as tests evolve.♻️ Proposed refactor
-pub fn test_addr() -> Address { - Address::dummy(Network::Regtest, 0) +pub fn test_addr(network: Network) -> Address { + Address::dummy(network, 0) }As per coding guidelines,
**/*.rs: Never hardcode network parameters, addresses, or keys in Rust code.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@key-wallet/src/transaction_checking/transaction_router/tests/helpers.rs` around lines 9 - 10, The helper test_addr currently hardcodes Network::Regtest via Address::dummy(Network::Regtest, 0); change test_addr to accept a Network parameter (e.g., fn test_addr(network: Network) -> Address) or provide an overload that takes Network and use Address::dummy(network, 0) so callers pass the intended network; update all test callers of test_addr to supply the appropriate Network to avoid implicit Regtest coupling.key-wallet/src/transaction_checking/transaction_router/tests/provider.rs (1)
176-226: Extract a shared ProRegTx builder to remove repeated literals.These blocks are structurally near-identical; a small helper would reduce maintenance drift and keep each test focused on the one varying field.
Also applies to: 312-362, 449-499, 648-703
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@key-wallet/src/transaction_checking/transaction_router/tests/provider.rs` around lines 176 - 226, Extract a reusable helper that constructs the Transaction with a ProviderRegistrationPayload to eliminate repeated literals (e.g., create a function like build_provider_registration_tx or pro_reg_tx_builder that returns dashcore::Transaction or ProviderRegistrationPayload), moving repeated fields such as version, masternode_type, collateral_outpoint, default service_address, owner_key_hash/voting_key_hash derivation, operator_public_key conversion, operator_reward, script_payout, inputs_hash, and default signature into that helper; update tests at the referenced blocks to call this helper and only override the varying field(s) (for example service_address, operator_public_key, signature) when needed so Tx construction code in tests (the Transaction and TransactionPayload::ProviderRegistrationPayloadType usage) is centralized and consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@key-wallet/src/transaction_checking/transaction_router/tests/helpers.rs`:
- Around line 9-10: The helper test_addr currently hardcodes Network::Regtest
via Address::dummy(Network::Regtest, 0); change test_addr to accept a Network
parameter (e.g., fn test_addr(network: Network) -> Address) or provide an
overload that takes Network and use Address::dummy(network, 0) so callers pass
the intended network; update all test callers of test_addr to supply the
appropriate Network to avoid implicit Regtest coupling.
In `@key-wallet/src/transaction_checking/transaction_router/tests/provider.rs`:
- Around line 176-226: Extract a reusable helper that constructs the Transaction
with a ProviderRegistrationPayload to eliminate repeated literals (e.g., create
a function like build_provider_registration_tx or pro_reg_tx_builder that
returns dashcore::Transaction or ProviderRegistrationPayload), moving repeated
fields such as version, masternode_type, collateral_outpoint, default
service_address, owner_key_hash/voting_key_hash derivation, operator_public_key
conversion, operator_reward, script_payout, inputs_hash, and default signature
into that helper; update tests at the referenced blocks to call this helper and
only override the varying field(s) (for example service_address,
operator_public_key, signature) when needed so Tx construction code in tests
(the Transaction and TransactionPayload::ProviderRegistrationPayloadType usage)
is centralized and consistent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 03af26d0-d470-4956-a3a1-cf041eb2bacf
📒 Files selected for processing (12)
dash/src/test_utils/transaction.rskey-wallet/src/managed_account/transaction_record.rskey-wallet/src/transaction_checking/transaction_router/tests/asset_unlock.rskey-wallet/src/transaction_checking/transaction_router/tests/classification.rskey-wallet/src/transaction_checking/transaction_router/tests/coinbase.rskey-wallet/src/transaction_checking/transaction_router/tests/coinjoin.rskey-wallet/src/transaction_checking/transaction_router/tests/helpers.rskey-wallet/src/transaction_checking/transaction_router/tests/identity_transactions.rskey-wallet/src/transaction_checking/transaction_router/tests/provider.rskey-wallet/src/transaction_checking/transaction_router/tests/routing.rskey-wallet/src/transaction_checking/transaction_router/tests/standard_transactions.rskey-wallet/src/transaction_checking/wallet_checker.rs
Transaction::empty()for creating transactions with no inputs/outputs, replacing the privatecreate_test_transaction()intransaction_record.rscreate_transaction_to_addressfromkey-wallet/src/test_utils/wallet.rsand replace all call sites inwallet_checkertests withTransaction::dummycreate_test_transactionfrom router test helpers and replace all call sites across all router test files withTransaction::dummytest_addr()helper in router test helpers to reduce verbositySummary by CodeRabbit