use super::super::*;
use crate::instruction::OpCode;
#[test]
fn high_level_pops_assert_condition() {
let script = [
OpCode::Push2.byte(),
OpCode::Push1.byte(),
OpCode::Assert.byte(),
OpCode::Ret.byte(),
];
let nef_bytes = build_nef(&script);
let decompilation = Decompiler::new()
.decompile_bytes(&nef_bytes)
.expect("decompile succeeds");
let high_level = decompilation
.high_level
.as_deref()
.expect("high-level output");
assert!(
high_level.contains("assert(t1);"),
"ASSERT should emit an assert call: {high_level}"
);
assert!(
high_level.contains("return t0;"),
"ASSERT should pop the condition, returning the original value: {high_level}"
);
}
#[test]
fn high_level_abort_clears_stack() {
let script = [
OpCode::Push1.byte(),
OpCode::Abort.byte(),
OpCode::Ret.byte(),
];
let nef_bytes = build_nef(&script);
let decompilation = Decompiler::new()
.decompile_bytes(&nef_bytes)
.expect("decompile succeeds");
let high_level = decompilation
.high_level
.as_deref()
.expect("high-level output");
assert!(
high_level.contains("abort();"),
"ABORT should emit an abort call: {high_level}"
);
assert!(
high_level.contains("return;"),
"stack should be cleared after ABORT: {high_level}"
);
}
#[test]
fn high_level_throw_clears_stack() {
let script = [
OpCode::Push1.byte(),
OpCode::Throw.byte(),
OpCode::Ret.byte(),
];
let nef_bytes = build_nef(&script);
let decompilation = Decompiler::new()
.decompile_bytes(&nef_bytes)
.expect("decompile succeeds");
let high_level = decompilation
.high_level
.as_deref()
.expect("high-level output");
assert!(
high_level.contains("throw(t0);"),
"THROW should emit a throw call: {high_level}"
);
assert!(
high_level.contains("return;"),
"stack should be cleared after THROW: {high_level}"
);
}