Skip to content

Commit 9b7c5e3

Browse files
authored
Test for Trap::OutOfFuel instead of strings (#5297)
Update a few locations to test for a specific error code
1 parent 54207d3 commit 9b7c5e3

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

crates/fuzzing/src/oracles.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,10 @@ pub fn instantiate_with_dummy(store: &mut Store<StoreLimits>, module: &Module) -
306306
}
307307

308308
let string = e.to_string();
309-
// Also allow errors related to fuel consumption
310-
if string.contains("all fuel consumed")
311-
// Currently we instantiate with a `Linker` which can't instantiate
312-
// every single module under the sun due to using name-based resolution
313-
// rather than positional-based resolution
314-
|| string.contains("incompatible import type")
315-
{
309+
// Currently we instantiate with a `Linker` which can't instantiate
310+
// every single module under the sun due to using name-based resolution
311+
// rather than positional-based resolution
312+
if string.contains("incompatible import type") {
316313
log::debug!("failed to instantiate: {}", string);
317314
return None;
318315
}

tests/all/fuel.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,7 @@ fn iloop() {
116116
let mut store = Store::new(&engine, ());
117117
store.add_fuel(10_000).unwrap();
118118
let error = Instance::new(&mut store, &module, &[]).err().unwrap();
119-
assert!(
120-
format!("{:?}", error).contains("all fuel consumed"),
121-
"bad error: {}",
122-
error
123-
);
119+
assert_eq!(error.downcast::<Trap>().unwrap(), Trap::OutOfFuel);
124120
}
125121
}
126122

@@ -172,10 +168,7 @@ fn host_function_consumes_all() {
172168
let instance = Instance::new(&mut store, &module, &[func.into()]).unwrap();
173169
let export = instance.get_typed_func::<(), ()>(&mut store, "").unwrap();
174170
let trap = export.call(&mut store, ()).unwrap_err();
175-
assert!(
176-
format!("{trap:?}").contains("all fuel consumed"),
177-
"bad error: {trap:?}"
178-
);
171+
assert_eq!(trap.downcast::<Trap>().unwrap(), Trap::OutOfFuel);
179172
}
180173

181174
#[test]

0 commit comments

Comments
 (0)