Skip to content

Commit

Permalink
Create GasInfo::free
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Jul 23, 2020
1 parent fe81ade commit 6c43eed
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 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 @@ -113,6 +123,13 @@ mod test {
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 6c43eed

Please sign in to comment.