Skip to content

test: consolidate test transaction creation#538

Open
xdustinface wants to merge 1 commit intov0.42-devfrom
test/create-transaction
Open

test: consolidate test transaction creation#538
xdustinface wants to merge 1 commit intov0.42-devfrom
test/create-transaction

Conversation

@xdustinface
Copy link
Collaborator

@xdustinface xdustinface commented Mar 15, 2026

  • 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

Summary by CodeRabbit

  • Tests
    • Consolidated and simplified transaction test setup across multiple test suites for improved maintainability.
    • Switched tests to use a shared dummy-transaction and dummy-address approach, and added an empty-transaction constructor used in tests.
    • Removed several local bespoke test helpers in favor of the unified helpers to reduce boilerplate.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 15, 2026

📝 Walkthrough

Walkthrough

Tests across the wallet repo replace bespoke local transaction builders with a shared dummy/address-based approach: tests now use test_addr() and Transaction::dummy(...); helpers remove create_test_transaction; a small test utility Transaction::empty() was added in dash test utils.

Changes

Cohort / File(s) Summary
Transaction router tests
key-wallet/src/transaction_checking/transaction_router/tests/coinbase.rs, .../classification.rs, .../coinjoin.rs, .../asset_unlock.rs, .../identity_transactions.rs, .../routing.rs, .../provider.rs, .../standard_transactions.rs, .../transaction_router/tests/*.rs
Removed local create_basic_transaction/create_test_transaction helpers and in-test manual Transaction builds. Tests now import test_addr() and use dashcore::blockdata::transaction::Transaction::dummy(&addr, 0..N, &[..]) to construct transactions; imports cleaned up accordingly.
Helpers (tests)
key-wallet/src/transaction_checking/transaction_router/tests/helpers.rs
Removed create_test_transaction; added pub fn test_addr() -> Address; updated helper functions (e.g., create_asset_lock_transaction) to use Transaction::dummy and to set credit outputs using addr.script_pubkey().
Managed account tests
key-wallet/src/managed_account/transaction_record.rs
Replaced local synthetic transaction helper with Transaction::empty() where appropriate in tests; removed the old helper.
Wallet checker tests
key-wallet/src/transaction_checking/wallet_checker.rs
Removed create_transaction_to_address test helper and switched tests to use Transaction::dummy(&address, 0..1, &[amount]).
Dash test utils
dash/src/test_utils/transaction.rs
Added pub fn empty() -> Transaction to create a minimal empty Transaction for tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I nibble code with careful paws,

Test hops now follow simpler laws.
One little addr, a dummy or two,
Cleaner tests — a carrot stew.
Hop, hop, compile; the CI applauds! 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The title 'test: consolidate test transaction creation' accurately summarizes the main objective of consolidating duplicated test transaction helpers into a shared approach, though it generalizes the specific mechanisms.

✏️ 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/create-transaction
📝 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.

@codecov
Copy link

codecov bot commented Mar 15, 2026

Codecov Report

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

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     
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.56% <ø> (-0.09%) ⬇️ Carriedforward from b946271
key-wallet-ffi 34.76% <ø> (ø) Carriedforward from b946271
key-wallet-manager 65.56% <ø> (-0.09%) ⬇️ Carriedforward from b946271
rpc 19.92% <ø> (ø)
spv 81.01% <ø> (-0.08%) ⬇️
wallet 65.61% <100.00%> (-0.07%) ⬇️

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

Files with missing lines Coverage Δ
...y-wallet/src/managed_account/transaction_record.rs 100.00% <100.00%> (ø)
...-wallet/src/transaction_checking/wallet_checker.rs 93.87% <100.00%> (-0.25%) ⬇️

... and 16 files with indirect coverage changes

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

- 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
@xdustinface xdustinface force-pushed the test/create-transaction branch from 0c394c7 to 0077e89 Compare March 15, 2026 08:08
@xdustinface xdustinface changed the title test: more use of helpers::create_test_transaction() test: consolidate test transaction creation 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.

🧹 Nitpick comments (2)
key-wallet/src/transaction_checking/transaction_router/tests/helpers.rs (1)

9-10: Parameterize the test network instead of hardcoding Regtest.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0c394c7 and 0077e89.

📒 Files selected for processing (12)
  • dash/src/test_utils/transaction.rs
  • key-wallet/src/managed_account/transaction_record.rs
  • key-wallet/src/transaction_checking/transaction_router/tests/asset_unlock.rs
  • key-wallet/src/transaction_checking/transaction_router/tests/classification.rs
  • key-wallet/src/transaction_checking/transaction_router/tests/coinbase.rs
  • key-wallet/src/transaction_checking/transaction_router/tests/coinjoin.rs
  • key-wallet/src/transaction_checking/transaction_router/tests/helpers.rs
  • key-wallet/src/transaction_checking/transaction_router/tests/identity_transactions.rs
  • key-wallet/src/transaction_checking/transaction_router/tests/provider.rs
  • key-wallet/src/transaction_checking/transaction_router/tests/routing.rs
  • key-wallet/src/transaction_checking/transaction_router/tests/standard_transactions.rs
  • key-wallet/src/transaction_checking/wallet_checker.rs

@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