diff --git a/e2e/tests/configurables.rs b/e2e/tests/configurables.rs index d9a002d56b..2dbd4a8e6a 100644 --- a/e2e/tests/configurables.rs +++ b/e2e/tests/configurables.rs @@ -13,7 +13,7 @@ async fn contract_default_configurables() -> Result<()> { let wallet = launch_provider_and_get_wallet().await?; - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "sway/contracts/configurables/out/release/configurables.bin", LoadConfiguration::default(), )? @@ -125,7 +125,7 @@ async fn contract_configurables() -> Result<()> { .with_STRUCT(new_struct.clone())? .with_ENUM(new_enum.clone())?; - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "sway/contracts/configurables/out/release/configurables.bin", LoadConfiguration::default().with_configurables(configurables), )? @@ -192,7 +192,7 @@ async fn contract_manual_configurables() -> Result<()> { .with_STRUCT(new_struct.clone())? .with_ENUM(new_enum.clone())?; - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "sway/contracts/configurables/out/release/configurables.bin", LoadConfiguration::default(), )? diff --git a/e2e/tests/contracts.rs b/e2e/tests/contracts.rs index eafb0253f2..2eff20b434 100644 --- a/e2e/tests/contracts.rs +++ b/e2e/tests/contracts.rs @@ -678,7 +678,7 @@ async fn setup_output_variable_estimation_test() -> Result<( let wallet_config = WalletsConfig::new(Some(3), None, None); let wallets = launch_custom_provider_and_get_wallets(wallet_config, None, None).await?; - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "sway/contracts/token_ops/out/release/token_ops.bin", LoadConfiguration::default(), )? @@ -1750,7 +1750,7 @@ async fn contract_encoder_config_is_applied() -> Result<()> { )), Wallets("wallet") ); - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -1959,7 +1959,7 @@ async fn simulations_can_be_made_without_coins() -> Result<()> { let wallets = setup_node_with_high_price().await?; let wallet = wallets.first().expect("has wallet"); - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -1990,7 +1990,7 @@ async fn simulations_can_be_made_without_coins_multicall() -> Result<()> { let wallets = setup_node_with_high_price().await?; let wallet = wallets.first().expect("has wallet"); - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -2049,7 +2049,7 @@ async fn contract_call_with_non_zero_base_asset_id_and_tip() -> Result<()> { let wallets = launch_custom_provider_and_get_wallets(wallet_config, None, Some(config)).await?; let wallet = wallets.first().expect("has wallet"); - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -2230,7 +2230,7 @@ async fn blob_contract_deployment() -> Result<()> { let contract = Contract::load_from(contract_binary, LoadConfiguration::default())?; - let contract_id = contract + let (contract_id, _) = contract .convert_to_loader(100_000)? .deploy_if_not_exists(&wallets[0], TxPolicies::default()) .await?; @@ -2258,7 +2258,7 @@ async fn regular_contract_can_be_deployed() -> Result<()> { let contract_binary = "sway/contracts/contract_test/out/release/contract_test.bin"; // when - let contract_id = Contract::load_from(contract_binary, LoadConfiguration::default())? + let (contract_id, _) = Contract::load_from(contract_binary, LoadConfiguration::default())? .deploy_if_not_exists(&wallet, TxPolicies::default()) .await?; @@ -2289,7 +2289,7 @@ async fn unuploaded_loader_can_be_deployed_directly() -> Result<()> { let contract_binary = "sway/contracts/huge_contract/out/release/huge_contract.bin"; - let contract_id = Contract::load_from(contract_binary, LoadConfiguration::default())? + let (contract_id, _) = Contract::load_from(contract_binary, LoadConfiguration::default())? .convert_to_loader(1024)? .deploy_if_not_exists(&wallet, TxPolicies::default()) .await?; @@ -2325,7 +2325,7 @@ async fn unuploaded_loader_can_upload_blobs_separately_then_deploy() -> Result<( // if this were an example for the user we'd just call `deploy` on the contract above // this way we are testing that the blobs were really deployed above, otherwise the following // would fail - let contract_id = Contract::loader_from_blob_ids( + let (contract_id, _) = Contract::loader_from_blob_ids( blob_ids.to_vec(), contract.salt(), contract.storage_slots().to_vec(), @@ -2361,7 +2361,7 @@ async fn loader_blob_already_uploaded_not_an_issue() -> Result<()> { .await?; // this will try to upload the blobs but skip upon encountering an error - let contract_id = contract + let (contract_id, _) = contract .deploy_if_not_exists(&wallet, TxPolicies::default()) .await?; @@ -2391,14 +2391,14 @@ async fn loader_works_via_proxy() -> Result<()> { let contract = Contract::load_from(contract_binary, LoadConfiguration::default())?; - let contract_id = contract + let (contract_id, _) = contract .convert_to_loader(100)? .deploy_if_not_exists(&wallet, TxPolicies::default()) .await?; let contract_binary = "sway/contracts/proxy/out/release/proxy.bin"; - let proxy_id = Contract::load_from(contract_binary, LoadConfiguration::default())? + let (proxy_id, _) = Contract::load_from(contract_binary, LoadConfiguration::default())? .deploy_if_not_exists(&wallet, TxPolicies::default()) .await?; @@ -2442,7 +2442,7 @@ async fn loader_storage_works_via_proxy() -> Result<()> { let contract = Contract::load_from(contract_binary, LoadConfiguration::default())?; let contract_storage_slots = contract.storage_slots().to_vec(); - let contract_id = contract + let (contract_id, _) = contract .convert_to_loader(100)? .deploy_if_not_exists(&wallet, TxPolicies::default()) .await?; @@ -2452,7 +2452,7 @@ async fn loader_storage_works_via_proxy() -> Result<()> { let combined_storage_slots = [&contract_storage_slots, proxy_contract.storage_slots()].concat(); - let proxy_id = proxy_contract + let (proxy_id, _) = proxy_contract .with_storage_slots(combined_storage_slots) .deploy_if_not_exists(&wallet, TxPolicies::default()) .await?; diff --git a/e2e/tests/logs.rs b/e2e/tests/logs.rs index 664333c0a9..d6a4d2e333 100644 --- a/e2e/tests/logs.rs +++ b/e2e/tests/logs.rs @@ -382,7 +382,7 @@ async fn test_multi_call_contract_with_contract_logs() -> Result<()> { ), ); - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "./sway/logs/contract_logs/out/release/contract_logs.bin", LoadConfiguration::default(), )? @@ -737,7 +737,7 @@ async fn test_contract_with_contract_logs() -> Result<()> { ) ); - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "./sway/logs/contract_logs/out/release/contract_logs.bin", LoadConfiguration::default(), )? @@ -1020,7 +1020,7 @@ async fn test_contract_require_from_contract() -> Result<()> { ) ); - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "./sway/contracts/lib_contract/out/release/lib_contract.bin", LoadConfiguration::default(), )? @@ -1074,7 +1074,7 @@ async fn test_multi_call_contract_require_from_contract() -> Result<()> { ), ); - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "./sway/contracts/lib_contract/out/release/lib_contract.bin", LoadConfiguration::default(), )? @@ -1166,7 +1166,7 @@ async fn test_loader_script_require_from_loader_contract() -> Result<()> { let contract_binary = "sway/contracts/lib_contract/out/release/lib_contract.bin"; let contract = Contract::load_from(contract_binary, LoadConfiguration::default())?; - let contract_id = contract + let (contract_id, _) = contract .convert_to_loader(100_000)? .deploy_if_not_exists(&wallet, TxPolicies::default()) .await?; diff --git a/e2e/tests/predicates.rs b/e2e/tests/predicates.rs index 3acd777e74..5761723785 100644 --- a/e2e/tests/predicates.rs +++ b/e2e/tests/predicates.rs @@ -115,7 +115,7 @@ async fn transfer_coins_and_messages_to_predicate() -> Result<()> { let num_coins = 16; let num_messages = 32; let amount = 64; - let total_balance = (num_coins + num_messages) * amount; + let balance_to_send = ((num_coins + num_messages) * amount) - 1; let mut wallet = WalletUnlocked::new_random(None); @@ -130,25 +130,18 @@ async fn transfer_coins_and_messages_to_predicate() -> Result<()> { Predicate::load_from("sway/predicates/basic_predicate/out/release/basic_predicate.bin")? .with_provider(provider.clone()); - // TODO: https://github.com/FuelLabs/fuels-rs/issues/1394 - let expected_fee = 1; wallet .transfer( predicate.address(), - total_balance - expected_fee, + balance_to_send, asset_id, TxPolicies::default(), ) .await?; // The predicate has received the funds - assert_address_balance( - predicate.address(), - &provider, - asset_id, - total_balance - expected_fee, - ) - .await; + assert_address_balance(predicate.address(), &provider, asset_id, balance_to_send).await; + Ok(()) } @@ -173,12 +166,11 @@ async fn spend_predicate_coins_messages_basic() -> Result<()> { predicate.set_provider(provider.clone()); - // TODO: https://github.com/FuelLabs/fuels-rs/issues/1394 - let expected_fee = 1; + let amount_to_send = predicate_balance - 1; predicate .transfer( receiver.address(), - predicate_balance - expected_fee, + amount_to_send, asset_id, TxPolicies::default(), ) @@ -192,7 +184,7 @@ async fn spend_predicate_coins_messages_basic() -> Result<()> { receiver.address(), &provider, asset_id, - receiver_balance + predicate_balance - expected_fee, + receiver_balance + amount_to_send, ) .await; @@ -221,12 +213,12 @@ async fn pay_with_predicate() -> Result<()> { 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, _) = setup_predicate_test(predicate.address(), num_coins, num_messages, amount).await?; predicate.set_provider(provider.clone()); - let contract_id = Contract::load_from( + let (contract_id, deploy_tx_status) = Contract::load_from( "sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -234,34 +226,27 @@ async fn pay_with_predicate() -> Result<()> { .await?; let contract_methods = MyContract::new(contract_id.clone(), predicate.clone()).methods(); - let tx_policies = TxPolicies::default() - .with_tip(1) - .with_script_gas_limit(1_000_000); - // TODO: https://github.com/FuelLabs/fuels-rs/issues/1394 - let expected_fee = 1; let consensus_parameters = provider.consensus_parameters().await?; + let deploy_fee = deploy_tx_status.unwrap().total_fee(); assert_eq!( predicate .get_asset_balance(consensus_parameters.base_asset_id()) .await?, - 192 - expected_fee + predicate_balance - deploy_fee ); let response = contract_methods .initialize_counter(42) // Build the ABI call - .with_tx_policies(tx_policies) .call() .await?; assert_eq!(42, response.value); - // TODO: https://github.com/FuelLabs/fuels-rs/issues/1394 - let expected_fee = 2; assert_eq!( predicate .get_asset_balance(consensus_parameters.base_asset_id()) .await?, - 191 - expected_fee + predicate_balance - deploy_fee - response.total_fee ); Ok(()) @@ -291,12 +276,12 @@ async fn pay_with_predicate_vector_data() -> Result<()> { 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, _) = setup_predicate_test(predicate.address(), num_coins, num_messages, amount).await?; predicate.set_provider(provider.clone()); - let contract_id = Contract::load_from( + let (contract_id, deploy_tx_status) = Contract::load_from( "sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -304,34 +289,24 @@ async fn pay_with_predicate_vector_data() -> Result<()> { .await?; let contract_methods = MyContract::new(contract_id.clone(), predicate.clone()).methods(); - let tx_policies = TxPolicies::default() - .with_tip(1) - .with_script_gas_limit(1_000_000); - // TODO: https://github.com/FuelLabs/fuels-rs/issues/1394 - let expected_fee = 1; let consensus_parameters = provider.consensus_parameters().await?; + let deploy_fee = deploy_tx_status.unwrap().total_fee(); assert_eq!( predicate .get_asset_balance(consensus_parameters.base_asset_id()) .await?, - 192 - expected_fee + predicate_balance - deploy_fee ); - let response = contract_methods - .initialize_counter(42) - .with_tx_policies(tx_policies) - .call() - .await?; + let response = contract_methods.initialize_counter(42).call().await?; - // TODO: https://github.com/FuelLabs/fuels-rs/issues/1394 - let expected_fee = 2; assert_eq!(42, response.value); assert_eq!( predicate .get_asset_balance(consensus_parameters.base_asset_id()) .await?, - 191 - expected_fee + predicate_balance - deploy_fee - response.total_fee ); Ok(()) @@ -359,7 +334,7 @@ async fn predicate_contract_transfer() -> Result<()> { predicate.set_provider(provider.clone()); - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -501,15 +476,13 @@ async fn predicate_transfer_with_signed_resources() -> Result<()> { let tx = tb.build(&provider).await?; - provider.send_transaction_and_await_commit(tx).await?; + let tx_status = provider.send_transaction_and_await_commit(tx).await?; - // TODO: https://github.com/FuelLabs/fuels-rs/issues/1394 - let expected_fee = 1; assert_address_balance( predicate.address(), &provider, asset_id, - predicate_balance + wallet_balance - expected_fee, + predicate_balance + wallet_balance - tx_status.total_fee(), ) .await; @@ -543,12 +516,12 @@ async fn contract_tx_and_call_params_with_predicate() -> Result<()> { let num_coins = 1; let num_messages = 1; let amount = 1000; - let (provider, _predicate_balance, _receiver, _receiver_balance, _asset_id, _) = + let (provider, predicate_balance, _receiver, _receiver_balance, _asset_id, _) = setup_predicate_test(predicate.address(), num_coins, num_messages, amount).await?; predicate.set_provider(provider.clone()); - let contract_id = Contract::load_from( + let (contract_id, deploy_tx_status) = Contract::load_from( "./sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -573,11 +546,11 @@ async fn contract_tx_and_call_params_with_predicate() -> Result<()> { .call() .await?; - // TODO: https://github.com/FuelLabs/fuels-rs/issues/1394 - let expected_fee = 2; + let deploy_fee = deploy_tx_status.unwrap().total_fee(); + let call_fee = response.total_fee; assert_eq!( predicate.get_asset_balance(&AssetId::zeroed()).await?, - 1800 - expected_fee + predicate_balance - deploy_fee - call_params_amount - call_fee ); } { @@ -628,7 +601,7 @@ async fn diff_asset_predicate_payment() -> Result<()> { predicate.set_provider(provider.clone()); - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "./sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -685,12 +658,11 @@ async fn predicate_default_configurables() -> Result<()> { predicate.set_provider(provider.clone()); - // TODO: https://github.com/FuelLabs/fuels-rs/issues/1394 - let expected_fee = 1; + let amount_to_send = predicate_balance - 1; predicate .transfer( receiver.address(), - predicate_balance - expected_fee, + amount_to_send, asset_id, TxPolicies::default(), ) @@ -704,7 +676,7 @@ async fn predicate_default_configurables() -> Result<()> { receiver.address(), &provider, asset_id, - receiver_balance + predicate_balance - expected_fee, + receiver_balance + amount_to_send, ) .await; @@ -752,12 +724,11 @@ async fn predicate_configurables() -> Result<()> { predicate.set_provider(provider.clone()); - // TODO: https://github.com/FuelLabs/fuels-rs/issues/1394 - let expected_fee = 1; - predicate + let amount_to_send = predicate_balance - 1; + let (_tx_id, tx_status) = predicate .transfer( receiver.address(), - predicate_balance - expected_fee, + amount_to_send, asset_id, TxPolicies::default(), ) @@ -767,11 +738,12 @@ async fn predicate_configurables() -> Result<()> { assert_address_balance(predicate.address(), &provider, asset_id, 0).await; // Funds were transferred + let fee = tx_status.total_fee(); assert_address_balance( receiver.address(), &provider, asset_id, - receiver_balance + predicate_balance - expected_fee, + receiver_balance + predicate_balance - fee, ) .await; @@ -928,16 +900,15 @@ async fn predicate_can_access_manually_added_witnesses() -> Result<()> { tx.append_witness(witness.into())?; tx.append_witness(witness2.into())?; - provider.send_transaction_and_await_commit(tx).await?; + let tx_status = provider.send_transaction_and_await_commit(tx).await?; - // TODO: https://github.com/FuelLabs/fuels-rs/issues/1394 - let expected_fee = 1; + let fee = tx_status.total_fee(); // The predicate has spent the funds assert_address_balance( predicate.address(), &provider, asset_id, - predicate_balance - amount_to_send - expected_fee, + predicate_balance - amount_to_send - fee, ) .await; @@ -1219,14 +1190,16 @@ async fn predicate_configurables_in_blobs() -> Result<()> { predicate.set_provider(provider.clone()); - loader.upload_blob(extra_wallet).await?; + loader + .upload_blob(extra_wallet) + .await? + .expect("has tx_status"); - // TODO: https://github.com/FuelLabs/fuels-rs/issues/1394 - let expected_fee = 1; + let amount_to_send = predicate_balance - 1; predicate .transfer( receiver.address(), - predicate_balance - expected_fee, + amount_to_send, asset_id, TxPolicies::default(), ) @@ -1240,7 +1213,7 @@ async fn predicate_configurables_in_blobs() -> Result<()> { receiver.address(), &provider, asset_id, - receiver_balance + predicate_balance - expected_fee, + receiver_balance + amount_to_send, ) .await; diff --git a/e2e/tests/providers.rs b/e2e/tests/providers.rs index b585b159f3..c70c1877ee 100644 --- a/e2e/tests/providers.rs +++ b/e2e/tests/providers.rs @@ -35,7 +35,7 @@ async fn test_provider_launch_and_connect() -> Result<()> { let provider = setup_test_provider(coins, vec![], None, None).await?; wallet.set_provider(provider.clone()); - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -176,7 +176,7 @@ async fn test_input_message_pays_fee() -> Result<()> { abi = "e2e/sway/contracts/contract_test/out/release/contract_test-abi.json" )); - let contract_id = Contract::load_from( + let (contract_id, deploy_tx_status) = Contract::load_from( "sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -194,9 +194,9 @@ async fn test_input_message_pays_fee() -> Result<()> { assert_eq!(42, response.value); let balance = wallet.get_asset_balance(base_asset_id).await?; - // TODO: https://github.com/FuelLabs/fuels-rs/issues/1394 - let expected_fee = 2; - assert_eq!(balance, DEFAULT_COIN_AMOUNT - expected_fee); + let deploy_fee = deploy_tx_status.unwrap().total_fee(); + let call_fee = response.total_fee; + assert_eq!(balance, DEFAULT_COIN_AMOUNT - deploy_fee - call_fee); Ok(()) } @@ -263,6 +263,7 @@ async fn can_set_custom_block_time() -> Result<()> { assert_eq!(blocks[1].header.time.unwrap().timestamp(), 20); assert_eq!(blocks[2].header.time.unwrap().timestamp(), 40); assert_eq!(blocks[3].header.time.unwrap().timestamp(), 60); + Ok(()) } @@ -1244,7 +1245,7 @@ async fn contract_call_with_impersonation() -> Result<()> { abi = "e2e/sway/contracts/contract_test/out/release/contract_test-abi.json" )); - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? diff --git a/e2e/tests/scripts.rs b/e2e/tests/scripts.rs index b2ce6cbadd..fbe7f14ea0 100644 --- a/e2e/tests/scripts.rs +++ b/e2e/tests/scripts.rs @@ -528,14 +528,14 @@ async fn loader_script_calling_loader_proxy() -> Result<()> { let contract = Contract::load_from(contract_binary, LoadConfiguration::default())?; - let contract_id = contract + let (contract_id, _) = contract .convert_to_loader(100)? .deploy_if_not_exists(&wallet, TxPolicies::default()) .await?; let contract_binary = "sway/contracts/proxy/out/release/proxy.bin"; - let proxy_id = Contract::load_from(contract_binary, LoadConfiguration::default())? + let (proxy_id, _) = Contract::load_from(contract_binary, LoadConfiguration::default())? .convert_to_loader(100)? .deploy_if_not_exists(&wallet, TxPolicies::default()) .await?; diff --git a/e2e/tests/storage.rs b/e2e/tests/storage.rs index 554b7123a1..3410dab304 100644 --- a/e2e/tests/storage.rs +++ b/e2e/tests/storage.rs @@ -19,7 +19,7 @@ async fn test_storage_initialization() -> Result<()> { let storage_vec = vec![storage_slot.clone()]; let storage_configuration = StorageConfiguration::default().add_slot_overrides(storage_vec); - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "sway/contracts/storage/out/release/storage.bin", LoadConfiguration::default().with_storage_configuration(storage_configuration), )? @@ -48,7 +48,7 @@ async fn test_init_storage_automatically() -> Result<()> { let wallet = launch_provider_and_get_wallet().await?; - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "sway/contracts/storage/out/release/storage.bin", LoadConfiguration::default(), )? diff --git a/e2e/tests/types_contracts.rs b/e2e/tests/types_contracts.rs index e4e7dd3aba..21742b32b6 100644 --- a/e2e/tests/types_contracts.rs +++ b/e2e/tests/types_contracts.rs @@ -76,7 +76,7 @@ async fn call_with_structs() -> Result<()> { let wallet = launch_provider_and_get_wallet().await?; - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "sway/types/contracts/complex_types_contract/out/release/complex_types_contract.bin", LoadConfiguration::default(), )? diff --git a/e2e/tests/wallets.rs b/e2e/tests/wallets.rs index e945b4d550..345ac8135e 100644 --- a/e2e/tests/wallets.rs +++ b/e2e/tests/wallets.rs @@ -226,7 +226,7 @@ async fn test_transfer() -> Result<()> { wallet_1.set_provider(provider.clone()); wallet_2.set_provider(provider); - let _receipts = wallet_1 + let _ = wallet_1 .transfer( wallet_2.address(), amount / 2, @@ -262,7 +262,7 @@ async fn send_transfer_transactions() -> Result<()> { // Transfer 1 from wallet 1 to wallet 2. const SEND_AMOUNT: u64 = 1; let base_asset_id = AssetId::zeroed(); - let (tx_id, _receipts) = wallet_1 + let (tx_id, _tx_status) = wallet_1 .transfer(wallet_2.address(), SEND_AMOUNT, base_asset_id, tx_policies) .await?; @@ -307,7 +307,7 @@ async fn transfer_coins_with_change() -> Result<()> { // Transfer 2 from wallet 1 to wallet 2. const SEND_AMOUNT: u64 = 2; - let _receipts = wallet_1 + let (_tx_id, tx_status) = wallet_1 .transfer( wallet_2.address(), SEND_AMOUNT, @@ -321,14 +321,10 @@ async fn transfer_coins_with_change() -> Result<()> { .get_spendable_resources(base_asset_id, 1, None) .await?; - // TODO: https://github.com/FuelLabs/fuels-rs/issues/1394 - let expected_fee = 1; // Assert that we've sent 2 from wallet 1, resulting in an amount of 3 in wallet 1. let resulting_amount = wallet_1_final_coins.first().unwrap(); - assert_eq!( - resulting_amount.amount(), - AMOUNT - SEND_AMOUNT - expected_fee - ); + let fee = tx_status.total_fee(); + assert_eq!(resulting_amount.amount(), AMOUNT - SEND_AMOUNT - fee); let wallet_2_final_coins = wallet_2.get_coins(base_asset_id).await?; assert_eq!(wallet_2_final_coins.len(), 1); @@ -415,7 +411,7 @@ async fn transfer_coins_of_non_base_asset() -> Result<()> { wallet_2.set_provider(provider); const SEND_AMOUNT: u64 = 200; - let _receipts = wallet_1 + let _ = wallet_1 .transfer( wallet_2.address(), SEND_AMOUNT, diff --git a/examples/contracts/src/lib.rs b/examples/contracts/src/lib.rs index 5ff6f5514f..101ea72524 100644 --- a/examples/contracts/src/lib.rs +++ b/examples/contracts/src/lib.rs @@ -45,7 +45,7 @@ mod tests { // This will load and deploy your contract binary to the chain so that its ID can // be used to initialize the instance - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -99,7 +99,7 @@ mod tests { let wallet = launch_provider_and_get_wallet().await?; - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -132,7 +132,7 @@ mod tests { let wallet = launch_provider_and_get_wallet().await?; - let contract_id_1 = Contract::load_from( + let (contract_id_1, _) = Contract::load_from( "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -162,7 +162,7 @@ mod tests { .with_script_gas_limit(1_000_000) .with_maturity(0); - let contract_id_2 = Contract::load_from( + let (contract_id_2, _) = Contract::load_from( "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", configuration, )? @@ -233,7 +233,7 @@ mod tests { let wallets = launch_custom_provider_and_get_wallets(WalletsConfig::default(), None, None).await?; - let contract_id_1 = Contract::load_from( + let (contract_id_1, _) = Contract::load_from( "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -251,7 +251,7 @@ mod tests { assert_eq!(42, response.value); - let contract_id_2 = Contract::load_from( + let (contract_id_2, _) = Contract::load_from( "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default().with_salt([1; 32]), )? @@ -283,7 +283,7 @@ mod tests { let wallet = launch_provider_and_get_wallet().await?; - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -352,7 +352,7 @@ mod tests { let wallet = launch_provider_and_get_wallet().await?; - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "../../e2e/sway/contracts/token_ops/out/release/token_ops\ .bin", LoadConfiguration::default(), @@ -414,11 +414,12 @@ mod tests { )? .deploy(&wallet, TxPolicies::default()) .await? + .0 .into(); let bin_path = "../../e2e/sway/contracts/lib_contract_caller/out/release/lib_contract_caller.bin"; - let caller_contract_id = Contract::load_from(bin_path, LoadConfiguration::default())? + let (caller_contract_id, _) = Contract::load_from(bin_path, LoadConfiguration::default())? .deploy(&wallet, TxPolicies::default()) .await?; @@ -513,7 +514,7 @@ mod tests { let wallet = launch_provider_and_get_wallet().await?; - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -551,7 +552,7 @@ mod tests { let wallet = launch_provider_and_get_wallet().await?; - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -609,7 +610,7 @@ mod tests { let wallet = launch_provider_and_get_wallet().await?; - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -654,7 +655,7 @@ mod tests { let wallet_1 = wallets.pop().unwrap(); let wallet_2 = wallets.pop().unwrap(); - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -963,7 +964,7 @@ mod tests { let provider = setup_test_provider(coins, vec![], Some(node_config), None).await?; wallet.set_provider(provider.clone()); - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? @@ -1060,14 +1061,14 @@ mod tests { already_uploaded_blobs.insert(blob_id); } - let contract_id = Contract::loader_from_blob_ids(all_blob_ids, random_salt(), vec![])? + let (contract_id, _) = Contract::loader_from_blob_ids(all_blob_ids, random_salt(), vec![])? .deploy(&wallet, TxPolicies::default()) .await?; // ANCHOR_END: manual_blob_upload_then_deploy // ANCHOR: deploy_via_loader let max_words_per_blob = 10_000; - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( contract_binary, LoadConfiguration::default().with_salt(random_salt()), )? @@ -1078,7 +1079,7 @@ mod tests { // ANCHOR: auto_convert_to_loader let max_words_per_blob = 10_000; - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( contract_binary, LoadConfiguration::default().with_salt(random_salt()), )? @@ -1087,7 +1088,7 @@ mod tests { // ANCHOR_END: auto_convert_to_loader // ANCHOR: upload_blobs_then_deploy - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( contract_binary, LoadConfiguration::default().with_salt(random_salt()), )? @@ -1134,7 +1135,7 @@ mod tests { .map(|chunk| Blob::new(chunk.to_vec())) .collect(); - let contract_id = Contract::loader_from_blobs(blobs, random_salt(), vec![])? + let (contract_id, _) = Contract::loader_from_blobs(blobs, random_salt(), vec![])? .deploy(&wallet, TxPolicies::default()) .await?; // ANCHOR_END: manual_blobs_then_deploy diff --git a/examples/cookbook/src/lib.rs b/examples/cookbook/src/lib.rs index e0c0e19b14..9911e7de67 100644 --- a/examples/cookbook/src/lib.rs +++ b/examples/cookbook/src/lib.rs @@ -51,7 +51,7 @@ mod tests { // ANCHOR_END: liquidity_wallet // ANCHOR: liquidity_deploy - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "../../e2e/sway/contracts/liquidity_pool/out/release/liquidity_pool.bin", LoadConfiguration::default(), )? diff --git a/examples/wallets/src/lib.rs b/examples/wallets/src/lib.rs index dff23836b1..fd9c2c9f73 100644 --- a/examples/wallets/src/lib.rs +++ b/examples/wallets/src/lib.rs @@ -180,7 +180,7 @@ mod tests { .pop() .unwrap(); - let contract_id = Contract::load_from( + let (contract_id, _) = Contract::load_from( "../../e2e/sway/contracts/contract_test/out/release/contract_test.bin", LoadConfiguration::default(), )? diff --git a/packages/fuels-accounts/src/account.rs b/packages/fuels-accounts/src/account.rs index 2090364e2b..7b4a96c40e 100644 --- a/packages/fuels-accounts/src/account.rs +++ b/packages/fuels-accounts/src/account.rs @@ -15,6 +15,7 @@ use fuels_core::types::{ transaction::{Transaction, TxPolicies}, transaction_builders::{BuildableTransaction, ScriptTransactionBuilder, TransactionBuilder}, transaction_response::TransactionResponse, + tx_status::TxStatus, }; use crate::{ @@ -167,7 +168,7 @@ pub trait Account: ViewOnlyAccount { amount: u64, asset_id: AssetId, tx_policies: TxPolicies, - ) -> Result<(TxId, Vec)> { + ) -> Result<(TxId, TxStatus)> { let provider = self.try_provider()?; let inputs = self @@ -194,9 +195,7 @@ pub trait Account: ViewOnlyAccount { let tx_status = provider.send_transaction_and_await_commit(tx).await?; - let receipts = tx_status.take_receipts_checked(None)?; - - Ok((tx_id, receipts)) + Ok((tx_id, tx_status)) } /// Unconditionally transfers `balance` of type `asset_id` to 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 a98a2911c2..6e256f023e 100644 --- a/packages/fuels-macros/src/setup_program_test/code_gen.rs +++ b/packages/fuels-macros/src/setup_program_test/code_gen.rs @@ -154,7 +154,7 @@ fn contract_deploying_code( ) .expect("Failed to load the contract"); - let contract_id = loaded_contract.deploy_if_not_exists( + let (contract_id, _) = loaded_contract.deploy_if_not_exists( &#wallet_name, ::fuels::types::transaction::TxPolicies::default() ) diff --git a/packages/fuels-programs/src/contract/loader.rs b/packages/fuels-programs/src/contract/loader.rs index 1c5f1c8516..b2b5dd63f5 100644 --- a/packages/fuels-programs/src/contract/loader.rs +++ b/packages/fuels-programs/src/contract/loader.rs @@ -9,6 +9,7 @@ use fuels_core::{ errors::{error, Result}, transaction::TxPolicies, transaction_builders::{Blob, BlobId, BlobTransactionBuilder, TransactionBuilder}, + tx_status::TxStatus, }, }; @@ -164,7 +165,7 @@ impl Contract> { self, account: &impl Account, tx_policies: TxPolicies, - ) -> Result { + ) -> Result<(Bech32ContractId, TxStatus)> { self.upload_blobs(account, tx_policies) .await? .deploy(account, tx_policies) @@ -177,7 +178,7 @@ impl Contract> { self, account: &impl Account, tx_policies: TxPolicies, - ) -> Result { + ) -> Result<(Bech32ContractId, Option)> { self.upload_blobs(account, tx_policies) .await? .deploy_if_not_exists(account, tx_policies) @@ -253,7 +254,7 @@ impl Contract> { self, account: &impl Account, tx_policies: TxPolicies, - ) -> Result { + ) -> Result<(Bech32ContractId, TxStatus)> { Contract::regular(self.code(), self.salt, self.storage_slots) .deploy(account, tx_policies) .await @@ -263,7 +264,7 @@ impl Contract> { self, account: &impl Account, tx_policies: TxPolicies, - ) -> Result { + ) -> Result<(Bech32ContractId, Option)> { Contract::regular(self.code(), self.salt, self.storage_slots) .deploy_if_not_exists(account, tx_policies) .await diff --git a/packages/fuels-programs/src/contract/regular.rs b/packages/fuels-programs/src/contract/regular.rs index 8c54a410bd..3c7bda9931 100644 --- a/packages/fuels-programs/src/contract/regular.rs +++ b/packages/fuels-programs/src/contract/regular.rs @@ -10,6 +10,7 @@ use fuels_core::{ errors::Result, transaction::TxPolicies, transaction_builders::{Blob, CreateTransactionBuilder}, + tx_status::TxStatus, }, Configurables, }; @@ -138,7 +139,7 @@ impl Contract { self, account: &impl Account, tx_policies: TxPolicies, - ) -> Result { + ) -> Result<(Bech32ContractId, TxStatus)> { let contract_id = self.contract_id(); let state_root = self.state_root(); let salt = self.salt; @@ -161,12 +162,10 @@ impl Contract { let tx = tb.build(provider).await?; - provider - .send_transaction_and_await_commit(tx) - .await? - .check(None)?; + let tx_status = provider.send_transaction_and_await_commit(tx).await?; + tx_status.check(None)?; - Ok(contract_id.into()) + Ok((contract_id.into(), tx_status)) } /// Deploys a compiled contract to a running node if a contract with @@ -175,13 +174,15 @@ impl Contract { self, account: &impl Account, tx_policies: TxPolicies, - ) -> Result { + ) -> Result<(Bech32ContractId, Option)> { let contract_id = Bech32ContractId::from(self.contract_id()); let provider = account.try_provider()?; if provider.contract_exists(&contract_id).await? { - Ok(contract_id) + Ok((contract_id, None)) } else { - self.deploy(account, tx_policies).await + let (contract_id, tx_status) = self.deploy(account, tx_policies).await?; + + Ok((contract_id, Some(tx_status))) } } @@ -208,7 +209,7 @@ impl Contract { account: &impl Account, tx_policies: TxPolicies, max_words_per_blob: usize, - ) -> Result { + ) -> Result<(Bech32ContractId, TxStatus)> { let provider = account.try_provider()?; let max_contract_size = provider .consensus_parameters() diff --git a/packages/fuels-programs/src/executable.rs b/packages/fuels-programs/src/executable.rs index 4703997520..e7dc0dcb97 100644 --- a/packages/fuels-programs/src/executable.rs +++ b/packages/fuels-programs/src/executable.rs @@ -2,6 +2,7 @@ use fuels_core::{ types::{ errors::Result, transaction_builders::{Blob, BlobTransactionBuilder}, + tx_status::TxStatus, }, Configurables, }; @@ -143,28 +144,26 @@ impl Executable { } /// Uploads a blob containing the original executable code minus the data section. - pub async fn upload_blob(&self, account: impl fuels_accounts::Account) -> Result<()> { + pub async fn upload_blob( + &self, + account: impl fuels_accounts::Account, + ) -> Result> { let blob = self.blob(); let provider = account.try_provider()?; if provider.blob_exists(blob.id()).await? { - return Ok(()); + return Ok(None); } let mut tb = BlobTransactionBuilder::default().with_blob(self.blob()); - account.adjust_for_fee(&mut tb, 0).await?; - account.add_witnesses(&mut tb)?; let tx = tb.build(provider).await?; + let tx_status = provider.send_transaction_and_await_commit(tx).await?; + tx_status.check(None)?; - provider - .send_transaction_and_await_commit(tx) - .await? - .check(None)?; - - Ok(()) + Ok(Some(tx_status)) } }