MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / host_function_consumes_all

Function host_function_consumes_all

tests/all/fuel.rs:480–509  ·  view source on GitHub ↗
(config: &mut Config)

Source from the content-addressed store, hash-verified

478#[wasmtime_test]
479#[cfg_attr(miri, ignore)]
480fn host_function_consumes_all(config: &mut Config) -> Result<()> {
481 const FUEL: u64 = 10_000;
482 config.consume_fuel(true);
483 let engine = Engine::new(&config)?;
484 let module = Module::new(
485 &engine,
486 r#"
487 (module
488 (import "" "" (func))
489 (func (export "")
490 call 0
491 call $other)
492 (func $other))
493 "#,
494 )
495 .unwrap();
496 let mut store = Store::new(&engine, ());
497 store.set_fuel(FUEL).unwrap();
498 let func = Func::wrap(&mut store, |mut caller: Caller<'_, ()>| {
499 let remaining = caller.get_fuel().unwrap();
500 assert_eq!(remaining, FUEL - 2);
501 assert!(caller.set_fuel(1).is_ok());
502 });
503
504 let instance = Instance::new(&mut store, &module, &[func.into()]).unwrap();
505 let export = instance.get_typed_func::<(), ()>(&mut store, "").unwrap();
506 let trap = export.call(&mut store, ()).unwrap_err();
507 assert_eq!(trap.downcast::<Trap>().unwrap(), Trap::OutOfFuel);
508 Ok(())
509}
510
511#[wasmtime_test]
512fn manual_edge_cases(config: &mut Config) -> Result<()> {

Callers

nothing calls this directly

Calls 7

OkFunction · 0.85
newFunction · 0.50
consume_fuelMethod · 0.45
unwrapMethod · 0.45
set_fuelMethod · 0.45
get_fuelMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected