Uh oh!
There was an error while loading. Please reload this page.
test: consolidate test transaction creation - #538
Conversation
📝 WalkthroughWalkthroughTests were refactored to 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 Tip CodeRabbit can enforce grammar and style rules using `languagetool`.Configure the |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@## v0.42-dev #538 +/- ##
=============================================
- Coverage 66.15% 66.15% -0.01%
=============================================
Files 311 311 Lines 64710 64681 -29 =============================================
- Hits 42812 42792 -20 + Misses 21898 21889 -9
|
0c394c7 to
0077e89Comparehelpers::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
| impl Transaction { | ||
| /// Creates a transaction with no inputs or outputs. | ||
| pub fn empty() -> Transaction { |
There was a problem hiding this comment.
something like dummy_empty or empty_dummy (i dont remember right now what pattern are we following) would be better to make it clear that this is only meant for tests
This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them. |
- 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
25eb46a to
2d99c00CompareThere was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/helpers.rs`:
- Around line 9-10: The helper test_addr currently hardcodes Network::Regtest;
change its signature to accept a Network parameter (e.g., pub fn
test_addr(network: Network) -> Address) and call Address::dummy(network, 0)
instead of Address::dummy(Network::Regtest, 0), then update callers in tests to
pass the desired Network; this removes the hardcoded Network::Regtest and lets
tests choose the network via the test_addr(Network::...) call.
- Line 16: The test silently truncates `inputs` by using `inputs as u8` when
constructing the dummy transaction with `Transaction::dummy(&addr, 0..inputs as
u8, &[output_value])`; change this to a checked conversion (e.g. use
`u8::try_from(inputs)` or `inputs.try_into()`) and either panic with a clear
message via `.expect("inputs must fit in u8")` or handle values >255 (e.g. split
into multiple transactions) so that oversized `inputs` do not silently truncate
and produce the wrong transaction shape; update the call site to pass the
safely-converted `u8` into `Transaction::dummy`.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e9d1a0fb-1b75-456e-96c5-d33fd5945c3b
📒 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
🚧 Files skipped from review as they are similar to previous changes (5)
- key-wallet/src/transaction_checking/transaction_router/tests/provider.rs
- key-wallet/src/transaction_checking/wallet_checker.rs
- key-wallet/src/transaction_checking/transaction_router/tests/coinjoin.rs
- dash/src/test_utils/transaction.rs
- key-wallet/src/managed_account/transaction_record.rs
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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