From 8f1e0574143d2f1f42a91c358257adae6b58148b Mon Sep 17 00:00:00 2001 From: iqdecay Date: Tue, 24 Oct 2023 14:01:38 +0200 Subject: [PATCH 01/30] test: add option to run against live node --- .github/workflows/ci.yml | 13 ++- examples/providers/src/lib.rs | 2 +- packages/fuels-core/src/utils/constants.rs | 2 + .../src/setup_program_test/code_gen.rs | 54 ++++++++---- .../parsing/command_parser.rs | 10 ++- .../setup_program_test/parsing/commands.rs | 4 +- .../setup_program_test/unknown_command.stderr | 2 +- packages/fuels-test-helpers/src/accounts.rs | 33 +++++++- packages/fuels/Cargo.toml | 1 + packages/fuels/tests/contracts.rs | 82 ++++++++++++++++++- packages/fuels/tests/providers.rs | 12 +-- 11 files changed, 186 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d97a4f400..7a4d670d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,10 @@ env: FORC_VERSION: 0.46.0 FORC_PATCH_BRANCH: "xunilrj/fix-implicit-std-env-vars" FORC_PATCH_REVISION: "" - FORC_IMPLICIT_STD_GIT_BRANCH: "xunilrj/fix-implicit-std-env-vars" + FORC_IMPLICIT_STD_GIT_BRANCH: "xunilrj/fix-implicit-std-env-vars" + SECRET_KEY_1: ${{ secrets.SECRET_KEY_1 }} + SECRET_KEY_2: ${{ secrets.SECRET_KEY_2 }} + SECRET_KEY_3: ${{ secrets.SECRET_KEY_3 }} jobs: setup-test-projects: @@ -279,3 +282,11 @@ jobs: with: publish-delay: 30000 registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} + + + run_against_live_node: + runs-on: ubuntu-latest + if: github.event_name == 'push' + steps: + run: | + cargo test --features test-against-live-node diff --git a/examples/providers/src/lib.rs b/examples/providers/src/lib.rs index e2864ce3c..ecb5ad873 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-4.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 6fe33a091..7df407467 100644 --- a/packages/fuels-core/src/utils/constants.rs +++ b/packages/fuels-core/src/utils/constants.rs @@ -11,3 +11,5 @@ pub const BASE_ASSET_ID: AssetId = AssetId::BASE; // ANCHOR_END: default_call_parameters pub const DEFAULT_GAS_ESTIMATION_TOLERANCE: f64 = 0.2; + +pub const TESTNET_NODE_URL: &str = "beta-4.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 121254e98..2f8848032 100644 --- a/packages/fuels-macros/src/setup_program_test/code_gen.rs +++ b/packages/fuels-macros/src/setup_program_test/code_gen.rs @@ -21,11 +21,12 @@ pub(crate) fn generate_setup_program_test_code( generate_bindings, deploy_contract, load_scripts, + run_on_live_node, } = commands; 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, run_on_live_node)?; let deploy_code = contract_deploying_code(&deploy_contract, &project_lookup); let script_code = script_loading_code(&load_scripts, &project_lookup); @@ -66,31 +67,54 @@ fn generate_abigen_targets(project_lookup: &HashMap) -> Vec) -> TokenStream { +fn wallet_initialization_code( + maybe_command: Option, + run_on_live_node: bool, +) -> 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! { - let [#(#wallet_names),*]: [_; #num_wallets] = launch_custom_provider_and_get_wallets( - WalletsConfig::new(Some(#num_wallets as u64), None, None), - None, - None, - ) - .await - .expect("Error while trying to fetch wallets from the custom provider") - .try_into() - .expect("Should have the exact number of wallets"); - } + return if run_on_live_node { + if num_wallets > 3 { + return Err(syn::Error::new_spanned( + "", + format!( + "Expected at most 3 wallet names inside 'Wallet' command, because 'RunOnLiveNode` command is 'true', found {} wallet names.", + num_wallets + ), + )); + } + + Ok(quote! { + let [#(#wallet_names),*]: [_; #num_wallets] = connect_to_testnet_node_and_get_wallets(#num_wallets) + .await + .expect("Error while trying to get wallets connected to testnet node") + .try_into() + .expect("Should have the exact number of wallets"); + }) + } else { + Ok(quote! { + let [#(#wallet_names),*]: [_; #num_wallets] = launch_custom_provider_and_get_wallets( + WalletsConfig::new(Some(#num_wallets as u64), None, None), + None, + None, + ) + .await + .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/command_parser.rs b/packages/fuels-macros/src/setup_program_test/parsing/command_parser.rs index e4acc99f3..4e34ec7e8 100644 --- a/packages/fuels-macros/src/setup_program_test/parsing/command_parser.rs +++ b/packages/fuels-macros/src/setup_program_test/parsing/command_parser.rs @@ -3,16 +3,24 @@ macro_rules! command_parser { #[derive(Default)] #[allow(non_snake_case)] pub(crate) struct CommandParser { + pub(crate) run_on_live_node: bool, $(pub(crate) $command_name: Vec<$command_struct>),* } impl CommandParser { fn available_commands() -> impl Iterator { - [$(stringify!($command_name)),*].into_iter() + ["RunOnLiveNode", $(stringify!($command_name)),*].into_iter() } pub(crate) fn parse_and_save(&mut self, command: $crate::parse_utils::Command) -> ::syn::Result<()>{ match command.name.to_string().as_str() { + "RunOnLiveNode" => { + if let Ok(content) = command.contents.to_string().parse() { + self.run_on_live_node = content + } else { + return Err(::syn::Error::new(command.name.span(), format!("Expected 'true' or 'false' inside 'RunOnLiveNode' command"))); + } + } $(stringify!($command_name) => self.$command_name.push(command.try_into()?),)* _ => { let msg = Self::available_commands().map(|command| format!("'{command}'")).join(", "); 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 7c1eae6da..a868d7965 100644 --- a/packages/fuels-macros/src/setup_program_test/parsing/commands.rs +++ b/packages/fuels-macros/src/setup_program_test/parsing/commands.rs @@ -29,13 +29,14 @@ pub(crate) struct TestProgramCommands { pub(crate) generate_bindings: AbigenCommand, pub(crate) deploy_contract: Vec, pub(crate) load_scripts: Vec, + pub(crate) run_on_live_node: bool, } command_parser!( Wallets -> InitializeWalletCommand, Abigen -> AbigenCommand, Deploy -> DeployContractCommand, - LoadScript -> LoadScriptCommand + LoadScript -> LoadScriptCommand, ); impl Parse for TestProgramCommands { @@ -57,6 +58,7 @@ impl Parse for TestProgramCommands { generate_bindings: abigen_command, deploy_contract: parsed_commands.Deploy, load_scripts: parsed_commands.LoadScript, + run_on_live_node: parsed_commands.run_on_live_node, }) } } diff --git a/packages/fuels-macros/tests/ui/setup_program_test/unknown_command.stderr b/packages/fuels-macros/tests/ui/setup_program_test/unknown_command.stderr index b39e2dad6..d0e065162 100644 --- a/packages/fuels-macros/tests/ui/setup_program_test/unknown_command.stderr +++ b/packages/fuels-macros/tests/ui/setup_program_test/unknown_command.stderr @@ -1,4 +1,4 @@ -error: Unrecognized command. Expected one of: 'Wallets', 'Abigen', 'Deploy', 'LoadScript' +error: Unrecognized command. Expected one of: 'RunOnLiveNode', 'Wallets', 'Abigen', 'Deploy', 'LoadScript' --> tests/ui/setup_program_test/unknown_command.rs:10:5 | 10 | UnknownCommand() diff --git a/packages/fuels-test-helpers/src/accounts.rs b/packages/fuels-test-helpers/src/accounts.rs index a19f924ad..a732d896c 100644 --- a/packages/fuels-test-helpers/src/accounts.rs +++ b/packages/fuels-test-helpers/src/accounts.rs @@ -1,7 +1,12 @@ use std::mem::size_of; +use std::str::FromStr; -use fuels_accounts::{fuel_crypto::SecretKey, wallet::WalletUnlocked, ViewOnlyAccount}; -use fuels_core::types::errors::Result; +use fuels_accounts::{ + fuel_crypto::SecretKey, provider::Provider, wallet::WalletUnlocked, ViewOnlyAccount, +}; +use fuels_core::constants::TESTNET_NODE_URL; +use fuels_core::error; +use fuels_core::types::errors::{Error, Result}; use crate::{ node_types::{ChainConfig, Config}, @@ -86,6 +91,30 @@ 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!("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) +} + #[cfg(test)] mod tests { use fuels_accounts::{fuel_crypto::fuel_types::AssetId, Account, ViewOnlyAccount}; diff --git a/packages/fuels/Cargo.toml b/packages/fuels/Cargo.toml index 67fbafd51..a0082d691 100644 --- a/packages/fuels/Cargo.toml +++ b/packages/fuels/Cargo.toml @@ -53,5 +53,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 189bb331c..8bce07026 100644 --- a/packages/fuels/tests/contracts.rs +++ b/packages/fuels/tests/contracts.rs @@ -41,9 +41,25 @@ async fn test_multiple_args() -> Result<()> { } #[tokio::test] -async fn test_contract_calling_contract() -> Result<()> { +#[cfg_attr(feature = "test-against-live-node", ignore)] +async fn test_contract_calling_contract_on_local_node() -> Result<()> { + let run_on_live_node = false; + test_contract_calling_contract(run_on_live_node).await?; + Ok(()) +} + +#[tokio::test] +#[cfg_attr(not(feature = "test-against-live-node"), ignore)] +async fn test_contract_calling_contract_on_live_node() -> Result<()> { + let run_on_live_node = true; + test_contract_calling_contract(run_on_live_node).await?; + Ok(()) +} + +async fn test_contract_calling_contract(run_on_live_node: bool) -> Result<()> { // Tests a contract call that calls another contract (FooCaller calls FooContract underneath) setup_program_test!( + RunOnLiveNode(false), Wallets("wallet"), Abigen( Contract( @@ -71,6 +87,37 @@ async fn test_contract_calling_contract() -> Result<()> { wallet = "wallet" ), ); + if run_on_live_node { + setup_program_test!( + RunOnLiveNode(true), + Wallets("wallet"), + Abigen( + Contract( + name = "LibContract", + project = "packages/fuels/tests/contracts/lib_contract" + ), + Contract( + name = "LibContractCaller", + project = "packages/fuels/tests/contracts/lib_contract_caller" + ), + ), + Deploy( + name = "lib_contract_instance", + contract = "LibContract", + wallet = "wallet" + ), + Deploy( + name = "lib_contract_instance2", + contract = "LibContract", + wallet = "wallet" + ), + Deploy( + name = "contract_caller_instance", + contract = "LibContractCaller", + wallet = "wallet" + ), + ); + }; let lib_contract_id = lib_contract_instance.contract_id(); let lib_contract_id2 = lib_contract_instance2.contract_id(); @@ -1501,8 +1548,24 @@ async fn can_configure_decoding_of_contract_return() -> Result<()> { } #[tokio::test] -async fn test_contract_submit_and_response() -> Result<()> { +#[cfg_attr(feature = "test-against-live-node", ignore)] +async fn contract_submit_and_response_local_node() -> Result<()> { + let run_on_live_node = false; + test_contract_submit_and_response(run_on_live_node).await?; + Ok(()) +} + +#[tokio::test] +#[cfg_attr(not(feature = "test-against-live-node"), ignore)] +async fn contract_submit_and_response_live_node() -> Result<()> { + let run_on_live_node = true; + test_contract_submit_and_response(run_on_live_node).await?; + Ok(()) +} + +async fn test_contract_submit_and_response(run_on_live_node: bool) -> Result<()> { setup_program_test!( + RunOnLiveNode(false), Wallets("wallet"), Abigen(Contract( name = "TestContract", @@ -1514,6 +1577,21 @@ async fn test_contract_submit_and_response() -> Result<()> { wallet = "wallet" ), ); + if run_on_live_node { + setup_program_test!( + RunOnLiveNode(true), + Wallets("wallet"), + Abigen(Contract( + name = "TestContract", + project = "packages/fuels/tests/contracts/contract_test" + )), + Deploy( + name = "contract_instance", + contract = "TestContract", + wallet = "wallet" + ), + ); + } let contract_methods = contract_instance.methods(); diff --git a/packages/fuels/tests/providers.rs b/packages/fuels/tests/providers.rs index 5be551853..ab39c35d7 100644 --- a/packages/fuels/tests/providers.rs +++ b/packages/fuels/tests/providers.rs @@ -12,10 +12,12 @@ use fuels::{ tx::Receipt, types::{block::Block, coin_type::CoinType, message::Message}, }; - -use fuels_core::types::{ - transaction_builders::{ScriptTransactionBuilder, TransactionBuilder}, - Bits256, +use fuels_core::{ + constants::TESTNET_NODE_URL, + types::{ + transaction_builders::{ScriptTransactionBuilder, TransactionBuilder}, + Bits256, + }, }; #[tokio::test] @@ -634,7 +636,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(TESTNET_NODE_URL).await.unwrap(); // Setup the private key. let secret = From 7eaca6d561346bf195b633e3b7d3d97dbf485844 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Tue, 24 Oct 2023 14:22:41 +0200 Subject: [PATCH 02/30] ci: test ci run --- .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 7a4d670d3..9e86c9d88 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -286,7 +286,7 @@ jobs: run_against_live_node: runs-on: ubuntu-latest - if: github.event_name == 'push' +# if: github.event_name == 'push' steps: run: | cargo test --features test-against-live-node From 14d3622b66b91df0d0c2a55f561a50f5a1e3a707 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Tue, 24 Oct 2023 14:26:54 +0200 Subject: [PATCH 03/30] add `continue-on-error` --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e86c9d88..9edbaa895 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -287,6 +287,7 @@ jobs: run_against_live_node: runs-on: ubuntu-latest # if: github.event_name == 'push' + continue-on-error: true steps: run: | cargo test --features test-against-live-node From 1d2f429a79258ff4caa5526df2fae6e524ddc247 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Tue, 24 Oct 2023 16:54:31 +0200 Subject: [PATCH 04/30] fix ci step --- .github/workflows/ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9edbaa895..d302fd67a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -286,8 +286,9 @@ jobs: run_against_live_node: runs-on: ubuntu-latest -# if: github.event_name == 'push' + # if: github.event_name == 'push' continue-on-error: true steps: - run: | - cargo test --features test-against-live-node + - name: Run some tests against live node + run: cargo test --features test-against-live-node + From f583ca88131dd9a0bc258c76ee567251a9ac1323 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Tue, 24 Oct 2023 16:59:30 +0200 Subject: [PATCH 05/30] use correct ci --- .github/workflows/ci.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d302fd67a..cc54e51f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -255,6 +255,9 @@ jobs: if: ${{ matrix.command == 'check_doc_unresolved_links' }} run: | ! cargo doc --document-private-items |& grep -A 6 "warning: unresolved link to" + - name: Run some tests against live node + run: cargo test --features test-against-live-node + continue-on-error: true publish: needs: @@ -284,11 +287,4 @@ jobs: registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} - run_against_live_node: - runs-on: ubuntu-latest - # if: github.event_name == 'push' - continue-on-error: true - steps: - - name: Run some tests against live node - run: cargo test --features test-against-live-node From c6c58177a9cc528a9c56bd017c813c3101abec7a Mon Sep 17 00:00:00 2001 From: iqdecay Date: Tue, 24 Oct 2023 17:21:16 +0200 Subject: [PATCH 06/30] style: appease clippy and all formatting gods --- packages/fuels-macros/src/setup_program_test/code_gen.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 2f8848032..c686212c0 100644 --- a/packages/fuels-macros/src/setup_program_test/code_gen.rs +++ b/packages/fuels-macros/src/setup_program_test/code_gen.rs @@ -84,7 +84,7 @@ fn wallet_initialization_code( } let num_wallets = wallet_names.len(); - return if run_on_live_node { + if run_on_live_node { if num_wallets > 3 { return Err(syn::Error::new_spanned( "", @@ -114,7 +114,7 @@ fn wallet_initialization_code( .try_into() .expect("Should have the exact number of wallets"); }) - }; + } } fn extract_wallet_names(command: &InitializeWalletCommand) -> Vec { From e97263855876729e0d2c6394dc2080d6d117025f Mon Sep 17 00:00:00 2001 From: iqdecay Date: Tue, 24 Oct 2023 17:47:14 +0200 Subject: [PATCH 07/30] run as matrix command --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc54e51f1..e208e6924 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -185,6 +185,8 @@ jobs: args: - command: check_doc_unresolved_links args: + - command: test_against_live_node + args: steps: - name: Checkout repository uses: actions/checkout@v3 @@ -255,9 +257,11 @@ jobs: if: ${{ matrix.command == 'check_doc_unresolved_links' }} run: | ! cargo doc --document-private-items |& grep -A 6 "warning: unresolved link to" + - name: Run some tests against live node - run: cargo test --features test-against-live-node continue-on-error: true + if: ${{ matrix.command == 'test_against_live_node' }} + run: cargo test --features test-against-live-node publish: needs: From 009a817e091a846fdd993e14ae1e77090109a93e Mon Sep 17 00:00:00 2001 From: iqdecay Date: Tue, 24 Oct 2023 18:28:22 +0200 Subject: [PATCH 08/30] dl sway artifacts --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e208e6924..cbf0fc377 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -187,6 +187,8 @@ jobs: args: - command: test_against_live_node args: + download_sway_artifacts: sway-examples-w-type-paths + install_fuel_core: true steps: - name: Checkout repository uses: actions/checkout@v3 From d8553868bf4219c07ec5568f29053e76ae726dbe Mon Sep 17 00:00:00 2001 From: iqdecay Date: Tue, 24 Oct 2023 19:18:00 +0200 Subject: [PATCH 09/30] move step outside matrix --- .github/workflows/ci.yml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cbf0fc377..1576a650f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -185,10 +185,6 @@ jobs: args: - command: check_doc_unresolved_links args: - - command: test_against_live_node - args: - download_sway_artifacts: sway-examples-w-type-paths - install_fuel_core: true steps: - name: Checkout repository uses: actions/checkout@v3 @@ -260,10 +256,6 @@ jobs: run: | ! cargo doc --document-private-items |& grep -A 6 "warning: unresolved link to" - - name: Run some tests against live node - continue-on-error: true - if: ${{ matrix.command == 'test_against_live_node' }} - run: cargo test --features test-against-live-node publish: needs: @@ -292,5 +284,21 @@ jobs: publish-delay: 30000 registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} + run-against-live-node: + needs: + - cargo-verifications + - publish-crates-check + # Only do this job if publishing a release + # if: github.event_name == 'push' + runs-on: ubuntu-latest + continue-on-error: true + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Run on a live node + run: cargo test --features test-against-live-node + + + From 27e6214d03d16b629efcfdfd31f94b18cef20d90 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Wed, 25 Oct 2023 12:05:35 +0200 Subject: [PATCH 10/30] Revert "move step outside matrix" This reverts commit 81531cfa46e86f8ce2201f8c2d76afeedcf397fa. --- .github/workflows/ci.yml | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1576a650f..cbf0fc377 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -185,6 +185,10 @@ jobs: args: - command: check_doc_unresolved_links args: + - command: test_against_live_node + args: + download_sway_artifacts: sway-examples-w-type-paths + install_fuel_core: true steps: - name: Checkout repository uses: actions/checkout@v3 @@ -256,6 +260,10 @@ jobs: run: | ! cargo doc --document-private-items |& grep -A 6 "warning: unresolved link to" + - name: Run some tests against live node + continue-on-error: true + if: ${{ matrix.command == 'test_against_live_node' }} + run: cargo test --features test-against-live-node publish: needs: @@ -284,21 +292,5 @@ jobs: publish-delay: 30000 registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} - run-against-live-node: - needs: - - cargo-verifications - - publish-crates-check - # Only do this job if publishing a release - # if: github.event_name == 'push' - runs-on: ubuntu-latest - continue-on-error: true - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - name: Run on a live node - run: cargo test --features test-against-live-node - - - From d1d09d191681193ef0f5f2c06590718924c90084 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Wed, 25 Oct 2023 12:08:17 +0200 Subject: [PATCH 11/30] setup test projects before --- .github/workflows/ci.yml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cbf0fc377..f664a8429 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -185,10 +185,6 @@ jobs: args: - command: check_doc_unresolved_links args: - - command: test_against_live_node - args: - download_sway_artifacts: sway-examples-w-type-paths - install_fuel_core: true steps: - name: Checkout repository uses: actions/checkout@v3 @@ -260,10 +256,6 @@ jobs: run: | ! cargo doc --document-private-items |& grep -A 6 "warning: unresolved link to" - - name: Run some tests against live node - continue-on-error: true - if: ${{ matrix.command == 'test_against_live_node' }} - run: cargo test --features test-against-live-node publish: needs: @@ -292,5 +284,21 @@ jobs: publish-delay: 30000 registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} + run-against-live-node: + needs: + - setup-test-projects + - cargo-verifications + # Only do this job if publishing a release + # if: github.event_name == 'push' + runs-on: ubuntu-latest + continue-on-error: true + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Run on a live node + run: cargo test --features test-against-live-node + + + From 1b599736422af8d14ecd157c203d75d5c9f9407c Mon Sep 17 00:00:00 2001 From: iqdecay Date: Wed, 25 Oct 2023 12:05:35 +0200 Subject: [PATCH 12/30] Revert "move step outside matrix" This reverts commit 81531cfa46e86f8ce2201f8c2d76afeedcf397fa. --- .github/workflows/ci.yml | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f664a8429..309f780d0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -185,6 +185,10 @@ jobs: args: - command: check_doc_unresolved_links args: + - command: test_against_live_node + args: + download_sway_artifacts: sway-examples-w-type-paths + install_fuel_core: true steps: - name: Checkout repository uses: actions/checkout@v3 @@ -255,9 +259,14 @@ jobs: if: ${{ matrix.command == 'check_doc_unresolved_links' }} run: | ! cargo doc --document-private-items |& grep -A 6 "warning: unresolved link to" + - name: Run some tests against live node + continue-on-error: true + if: ${{ matrix.command == 'test_against_live_node' }} + run: cargo test --features test-against-live-node - publish: + +publish: needs: - cargo-verifications - publish-crates-check @@ -284,21 +293,4 @@ jobs: publish-delay: 30000 registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} - run-against-live-node: - needs: - - setup-test-projects - - cargo-verifications - # Only do this job if publishing a release - # if: github.event_name == 'push' - runs-on: ubuntu-latest - continue-on-error: true - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - name: Run on a live node - run: cargo test --features test-against-live-node - - - - From be10828f1f15e3f7310f4ebc282cb5b3e9a11a4f Mon Sep 17 00:00:00 2001 From: iqdecay Date: Wed, 25 Oct 2023 13:27:09 +0200 Subject: [PATCH 13/30] add commented condition on push --- .github/workflows/ci.yml | 51 ++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 309f780d0..e5c2ef093 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -261,36 +261,37 @@ jobs: ! cargo doc --document-private-items |& grep -A 6 "warning: unresolved link to" - name: Run some tests against live node continue-on-error: true + # if: github.event_name == "push" && ${{ matrix.command == 'test_against_live_node' }} if: ${{ matrix.command == 'test_against_live_node' }} run: cargo test --features test-against-live-node publish: - needs: - - cargo-verifications - - publish-crates-check - # Only do this job if publishing a release - if: github.event_name == 'release' && github.event.action == 'published' - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{ env.RUST_VERSION }} - - - name: Verify tag version - run: | - curl -sSLf "$DASEL_VERSION" -L -o dasel && chmod +x dasel - mv ./dasel /usr/local/bin/dasel - ./.github/workflows/scripts/verify_tag.sh ${{ github.ref_name }} Cargo.toml - - name: Publish crate - uses: katyo/publish-crates@v2 - with: - publish-delay: 30000 - registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} + needs: + - cargo-verifications + - publish-crates-check + # Only do this job if publishing a release + if: github.event_name == 'release' && github.event.action == 'published' + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_VERSION }} + + - name: Verify tag version + run: | + curl -sSLf "$DASEL_VERSION" -L -o dasel && chmod +x dasel + mv ./dasel /usr/local/bin/dasel + ./.github/workflows/scripts/verify_tag.sh ${{ github.ref_name }} Cargo.toml + - name: Publish crate + uses: katyo/publish-crates@v2 + with: + publish-delay: 30000 + registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} From 66c450e304985a9d61ad0aa448f535eeba4ad200 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Thu, 26 Oct 2023 13:17:36 +0200 Subject: [PATCH 14/30] fix with review comments --- packages/fuels/tests/contracts.rs | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/packages/fuels/tests/contracts.rs b/packages/fuels/tests/contracts.rs index 8bce07026..cc0240b28 100644 --- a/packages/fuels/tests/contracts.rs +++ b/packages/fuels/tests/contracts.rs @@ -41,22 +41,7 @@ async fn test_multiple_args() -> Result<()> { } #[tokio::test] -#[cfg_attr(feature = "test-against-live-node", ignore)] -async fn test_contract_calling_contract_on_local_node() -> Result<()> { - let run_on_live_node = false; - test_contract_calling_contract(run_on_live_node).await?; - Ok(()) -} - -#[tokio::test] -#[cfg_attr(not(feature = "test-against-live-node"), ignore)] -async fn test_contract_calling_contract_on_live_node() -> Result<()> { - let run_on_live_node = true; - test_contract_calling_contract(run_on_live_node).await?; - Ok(()) -} - -async fn test_contract_calling_contract(run_on_live_node: bool) -> Result<()> { +async fn test_contract_calling_contract() -> Result<()> { // Tests a contract call that calls another contract (FooCaller calls FooContract underneath) setup_program_test!( RunOnLiveNode(false), @@ -87,7 +72,8 @@ async fn test_contract_calling_contract(run_on_live_node: bool) -> Result<()> { wallet = "wallet" ), ); - if run_on_live_node { + if cfg!(feature = "test-against-live-node") { + println!("Testing against live node"); setup_program_test!( RunOnLiveNode(true), Wallets("wallet"), From 2410a45700f6a79c133905ed51c5754c36fb5f61 Mon Sep 17 00:00:00 2001 From: hal3e Date: Wed, 25 Oct 2023 17:08:14 +0200 Subject: [PATCH 15/30] PR comments --- .../fuels-macros/src/parse_utils/command.rs | 42 ++++--- .../src/setup_program_test/code_gen.rs | 12 +- .../src/setup_program_test/parsing.rs | 2 +- .../parsing/command_parser.rs | 10 +- .../setup_program_test/parsing/commands.rs | 9 +- .../parsing/commands/initialize_wallet.rs | 12 +- .../parsing/commands/run_on_live_node.rs | 28 +++++ .../setup_program_test/parsing/validations.rs | 14 +++ .../setup_program_test/unknown_command.stderr | 2 +- packages/fuels/tests/contracts.rs | 108 ++++++++---------- 10 files changed, 140 insertions(+), 99 deletions(-) create mode 100644 packages/fuels-macros/src/setup_program_test/parsing/commands/run_on_live_node.rs diff --git a/packages/fuels-macros/src/parse_utils/command.rs b/packages/fuels-macros/src/parse_utils/command.rs index e634f2787..4422ee7d3 100644 --- a/packages/fuels-macros/src/parse_utils/command.rs +++ b/packages/fuels-macros/src/parse_utils/command.rs @@ -5,6 +5,7 @@ use syn::{ token::Comma, Error, Meta, Meta::List, + Meta::Path, }; #[derive(Debug)] @@ -23,23 +24,34 @@ impl Command { } pub fn new(meta: Meta) -> syn::Result { - if let List(meta_list) = meta { - let name = meta_list.path.get_ident().cloned().ok_or_else(|| { - Error::new_spanned( - &meta_list.path, - "Command name cannot be a Path -- i.e. contain ':'.", - ) - })?; + match meta { + List(meta_list) => { + let name = meta_list.path.get_ident().cloned().ok_or_else(|| { + Error::new_spanned( + &meta_list.path, + "Command name cannot be a Path -- i.e. contain ':'.", + ) + })?; - Ok(Self { - name, - contents: meta_list.tokens, - }) - } else { - Err(Error::new_spanned( + Ok(Self { + name, + contents: meta_list.tokens, + }) + } + Path(ref path) => { + let name = path.get_ident().cloned().ok_or_else(|| { + Error::new_spanned(path, "Command name cannot be a Path -- i.e. contain ':'.") + })?; + + Ok(Self { + name, + contents: Default::default(), + }) + } + _ => Err(Error::new_spanned( meta, - "Expected a command name literal -- e.g. `Something(...)`", - )) + "Expected a command name literal or Path -- e.g. `Something(...)` or `Something`", + )), } } 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 c686212c0..4ce08f608 100644 --- a/packages/fuels-macros/src/setup_program_test/code_gen.rs +++ b/packages/fuels-macros/src/setup_program_test/code_gen.rs @@ -78,18 +78,14 @@ fn wallet_initialization_code( }; let wallet_names = extract_wallet_names(&command); - - if wallet_names.is_empty() { - return Ok(Default::default()); - } - let num_wallets = wallet_names.len(); + if run_on_live_node { if num_wallets > 3 { - return Err(syn::Error::new_spanned( - "", + return Err(syn::Error::new( + command.span, format!( - "Expected at most 3 wallet names inside 'Wallet' command, because 'RunOnLiveNode` command is 'true', found {} wallet names.", + "'RunOnLiveNode` supports at most 3 wallet names inside the 'Wallets' command. Found {}.", num_wallets ), )); diff --git a/packages/fuels-macros/src/setup_program_test/parsing.rs b/packages/fuels-macros/src/setup_program_test/parsing.rs index 4057e6b3d..36029da63 100644 --- a/packages/fuels-macros/src/setup_program_test/parsing.rs +++ b/packages/fuels-macros/src/setup_program_test/parsing.rs @@ -1,6 +1,6 @@ pub(crate) use commands::{ AbigenCommand, DeployContractCommand, InitializeWalletCommand, LoadScriptCommand, - TestProgramCommands, + RunOnLiveNodeCommand, TestProgramCommands, }; mod command_parser; diff --git a/packages/fuels-macros/src/setup_program_test/parsing/command_parser.rs b/packages/fuels-macros/src/setup_program_test/parsing/command_parser.rs index 4e34ec7e8..e4acc99f3 100644 --- a/packages/fuels-macros/src/setup_program_test/parsing/command_parser.rs +++ b/packages/fuels-macros/src/setup_program_test/parsing/command_parser.rs @@ -3,24 +3,16 @@ macro_rules! command_parser { #[derive(Default)] #[allow(non_snake_case)] pub(crate) struct CommandParser { - pub(crate) run_on_live_node: bool, $(pub(crate) $command_name: Vec<$command_struct>),* } impl CommandParser { fn available_commands() -> impl Iterator { - ["RunOnLiveNode", $(stringify!($command_name)),*].into_iter() + [$(stringify!($command_name)),*].into_iter() } pub(crate) fn parse_and_save(&mut self, command: $crate::parse_utils::Command) -> ::syn::Result<()>{ match command.name.to_string().as_str() { - "RunOnLiveNode" => { - if let Ok(content) = command.contents.to_string().parse() { - self.run_on_live_node = content - } else { - return Err(::syn::Error::new(command.name.span(), format!("Expected 'true' or 'false' inside 'RunOnLiveNode' command"))); - } - } $(stringify!($command_name) => self.$command_name.push(command.try_into()?),)* _ => { let msg = Self::available_commands().map(|command| format!("'{command}'")).join(", "); 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 a868d7965..6113ba1fa 100644 --- a/packages/fuels-macros/src/setup_program_test/parsing/commands.rs +++ b/packages/fuels-macros/src/setup_program_test/parsing/commands.rs @@ -3,6 +3,7 @@ pub(crate) use deploy_contract::DeployContractCommand; pub(crate) use initialize_wallet::InitializeWalletCommand; use itertools::Itertools; pub(crate) use load_script::LoadScriptCommand; +pub(crate) use run_on_live_node::RunOnLiveNodeCommand; use syn::{ parse::{Parse, ParseStream}, Result, @@ -16,10 +17,13 @@ use crate::setup_program_test::parsing::{ }, }; +use super::validations::should_run_on_live_node_command; + mod abigen; mod deploy_contract; mod initialize_wallet; mod load_script; +mod run_on_live_node; // Contains the result of parsing the input to the `setup_program_test` macro. // Contents represent the users wishes with regards to wallet initialization, @@ -37,6 +41,7 @@ command_parser!( Abigen -> AbigenCommand, Deploy -> DeployContractCommand, LoadScript -> LoadScriptCommand, + RunOnLiveNode -> RunOnLiveNodeCommand, ); impl Parse for TestProgramCommands { @@ -53,12 +58,14 @@ impl Parse for TestProgramCommands { validate_zero_or_one_wallet_command_present(&parsed_commands.Wallets)?; + let run_on_live_node = should_run_on_live_node_command(&parsed_commands.RunOnLiveNode)?; + Ok(Self { initialize_wallets: parsed_commands.Wallets.pop(), generate_bindings: abigen_command, deploy_contract: parsed_commands.Deploy, load_scripts: parsed_commands.LoadScript, - run_on_live_node: parsed_commands.run_on_live_node, + run_on_live_node, }) } } diff --git a/packages/fuels-macros/src/setup_program_test/parsing/commands/initialize_wallet.rs b/packages/fuels-macros/src/setup_program_test/parsing/commands/initialize_wallet.rs index 2396eaa09..fe37bf22f 100644 --- a/packages/fuels-macros/src/setup_program_test/parsing/commands/initialize_wallet.rs +++ b/packages/fuels-macros/src/setup_program_test/parsing/commands/initialize_wallet.rs @@ -15,11 +15,19 @@ impl TryFrom for InitializeWalletCommand { type Error = Error; fn try_from(command: Command) -> Result { - let wallets = UniqueLitStrs::new(command.contents)?; + let wallets = UniqueLitStrs::new(command.contents.clone())?; + let names: Vec = wallets.into_iter().collect(); + + if names.is_empty() { + return Err(Error::new( + command.name.span(), + "`Wallets` command can not be empty", + )); + } Ok(Self { span: command.name.span(), - names: wallets.into_iter().collect(), + names, }) } } diff --git a/packages/fuels-macros/src/setup_program_test/parsing/commands/run_on_live_node.rs b/packages/fuels-macros/src/setup_program_test/parsing/commands/run_on_live_node.rs new file mode 100644 index 000000000..df6de7705 --- /dev/null +++ b/packages/fuels-macros/src/setup_program_test/parsing/commands/run_on_live_node.rs @@ -0,0 +1,28 @@ +use std::convert::TryFrom; + +use proc_macro2::Span; +use syn::Error; + +use crate::parse_utils::Command; + +#[derive(Debug, Clone)] +pub struct RunOnLiveNodeCommand { + pub span: Span, +} + +impl TryFrom for RunOnLiveNodeCommand { + type Error = Error; + + fn try_from(command: Command) -> Result { + if command.contents.is_empty() { + Ok(Self { + span: command.name.span(), + }) + } else { + Err(Error::new( + command.name.span(), + "`RunOnLiveNode` does not accept arguments", + )) + } + } +} diff --git a/packages/fuels-macros/src/setup_program_test/parsing/validations.rs b/packages/fuels-macros/src/setup_program_test/parsing/validations.rs index 3057a97bc..4132c07f7 100644 --- a/packages/fuels-macros/src/setup_program_test/parsing/validations.rs +++ b/packages/fuels-macros/src/setup_program_test/parsing/validations.rs @@ -8,6 +8,7 @@ use crate::{ parse_utils::ErrorsExt, setup_program_test::parsing::{ AbigenCommand, DeployContractCommand, InitializeWalletCommand, LoadScriptCommand, + RunOnLiveNodeCommand, }, }; @@ -77,6 +78,19 @@ pub(crate) fn validate_all_scripts_are_known( .validate_no_errors() } +pub(crate) fn should_run_on_live_node_command(commands: &[RunOnLiveNodeCommand]) -> Result { + match commands.len() { + 0 => Ok(false), + 1 => Ok(true), + _ => commands + .iter() + .map(|command| Error::new(command.span, "Only one `RunOnLiveNode` command allowed")) + .combine_errors() + .map(Err) + .expect("Known to have at least one error"), + } +} + pub(crate) fn validate_zero_or_one_wallet_command_present( commands: &[InitializeWalletCommand], ) -> Result<()> { diff --git a/packages/fuels-macros/tests/ui/setup_program_test/unknown_command.stderr b/packages/fuels-macros/tests/ui/setup_program_test/unknown_command.stderr index d0e065162..4851b1e14 100644 --- a/packages/fuels-macros/tests/ui/setup_program_test/unknown_command.stderr +++ b/packages/fuels-macros/tests/ui/setup_program_test/unknown_command.stderr @@ -1,4 +1,4 @@ -error: Unrecognized command. Expected one of: 'RunOnLiveNode', 'Wallets', 'Abigen', 'Deploy', 'LoadScript' +error: Unrecognized command. Expected one of: 'Wallets', 'Abigen', 'Deploy', 'LoadScript', 'RunOnLiveNode' --> tests/ui/setup_program_test/unknown_command.rs:10:5 | 10 | UnknownCommand() diff --git a/packages/fuels/tests/contracts.rs b/packages/fuels/tests/contracts.rs index cc0240b28..2028c162c 100644 --- a/packages/fuels/tests/contracts.rs +++ b/packages/fuels/tests/contracts.rs @@ -43,8 +43,8 @@ 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) + #[cfg(not(feature = "test-against-live-node"))] setup_program_test!( - RunOnLiveNode(false), Wallets("wallet"), Abigen( Contract( @@ -72,38 +72,37 @@ async fn test_contract_calling_contract() -> Result<()> { wallet = "wallet" ), ); - if cfg!(feature = "test-against-live-node") { - println!("Testing against live node"); - setup_program_test!( - RunOnLiveNode(true), - Wallets("wallet"), - Abigen( - Contract( - name = "LibContract", - project = "packages/fuels/tests/contracts/lib_contract" - ), - Contract( - name = "LibContractCaller", - project = "packages/fuels/tests/contracts/lib_contract_caller" - ), - ), - Deploy( - name = "lib_contract_instance", - contract = "LibContract", - wallet = "wallet" - ), - Deploy( - name = "lib_contract_instance2", - contract = "LibContract", - wallet = "wallet" + #[cfg(feature = "test-against-live-node")] + setup_program_test!( + RunOnLiveNode, + Wallets("wallet"), + Abigen( + Contract( + name = "LibContract", + project = "packages/fuels/tests/contracts/lib_contract" ), - Deploy( - name = "contract_caller_instance", - contract = "LibContractCaller", - wallet = "wallet" + Contract( + name = "LibContractCaller", + project = "packages/fuels/tests/contracts/lib_contract_caller" ), - ); - }; + ), + Deploy( + name = "lib_contract_instance", + contract = "LibContract", + wallet = "wallet" + ), + Deploy( + name = "lib_contract_instance2", + contract = "LibContract", + wallet = "wallet" + ), + Deploy( + name = "contract_caller_instance", + contract = "LibContractCaller", + wallet = "wallet" + ), + ); + let lib_contract_id = lib_contract_instance.contract_id(); let lib_contract_id2 = lib_contract_instance2.contract_id(); @@ -1534,24 +1533,24 @@ async fn can_configure_decoding_of_contract_return() -> Result<()> { } #[tokio::test] -#[cfg_attr(feature = "test-against-live-node", ignore)] -async fn contract_submit_and_response_local_node() -> Result<()> { - let run_on_live_node = false; - test_contract_submit_and_response(run_on_live_node).await?; - Ok(()) -} - -#[tokio::test] -#[cfg_attr(not(feature = "test-against-live-node"), ignore)] -async fn contract_submit_and_response_live_node() -> Result<()> { - let run_on_live_node = true; - test_contract_submit_and_response(run_on_live_node).await?; - Ok(()) -} +async fn test_contract_submit_and_response() -> Result<()> { + #[cfg(not(feature = "test-against-live-node"))] + setup_program_test!( + Wallets("wallet"), + Abigen(Contract( + name = "TestContract", + project = "packages/fuels/tests/contracts/contract_test" + )), + Deploy( + name = "contract_instance", + contract = "TestContract", + wallet = "wallet" + ), + ); -async fn test_contract_submit_and_response(run_on_live_node: bool) -> Result<()> { + #[cfg(feature = "test-against-live-node")] setup_program_test!( - RunOnLiveNode(false), + RunOnLiveNode, Wallets("wallet"), Abigen(Contract( name = "TestContract", @@ -1563,21 +1562,6 @@ async fn test_contract_submit_and_response(run_on_live_node: bool) -> Result<()> wallet = "wallet" ), ); - if run_on_live_node { - setup_program_test!( - RunOnLiveNode(true), - Wallets("wallet"), - Abigen(Contract( - name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" - )), - Deploy( - name = "contract_instance", - contract = "TestContract", - wallet = "wallet" - ), - ); - } let contract_methods = contract_instance.methods(); From 4000715c647ee7db35d779dda2e5e6c6458c940a Mon Sep 17 00:00:00 2001 From: iqdecay Date: Thu, 26 Oct 2023 13:38:51 +0200 Subject: [PATCH 16/30] fix ci file formatting --- .github/workflows/ci.yml | 51 +++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e5c2ef093..aa41c1ec7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -259,39 +259,36 @@ jobs: if: ${{ matrix.command == 'check_doc_unresolved_links' }} run: | ! cargo doc --document-private-items |& grep -A 6 "warning: unresolved link to" + - name: Run some tests against live node continue-on-error: true # if: github.event_name == "push" && ${{ matrix.command == 'test_against_live_node' }} if: ${{ matrix.command == 'test_against_live_node' }} run: cargo test --features test-against-live-node + publish: + needs: + - cargo-verifications + - publish-crates-check + # Only do this job if publishing a release + if: github.event_name == 'release' && github.event.action == 'published' + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 -publish: - needs: - - cargo-verifications - - publish-crates-check - # Only do this job if publishing a release - if: github.event_name == 'release' && github.event.action == 'published' - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{ env.RUST_VERSION }} - - - name: Verify tag version - run: | - curl -sSLf "$DASEL_VERSION" -L -o dasel && chmod +x dasel - mv ./dasel /usr/local/bin/dasel - ./.github/workflows/scripts/verify_tag.sh ${{ github.ref_name }} Cargo.toml - - name: Publish crate - uses: katyo/publish-crates@v2 - with: - publish-delay: 30000 - registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} - + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_VERSION }} + - name: Verify tag version + run: | + curl -sSLf "$DASEL_VERSION" -L -o dasel && chmod +x dasel + mv ./dasel /usr/local/bin/dasel + ./.github/workflows/scripts/verify_tag.sh ${{ github.ref_name }} Cargo.toml + - name: Publish crate + uses: katyo/publish-crates@v2 + with: + publish-delay: 30000 + registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} From 5e6c02ed23cdf189b764b79774a5cb952285785f Mon Sep 17 00:00:00 2001 From: iqdecay Date: Thu, 26 Oct 2023 14:01:40 +0200 Subject: [PATCH 17/30] move the step up --- .github/workflows/ci.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aa41c1ec7..713b2d0f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -255,16 +255,17 @@ jobs: if: ${{ matrix.command == 'check_doc_anchors_valid' }} run: cargo run --bin check-docs + - name: Run some tests against live node + continue-on-error: true +# if: github.event_name == "push" && ${{ matrix.command == 'test_against_live_node' }} + if: ${{ matrix.command == 'test_against_live_node' }} + run: cargo test --features test-against-live-node + - name: Check for unresolved documentation links if: ${{ matrix.command == 'check_doc_unresolved_links' }} run: | ! cargo doc --document-private-items |& grep -A 6 "warning: unresolved link to" - - name: Run some tests against live node - continue-on-error: true - # if: github.event_name == "push" && ${{ matrix.command == 'test_against_live_node' }} - if: ${{ matrix.command == 'test_against_live_node' }} - run: cargo test --features test-against-live-node publish: needs: From 3959fc156a75446f93a1214aeb0b4530ade6eb34 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Thu, 26 Oct 2023 14:03:10 +0200 Subject: [PATCH 18/30] ci: use new secrets name --- .github/workflows/ci.yml | 6 +++--- packages/fuels-test-helpers/src/accounts.rs | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 713b2d0f9..b3eb4d801 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,9 +22,9 @@ env: FORC_PATCH_BRANCH: "xunilrj/fix-implicit-std-env-vars" FORC_PATCH_REVISION: "" FORC_IMPLICIT_STD_GIT_BRANCH: "xunilrj/fix-implicit-std-env-vars" - SECRET_KEY_1: ${{ secrets.SECRET_KEY_1 }} - SECRET_KEY_2: ${{ secrets.SECRET_KEY_2 }} - SECRET_KEY_3: ${{ secrets.SECRET_KEY_3 }} + 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: diff --git a/packages/fuels-test-helpers/src/accounts.rs b/packages/fuels-test-helpers/src/accounts.rs index a732d896c..cadbed019 100644 --- a/packages/fuels-test-helpers/src/accounts.rs +++ b/packages/fuels-test-helpers/src/accounts.rs @@ -105,8 +105,9 @@ pub async fn connect_to_testnet_node_and_get_wallets( .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!("SECRET_KEY_{wallet_counter}")) - .expect("Should find private key in ENV"); + 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())) From 1451f9a5be0e8c5215a12e14b3edae253c9613fb Mon Sep 17 00:00:00 2001 From: iqdecay Date: Fri, 27 Oct 2023 19:08:11 +0200 Subject: [PATCH 19/30] ci: live node tests on their own job --- .github/workflows/ci.yml | 43 ++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b3eb4d801..7635519b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -185,10 +185,6 @@ jobs: args: - command: check_doc_unresolved_links args: - - command: test_against_live_node - args: - download_sway_artifacts: sway-examples-w-type-paths - install_fuel_core: true steps: - name: Checkout repository uses: actions/checkout@v3 @@ -255,18 +251,45 @@ jobs: if: ${{ matrix.command == 'check_doc_anchors_valid' }} run: cargo run --bin check-docs - - name: Run some tests against live node - continue-on-error: true -# if: github.event_name == "push" && ${{ matrix.command == 'test_against_live_node' }} - if: ${{ matrix.command == 'test_against_live_node' }} - run: cargo test --features test-against-live-node - - name: Check for unresolved documentation links if: ${{ matrix.command == 'check_doc_unresolved_links' }} run: | ! cargo doc --document-private-items |& grep -A 6 "warning: unresolved link to" + run-live-node: + # if: github.event_name == "push" + needs: + - setup-test-projects + - verify-rust-version + - get-workspace-members + - publish-crates-check + - cargo-verifications + runs-on: ubuntu-latest + continue-on-error: true + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_VERSION }} + components: clippy,rustfmt + - name: Install Fuel Core + run: | + curl -sSLf https://github.com/FuelLabs/fuel-core/releases/download/v${{ env.FUEL_CORE_VERSION }}/fuel-core-${{ env.FUEL_CORE_VERSION }}-x86_64-unknown-linux-gnu.tar.gz -L -o fuel-core.tar.gz + tar -xvf fuel-core.tar.gz + chmod +x fuel-core-${{ env.FUEL_CORE_VERSION }}-x86_64-unknown-linux-gnu/fuel-core + mv fuel-core-${{ env.FUEL_CORE_VERSION }}-x86_64-unknown-linux-gnu/fuel-core /usr/local/bin/fuel-core + - name: Download sway example artifacts + uses: actions/download-artifact@v3 + with: + name: sway-examples-w-types-paths + path: packages/fuels/tests/ + - name: Test against live node + run: cargo test --features test-against-live-node publish: needs: - cargo-verifications From 8166869b32324806a7857de998c1c609826c9373 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Fri, 27 Oct 2023 19:29:40 +0200 Subject: [PATCH 20/30] fix typo --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7635519b9..2709bd459 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -286,10 +286,11 @@ jobs: - name: Download sway example artifacts uses: actions/download-artifact@v3 with: - name: sway-examples-w-types-paths + name: sway-examples-w-type-paths path: packages/fuels/tests/ - name: Test against live node run: cargo test --features test-against-live-node + publish: needs: - cargo-verifications From 9d3f56e2ed53eb84ea2a9dd23ddb24b3a65980f1 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Fri, 27 Oct 2023 19:32:13 +0200 Subject: [PATCH 21/30] don't wait for cargo verificationsgq --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2709bd459..96e6fab49 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -264,7 +264,6 @@ jobs: - verify-rust-version - get-workspace-members - publish-crates-check - - cargo-verifications runs-on: ubuntu-latest continue-on-error: true From 6482f450926ab830144a73c19db467caf086b387 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Fri, 27 Oct 2023 19:49:06 +0200 Subject: [PATCH 22/30] add continue on error --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96e6fab49..50a1f9732 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -289,6 +289,7 @@ jobs: path: packages/fuels/tests/ - name: Test against live node run: cargo test --features test-against-live-node + continue-on-error: true publish: needs: From 0cca920a6560959f584691a5fe9430e1f2eb5334 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Mon, 30 Oct 2023 15:51:43 +0100 Subject: [PATCH 23/30] move continue on error --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 50a1f9732..1b32849ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -265,8 +265,6 @@ jobs: - get-workspace-members - publish-crates-check runs-on: ubuntu-latest - continue-on-error: true - steps: - name: Checkout repository uses: actions/checkout@v3 From 41f15bdc9d1f6dce0c875ae32b76fc1732f18341 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Wed, 15 Nov 2023 18:59:05 +0100 Subject: [PATCH 24/30] feat: implement suggestion --- .../parsing/commands/run_on_live_node.rs | 28 --------- packages/fuels-test-helpers/Cargo.toml | 1 + packages/fuels-test-helpers/src/accounts.rs | 15 ++++- packages/fuels/tests/contracts.rs | 57 +++---------------- 4 files changed, 23 insertions(+), 78 deletions(-) delete mode 100644 packages/fuels-macros/src/setup_program_test/parsing/commands/run_on_live_node.rs diff --git a/packages/fuels-macros/src/setup_program_test/parsing/commands/run_on_live_node.rs b/packages/fuels-macros/src/setup_program_test/parsing/commands/run_on_live_node.rs deleted file mode 100644 index df6de7705..000000000 --- a/packages/fuels-macros/src/setup_program_test/parsing/commands/run_on_live_node.rs +++ /dev/null @@ -1,28 +0,0 @@ -use std::convert::TryFrom; - -use proc_macro2::Span; -use syn::Error; - -use crate::parse_utils::Command; - -#[derive(Debug, Clone)] -pub struct RunOnLiveNodeCommand { - pub span: Span, -} - -impl TryFrom for RunOnLiveNodeCommand { - type Error = Error; - - fn try_from(command: Command) -> Result { - if command.contents.is_empty() { - Ok(Self { - span: command.name.span(), - }) - } else { - Err(Error::new( - command.name.span(), - "`RunOnLiveNode` does not accept arguments", - )) - } - } -} diff --git a/packages/fuels-test-helpers/Cargo.toml b/packages/fuels-test-helpers/Cargo.toml index a99dc7b68..2f226702e 100644 --- a/packages/fuels-test-helpers/Cargo.toml +++ b/packages/fuels-test-helpers/Cargo.toml @@ -34,3 +34,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 cadbed019..0b1925f67 100644 --- a/packages/fuels-test-helpers/src/accounts.rs +++ b/packages/fuels-test-helpers/src/accounts.rs @@ -6,7 +6,7 @@ use fuels_accounts::{ }; use fuels_core::constants::TESTNET_NODE_URL; use fuels_core::error; -use fuels_core::types::errors::{Error, Result}; +use fuels_core::types::errors::Result; use crate::{ node_types::{ChainConfig, Config}, @@ -116,6 +116,19 @@ pub async fn connect_to_testnet_node_and_get_wallets( 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 fuels_accounts::{fuel_crypto::fuel_types::AssetId, Account, ViewOnlyAccount}; diff --git a/packages/fuels/tests/contracts.rs b/packages/fuels/tests/contracts.rs index 2028c162c..62a138a37 100644 --- a/packages/fuels/tests/contracts.rs +++ b/packages/fuels/tests/contracts.rs @@ -43,39 +43,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) - #[cfg(not(feature = "test-against-live-node"))] - setup_program_test!( - Wallets("wallet"), - Abigen( - Contract( - name = "LibContract", - project = "packages/fuels/tests/contracts/lib_contract" - ), - Contract( - name = "LibContractCaller", - project = "packages/fuels/tests/contracts/lib_contract_caller" - ), - ), - Deploy( - name = "lib_contract_instance", - contract = "LibContract", - wallet = "wallet" - ), - Deploy( - name = "lib_contract_instance2", - contract = "LibContract", - wallet = "wallet" - ), - Deploy( - name = "contract_caller_instance", - contract = "LibContractCaller", - wallet = "wallet" - ), - ); - #[cfg(feature = "test-against-live-node")] + let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) + .await? + .try_into() + .expect("Vec can be converted to an array"); setup_program_test!( - RunOnLiveNode, - Wallets("wallet"), Abigen( Contract( name = "LibContract", @@ -1534,24 +1506,11 @@ async fn can_configure_decoding_of_contract_return() -> Result<()> { #[tokio::test] async fn test_contract_submit_and_response() -> Result<()> { - #[cfg(not(feature = "test-against-live-node"))] - setup_program_test!( - Wallets("wallet"), - Abigen(Contract( - name = "TestContract", - project = "packages/fuels/tests/contracts/contract_test" - )), - Deploy( - name = "contract_instance", - contract = "TestContract", - wallet = "wallet" - ), - ); - - #[cfg(feature = "test-against-live-node")] + let [wallet]: [WalletUnlocked; 1] = maybe_live_wallet(1) + .await? + .try_into() + .expect("Vec can be converted to an array"); setup_program_test!( - RunOnLiveNode, - Wallets("wallet"), Abigen(Contract( name = "TestContract", project = "packages/fuels/tests/contracts/contract_test" From bf6b63b792d9c9374da60f6864d5e5708db91ee9 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Wed, 15 Nov 2023 18:59:48 +0100 Subject: [PATCH 25/30] remove RunOnLiveNode command --- .../src/setup_program_test/code_gen.rs | 46 +++++-------------- .../src/setup_program_test/parsing.rs | 2 +- .../setup_program_test/parsing/commands.rs | 9 ---- .../setup_program_test/parsing/validations.rs | 13 ------ 4 files changed, 13 insertions(+), 57 deletions(-) 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 4ce08f608..cfc06c630 100644 --- a/packages/fuels-macros/src/setup_program_test/code_gen.rs +++ b/packages/fuels-macros/src/setup_program_test/code_gen.rs @@ -21,12 +21,11 @@ pub(crate) fn generate_setup_program_test_code( generate_bindings, deploy_contract, load_scripts, - run_on_live_node, } = commands; let project_lookup = generate_project_lookup(&generate_bindings)?; let abigen_code = abigen_code(&project_lookup); - let wallet_code = wallet_initialization_code(initialize_wallets, run_on_live_node)?; + 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); @@ -69,7 +68,6 @@ fn generate_abigen_targets(project_lookup: &HashMap) -> Vec, - run_on_live_node: bool, ) -> syn::Result { let command = if let Some(command) = maybe_command { command @@ -80,37 +78,17 @@ fn wallet_initialization_code( let wallet_names = extract_wallet_names(&command); let num_wallets = wallet_names.len(); - if run_on_live_node { - if num_wallets > 3 { - return Err(syn::Error::new( - command.span, - format!( - "'RunOnLiveNode` supports at most 3 wallet names inside the 'Wallets' command. Found {}.", - num_wallets - ), - )); - } - - Ok(quote! { - let [#(#wallet_names),*]: [_; #num_wallets] = connect_to_testnet_node_and_get_wallets(#num_wallets) - .await - .expect("Error while trying to get wallets connected to testnet node") - .try_into() - .expect("Should have the exact number of wallets"); - }) - } else { - Ok(quote! { - let [#(#wallet_names),*]: [_; #num_wallets] = launch_custom_provider_and_get_wallets( - WalletsConfig::new(Some(#num_wallets as u64), None, None), - None, - None, - ) - .await - .expect("Error while trying to fetch wallets from the custom provider") - .try_into() - .expect("Should have the exact number of wallets"); - }) - } + Ok(quote! { + let [#(#wallet_names),*]: [_; #num_wallets] = launch_custom_provider_and_get_wallets( + WalletsConfig::new(Some(#num_wallets as u64), None, None), + None, + None, + ) + .await + .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.rs b/packages/fuels-macros/src/setup_program_test/parsing.rs index 36029da63..4057e6b3d 100644 --- a/packages/fuels-macros/src/setup_program_test/parsing.rs +++ b/packages/fuels-macros/src/setup_program_test/parsing.rs @@ -1,6 +1,6 @@ pub(crate) use commands::{ AbigenCommand, DeployContractCommand, InitializeWalletCommand, LoadScriptCommand, - RunOnLiveNodeCommand, TestProgramCommands, + TestProgramCommands, }; mod command_parser; 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 6113ba1fa..0653ea77b 100644 --- a/packages/fuels-macros/src/setup_program_test/parsing/commands.rs +++ b/packages/fuels-macros/src/setup_program_test/parsing/commands.rs @@ -3,7 +3,6 @@ pub(crate) use deploy_contract::DeployContractCommand; pub(crate) use initialize_wallet::InitializeWalletCommand; use itertools::Itertools; pub(crate) use load_script::LoadScriptCommand; -pub(crate) use run_on_live_node::RunOnLiveNodeCommand; use syn::{ parse::{Parse, ParseStream}, Result, @@ -17,13 +16,10 @@ use crate::setup_program_test::parsing::{ }, }; -use super::validations::should_run_on_live_node_command; - mod abigen; mod deploy_contract; mod initialize_wallet; mod load_script; -mod run_on_live_node; // Contains the result of parsing the input to the `setup_program_test` macro. // Contents represent the users wishes with regards to wallet initialization, @@ -33,7 +29,6 @@ pub(crate) struct TestProgramCommands { pub(crate) generate_bindings: AbigenCommand, pub(crate) deploy_contract: Vec, pub(crate) load_scripts: Vec, - pub(crate) run_on_live_node: bool, } command_parser!( @@ -41,7 +36,6 @@ command_parser!( Abigen -> AbigenCommand, Deploy -> DeployContractCommand, LoadScript -> LoadScriptCommand, - RunOnLiveNode -> RunOnLiveNodeCommand, ); impl Parse for TestProgramCommands { @@ -58,14 +52,11 @@ impl Parse for TestProgramCommands { validate_zero_or_one_wallet_command_present(&parsed_commands.Wallets)?; - let run_on_live_node = should_run_on_live_node_command(&parsed_commands.RunOnLiveNode)?; - Ok(Self { initialize_wallets: parsed_commands.Wallets.pop(), generate_bindings: abigen_command, deploy_contract: parsed_commands.Deploy, load_scripts: parsed_commands.LoadScript, - run_on_live_node, }) } } diff --git a/packages/fuels-macros/src/setup_program_test/parsing/validations.rs b/packages/fuels-macros/src/setup_program_test/parsing/validations.rs index 4132c07f7..42c5abed7 100644 --- a/packages/fuels-macros/src/setup_program_test/parsing/validations.rs +++ b/packages/fuels-macros/src/setup_program_test/parsing/validations.rs @@ -78,19 +78,6 @@ pub(crate) fn validate_all_scripts_are_known( .validate_no_errors() } -pub(crate) fn should_run_on_live_node_command(commands: &[RunOnLiveNodeCommand]) -> Result { - match commands.len() { - 0 => Ok(false), - 1 => Ok(true), - _ => commands - .iter() - .map(|command| Error::new(command.span, "Only one `RunOnLiveNode` command allowed")) - .combine_errors() - .map(Err) - .expect("Known to have at least one error"), - } -} - pub(crate) fn validate_zero_or_one_wallet_command_present( commands: &[InitializeWalletCommand], ) -> Result<()> { From da4f61d76369b09406a0e8180bdcea388c53dbd3 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Wed, 15 Nov 2023 19:15:48 +0100 Subject: [PATCH 26/30] Revert "PR comments" This reverts commit 2410a45700f6a79c133905ed51c5754c36fb5f61. --- .../fuels-macros/src/parse_utils/command.rs | 42 +++++++------------ .../parsing/command_parser.rs | 10 ++++- .../parsing/commands/initialize_wallet.rs | 12 +----- .../setup_program_test/parsing/validations.rs | 1 - .../setup_program_test/unknown_command.stderr | 2 +- packages/fuels/tests/contracts.rs | 1 - 6 files changed, 27 insertions(+), 41 deletions(-) diff --git a/packages/fuels-macros/src/parse_utils/command.rs b/packages/fuels-macros/src/parse_utils/command.rs index 4422ee7d3..e634f2787 100644 --- a/packages/fuels-macros/src/parse_utils/command.rs +++ b/packages/fuels-macros/src/parse_utils/command.rs @@ -5,7 +5,6 @@ use syn::{ token::Comma, Error, Meta, Meta::List, - Meta::Path, }; #[derive(Debug)] @@ -24,34 +23,23 @@ impl Command { } pub fn new(meta: Meta) -> syn::Result { - match meta { - List(meta_list) => { - let name = meta_list.path.get_ident().cloned().ok_or_else(|| { - Error::new_spanned( - &meta_list.path, - "Command name cannot be a Path -- i.e. contain ':'.", - ) - })?; + if let List(meta_list) = meta { + let name = meta_list.path.get_ident().cloned().ok_or_else(|| { + Error::new_spanned( + &meta_list.path, + "Command name cannot be a Path -- i.e. contain ':'.", + ) + })?; - Ok(Self { - name, - contents: meta_list.tokens, - }) - } - Path(ref path) => { - let name = path.get_ident().cloned().ok_or_else(|| { - Error::new_spanned(path, "Command name cannot be a Path -- i.e. contain ':'.") - })?; - - Ok(Self { - name, - contents: Default::default(), - }) - } - _ => Err(Error::new_spanned( + Ok(Self { + name, + contents: meta_list.tokens, + }) + } else { + Err(Error::new_spanned( meta, - "Expected a command name literal or Path -- e.g. `Something(...)` or `Something`", - )), + "Expected a command name literal -- e.g. `Something(...)`", + )) } } diff --git a/packages/fuels-macros/src/setup_program_test/parsing/command_parser.rs b/packages/fuels-macros/src/setup_program_test/parsing/command_parser.rs index e4acc99f3..4e34ec7e8 100644 --- a/packages/fuels-macros/src/setup_program_test/parsing/command_parser.rs +++ b/packages/fuels-macros/src/setup_program_test/parsing/command_parser.rs @@ -3,16 +3,24 @@ macro_rules! command_parser { #[derive(Default)] #[allow(non_snake_case)] pub(crate) struct CommandParser { + pub(crate) run_on_live_node: bool, $(pub(crate) $command_name: Vec<$command_struct>),* } impl CommandParser { fn available_commands() -> impl Iterator { - [$(stringify!($command_name)),*].into_iter() + ["RunOnLiveNode", $(stringify!($command_name)),*].into_iter() } pub(crate) fn parse_and_save(&mut self, command: $crate::parse_utils::Command) -> ::syn::Result<()>{ match command.name.to_string().as_str() { + "RunOnLiveNode" => { + if let Ok(content) = command.contents.to_string().parse() { + self.run_on_live_node = content + } else { + return Err(::syn::Error::new(command.name.span(), format!("Expected 'true' or 'false' inside 'RunOnLiveNode' command"))); + } + } $(stringify!($command_name) => self.$command_name.push(command.try_into()?),)* _ => { let msg = Self::available_commands().map(|command| format!("'{command}'")).join(", "); diff --git a/packages/fuels-macros/src/setup_program_test/parsing/commands/initialize_wallet.rs b/packages/fuels-macros/src/setup_program_test/parsing/commands/initialize_wallet.rs index fe37bf22f..2396eaa09 100644 --- a/packages/fuels-macros/src/setup_program_test/parsing/commands/initialize_wallet.rs +++ b/packages/fuels-macros/src/setup_program_test/parsing/commands/initialize_wallet.rs @@ -15,19 +15,11 @@ impl TryFrom for InitializeWalletCommand { type Error = Error; fn try_from(command: Command) -> Result { - let wallets = UniqueLitStrs::new(command.contents.clone())?; - let names: Vec = wallets.into_iter().collect(); - - if names.is_empty() { - return Err(Error::new( - command.name.span(), - "`Wallets` command can not be empty", - )); - } + let wallets = UniqueLitStrs::new(command.contents)?; Ok(Self { span: command.name.span(), - names, + names: wallets.into_iter().collect(), }) } } diff --git a/packages/fuels-macros/src/setup_program_test/parsing/validations.rs b/packages/fuels-macros/src/setup_program_test/parsing/validations.rs index 42c5abed7..3057a97bc 100644 --- a/packages/fuels-macros/src/setup_program_test/parsing/validations.rs +++ b/packages/fuels-macros/src/setup_program_test/parsing/validations.rs @@ -8,7 +8,6 @@ use crate::{ parse_utils::ErrorsExt, setup_program_test::parsing::{ AbigenCommand, DeployContractCommand, InitializeWalletCommand, LoadScriptCommand, - RunOnLiveNodeCommand, }, }; diff --git a/packages/fuels-macros/tests/ui/setup_program_test/unknown_command.stderr b/packages/fuels-macros/tests/ui/setup_program_test/unknown_command.stderr index 4851b1e14..d0e065162 100644 --- a/packages/fuels-macros/tests/ui/setup_program_test/unknown_command.stderr +++ b/packages/fuels-macros/tests/ui/setup_program_test/unknown_command.stderr @@ -1,4 +1,4 @@ -error: Unrecognized command. Expected one of: 'Wallets', 'Abigen', 'Deploy', 'LoadScript', 'RunOnLiveNode' +error: Unrecognized command. Expected one of: 'RunOnLiveNode', 'Wallets', 'Abigen', 'Deploy', 'LoadScript' --> tests/ui/setup_program_test/unknown_command.rs:10:5 | 10 | UnknownCommand() diff --git a/packages/fuels/tests/contracts.rs b/packages/fuels/tests/contracts.rs index 62a138a37..aef1e597c 100644 --- a/packages/fuels/tests/contracts.rs +++ b/packages/fuels/tests/contracts.rs @@ -74,7 +74,6 @@ async fn test_contract_calling_contract() -> Result<()> { wallet = "wallet" ), ); - let lib_contract_id = lib_contract_instance.contract_id(); let lib_contract_id2 = lib_contract_instance2.contract_id(); From 25302690780f16d307bde56d51a0bf10f735f777 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Wed, 15 Nov 2023 19:26:37 +0100 Subject: [PATCH 27/30] add comment --- .github/workflows/ci.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b32849ca..bf551a533 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 @@ -258,6 +258,8 @@ jobs: run-live-node: + + # is commented out for now so we can test the CI works properly # if: github.event_name == "push" needs: - setup-test-projects From 67f8054003c6748571f44d658a0a2d8c3f0fc737 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Wed, 15 Nov 2023 19:34:11 +0100 Subject: [PATCH 28/30] fmt --- .github/workflows/ci.yml | 6 +++--- packages/fuels/tests/scripts.rs | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf551a533..e30d82d7a 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 diff --git a/packages/fuels/tests/scripts.rs b/packages/fuels/tests/scripts.rs index 3f1f021e1..a8edbd98b 100644 --- a/packages/fuels/tests/scripts.rs +++ b/packages/fuels/tests/scripts.rs @@ -26,8 +26,11 @@ async fn test_transaction_script_workflow() -> Result<()> { #[tokio::test] async fn test_multi_call_script_workflow() -> 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" @@ -404,8 +407,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" From 2d6b35c40b3f8dc9f49799c6cd8981aad782bc56 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Wed, 15 Nov 2023 19:36:36 +0100 Subject: [PATCH 29/30] remove artifacts --- .../src/setup_program_test/parsing/command_parser.rs | 10 +--------- .../tests/ui/setup_program_test/unknown_command.stderr | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/packages/fuels-macros/src/setup_program_test/parsing/command_parser.rs b/packages/fuels-macros/src/setup_program_test/parsing/command_parser.rs index 4e34ec7e8..e4acc99f3 100644 --- a/packages/fuels-macros/src/setup_program_test/parsing/command_parser.rs +++ b/packages/fuels-macros/src/setup_program_test/parsing/command_parser.rs @@ -3,24 +3,16 @@ macro_rules! command_parser { #[derive(Default)] #[allow(non_snake_case)] pub(crate) struct CommandParser { - pub(crate) run_on_live_node: bool, $(pub(crate) $command_name: Vec<$command_struct>),* } impl CommandParser { fn available_commands() -> impl Iterator { - ["RunOnLiveNode", $(stringify!($command_name)),*].into_iter() + [$(stringify!($command_name)),*].into_iter() } pub(crate) fn parse_and_save(&mut self, command: $crate::parse_utils::Command) -> ::syn::Result<()>{ match command.name.to_string().as_str() { - "RunOnLiveNode" => { - if let Ok(content) = command.contents.to_string().parse() { - self.run_on_live_node = content - } else { - return Err(::syn::Error::new(command.name.span(), format!("Expected 'true' or 'false' inside 'RunOnLiveNode' command"))); - } - } $(stringify!($command_name) => self.$command_name.push(command.try_into()?),)* _ => { let msg = Self::available_commands().map(|command| format!("'{command}'")).join(", "); diff --git a/packages/fuels-macros/tests/ui/setup_program_test/unknown_command.stderr b/packages/fuels-macros/tests/ui/setup_program_test/unknown_command.stderr index d0e065162..b39e2dad6 100644 --- a/packages/fuels-macros/tests/ui/setup_program_test/unknown_command.stderr +++ b/packages/fuels-macros/tests/ui/setup_program_test/unknown_command.stderr @@ -1,4 +1,4 @@ -error: Unrecognized command. Expected one of: 'RunOnLiveNode', 'Wallets', 'Abigen', 'Deploy', 'LoadScript' +error: Unrecognized command. Expected one of: 'Wallets', 'Abigen', 'Deploy', 'LoadScript' --> tests/ui/setup_program_test/unknown_command.rs:10:5 | 10 | UnknownCommand() From ecd0f83caef32029b32977ddf0e919c0344ecb39 Mon Sep 17 00:00:00 2001 From: iqdecay Date: Wed, 15 Nov 2023 20:20:02 +0100 Subject: [PATCH 30/30] remove the CI step --- .github/workflows/ci.yml | 35 ------------------- .../src/setup_program_test/code_gen.rs | 3 ++ 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e30d82d7a..03a5b6751 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -256,41 +256,6 @@ jobs: run: | ! cargo doc --document-private-items |& grep -A 6 "warning: unresolved link to" - - run-live-node: - - # is commented out for now so we can test the CI works properly - # if: github.event_name == "push" - needs: - - setup-test-projects - - verify-rust-version - - get-workspace-members - - publish-crates-check - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - ref: ${{ github.event.pull_request.head.sha }} - - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{ env.RUST_VERSION }} - components: clippy,rustfmt - - name: Install Fuel Core - run: | - curl -sSLf https://github.com/FuelLabs/fuel-core/releases/download/v${{ env.FUEL_CORE_VERSION }}/fuel-core-${{ env.FUEL_CORE_VERSION }}-x86_64-unknown-linux-gnu.tar.gz -L -o fuel-core.tar.gz - tar -xvf fuel-core.tar.gz - chmod +x fuel-core-${{ env.FUEL_CORE_VERSION }}-x86_64-unknown-linux-gnu/fuel-core - mv fuel-core-${{ env.FUEL_CORE_VERSION }}-x86_64-unknown-linux-gnu/fuel-core /usr/local/bin/fuel-core - - name: Download sway example artifacts - uses: actions/download-artifact@v3 - with: - name: sway-examples-w-type-paths - path: packages/fuels/tests/ - - name: Test against live node - run: cargo test --features test-against-live-node - continue-on-error: true - publish: needs: - cargo-verifications 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 cfc06c630..44caaf67e 100644 --- a/packages/fuels-macros/src/setup_program_test/code_gen.rs +++ b/packages/fuels-macros/src/setup_program_test/code_gen.rs @@ -76,6 +76,9 @@ fn wallet_initialization_code( }; let wallet_names = extract_wallet_names(&command); + if wallet_names.is_empty() { + return Ok(Default::default()); + } let num_wallets = wallet_names.len(); Ok(quote! {