Documentation Index
Fetch the complete documentation index at: https://docs.starknet.io/llms.txt
Use this file to discover all available pages before exploring further.
Returns the amount of gas available in the GasBuiltin.
Useful for asserting that a certain amount of gas was consumed.
Note: The actual gas consumption observed by calls to get_available_gas is only exact
immediately before calls to withdraw_gas.
Examples
use core::testing::get_available_gas;
fn gas_heavy_function() {
// ... some gas-intensive code
}
fn test_gas_consumption() {
let gas_before = get_available_gas();
// Making sure `gas_before` is exact.
core::gas::withdraw_gas().unwrap();
gas_heavy_function();
let gas_after = get_available_gas();
// Making sure `gas_after` is exact
core::gas::withdraw_gas().unwrap();
assert!(gas_after - gas_before u128 implicits(GasBuiltin) nopanic;