refactor(test-loop): migrate transaction helpers to tx_* node API#15305
refactor(test-loop): migrate transaction helpers to tx_* node API#15305
Conversation
e52f932 to
2c8b3c8
Compare
- Remove do_create_account, do_delete_account, do_deploy_contract, do_call_contract from transactions.rs — replaced by the simplified tx_* API on TestLoopNode combined with NodeRunner::run_tx() - Remove test_create_delete_account (covered by test_create_and_delete_account in examples/basic.rs) - Migrate contract_distribution_simple tests to use rpc_node()/rpc_runner() by adding a dedicated RPC node to the test setup Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…e API Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… resharding.rs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ding test node.tx_delete_account() uses node.head().last_block_hash, which is the head of a single node. With shard shuffling enabled, nodes can be at different heights and the chunk producer that processes the tx might not know about that block hash yet, causing the tx to be silently dropped. Use get_shared_block_hash() instead, which picks the block at the minimum head height across all nodes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
c975956 to
7a6eaf3
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #15305 +/- ##
==========================================
- Coverage 69.30% 69.25% -0.05%
==========================================
Files 931 931
Lines 207312 207148 -164
Branches 207312 207148 -164
==========================================
- Hits 143668 143467 -201
- Misses 57725 57772 +47
+ Partials 5919 5909 -10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ntract with tx_* node API Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ode API Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
06fe160 to
9dd2d95
Compare
There was a problem hiding this comment.
Pull request overview
Refactors test-loop-tests transaction submission in tests/utilities to rely on TestLoopNode::tx_* builders plus NodeRunner::run_tx()/execute_tx(), removing duplicated transaction helper functions and updating affected tests accordingly.
Changes:
- Removes many ad-hoc tx helper functions from
utils/transactions.rs, migrating call sites toTestLoopNode/NodeRunner. - Adds
tx_deploy_global_contractandtx_use_global_contractto theTestLoopNodeAPI and updates global-contract-related tests to use them. - Refactors resharding utilities/tests to use node APIs directly and relocates the few remaining resharding-specific tx helpers into
utils/resharding.rs.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test-loop-tests/src/utils/transactions.rs | Deletes legacy tx helper functions; keeps shared query/tx-status helpers used across tests. |
| test-loop-tests/src/utils/resharding.rs | Migrates transfer submission to TestLoopNode; inlines resharding-only tx tracking helpers. |
| test-loop-tests/src/utils/node.rs | Extends node tx builder API with global-contract deploy/use helpers. |
| test-loop-tests/src/tests/resharding_v3.rs | Switches setup txs to node API and adds a local create_account helper. |
| test-loop-tests/src/tests/global_contracts_distribution.rs | Migrates global contract distribution tests to node tx API + runners. |
| test-loop-tests/src/tests/create_delete_account.rs | Removes the old create/delete flow test, leaving the instant DeleteAccount receipt test. |
| test-loop-tests/src/tests/contract_distribution_simple.rs | Updates contract distribution tests to use a dedicated RPC node and node tx API. |
| test-loop-tests/src/tests/contract_distribution_cross_shard.rs | Updates cross-shard contract distribution test to node tx API. |
| test-loop-tests/src/tests/congestion_control.rs | Updates congestion control tests to use node tx API and node runners. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let anchor_hash = get_anchor_hash(&clients); | ||
| let nonce = get_next_nonce(&test_loop_data, &node_datas, &sender); | ||
| let node = TestLoopNode { | ||
| data: test_loop_data, | ||
| node_data: get_node_data(node_datas, &client_account_id), | ||
| }; | ||
| let nonce = node.get_next_nonce(&sender); | ||
| let amount = Balance::from_near(1).checked_mul(rng.gen_range(1..=10)).unwrap(); |
There was a problem hiding this comment.
tx_send_money() uses self.head().last_block_hash as the anchor hash. In this module you already note (later) that using a single node’s head can break when shard shuffling causes nodes to be at different heights (the chunk producer may not know that block yet). Consider building transfer txs using get_shared_block_hash(node_datas, test_loop_data) (or a shared-head helper) instead of the local head, at least for resharding/shard-shuffling loop actions.
| SignedTransaction::deploy_global_contract( | ||
| self.get_next_nonce(deployer_id), | ||
| deployer_id.clone(), | ||
| code, | ||
| &create_user_test_signer(deployer_id), | ||
| self.head().last_block_hash, | ||
| deploy_mode, | ||
| ) |
There was a problem hiding this comment.
tx_deploy_global_contract anchors the tx to self.head().last_block_hash. Previously the test-loop transaction helpers used a shared/minimum head hash across nodes to ensure every node (including the chunk producer) recognizes the referenced block, which matters when nodes are at different heights (e.g. with shard shuffling). Consider adding an API that accepts an explicit block_hash or otherwise uses a shared block hash for building these txs.
| SignedTransaction::use_global_contract( | ||
| self.get_next_nonce(user_id), | ||
| user_id, | ||
| &create_user_test_signer(user_id), | ||
| self.head().last_block_hash, | ||
| identifier, | ||
| ) |
There was a problem hiding this comment.
Same anchoring concern as tx_deploy_global_contract: tx_use_global_contract uses self.head().last_block_hash. In shard-shuffling / multi-node setups this can produce txs referencing a block unknown to the node that ends up processing the tx. Consider allowing callers to pass a shared block hash (or providing a *_with_block_hash variant).
| let tx = SignedTransaction::create_account( | ||
| nonce, | ||
| originator.clone(), | ||
| new_account_id.clone(), | ||
| amount, | ||
| new_signer.public_key(), | ||
| &signer, | ||
| node.head().last_block_hash, | ||
| ); |
There was a problem hiding this comment.
This helper now anchors the create-account tx to node.head().last_block_hash. The old helper in utils/transactions.rs used get_shared_block_hash(...) to avoid referencing a block that some nodes (or the eventual chunk producer) may not have yet when shard shuffling causes height skew. Consider switching back to get_shared_block_hash(&env.node_datas, &env.test_loop.data) (or passing an explicit anchor hash) to preserve the previous, more robust behavior.
9dd2d95 to
d68752b
Compare
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
d68752b to
a5cea57
Compare
darioush
left a comment
There was a problem hiding this comment.
nice cleanup, leaving some suggestions
| use crate::utils::get_node_head_height; | ||
| use crate::utils::transactions::{call_contract, check_txs, deploy_contract, make_accounts}; | ||
| use crate::utils::transactions::{check_txs, make_accounts}; | ||
| use near_primitives::gas::Gas; |
There was a problem hiding this comment.
nit: import group ordering, seems should be merged with above group which has near_primitives
Separately, it would be great to have a linter for this, to avoid spending time on formatting in code review. Let me create an issue: #15329
| let tx = env.rpc_node().tx_delete_account(&contract_id, &beneficiary); | ||
| env.rpc_runner().run_tx(tx, Duration::seconds(5)); |
There was a problem hiding this comment.
Looking at this and other tests, I wonder if the distinction of runner and node is useful from the client perspective?
There was a problem hiding this comment.
node doesn't require mutable reference to TestLoopData, so there can be multiple instances and it can be derived from &TestLoopEnv.
do you think it would be worthwhile to merge everything into single node api?
There was a problem hiding this comment.
also see our previous related discussion here
There was a problem hiding this comment.
another important consideration: NodeRunner::run_until condition operates on node instance, so it would be hard to merge those together
There was a problem hiding this comment.
It is already a great improvement, we can keep it for now. The mut reference problem seems worse.
| near_primitives::test_utils::create_user_test_signer(&temporary_account_id); | ||
| let nonce = node.get_next_nonce(&temporary_account_id); | ||
| let block_hash = get_shared_block_hash(node_datas, test_loop_data); | ||
| let tx = near_primitives::transaction::SignedTransaction::delete_account( |
There was a problem hiding this comment.
sorry for that, claude refuses to comply with CLAUDE.md instructions 😞
There was a problem hiding this comment.
yeah, I noticed it too. probably we need some script.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This is follow-up to #15296.