Skip to content

Commit

Permalink
Merge pull request #493 from CosmWasm/gas_info_free
Browse files Browse the repository at this point in the history
Add GasInfo::free
  • Loading branch information
webmaster128 authored Jul 23, 2020
2 parents 3d36a3a + 6c43eed commit 5e41e96
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/vm/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ impl GasInfo {
externally_used: amount,
}
}

/// Creates a gas information with no cost for the caller and with zero externally used gas.
///
/// Caution: when using this you need to make sure no gas was metered externally to keep the gas values in sync.
pub fn free() -> Self {
GasInfo {
cost: 0,
externally_used: 0,
}
}
}

#[derive(Debug, Snafu)]
Expand Down Expand Up @@ -99,6 +109,27 @@ impl From<FromUtf8Error> for FfiError {
mod test {
use super::*;

#[test]
fn gas_info_with_cost_works() {
let gas_info = GasInfo::with_cost(21);
assert_eq!(gas_info.cost, 21);
assert_eq!(gas_info.externally_used, 0);
}

#[test]
fn gas_info_with_externally_used_works() {
let gas_info = GasInfo::with_externally_used(65);
assert_eq!(gas_info.cost, 0);
assert_eq!(gas_info.externally_used, 65);
}

#[test]
fn gas_info_free_works() {
let gas_info = GasInfo::free();
assert_eq!(gas_info.cost, 0);
assert_eq!(gas_info.externally_used, 0);
}

// constructors

#[test]
Expand Down

0 comments on commit 5e41e96

Please sign in to comment.