Skip to content

Commit e4cabdd

Browse files
authored
Fix "Transaction collided" issue when running run_on_node tests (#7461)
## Description This PR fixes non-deterministic "Transaction collided" error when running `run_on_node` tests in parallel: ```console { kind: Other, error: "Response errors; Transaction collided: Transaction with the same UTXO (id: 00000000000000000000000000000000000000000000000000000000000000010000) already exists and is more worth it" } ``` The root-cause was using the same wallet to sign all transactions which could sometimes end up in race conditions on the node. The PR now uses five different wallets available on `fuel-core` local test instance and executes tests in parallel over those five wallets, ensuring only different wallets are used in parallel. ## Checklist - [ ] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [ ] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
1 parent 46e83a6 commit e4cabdd

File tree

2 files changed

+189
-79
lines changed

2 files changed

+189
-79
lines changed

test/src/e2e_vm_tests/harness.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ use futures::Future;
1919
use rand::rngs::StdRng;
2020
use rand::{Rng, SeedableRng};
2121
use regex::{Captures, Regex};
22-
use std::{fs, io::Read, path::PathBuf, str::FromStr};
22+
use std::{fs, io::Read, path::PathBuf};
2323
use sway_core::{asm_generation::ProgramABI, BuildTarget, Observer};
2424

2525
pub const NODE_URL: &str = "http://127.0.0.1:4000";
26-
pub const SECRET_KEY: &str = "de97d8624a438121b86a1956544bd72ed68cd69f2c99555b08b1e8c51ffd511c";
2726

2827
pub(crate) async fn run_and_capture_output<F, Fut, T>(func: F) -> (T, String)
2928
where
@@ -61,10 +60,14 @@ where
6160
(result, output)
6261
}
6362

64-
pub(crate) async fn deploy_contract(file_name: &str, run_config: &RunConfig) -> Result<ContractId> {
65-
// build the contract
66-
// deploy it
63+
pub(crate) async fn deploy_contract(
64+
file_name: &str,
65+
run_config: &RunConfig,
66+
signing_key: &SecretKey,
67+
) -> Result<ContractId> {
6768
println!(" Deploying {} ...", file_name.bold());
69+
println!(" Signing key used: {}", signing_key.to_string().bold());
70+
6871
let manifest_dir = env!("CARGO_MANIFEST_DIR");
6972

7073
let deployed_packages = deploy(DeployCommand {
@@ -76,7 +79,7 @@ pub(crate) async fn deploy_contract(file_name: &str, run_config: &RunConfig) ->
7679
locked: run_config.locked,
7780
..Default::default()
7881
},
79-
signing_key: Some(SecretKey::from_str(SECRET_KEY).unwrap()),
82+
signing_key: Some(*signing_key),
8083
default_salt: true,
8184
build_profile: match run_config.release {
8285
true => BuildProfile::RELEASE.to_string(),
@@ -106,16 +109,16 @@ pub(crate) async fn runs_on_node(
106109
file_name: &str,
107110
run_config: &RunConfig,
108111
contract_ids: &[fuel_tx::ContractId],
112+
signing_key: &SecretKey,
109113
) -> (Result<Vec<fuel_tx::Receipt>>, String) {
110114
run_and_capture_output(|| async {
111115
println!(" Running on node {} ...", file_name.bold());
112116
let manifest_dir = env!("CARGO_MANIFEST_DIR");
113117

114-
let mut contracts = Vec::<String>::with_capacity(contract_ids.len());
115-
for contract_id in contract_ids {
116-
let contract = format!("0x{contract_id:x}");
117-
contracts.push(contract);
118-
}
118+
let contracts = contract_ids
119+
.iter()
120+
.map(|contract_id| format!("0x{contract_id:x}"))
121+
.collect::<Vec<_>>();
119122

120123
let command = RunCommand {
121124
pkg: forc_client::cmd::run::Pkg {
@@ -131,7 +134,7 @@ pub(crate) async fn runs_on_node(
131134
..Default::default()
132135
},
133136
contract: Some(contracts),
134-
signing_key: Some(SecretKey::from_str(SECRET_KEY).unwrap()),
137+
signing_key: Some(*signing_key),
135138
experimental: run_config.experimental.clone(),
136139
..Default::default()
137140
};

0 commit comments

Comments
 (0)