diff --git a/contracts/examples/adder/interact/config.toml b/contracts/examples/adder/interact/config.toml index aca748706a..c6f9a97a1d 100644 --- a/contracts/examples/adder/interact/config.toml +++ b/contracts/examples/adder/interact/config.toml @@ -1,5 +1,5 @@ -chain_type = 'simulator' -gateway_uri = 'http://localhost:8085' +# chain_type = 'simulator' +# gateway_uri = 'http://localhost:8085' -# chain_type = 'real' -# gateway_uri = 'https://devnet-gateway.multiversx.com' +chain_type = 'real' +gateway_uri = 'https://devnet-gateway.multiversx.com' diff --git a/contracts/examples/adder/interact/src/basic_interact.rs b/contracts/examples/adder/interact/src/basic_interact.rs index f9760defd5..f5a26a7afd 100644 --- a/contracts/examples/adder/interact/src/basic_interact.rs +++ b/contracts/examples/adder/interact/src/basic_interact.rs @@ -168,13 +168,19 @@ impl AdderInteract { .to(self.state.current_adder_address()) .typed(adder_proxy::AdderProxy) .add(value) + .returns(ReturnsGasUsed) .gas(6_000_000) }); } - let _ = buffer.run().await; + let gas_used = buffer.run().await; + let gas_used_sum = gas_used.iter().sum::(); - println!("successfully performed add {count} times"); + println!( + "successfully performed add {count} times, total gas used: {}, avg gas used: {}", + gas_used_sum, + gas_used_sum / count as u64 + ); } pub async fn feed_contract_egld(&mut self) { diff --git a/framework/scenario/src/facade/result_handlers.rs b/framework/scenario/src/facade/result_handlers.rs index 454f235b22..0df62dae43 100644 --- a/framework/scenario/src/facade/result_handlers.rs +++ b/framework/scenario/src/facade/result_handlers.rs @@ -2,6 +2,7 @@ mod expect_error; mod expect_message; mod expect_status; mod expect_value; +mod returns_gas_used; mod returns_handled_or_err; mod returns_logs; mod returns_message; @@ -15,6 +16,7 @@ pub use expect_error::ExpectError; pub use expect_message::ExpectMessage; pub use expect_status::ExpectStatus; pub use expect_value::ExpectValue; +pub use returns_gas_used::ReturnsGasUsed; pub use returns_handled_or_err::ReturnsHandledOrError; pub use returns_logs::ReturnsLogs; pub use returns_message::ReturnsMessage; diff --git a/framework/scenario/src/facade/result_handlers/returns_gas_used.rs b/framework/scenario/src/facade/result_handlers/returns_gas_used.rs new file mode 100644 index 0000000000..e8bc605224 --- /dev/null +++ b/framework/scenario/src/facade/result_handlers/returns_gas_used.rs @@ -0,0 +1,22 @@ +use multiversx_sc::types::{RHListItem, RHListItemExec, TxEnv}; + +use crate::scenario_model::TxResponse; + +/// Indicates that the newly deployed address will be returned after a deploy. +pub struct ReturnsGasUsed; + +impl RHListItem for ReturnsGasUsed +where + Env: TxEnv, +{ + type Returns = u64; +} + +impl RHListItemExec for ReturnsGasUsed +where + Env: TxEnv, +{ + fn item_process_result(self, tx_response: &TxResponse) -> Self::Returns { + tx_response.gas_used + } +} diff --git a/framework/scenario/src/scenario/model/transaction/tx_response.rs b/framework/scenario/src/scenario/model/transaction/tx_response.rs index 8215a60756..60fed34e1c 100644 --- a/framework/scenario/src/scenario/model/transaction/tx_response.rs +++ b/framework/scenario/src/scenario/model/transaction/tx_response.rs @@ -17,7 +17,7 @@ pub struct TxResponse { /// The logs of the transaction. pub logs: Vec, /// The gas used by the transaction. - pub gas: u64, + pub gas_used: u64, /// The refund of the transaction. pub refund: u64, /// The transaction hash, if available. diff --git a/framework/scenario/src/scenario/model/transaction/typed_response.rs b/framework/scenario/src/scenario/model/transaction/typed_response.rs index a25974a1b8..aae20a0be5 100644 --- a/framework/scenario/src/scenario/model/transaction/typed_response.rs +++ b/framework/scenario/src/scenario/model/transaction/typed_response.rs @@ -31,7 +31,7 @@ where result, new_issued_token_identifier: raw_response.new_issued_token_identifier.clone(), logs: raw_response.logs.clone(), - gas: raw_response.gas, + gas: raw_response.gas_used, refund: raw_response.refund, } } diff --git a/framework/snippets-base/src/network_response.rs b/framework/snippets-base/src/network_response.rs index b35ce89f6a..c17ae4456d 100644 --- a/framework/snippets-base/src/network_response.rs +++ b/framework/snippets-base/src/network_response.rs @@ -43,6 +43,7 @@ fn process_success(tx: &TransactionOnNetwork) -> TxResponse { new_issued_token_identifier: process_new_issued_token_identifier(tx), logs: process_logs(tx), tx_hash: process_tx_hash(tx), + gas_used: tx.gas_used, ..Default::default() } } diff --git a/sdk/core/src/data/transaction.rs b/sdk/core/src/data/transaction.rs index 29f04e6e68..46783cfaea 100644 --- a/sdk/core/src/data/transaction.rs +++ b/sdk/core/src/data/transaction.rs @@ -63,6 +63,8 @@ pub struct TransactionOnNetwork { pub gas_price: u64, pub gas_limit: u64, #[serde(default)] + pub gas_used: u64, + #[serde(default)] pub signature: String, pub source_shard: u32, pub destination_shard: u32,