Skip to content

Commit

Permalink
REMOVE ME Show example usage
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Apr 20, 2023
1 parent f16f975 commit f06e38b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/vm/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ where
mod tests {
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::SystemTime;

use super::*;
use crate::backend::Storage;
Expand Down Expand Up @@ -716,9 +717,27 @@ mod tests {
assert_eq!(report1.limit, LIMIT);
assert_eq!(report1.remaining, LIMIT);

// Test this with
// (cd packages/vm && cargo test create_gas_report_works -- --nocapture)
let start = SystemTime::now();
instance.set_debug_handler(move |msg: &str, gas_remaining| {
let ts = SystemTime::now().duration_since(start).unwrap().as_micros();
println!("{msg} (gas: {gas_remaining}, runtime: {ts}µs)");
});

// init contract
let info = mock_info("creator", &coins(1000, "earth"));
let msg = br#"{"verifier": "verifies", "beneficiary": "benefits"}"#;
call_instantiate::<_, _, _, Empty>(&mut instance, &mock_env(), &info, msg)
.unwrap()
.unwrap();
call_instantiate::<_, _, _, Empty>(&mut instance, &mock_env(), &info, msg)
.unwrap()
.unwrap();
call_instantiate::<_, _, _, Empty>(&mut instance, &mock_env(), &info, msg)
.unwrap()
.unwrap();
instance.unset_debug_handler();
call_instantiate::<_, _, _, Empty>(&mut instance, &mock_env(), &info, msg)
.unwrap()
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions packages/vm/src/testing/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub fn mock_instance_with_gas_limit(
wasm,
MockInstanceOptions {
gas_limit,
print_debug: true,
..Default::default()
},
)
Expand Down

0 comments on commit f06e38b

Please sign in to comment.