diff --git a/e2e/Cargo.toml b/e2e/Cargo.toml index 1dc6a7110..9693a39c8 100644 --- a/e2e/Cargo.toml +++ b/e2e/Cargo.toml @@ -23,6 +23,7 @@ fuels = { workspace = true } tai64 = { workspace = true } tempfile = { workspace = true } tokio = { workspace = true, features = ["test-util"] } +test-case = { workspace = true } [build-dependencies] anyhow = { workspace = true, features = ["std"] } diff --git a/e2e/tests/configurables.rs b/e2e/tests/configurables.rs index ad23a07e9..0d7ddc76a 100644 --- a/e2e/tests/configurables.rs +++ b/e2e/tests/configurables.rs @@ -3,22 +3,36 @@ use fuels::{ prelude::*, types::{Bits256, SizedAsciiString, U256}, }; +use test_case::test_case; +#[test_case(true ; "regular")] +#[test_case(false ; "use loader")] #[tokio::test] -async fn contract_default_configurables() -> Result<()> { - setup_program_test!( - Wallets("wallet"), - Abigen(Contract( - name = "MyContract", - project = "e2e/sway/contracts/configurables" - )), - Deploy( - name = "contract_instance", - contract = "MyContract", - wallet = "wallet", - random_salt = false, - ), - ); +async fn contract_default_configurables(is_regular: bool) -> Result<()> { + abigen!(Contract( + name = "MyContract", + abi = "e2e/sway/contracts/configurables/out/release/configurables-abi.json" + )); + + let wallet = launch_provider_and_get_wallet().await?; + + let contract = Contract::load_from( + "sway/contracts/configurables/out/release/configurables.bin", + LoadConfiguration::default(), + )?; + + let contract_id = if is_regular { + contract + .deploy_if_not_exists(&wallet, TxPolicies::default()) + .await? + } else { + contract + .convert_to_loader(124)? + .deploy_if_not_exists(&wallet, TxPolicies::default()) + .await? + }; + + let contract_instance = MyContract::new(contract_id, wallet.clone()); let response = contract_instance .methods() @@ -49,25 +63,29 @@ async fn contract_default_configurables() -> Result<()> { Ok(()) } +#[test_case(true ; "regular")] +#[test_case(false ; "use loader")] #[tokio::test] -async fn script_default_configurables() -> Result<()> { - setup_program_test!( - Wallets("wallet"), - Abigen(Script( - name = "MyScript", - project = "e2e/sway/scripts/script_configurables" - )), - LoadScript( - name = "script_instance", - script = "MyScript", - wallet = "wallet" - ) - ); - - let mut script_instance = script_instance; - script_instance.convert_into_loader().await?; +async fn script_default_configurables(is_regular: bool) -> Result<()> { + abigen!(Script( + name = "MyScript", + abi = "e2e/sway/scripts/script_configurables/out/release/script_configurables-abi.json" + )); - let response = script_instance.main().call().await?; + let wallet = launch_provider_and_get_wallet().await?; + let bin_path = "sway/scripts/script_configurables/out/release/script_configurables.bin"; + let mut script_instance = MyScript::new(wallet, bin_path); + + let response = if is_regular { + script_instance.main().call().await? + } else { + script_instance + .convert_into_loader() + .await? + .main() + .call() + .await? + }; let expected_value = ( true, @@ -92,9 +110,10 @@ async fn script_default_configurables() -> Result<()> { Ok(()) } +#[test_case(true ; "regular")] +#[test_case(false ; "use loader")] #[tokio::test] -async fn contract_configurables() -> Result<()> { - // ANCHOR: contract_configurables +async fn contract_configurables(is_regular: bool) -> Result<()> { abigen!(Contract( name = "MyContract", abi = "e2e/sway/contracts/configurables/out/release/configurables-abi.json" @@ -123,15 +142,23 @@ async fn contract_configurables() -> Result<()> { .with_STRUCT(new_struct.clone())? .with_ENUM(new_enum.clone())?; - let contract_id = Contract::load_from( + let contract = Contract::load_from( "sway/contracts/configurables/out/release/configurables.bin", LoadConfiguration::default().with_configurables(configurables), - )? - .deploy_if_not_exists(&wallet, TxPolicies::default()) - .await?; + )?; + + let contract_id = if is_regular { + contract + .deploy_if_not_exists(&wallet, TxPolicies::default()) + .await? + } else { + contract + .convert_to_loader(124)? + .deploy_if_not_exists(&wallet, TxPolicies::default()) + .await? + }; let contract_instance = MyContract::new(contract_id, wallet.clone()); - // ANCHOR_END: contract_configurables let response = contract_instance .methods() @@ -159,8 +186,10 @@ async fn contract_configurables() -> Result<()> { Ok(()) } +#[test_case(true ; "regular")] +#[test_case(false ; "use loader")] #[tokio::test] -async fn contract_dyn_configurables() -> Result<()> { +async fn contract_dyn_configurables(is_regular: bool) -> Result<()> { abigen!(Contract( name = "MyContract", abi = "e2e/sway/contracts/dyn_configurables/out/release/dyn_configurables-abi.json" @@ -175,15 +204,21 @@ async fn contract_dyn_configurables() -> Result<()> { .with_STR_3("fuel-fuel".try_into()?)? .with_LAST_U8(12)?; - dbg!(&configurables); - - let contract_id = Contract::load_from( + let contract = Contract::load_from( "sway/contracts/dyn_configurables/out/release/dyn_configurables.bin", LoadConfiguration::default().with_configurables(configurables), - )? - .convert_to_loader(100)? //TODO: @hal3e add test-case for convert to loader with or without - .deploy_if_not_exists(&wallet, TxPolicies::default()) - .await?; + )?; + + let contract_id = if is_regular { + contract + .deploy_if_not_exists(&wallet, TxPolicies::default()) + .await? + } else { + contract + .convert_to_loader(124)? + .deploy_if_not_exists(&wallet, TxPolicies::default()) + .await? + }; let contract_instance = MyContract::new(contract_id, wallet.clone()); @@ -207,9 +242,10 @@ async fn contract_dyn_configurables() -> Result<()> { Ok(()) } +#[test_case(true ; "regular")] +#[test_case(false ; "use loader")] #[tokio::test] -async fn script_configurables() -> Result<()> { - // ANCHOR: script_configurables +async fn script_configurables(is_regular: bool) -> Result<()> { abigen!(Script( name = "MyScript", abi = "e2e/sway/scripts/script_configurables/out/release/script_configurables-abi.json" @@ -243,12 +279,18 @@ async fn script_configurables() -> Result<()> { .with_STRUCT(new_struct.clone())? .with_ENUM(new_enum.clone())?; - let response = script_instance - .with_configurables(configurables) - .main() - .call() - .await?; - // ANCHOR_END: script_configurables + let mut script_instance = script_instance.with_configurables(configurables); + + let response = if is_regular { + script_instance.main().call().await? + } else { + script_instance + .convert_into_loader() + .await? + .main() + .call() + .await? + }; let expected_value = ( false, @@ -270,8 +312,10 @@ async fn script_configurables() -> Result<()> { Ok(()) } +#[test_case(true ; "regular")] +#[test_case(false ; "use loader")] #[tokio::test] -async fn script_dyn_configurables() -> Result<()> { +async fn script_dyn_configurables(is_regular: bool) -> Result<()> { abigen!(Script( name = "MyScript", abi = "e2e/sway/scripts/script_dyn_configurables/out/release/script_dyn_configurables-abi.json" @@ -288,15 +332,18 @@ async fn script_dyn_configurables() -> Result<()> { .with_STR_3("fuel-fuel".try_into()?)? .with_LAST_U8(12)?; - dbg!(&configurables); - - let response = script_instance - .with_configurables(configurables) - .convert_into_loader() //TODO: @hal3e add test-case for this - .await? - .main() - .call() - .await?; + let mut script_instance = script_instance.with_configurables(configurables); + + let response = if is_regular { + script_instance.main().call().await? + } else { + script_instance + .convert_into_loader() + .await? + .main() + .call() + .await? + }; let expected_value = ( false, diff --git a/e2e/tests/predicates.rs b/e2e/tests/predicates.rs index 3dc20b5e3..4a394a769 100644 --- a/e2e/tests/predicates.rs +++ b/e2e/tests/predicates.rs @@ -9,6 +9,7 @@ use fuels::{ programs::executable::Executable, types::{coin::Coin, coin_type::CoinType, input::Input, message::Message, output::Output}, }; +use test_case::test_case; async fn assert_address_balance( address: &Bech32Address, @@ -776,8 +777,10 @@ async fn predicate_configurables() -> Result<()> { Ok(()) } +#[test_case(true ; "regular")] +#[test_case(false ; "use loader")] #[tokio::test] -async fn predicate_dyn_configurables() -> Result<()> { +async fn predicate_dyn_configurables(is_regular: bool) -> Result<()> { abigen!(Predicate( name = "MyPredicate", abi = "e2e/sway/predicates/predicate_dyn_configurables/out/release/predicate_dyn_configurables-abi.json" @@ -799,18 +802,32 @@ async fn predicate_dyn_configurables() -> Result<()> { 12, )?; - let mut predicate: Predicate = Predicate::load_from( + let executable = Executable::load_from( "sway/predicates/predicate_dyn_configurables/out/release/predicate_dyn_configurables.bin", )? - .with_data(predicate_data) - .with_configurables(configurables)?; + .with_configurables(configurables); + + let (maybe_loader, code) = if is_regular { + (None, executable.code()?) + } else { + let loader = executable.convert_to_loader()?; + let code = loader.code()?; + + (Some(loader), code) + }; + + let mut predicate: Predicate = Predicate::from_code(code).with_data(predicate_data); let num_coins = 4; let num_messages = 8; let amount = 16; - let (provider, predicate_balance, receiver, receiver_balance, asset_id, _) = + let (provider, predicate_balance, receiver, receiver_balance, asset_id, extra_wallet) = setup_predicate_test(predicate.address(), num_coins, num_messages, amount).await?; + if let Some(loader) = maybe_loader { + loader.upload_blob(extra_wallet).await?; + } + predicate.set_provider(provider.clone()); // TODO: https://github.com/FuelLabs/fuels-rs/issues/1394 diff --git a/e2e/tests/providers.rs b/e2e/tests/providers.rs index 5e69906f7..0352522a2 100644 --- a/e2e/tests/providers.rs +++ b/e2e/tests/providers.rs @@ -549,7 +549,6 @@ async fn test_call_param_gas_errors() -> Result<()> { .expect_err("should error"); let expected = "transaction reverted: OutOfGas"; - dbg!(&response.to_string()); assert!(response.to_string().starts_with(expected)); // Call params gas_forwarded exceeds transaction limit