use super::super::super::*;
#[test]
fn high_level_roll_dynamic_index_preserves_stack_depth_after_drops() {
let script = [
0x57, 0x00, 0x01, 0x11, 0x12, 0x78, 0x52, 0x45, 0x45,
0x40, ];
let high_level = decompile_high_level(&script);
assert!(
high_level.contains("roll(arg0)"),
"dynamic ROLL should still surface the helper expression: {high_level}"
);
assert!(
high_level.contains("return;"),
"dynamic ROLL must preserve stack depth after its result is dropped: {high_level}"
);
assert!(
!high_level.contains("return 1;")
&& !high_level.contains("return 2;")
&& !high_level.contains("return t"),
"dynamic ROLL must not leave a phantom stack value behind: {high_level}"
);
}
#[test]
fn high_level_xdrop_dynamic_index_preserves_stack_depth_after_drop() {
let script = [
0x57, 0x00, 0x01, 0x11, 0x12, 0x78, 0x48, 0x45, 0x40, ];
let high_level = decompile_high_level(&script);
assert!(
high_level.contains("return;"),
"dynamic XDROP must preserve stack depth after a follow-up DROP: {high_level}"
);
assert!(
!high_level.contains("return 1;")
&& !high_level.contains("return 2;")
&& !high_level.contains("return t"),
"dynamic XDROP must not leave a phantom stack value behind: {high_level}"
);
}
#[test]
fn high_level_xdrop_dynamic_index_does_not_return_stale_known_value() {
let script = [
0x57, 0x00, 0x01, 0x11, 0x12, 0x78, 0x48, 0x40, ];
let high_level = decompile_high_level(&script);
assert!(
high_level.contains("xdrop_remaining(arg0)"),
"dynamic XDROP should surface an unknown remaining top value: {high_level}"
);
assert!(
!high_level.contains("return 1;") && !high_level.contains("return 2;"),
"dynamic XDROP must not return a stale known value: {high_level}"
);
}
#[test]
fn high_level_xdrop_dynamic_index_drop_does_not_return_deeper_stale_known_value() {
let script = [
0x57, 0x00, 0x01, 0x11, 0x12, 0x13, 0x78, 0x48, 0x45,
0x40,
];
let high_level = decompile_high_level(&script);
assert!(
high_level.contains("xdrop_remaining(arg0)"),
"dynamic XDROP should keep deeper survivors unknown: {high_level}"
);
assert!(
!high_level.contains("return 1;")
&& !high_level.contains("return 2;")
&& !high_level.contains("return 3;"),
"dynamic XDROP must not return a stale deeper value: {high_level}"
);
}
#[test]
fn high_level_roll_dynamic_index_result_drop_does_not_return_stale_known_value() {
let script = [
0x57, 0x00, 0x01, 0x11, 0x12, 0x78, 0x52, 0x45, 0x40, ];
let high_level = decompile_high_level(&script);
assert!(
high_level.contains("roll_remaining(arg0)"),
"dynamic ROLL should preserve an unknown remaining top value: {high_level}"
);
assert!(
!high_level.contains("return 1;") && !high_level.contains("return 2;"),
"dynamic ROLL must not return a stale known value after dropping its result: {high_level}"
);
}
#[test]
fn high_level_roll_dynamic_index_drops_do_not_return_deeper_stale_known_value() {
let script = [
0x57, 0x00, 0x01, 0x11, 0x12, 0x13, 0x78, 0x52, 0x45, 0x45,
0x40,
];
let high_level = decompile_high_level(&script);
assert!(
high_level.contains("roll_remaining(arg0)"),
"dynamic ROLL should keep deeper survivors unknown: {high_level}"
);
assert!(
!high_level.contains("return 1;")
&& !high_level.contains("return 2;")
&& !high_level.contains("return 3;"),
"dynamic ROLL must not return a stale deeper value: {high_level}"
);
}
#[test]
fn high_level_reversen_dynamic_count_does_not_return_stale_known_value() {
let script = [
0x57, 0x00, 0x01, 0x11, 0x12, 0x78, 0x55, 0x40, ];
let high_level = decompile_high_level(&script);
assert!(
high_level.contains("reverse_n_top(arg0)"),
"dynamic REVERSEN should surface an unknown top value: {high_level}"
);
assert!(
!high_level.contains("return 1;") && !high_level.contains("return 2;"),
"dynamic REVERSEN must not return a stale known value: {high_level}"
);
}
#[test]
fn high_level_reversen_dynamic_count_drop_does_not_return_deeper_stale_known_value() {
let script = [
0x57, 0x00, 0x01, 0x11, 0x12, 0x13, 0x78, 0x55, 0x45,
0x40,
];
let high_level = decompile_high_level(&script);
assert!(
high_level.contains("reverse_n_top(arg0)"),
"dynamic REVERSEN should keep deeper survivors unknown: {high_level}"
);
assert!(
!high_level.contains("return 1;")
&& !high_level.contains("return 2;")
&& !high_level.contains("return 3;"),
"dynamic REVERSEN must not return a stale deeper value: {high_level}"
);
}
fn decompile_high_level(script: &[u8]) -> String {
let nef_bytes = build_nef(script);
let decompilation = Decompiler::new()
.decompile_bytes(&nef_bytes)
.expect("decompile succeeds");
decompilation.high_level.expect("high-level output")
}