From e92f8425f727ca604a0f913bdb2615b450562aa6 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Wed, 10 Jan 2024 16:21:34 +0100 Subject: [PATCH 01/19] chore: use `beta-5` endpoint --- docs/src/connecting/external-node.md | 2 +- examples/providers/src/lib.rs | 3 +-- packages/fuels/tests/providers.rs | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/src/connecting/external-node.md b/docs/src/connecting/external-node.md index 502a5a0a5b..a954be2e0d 100644 --- a/docs/src/connecting/external-node.md +++ b/docs/src/connecting/external-node.md @@ -14,7 +14,7 @@ In the code example, we connected a new provider to the Testnet node and created > **Note:** New wallets on the Testnet will not have any assets! They can be obtained by providing the wallet address to the faucet at > ->[faucet-beta-4.fuel.network](https://faucet-beta-4.fuel.network) +>[faucet-beta-5.fuel.network](https://faucet-beta-5.fuel.network) > > Once the assets have been transferred to the wallet, you can reuse it in other tests by providing the private key! > diff --git a/examples/providers/src/lib.rs b/examples/providers/src/lib.rs index f8e9f9d2a2..850914b0ff 100644 --- a/examples/providers/src/lib.rs +++ b/examples/providers/src/lib.rs @@ -5,7 +5,6 @@ mod tests { use fuels::prelude::Result; #[tokio::test] - #[ignore] //TODO: Enable this test once beta supports the new `fuel-core` >= `0.21.0` async fn connect_to_fuel_node() -> Result<()> { // ANCHOR: connect_to_testnet use std::str::FromStr; @@ -15,7 +14,7 @@ mod tests { // Create a provider pointing to the testnet. // This example will not work as the testnet does not support the new version of fuel-core // yet - let provider = Provider::connect("beta-4.fuel.network").await.unwrap(); + let provider = Provider::connect("beta-5.fuel.network").await.unwrap(); // Setup a private key let secret = diff --git a/packages/fuels/tests/providers.rs b/packages/fuels/tests/providers.rs index d59917ef99..b7a02e4860 100644 --- a/packages/fuels/tests/providers.rs +++ b/packages/fuels/tests/providers.rs @@ -573,7 +573,6 @@ async fn test_get_gas_used() -> Result<()> { } #[tokio::test] -#[ignore] async fn testnet_hello_world() -> Result<()> { // Note that this test might become flaky. // This test depends on: @@ -588,7 +587,7 @@ async fn testnet_hello_world() -> Result<()> { )); // Create a provider pointing to the testnet. - let provider = Provider::connect("beta-4.fuel.network").await.unwrap(); + let provider = Provider::connect("beta-5.fuel.network").await.unwrap(); // Setup the private key. let secret = From 8a4895bbd79f77056570d278734e50e83311b55a Mon Sep 17 00:00:00 2001 From: iqdecay Date: Mon, 15 Jan 2024 17:47:34 +0100 Subject: [PATCH 02/19] update gas price --- packages/fuels/tests/providers.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/fuels/tests/providers.rs b/packages/fuels/tests/providers.rs index b7a02e4860..13fce9d906 100644 --- a/packages/fuels/tests/providers.rs +++ b/packages/fuels/tests/providers.rs @@ -596,14 +596,14 @@ async fn testnet_hello_world() -> Result<()> { // Create the wallet. let wallet = WalletUnlocked::new_from_private_key(secret, Some(provider)); + let address = wallet.address(); + println!("Address {:?} \n{:?}", address, wallet.get_balances().await?); let mut rng = rand::thread_rng(); let salt: [u8; 32] = rng.gen(); let configuration = LoadConfiguration::default().with_salt(salt); - let tx_policies = TxPolicies::default() - .with_gas_price(1) - .with_script_gas_limit(2000); + let tx_policies = TxPolicies::default(); let contract_id = Contract::load_from( "tests/contracts/contract_test/out/debug/contract_test.bin", From 33552502f7bc39cc0ce1220842cd876d0151980b Mon Sep 17 00:00:00 2001 From: iqdecay Date: Mon, 15 Jan 2024 20:20:57 +0100 Subject: [PATCH 03/19] chore: remove extra lines --- packages/fuels/tests/providers.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/fuels/tests/providers.rs b/packages/fuels/tests/providers.rs index 13fce9d906..dd66d81135 100644 --- a/packages/fuels/tests/providers.rs +++ b/packages/fuels/tests/providers.rs @@ -596,8 +596,6 @@ async fn testnet_hello_world() -> Result<()> { // Create the wallet. let wallet = WalletUnlocked::new_from_private_key(secret, Some(provider)); - let address = wallet.address(); - println!("Address {:?} \n{:?}", address, wallet.get_balances().await?); let mut rng = rand::thread_rng(); let salt: [u8; 32] = rng.gen(); From e6de82aa97ddf356a99fc24460cc1593cedfcdda Mon Sep 17 00:00:00 2001 From: iqdecay Date: Mon, 22 Jan 2024 17:14:18 +0100 Subject: [PATCH 04/19] test: enable testing against a live node --- .github/workflows/ci.yml | 9 +++ examples/providers/src/lib.rs | 2 +- packages/fuels-core/src/utils/constants.rs | 1 + .../src/setup_program_test/code_gen.rs | 17 ++-- .../setup_program_test/parsing/commands.rs | 2 +- packages/fuels-test-helpers/Cargo.toml | 1 + packages/fuels-test-helpers/src/accounts.rs | 45 ++++++++++- packages/fuels/Cargo.toml | 1 + packages/fuels/tests/contracts.rs | 79 +++++++++++++++---- packages/fuels/tests/providers.rs | 2 +- packages/fuels/tests/scripts.rs | 21 ++++- 11 files changed, 149 insertions(+), 31 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 763ead3d5f..fe9a2573da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,6 +22,9 @@ env: FORC_VERSION: 0.49.1 FORC_PATCH_BRANCH: "" FORC_PATCH_REVISION: "" + TEST_WALLET_SECRET_KEY_1: ${{ secrets.TEST_WALLET_SECRET_KEY_1 }} + TEST_WALLET_SECRET_KEY_2: ${{ secrets.TEST_WALLET_SECRET_KEY_2 }} + TEST_WALLET_SECRET_KEY_3: ${{ secrets.TEST_WALLET_SECRET_KEY_3 }} jobs: setup-test-projects: @@ -172,6 +175,12 @@ jobs: args: run --all-targets --workspace download_sway_artifacts: sway-examples install_fuel_core: true + - command: nextest # test some functions against live nodes + # the live node features requires using one thread only to avoid transaction collision + args: run --features "test-against-live-node" -j 1 --workspace + download_sway_artifacts: sway-examples + # not all tests use the live nodes so fuel-core binary remains necessary + install_fuel_core: true - cargo_command: test args: --doc --workspace - cargo_command: machete diff --git a/examples/providers/src/lib.rs b/examples/providers/src/lib.rs index 850914b0ff..5fd1ae417e 100644 --- a/examples/providers/src/lib.rs +++ b/examples/providers/src/lib.rs @@ -14,7 +14,7 @@ mod tests { // Create a provider pointing to the testnet. // This example will not work as the testnet does not support the new version of fuel-core // yet - let provider = Provider::connect("beta-5.fuel.network").await.unwrap(); + let provider = Provider::connect(TESTNET_NODE_URL).await.unwrap(); // Setup a private key let secret = diff --git a/packages/fuels-core/src/utils/constants.rs b/packages/fuels-core/src/utils/constants.rs index 8596475903..94907f7080 100644 --- a/packages/fuels-core/src/utils/constants.rs +++ b/packages/fuels-core/src/utils/constants.rs @@ -16,3 +16,4 @@ pub const DEFAULT_GAS_ESTIMATION_TOLERANCE: f64 = 0.2; pub const WITNESS_STATIC_SIZE: usize = 8; const SIGNATURE_SIZE: usize = 64; pub const SIGNATURE_WITNESS_SIZE: usize = WITNESS_STATIC_SIZE + SIGNATURE_SIZE; +pub const TESTNET_NODE_URL: &str = "beta-5.fuel.network"; diff --git a/packages/fuels-macros/src/setup_program_test/code_gen.rs b/packages/fuels-macros/src/setup_program_test/code_gen.rs index 9b528e238d..f22012b33a 100644 --- a/packages/fuels-macros/src/setup_program_test/code_gen.rs +++ b/packages/fuels-macros/src/setup_program_test/code_gen.rs @@ -25,7 +25,7 @@ pub(crate) fn generate_setup_program_test_code( let project_lookup = generate_project_lookup(&generate_bindings)?; let abigen_code = abigen_code(&project_lookup); - let wallet_code = wallet_initialization_code(initialize_wallets); + let wallet_code = wallet_initialization_code(initialize_wallets)?; let deploy_code = contract_deploying_code(&deploy_contract, &project_lookup); let script_code = script_loading_code(&load_scripts, &project_lookup); @@ -66,21 +66,22 @@ fn generate_abigen_targets(project_lookup: &HashMap) -> Vec) -> TokenStream { +fn wallet_initialization_code( + maybe_command: Option, +) -> syn::Result { let command = if let Some(command) = maybe_command { command } else { - return Default::default(); + return Ok(Default::default()); }; let wallet_names = extract_wallet_names(&command); - if wallet_names.is_empty() { - return Default::default(); + return Ok(Default::default()); } - let num_wallets = wallet_names.len(); - quote! { + + Ok(quote! { let [#(#wallet_names),*]: [_; #num_wallets] = launch_custom_provider_and_get_wallets( WalletsConfig::new(Some(#num_wallets as u64), None, None), None, @@ -90,7 +91,7 @@ fn wallet_initialization_code(maybe_command: Option) -> .expect("Error while trying to fetch wallets from the custom provider") .try_into() .expect("Should have the exact number of wallets"); - } + }) } fn extract_wallet_names(command: &InitializeWalletCommand) -> Vec { diff --git a/packages/fuels-macros/src/setup_program_test/parsing/commands.rs b/packages/fuels-macros/src/setup_program_test/parsing/commands.rs index 7c1eae6dad..0653ea77b5 100644 --- a/packages/fuels-macros/src/setup_program_test/parsing/commands.rs +++ b/packages/fuels-macros/src/setup_program_test/parsing/commands.rs @@ -35,7 +35,7 @@ command_parser!( Wallets -> InitializeWalletCommand, Abigen -> AbigenCommand, Deploy -> DeployContractCommand, - LoadScript -> LoadScriptCommand + LoadScript -> LoadScriptCommand, ); impl Parse for TestProgramCommands { diff --git a/packages/fuels-test-helpers/Cargo.toml b/packages/fuels-test-helpers/Cargo.toml index b3e3bcee13..3f03a9f064 100644 --- a/packages/fuels-test-helpers/Cargo.toml +++ b/packages/fuels-test-helpers/Cargo.toml @@ -35,3 +35,4 @@ which = { workspace = true, default-features = false } default = ["fuels-accounts", "std"] std = ["fuels-accounts?/std", "fuels-core/std"] fuel-core-lib = ["fuel-core"] +test-against-live-node = [] diff --git a/packages/fuels-test-helpers/src/accounts.rs b/packages/fuels-test-helpers/src/accounts.rs index a565739222..29543de386 100644 --- a/packages/fuels-test-helpers/src/accounts.rs +++ b/packages/fuels-test-helpers/src/accounts.rs @@ -1,8 +1,9 @@ +use fuel_crypto::SecretKey; use std::mem::size_of; +use std::str::FromStr; -use fuel_crypto::SecretKey; -use fuels_accounts::wallet::WalletUnlocked; -use fuels_core::types::errors::Result; +use fuels_accounts::{provider::Provider, wallet::WalletUnlocked}; +use fuels_core::{constants::TESTNET_NODE_URL, error, types::errors::Result}; use crate::{ node_types::{ChainConfig, Config}, @@ -85,6 +86,44 @@ pub async fn launch_custom_provider_and_get_wallets( Ok(wallets) } +pub async fn connect_to_testnet_node_and_get_wallets( + num_wallets: usize, +) -> Result> { + if num_wallets > 3 { + error!( + InvalidData, + "Trying to get more than 3 wallets from beta node" + ); + } + let provider = Provider::connect(TESTNET_NODE_URL) + .await + .expect("Should be able to connect to {TESTNET_NODE_URL}"); + let wallets = (1..=num_wallets) + .map(|wallet_counter| { + let private_key_string = + std::env::var(format!("TEST_WALLET_SECRET_KEY_{wallet_counter}")) + .expect("Should find private key in ENV"); + let private_key = SecretKey::from_str(private_key_string.as_str()) + .expect("Should be able to transform into private key"); + WalletUnlocked::new_from_private_key(private_key, Some(provider.clone())) + }) + .collect::>(); + Ok(wallets) +} + +pub async fn maybe_live_wallet(num_wallets: usize) -> Result> { + if cfg!(feature = "test-against-live-node") { + connect_to_testnet_node_and_get_wallets(num_wallets).await + } else { + launch_custom_provider_and_get_wallets( + WalletsConfig::new(Some(num_wallets as u64), None, None), + None, + None, + ) + .await + } +} + #[cfg(test)] mod tests { use fuel_core_chain_config::ChainConfig; diff --git a/packages/fuels/Cargo.toml b/packages/fuels/Cargo.toml index 4a213e9a64..0a7d697be9 100644 --- a/packages/fuels/Cargo.toml +++ b/packages/fuels/Cargo.toml @@ -55,5 +55,6 @@ std = [ ] # TODO: To be removed once https://github.com/FuelLabs/fuels-rs/issues/881 is unblocked. test-type-paths = [] +test-against-live-node = [] fuel-core-lib = ["fuels-test-helpers?/fuel-core-lib", "dep:fuel-core"] rocksdb = ["fuel-core?/rocksdb"] diff --git a/packages/fuels/tests/contracts.rs b/packages/fuels/tests/contracts.rs index 48644a5e7d..4bb0efdd2d 100644 --- a/packages/fuels/tests/contracts.rs +++ b/packages/fuels/tests/contracts.rs @@ -1,5 +1,7 @@ #[allow(unused_imports)] use std::future::Future; +use std::thread::sleep; +use std::time::Duration; use std::vec; use fuels::{ @@ -43,8 +45,11 @@ async fn test_multiple_args() -> Result<()> { #[tokio::test] async fn test_contract_calling_contract() -> Result<()> { // Tests a contract call that calls another contract (FooCaller calls FooContract underneath) + let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) + .await? + .try_into() + .expect("Vec can be converted to an array"); setup_program_test!( - Wallets("wallet"), Abigen( Contract( name = "LibContract", @@ -75,6 +80,9 @@ async fn test_contract_calling_contract() -> Result<()> { let lib_contract_id2 = lib_contract_instance2.contract_id(); // Call the contract directly. It increments the given value. + if cfg!(feature = "test-against-live-node") { + sleep(Duration::from_secs(10)); + } let response = lib_contract_instance.methods().increment(42).call().await?; assert_eq!(43, response.value); @@ -144,8 +152,11 @@ async fn test_reverting_transaction() -> Result<()> { #[tokio::test] async fn test_multiple_read_calls() -> Result<()> { + let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) + .await? + .try_into() + .expect("Vec can be converted to an array"); setup_program_test!( - Wallets("wallet"), Abigen(Contract( name = "MultiReadContract", project = "packages/fuels/tests/contracts/multiple_read_calls" @@ -175,8 +186,11 @@ async fn test_multiple_read_calls() -> Result<()> { #[tokio::test] async fn test_multi_call_beginner() -> Result<()> { + let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) + .await? + .try_into() + .expect("Vec can be converted to an array"); setup_program_test!( - Wallets("wallet"), Abigen(Contract( name = "TestContract", project = "packages/fuels/tests/contracts/contract_test" @@ -198,6 +212,10 @@ async fn test_multi_call_beginner() -> Result<()> { .add_call(call_handler_1) .add_call(call_handler_2); + if cfg!(feature = "test-against-live-node") { + sleep(Duration::from_secs(10)); + } + let (val_1, val_2): (u64, u64) = multi_call_handler.call().await?.value; assert_eq!(val_1, 7); @@ -208,8 +226,11 @@ async fn test_multi_call_beginner() -> Result<()> { #[tokio::test] async fn test_multi_call_pro() -> Result<()> { + let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) + .await? + .try_into() + .expect("Vec can be converted to an array"); setup_program_test!( - Wallets("wallet"), Abigen(Contract( name = "TestContract", project = "packages/fuels/tests/contracts/contract_test" @@ -263,8 +284,11 @@ async fn test_multi_call_pro() -> Result<()> { #[tokio::test] async fn test_contract_call_fee_estimation() -> Result<()> { + let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) + .await? + .try_into() + .expect("Vec can be converted to an array"); setup_program_test!( - Wallets("wallet"), Abigen(Contract( name = "TestContract", project = "packages/fuels/tests/contracts/contract_test" @@ -276,14 +300,22 @@ async fn test_contract_call_fee_estimation() -> Result<()> { ), ); - let gas_price = 100_000_000; + let gas_price = if cfg!(feature = "test-against-live-node") { + 1000 + } else { + 100_000_000 + }; let gas_limit = 800; let tolerance = 0.2; - let expected_min_gas_price = 0; // This is the default min_gas_price from the ConsensusParameters - let expected_gas_used = 675; let expected_metered_bytes_size = 792; - let expected_total_fee = 898; + let (expected_min_gas_price, expected_gas_used, expected_total_fee) = + if cfg!(feature = "test-against-live-node") { + (1, 960, 1_074_685) + } else { + // 0 is the default min_gas_price from the ConsensusParameters + (0, 675, 898) + }; let estimated_transaction_cost = contract_instance .methods() @@ -312,8 +344,11 @@ async fn test_contract_call_fee_estimation() -> Result<()> { #[tokio::test] async fn contract_call_has_same_estimated_and_used_gas() -> Result<()> { + let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) + .await? + .try_into() + .expect("Vec can be converted to an array"); setup_program_test!( - Wallets("wallet"), Abigen(Contract( name = "TestContract", project = "packages/fuels/tests/contracts/contract_test" @@ -345,8 +380,11 @@ async fn contract_call_has_same_estimated_and_used_gas() -> Result<()> { #[tokio::test] async fn mult_call_has_same_estimated_and_used_gas() -> Result<()> { + let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) + .await? + .try_into() + .expect("Vec can be converted to an array"); setup_program_test!( - Wallets("wallet"), Abigen(Contract( name = "TestContract", project = "packages/fuels/tests/contracts/contract_test" @@ -1503,8 +1541,11 @@ async fn can_configure_decoding_of_contract_return() -> Result<()> { #[tokio::test] async fn test_contract_submit_and_response() -> Result<()> { + let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) + .await? + .try_into() + .expect("Vec can be converted to an array"); setup_program_test!( - Wallets("wallet"), Abigen(Contract( name = "TestContract", project = "packages/fuels/tests/contracts/contract_test" @@ -1519,6 +1560,9 @@ async fn test_contract_submit_and_response() -> Result<()> { let contract_methods = contract_instance.methods(); let submitted_tx = contract_methods.get(1, 2).submit().await?; + if cfg!(feature = "test-against-live-node") { + sleep(Duration::from_secs(10)); + } let value = submitted_tx.response().await?.value; assert_eq!(value, 3); @@ -1534,6 +1578,9 @@ async fn test_contract_submit_and_response() -> Result<()> { .add_call(call_handler_2); let handle = multi_call_handler.submit().await?; + if cfg!(feature = "test-against-live-node") { + sleep(Duration::from_secs(10)); + } let (val_1, val_2): (u64, u64) = handle.response().await?.value; assert_eq!(val_1, 7); @@ -1670,8 +1717,11 @@ async fn heap_types_correctly_offset_in_create_transactions_w_storage_slots() -> #[tokio::test] async fn test_arguments_with_gas_forwarded() -> Result<()> { + let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) + .await? + .try_into() + .expect("Vec can be converted to an array"); setup_program_test!( - Wallets("wallet"), Abigen( Contract( name = "TestContract", @@ -1710,7 +1760,8 @@ async fn test_arguments_with_gas_forwarded() -> Result<()> { contract_instance_2 .methods() .u32_vec(vec_input.clone()) - .call_params(CallParameters::default().with_gas_forwarded(1024))? + // from tests, it seems that it uses ~2500gas + .call_params(CallParameters::default().with_gas_forwarded(3000))? .call() .await?; } diff --git a/packages/fuels/tests/providers.rs b/packages/fuels/tests/providers.rs index dd66d81135..02a72d2d89 100644 --- a/packages/fuels/tests/providers.rs +++ b/packages/fuels/tests/providers.rs @@ -587,7 +587,7 @@ async fn testnet_hello_world() -> Result<()> { )); // Create a provider pointing to the testnet. - let provider = Provider::connect("beta-5.fuel.network").await.unwrap(); + let provider = Provider::connect(TESTNET_NODE_URL).await.unwrap(); // Setup the private key. let secret = diff --git a/packages/fuels/tests/scripts.rs b/packages/fuels/tests/scripts.rs index ea66d7f92f..24b3e52d77 100644 --- a/packages/fuels/tests/scripts.rs +++ b/packages/fuels/tests/scripts.rs @@ -1,5 +1,7 @@ use fuels::{prelude::*, types::Bits256}; use fuels_core::codec::DecoderConfig; +use std::thread::sleep; +use std::time::Duration; #[tokio::test] async fn test_transaction_script_workflow() -> Result<()> { @@ -85,8 +87,11 @@ async fn main_function_arguments() -> Result<()> { #[tokio::test] async fn script_call_has_same_estimated_and_used_gas() -> Result<()> { + let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) + .await? + .try_into() + .expect("Vec can be converted to an array"); setup_program_test!( - Wallets("wallet"), Abigen(Script( name = "MyScript", project = "packages/fuels/tests/scripts/basic_script" @@ -116,8 +121,11 @@ async fn script_call_has_same_estimated_and_used_gas() -> Result<()> { #[tokio::test] async fn test_basic_script_with_tx_policies() -> Result<()> { + let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) + .await? + .try_into() + .expect("Vec can be converted to an array"); setup_program_test!( - Wallets("wallet"), Abigen(Script( name = "bimbam_script", project = "packages/fuels/tests/scripts/basic_script" @@ -378,8 +386,11 @@ async fn can_configure_decoder_on_script_call() -> Result<()> { #[tokio::test] async fn test_script_submit_and_response() -> Result<()> { + let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) + .await? + .try_into() + .expect("Vec can be converted to an array"); setup_program_test!( - Wallets("wallet"), Abigen(Script( name = "MyScript", project = "packages/fuels/tests/scripts/script_struct" @@ -398,6 +409,10 @@ async fn test_script_submit_and_response() -> Result<()> { // ANCHOR: submit_response_script let submitted_tx = script_instance.main(my_struct).submit().await?; + if cfg!(feature = "test-against-live-node") { + // add delay when testing against live node to make sure the receipts propagate + sleep(Duration::from_secs(10)); + } let value = submitted_tx.response().await?.value; // ANCHOR_END: submit_response_script From 60cd5fc3e3f8192543da4c51a1bea7c52ca945a6 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Mon, 22 Jan 2024 17:21:19 +0100 Subject: [PATCH 05/19] ci: use secret key from template to avoid leaking private key --- packages/fuels/tests/providers.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/fuels/tests/providers.rs b/packages/fuels/tests/providers.rs index 02a72d2d89..d636bce7e5 100644 --- a/packages/fuels/tests/providers.rs +++ b/packages/fuels/tests/providers.rs @@ -590,12 +590,13 @@ async fn testnet_hello_world() -> Result<()> { let provider = Provider::connect(TESTNET_NODE_URL).await.unwrap(); // Setup the private key. - let secret = - SecretKey::from_str("a0447cd75accc6b71a976fd3401a1f6ce318d27ba660b0315ee6ac347bf39568") - .unwrap(); + let private_key_string = + std::env::var(format!("TEST_WALLET_SECRET_KEY_1")).expect("Should find private key in ENV"); + let private_key = SecretKey::from_str(private_key_string.as_str()) + .expect("Should be able to transform into private key"); // Create the wallet. - let wallet = WalletUnlocked::new_from_private_key(secret, Some(provider)); + let wallet = WalletUnlocked::new_from_private_key(private_key, Some(provider)); let mut rng = rand::thread_rng(); let salt: [u8; 32] = rng.gen(); From 4e449b0d3a452af542d3d4b44475a5481daef1e6 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Mon, 22 Jan 2024 17:26:04 +0100 Subject: [PATCH 06/19] refactor: use helper function for testnet hello world --- packages/fuels/tests/providers.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/packages/fuels/tests/providers.rs b/packages/fuels/tests/providers.rs index d636bce7e5..c86d0e3e08 100644 --- a/packages/fuels/tests/providers.rs +++ b/packages/fuels/tests/providers.rs @@ -1,10 +1,9 @@ -use std::{iter, ops::Add, str::FromStr, vec}; +use std::{iter, ops::Add, vec}; use chrono::{DateTime, Duration, NaiveDateTime, TimeZone, Utc}; use fuels::{ accounts::Account, client::{PageDirection, PaginationRequest}, - crypto::SecretKey, prelude::*, tx::Receipt, types::{ @@ -586,18 +585,10 @@ async fn testnet_hello_world() -> Result<()> { abi = "packages/fuels/tests/contracts/contract_test/out/debug/contract_test-abi.json" )); - // Create a provider pointing to the testnet. - let provider = Provider::connect(TESTNET_NODE_URL).await.unwrap(); - - // Setup the private key. - let private_key_string = - std::env::var(format!("TEST_WALLET_SECRET_KEY_1")).expect("Should find private key in ENV"); - let private_key = SecretKey::from_str(private_key_string.as_str()) - .expect("Should be able to transform into private key"); - - // Create the wallet. - let wallet = WalletUnlocked::new_from_private_key(private_key, Some(provider)); - + let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) + .await? + .try_into() + .expect("Vec can be converted to an array"); let mut rng = rand::thread_rng(); let salt: [u8; 32] = rng.gen(); let configuration = LoadConfiguration::default().with_salt(salt); From 02eaf1215855eb68c75f737d2549de9646058bc8 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Mon, 22 Jan 2024 17:26:58 +0100 Subject: [PATCH 07/19] fix: use the function that doesn't depend on the feature --- packages/fuels/tests/providers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fuels/tests/providers.rs b/packages/fuels/tests/providers.rs index c86d0e3e08..a0f0fdf2d4 100644 --- a/packages/fuels/tests/providers.rs +++ b/packages/fuels/tests/providers.rs @@ -585,7 +585,7 @@ async fn testnet_hello_world() -> Result<()> { abi = "packages/fuels/tests/contracts/contract_test/out/debug/contract_test-abi.json" )); - let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) + let [wallet]: [WalletUnlocked; 1] = connect_to_testnet_node_and_get_wallets(1) .await? .try_into() .expect("Vec can be converted to an array"); From 973618c9e7033b71d8c7180c7b46e9ddd75764c6 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Mon, 22 Jan 2024 17:38:07 +0100 Subject: [PATCH 08/19] ci: change ci step --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe9a2573da..6bc83f5cba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -177,7 +177,7 @@ jobs: install_fuel_core: true - command: nextest # test some functions against live nodes # the live node features requires using one thread only to avoid transaction collision - args: run --features "test-against-live-node" -j 1 --workspace + args: run --all-targets --features "test-against-live-node" -j 1 --workspace download_sway_artifacts: sway-examples # not all tests use the live nodes so fuel-core binary remains necessary install_fuel_core: true From 00199e1bc59adcacb7d1cd57232cf6e91fb2cf67 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Mon, 22 Jan 2024 17:43:58 +0100 Subject: [PATCH 09/19] use cargo command --- .github/workflows/ci.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6bc83f5cba..dc7687a6f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ on: - master pull_request: release: - types: [published] + types: [ published ] concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} @@ -155,8 +155,8 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - cargo_command: [check] - args: [--all-features] + cargo_command: [ check ] + args: [ --all-features ] package: ${{fromJSON(needs.get-workspace-members.outputs.members)}} include: - cargo_command: fmt @@ -175,7 +175,8 @@ jobs: args: run --all-targets --workspace download_sway_artifacts: sway-examples install_fuel_core: true - - command: nextest # test some functions against live nodes + # test some functions against live nodes + - cargo_command: nextest # the live node features requires using one thread only to avoid transaction collision args: run --all-targets --features "test-against-live-node" -j 1 --workspace download_sway_artifacts: sway-examples From 6165c9707cb5d5fd74e1b6350800d06993267261 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Tue, 23 Jan 2024 15:45:15 +0100 Subject: [PATCH 10/19] tests: use `serial_test` crate to run live node tests sequentially --- .github/workflows/ci.yml | 8 +++++--- Cargo.toml | 1 + packages/fuels/Cargo.toml | 1 + packages/fuels/tests/contracts.rs | 10 ++++++++++ packages/fuels/tests/scripts.rs | 4 ++++ 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dc7687a6f8..084dffd5e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -176,9 +176,11 @@ jobs: download_sway_artifacts: sway-examples install_fuel_core: true # test some functions against live nodes - - cargo_command: nextest - # the live node features requires using one thread only to avoid transaction collision - args: run --all-targets --features "test-against-live-node" -j 1 --workspace + - cargo_command: test + # we use `test` instead of `nextest` so that the `serial_test` crate can enable running + # non-live node tests in parallel, while the live node ones run sequentially, + # thus preventing transaction collision which could happen otherwise. + args: --all-targets --features "test-against-live-node" --workspace download_sway_artifacts: sway-examples # not all tests use the live nodes so fuel-core binary remains necessary install_fuel_core: true diff --git a/Cargo.toml b/Cargo.toml index d6d0f4b156..187ec9b423 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,6 +59,7 @@ semver = "1.0.20" serde = { version = "1.0.193", default-features = false } serde_json = "1.0.108" serde_with = { version = "3.4.0", default-features = false } +serial_test = "3.0.0" sha2 = { version = "0.10.8", default-features = false } syn = "2.0.39" tai64 = { version = "4.0.0", default-features = false } diff --git a/packages/fuels/Cargo.toml b/packages/fuels/Cargo.toml index 0a7d697be9..0894d28996 100644 --- a/packages/fuels/Cargo.toml +++ b/packages/fuels/Cargo.toml @@ -32,6 +32,7 @@ fuels-code-gen = { workspace = true } fuels-test-helpers = { workspace = true } hex = { workspace = true, default-features = false } rand = { workspace = true } +serial_test = { workspace = true } sha2 = { workspace = true } tempfile = { workspace = true } tokio = { workspace = true, features = ["time", "test-util"] } diff --git a/packages/fuels/tests/contracts.rs b/packages/fuels/tests/contracts.rs index 4bb0efdd2d..8726dfa6c1 100644 --- a/packages/fuels/tests/contracts.rs +++ b/packages/fuels/tests/contracts.rs @@ -1,4 +1,5 @@ #[allow(unused_imports)] +use serial_test::serial; use std::future::Future; use std::thread::sleep; use std::time::Duration; @@ -43,6 +44,7 @@ async fn test_multiple_args() -> Result<()> { } #[tokio::test] +#[cfg_attr(feature = "test-against-live-node", serial)] async fn test_contract_calling_contract() -> Result<()> { // Tests a contract call that calls another contract (FooCaller calls FooContract underneath) let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) @@ -151,6 +153,7 @@ async fn test_reverting_transaction() -> Result<()> { } #[tokio::test] +#[cfg_attr(feature = "test-against-live-node", serial)] async fn test_multiple_read_calls() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? @@ -185,6 +188,7 @@ async fn test_multiple_read_calls() -> Result<()> { } #[tokio::test] +#[cfg_attr(feature = "test-against-live-node", serial)] async fn test_multi_call_beginner() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? @@ -225,6 +229,7 @@ async fn test_multi_call_beginner() -> Result<()> { } #[tokio::test] +#[cfg_attr(feature = "test-against-live-node", serial)] async fn test_multi_call_pro() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? @@ -283,6 +288,7 @@ async fn test_multi_call_pro() -> Result<()> { } #[tokio::test] +#[cfg_attr(feature = "test-against-live-node", serial)] async fn test_contract_call_fee_estimation() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? @@ -343,6 +349,7 @@ async fn test_contract_call_fee_estimation() -> Result<()> { } #[tokio::test] +#[cfg_attr(feature = "test-against-live-node", serial)] async fn contract_call_has_same_estimated_and_used_gas() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? @@ -379,6 +386,7 @@ async fn contract_call_has_same_estimated_and_used_gas() -> Result<()> { } #[tokio::test] +#[cfg_attr(feature = "test-against-live-node", serial)] async fn mult_call_has_same_estimated_and_used_gas() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? @@ -1540,6 +1548,7 @@ async fn can_configure_decoding_of_contract_return() -> Result<()> { } #[tokio::test] +#[cfg_attr(feature = "test-against-live-node", serial)] async fn test_contract_submit_and_response() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? @@ -1716,6 +1725,7 @@ async fn heap_types_correctly_offset_in_create_transactions_w_storage_slots() -> } #[tokio::test] +#[cfg_attr(feature = "test-against-live-node", serial)] async fn test_arguments_with_gas_forwarded() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? diff --git a/packages/fuels/tests/scripts.rs b/packages/fuels/tests/scripts.rs index 24b3e52d77..487112a320 100644 --- a/packages/fuels/tests/scripts.rs +++ b/packages/fuels/tests/scripts.rs @@ -1,5 +1,6 @@ use fuels::{prelude::*, types::Bits256}; use fuels_core::codec::DecoderConfig; +use serial_test::serial; use std::thread::sleep; use std::time::Duration; @@ -86,6 +87,7 @@ async fn main_function_arguments() -> Result<()> { } #[tokio::test] +#[cfg_attr(feature = "test-against-live-node", serial)] async fn script_call_has_same_estimated_and_used_gas() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? @@ -120,6 +122,7 @@ async fn script_call_has_same_estimated_and_used_gas() -> Result<()> { } #[tokio::test] +#[cfg_attr(feature = "test-against-live-node", serial)] async fn test_basic_script_with_tx_policies() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? @@ -385,6 +388,7 @@ async fn can_configure_decoder_on_script_call() -> Result<()> { } #[tokio::test] +#[cfg_attr(feature = "test-against-live-node", serial)] async fn test_script_submit_and_response() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? From 8fb7187d21630a3015b3c541b2193ccf2b94e8c6 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Tue, 23 Jan 2024 16:09:53 +0100 Subject: [PATCH 11/19] style: appease clippy and all formatting gods --- packages/fuels/tests/contracts.rs | 5 +---- packages/fuels/tests/scripts.rs | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/fuels/tests/contracts.rs b/packages/fuels/tests/contracts.rs index 8726dfa6c1..f40ce0beb9 100644 --- a/packages/fuels/tests/contracts.rs +++ b/packages/fuels/tests/contracts.rs @@ -1,9 +1,6 @@ #[allow(unused_imports)] use serial_test::serial; -use std::future::Future; -use std::thread::sleep; -use std::time::Duration; -use std::vec; +use std::{future::Future, thread::sleep, time::Duration, vec}; use fuels::{ accounts::{predicate::Predicate, Account}, diff --git a/packages/fuels/tests/scripts.rs b/packages/fuels/tests/scripts.rs index 487112a320..875902f06d 100644 --- a/packages/fuels/tests/scripts.rs +++ b/packages/fuels/tests/scripts.rs @@ -1,8 +1,8 @@ use fuels::{prelude::*, types::Bits256}; use fuels_core::codec::DecoderConfig; +#[allow(unused_imports)] // the use of the serial feature is not detected by rustfmt use serial_test::serial; -use std::thread::sleep; -use std::time::Duration; +use std::{thread::sleep, time::Duration}; #[tokio::test] async fn test_transaction_script_workflow() -> Result<()> { From 15839a1f17b270005ce98fb66dc3b8ab06833aab Mon Sep 17 00:00:00 2001 From: iqdecay Date: Tue, 23 Jan 2024 17:25:17 +0100 Subject: [PATCH 12/19] Revert "tests: use `serial_test` crate to run live node tests sequentially" This reverts commit 6165c9707cb5d5fd74e1b6350800d06993267261. --- .github/workflows/ci.yml | 8 +++----- Cargo.toml | 1 - packages/fuels/Cargo.toml | 1 - packages/fuels/tests/contracts.rs | 11 ----------- packages/fuels/tests/scripts.rs | 5 ----- 5 files changed, 3 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 084dffd5e4..dc7687a6f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -176,11 +176,9 @@ jobs: download_sway_artifacts: sway-examples install_fuel_core: true # test some functions against live nodes - - cargo_command: test - # we use `test` instead of `nextest` so that the `serial_test` crate can enable running - # non-live node tests in parallel, while the live node ones run sequentially, - # thus preventing transaction collision which could happen otherwise. - args: --all-targets --features "test-against-live-node" --workspace + - cargo_command: nextest + # the live node features requires using one thread only to avoid transaction collision + args: run --all-targets --features "test-against-live-node" -j 1 --workspace download_sway_artifacts: sway-examples # not all tests use the live nodes so fuel-core binary remains necessary install_fuel_core: true diff --git a/Cargo.toml b/Cargo.toml index 187ec9b423..d6d0f4b156 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,7 +59,6 @@ semver = "1.0.20" serde = { version = "1.0.193", default-features = false } serde_json = "1.0.108" serde_with = { version = "3.4.0", default-features = false } -serial_test = "3.0.0" sha2 = { version = "0.10.8", default-features = false } syn = "2.0.39" tai64 = { version = "4.0.0", default-features = false } diff --git a/packages/fuels/Cargo.toml b/packages/fuels/Cargo.toml index 0894d28996..0a7d697be9 100644 --- a/packages/fuels/Cargo.toml +++ b/packages/fuels/Cargo.toml @@ -32,7 +32,6 @@ fuels-code-gen = { workspace = true } fuels-test-helpers = { workspace = true } hex = { workspace = true, default-features = false } rand = { workspace = true } -serial_test = { workspace = true } sha2 = { workspace = true } tempfile = { workspace = true } tokio = { workspace = true, features = ["time", "test-util"] } diff --git a/packages/fuels/tests/contracts.rs b/packages/fuels/tests/contracts.rs index f40ce0beb9..21f247afc9 100644 --- a/packages/fuels/tests/contracts.rs +++ b/packages/fuels/tests/contracts.rs @@ -1,5 +1,3 @@ -#[allow(unused_imports)] -use serial_test::serial; use std::{future::Future, thread::sleep, time::Duration, vec}; use fuels::{ @@ -41,7 +39,6 @@ async fn test_multiple_args() -> Result<()> { } #[tokio::test] -#[cfg_attr(feature = "test-against-live-node", serial)] async fn test_contract_calling_contract() -> Result<()> { // Tests a contract call that calls another contract (FooCaller calls FooContract underneath) let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) @@ -150,7 +147,6 @@ async fn test_reverting_transaction() -> Result<()> { } #[tokio::test] -#[cfg_attr(feature = "test-against-live-node", serial)] async fn test_multiple_read_calls() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? @@ -185,7 +181,6 @@ async fn test_multiple_read_calls() -> Result<()> { } #[tokio::test] -#[cfg_attr(feature = "test-against-live-node", serial)] async fn test_multi_call_beginner() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? @@ -226,7 +221,6 @@ async fn test_multi_call_beginner() -> Result<()> { } #[tokio::test] -#[cfg_attr(feature = "test-against-live-node", serial)] async fn test_multi_call_pro() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? @@ -285,7 +279,6 @@ async fn test_multi_call_pro() -> Result<()> { } #[tokio::test] -#[cfg_attr(feature = "test-against-live-node", serial)] async fn test_contract_call_fee_estimation() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? @@ -346,7 +339,6 @@ async fn test_contract_call_fee_estimation() -> Result<()> { } #[tokio::test] -#[cfg_attr(feature = "test-against-live-node", serial)] async fn contract_call_has_same_estimated_and_used_gas() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? @@ -383,7 +375,6 @@ async fn contract_call_has_same_estimated_and_used_gas() -> Result<()> { } #[tokio::test] -#[cfg_attr(feature = "test-against-live-node", serial)] async fn mult_call_has_same_estimated_and_used_gas() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? @@ -1545,7 +1536,6 @@ async fn can_configure_decoding_of_contract_return() -> Result<()> { } #[tokio::test] -#[cfg_attr(feature = "test-against-live-node", serial)] async fn test_contract_submit_and_response() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? @@ -1722,7 +1712,6 @@ async fn heap_types_correctly_offset_in_create_transactions_w_storage_slots() -> } #[tokio::test] -#[cfg_attr(feature = "test-against-live-node", serial)] async fn test_arguments_with_gas_forwarded() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? diff --git a/packages/fuels/tests/scripts.rs b/packages/fuels/tests/scripts.rs index 875902f06d..d75023e6a5 100644 --- a/packages/fuels/tests/scripts.rs +++ b/packages/fuels/tests/scripts.rs @@ -1,7 +1,5 @@ use fuels::{prelude::*, types::Bits256}; use fuels_core::codec::DecoderConfig; -#[allow(unused_imports)] // the use of the serial feature is not detected by rustfmt -use serial_test::serial; use std::{thread::sleep, time::Duration}; #[tokio::test] @@ -87,7 +85,6 @@ async fn main_function_arguments() -> Result<()> { } #[tokio::test] -#[cfg_attr(feature = "test-against-live-node", serial)] async fn script_call_has_same_estimated_and_used_gas() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? @@ -122,7 +119,6 @@ async fn script_call_has_same_estimated_and_used_gas() -> Result<()> { } #[tokio::test] -#[cfg_attr(feature = "test-against-live-node", serial)] async fn test_basic_script_with_tx_policies() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? @@ -388,7 +384,6 @@ async fn can_configure_decoder_on_script_call() -> Result<()> { } #[tokio::test] -#[cfg_attr(feature = "test-against-live-node", serial)] async fn test_script_submit_and_response() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? From ac7044d45f472f69ce2b0e47c04193bd671f7ba3 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Tue, 23 Jan 2024 17:35:08 +0100 Subject: [PATCH 13/19] try ignoring the faulty test --- packages/fuels/tests/contracts.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/fuels/tests/contracts.rs b/packages/fuels/tests/contracts.rs index 21f247afc9..9594ae6621 100644 --- a/packages/fuels/tests/contracts.rs +++ b/packages/fuels/tests/contracts.rs @@ -1712,6 +1712,7 @@ async fn heap_types_correctly_offset_in_create_transactions_w_storage_slots() -> } #[tokio::test] +#[ignore] async fn test_arguments_with_gas_forwarded() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? From eb9f942caad0913f29e89f4f3788224977d9db4d Mon Sep 17 00:00:00 2001 From: iqdecay Date: Tue, 23 Jan 2024 21:34:37 +0100 Subject: [PATCH 14/19] add timeout to avoid 429 errors --- packages/fuels/tests/contracts.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/fuels/tests/contracts.rs b/packages/fuels/tests/contracts.rs index 9594ae6621..09d22aac40 100644 --- a/packages/fuels/tests/contracts.rs +++ b/packages/fuels/tests/contracts.rs @@ -1712,7 +1712,6 @@ async fn heap_types_correctly_offset_in_create_transactions_w_storage_slots() -> } #[tokio::test] -#[ignore] async fn test_arguments_with_gas_forwarded() -> Result<()> { let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) .await? @@ -1753,6 +1752,10 @@ async fn test_arguments_with_gas_forwarded() -> Result<()> { assert_eq!(response.value, x); } + if cfg!(feature = "test-against-live-node") { + // avoid getting HTTP 429 errors + sleep(Duration::from_secs(5)); + } { contract_instance_2 .methods() @@ -1762,6 +1765,9 @@ async fn test_arguments_with_gas_forwarded() -> Result<()> { .call() .await?; } + if cfg!(feature = "test-against-live-node") { + sleep(Duration::from_secs(5)); + } { let call_handler_1 = contract_instance.methods().get_single(x); let call_handler_2 = contract_instance_2.methods().u32_vec(vec_input); From 6692550085ef25e54b2b5c3ae9cef95de51c8b3d Mon Sep 17 00:00:00 2001 From: iqdecay Date: Tue, 30 Jan 2024 16:23:29 +0100 Subject: [PATCH 15/19] add another timeout --- packages/fuels/tests/contracts.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/fuels/tests/contracts.rs b/packages/fuels/tests/contracts.rs index 09d22aac40..db32dba174 100644 --- a/packages/fuels/tests/contracts.rs +++ b/packages/fuels/tests/contracts.rs @@ -1739,7 +1739,10 @@ async fn test_arguments_with_gas_forwarded() -> Result<()> { wallet = "wallet" ), ); - + if cfg!(feature = "test-against-live-node") { + // avoid getting HTTP 429 errors, two calls were made to deploy already + sleep(Duration::from_secs(5)); + } let x = 128; let vec_input = vec![0, 1, 2]; { @@ -1753,7 +1756,6 @@ async fn test_arguments_with_gas_forwarded() -> Result<()> { assert_eq!(response.value, x); } if cfg!(feature = "test-against-live-node") { - // avoid getting HTTP 429 errors sleep(Duration::from_secs(5)); } { From 246290f6aee4adbbd1ce5f424023063ec19fe40f Mon Sep 17 00:00:00 2001 From: iqdecay Date: Tue, 30 Jan 2024 16:25:46 +0100 Subject: [PATCH 16/19] deploy in two times --- packages/fuels/tests/contracts.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/fuels/tests/contracts.rs b/packages/fuels/tests/contracts.rs index db32dba174..ad40288538 100644 --- a/packages/fuels/tests/contracts.rs +++ b/packages/fuels/tests/contracts.rs @@ -1733,12 +1733,16 @@ async fn test_arguments_with_gas_forwarded() -> Result<()> { contract = "TestContract", wallet = "wallet" ), - Deploy( - name = "contract_instance_2", - contract = "VectorOutputContract", - wallet = "wallet" - ), ); + if cfg!(feature = "test-against-live-node") { + // avoid getting HTTP 429 errors + sleep(Duration::from_secs(5)); + } + setup_program_test!(Deploy( + name = "contract_instance_2", + contract = "VectorOutputContract", + wallet = "wallet" + )); if cfg!(feature = "test-against-live-node") { // avoid getting HTTP 429 errors, two calls were made to deploy already sleep(Duration::from_secs(5)); From 8bc4880453e639843d31ad07c3f972c215e35c68 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Tue, 30 Jan 2024 16:57:48 +0100 Subject: [PATCH 17/19] Revert "add another timeout" This reverts commit 6692550085ef25e54b2b5c3ae9cef95de51c8b3d. --- packages/fuels/tests/contracts.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/packages/fuels/tests/contracts.rs b/packages/fuels/tests/contracts.rs index ad40288538..45a91ca640 100644 --- a/packages/fuels/tests/contracts.rs +++ b/packages/fuels/tests/contracts.rs @@ -1734,15 +1734,6 @@ async fn test_arguments_with_gas_forwarded() -> Result<()> { wallet = "wallet" ), ); - if cfg!(feature = "test-against-live-node") { - // avoid getting HTTP 429 errors - sleep(Duration::from_secs(5)); - } - setup_program_test!(Deploy( - name = "contract_instance_2", - contract = "VectorOutputContract", - wallet = "wallet" - )); if cfg!(feature = "test-against-live-node") { // avoid getting HTTP 429 errors, two calls were made to deploy already sleep(Duration::from_secs(5)); @@ -1760,6 +1751,7 @@ async fn test_arguments_with_gas_forwarded() -> Result<()> { assert_eq!(response.value, x); } if cfg!(feature = "test-against-live-node") { + // avoid getting HTTP 429 errors sleep(Duration::from_secs(5)); } { From c99784d54cad967c1c1c1171883d03c06befe628 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Tue, 30 Jan 2024 16:59:20 +0100 Subject: [PATCH 18/19] remove faulty test --- packages/fuels/tests/contracts.rs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/packages/fuels/tests/contracts.rs b/packages/fuels/tests/contracts.rs index 45a91ca640..8ed3b192f9 100644 --- a/packages/fuels/tests/contracts.rs +++ b/packages/fuels/tests/contracts.rs @@ -1713,10 +1713,6 @@ async fn heap_types_correctly_offset_in_create_transactions_w_storage_slots() -> #[tokio::test] async fn test_arguments_with_gas_forwarded() -> Result<()> { - let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) - .await? - .try_into() - .expect("Vec can be converted to an array"); setup_program_test!( Abigen( Contract( @@ -1728,16 +1724,13 @@ async fn test_arguments_with_gas_forwarded() -> Result<()> { project = "packages/fuels/tests/types/contracts/vectors" ) ), + Wallets("wallet"), Deploy( name = "contract_instance", contract = "TestContract", wallet = "wallet" ), ); - if cfg!(feature = "test-against-live-node") { - // avoid getting HTTP 429 errors, two calls were made to deploy already - sleep(Duration::from_secs(5)); - } let x = 128; let vec_input = vec![0, 1, 2]; { @@ -1750,10 +1743,6 @@ async fn test_arguments_with_gas_forwarded() -> Result<()> { assert_eq!(response.value, x); } - if cfg!(feature = "test-against-live-node") { - // avoid getting HTTP 429 errors - sleep(Duration::from_secs(5)); - } { contract_instance_2 .methods() @@ -1763,9 +1752,6 @@ async fn test_arguments_with_gas_forwarded() -> Result<()> { .call() .await?; } - if cfg!(feature = "test-against-live-node") { - sleep(Duration::from_secs(5)); - } { let call_handler_1 = contract_instance.methods().get_single(x); let call_handler_2 = contract_instance_2.methods().u32_vec(vec_input); From d16a5cefbe67472f63b899a8719c026f24ea9138 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Tue, 30 Jan 2024 22:12:41 +0100 Subject: [PATCH 19/19] fix test --- packages/fuels/tests/contracts.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/fuels/tests/contracts.rs b/packages/fuels/tests/contracts.rs index 8ed3b192f9..853f1828d9 100644 --- a/packages/fuels/tests/contracts.rs +++ b/packages/fuels/tests/contracts.rs @@ -1730,6 +1730,11 @@ async fn test_arguments_with_gas_forwarded() -> Result<()> { contract = "TestContract", wallet = "wallet" ), + Deploy( + name = "contract_instance_2", + contract = "VectorOutputContract", + wallet = "wallet" + ), ); let x = 128; let vec_input = vec![0, 1, 2];