Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unified syntax - ReturnsGasUsed #1828

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions contracts/examples/adder/interact/config.toml
Original file line number Diff line number Diff line change
@@ -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'
10 changes: 8 additions & 2 deletions contracts/examples/adder/interact/src/basic_interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u64>();

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) {
Expand Down
2 changes: 2 additions & 0 deletions framework/scenario/src/facade/result_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions framework/scenario/src/facade/result_handlers/returns_gas_used.rs
Original file line number Diff line number Diff line change
@@ -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<Env, Original> RHListItem<Env, Original> for ReturnsGasUsed
where
Env: TxEnv,
{
type Returns = u64;
}

impl<Env, Original> RHListItemExec<TxResponse, Env, Original> for ReturnsGasUsed
where
Env: TxEnv,
{
fn item_process_result(self, tx_response: &TxResponse) -> Self::Returns {
tx_response.gas_used
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct TxResponse {
/// The logs of the transaction.
pub logs: Vec<Log>,
/// 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
1 change: 1 addition & 0 deletions framework/snippets-base/src/network_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
2 changes: 2 additions & 0 deletions sdk/core/src/data/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading