Skip to content

Commit

Permalink
test return data api on nested calls in the mock
Browse files Browse the repository at this point in the history
Signed-off-by: xermicus <[email protected]>
  • Loading branch information
xermicus committed Sep 20, 2024
1 parent 8e8b2a2 commit 4caa6a0
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub extern "C" fn deploy() {}
pub extern "C" fn call() {
input!(code_hash: &[u8; 32],);

// we didn't do anything yet; return data size should be 0
// We didn't do anything yet; return data size should be 0
assert_return_data_size_of(0);

recursion_guard();
Expand Down
68 changes: 68 additions & 0 deletions substrate/frame/revive/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4208,4 +4208,72 @@ mod tests {
.unwrap()
});
}

#[test]
fn last_frame_output_works_on_nested_call() {
// Call stack: BOB -> CHARLIE(revert) -> BOB' (success)
let code_bob = MockLoader::insert(Call, |ctx, _| {
if ctx.input_data.is_empty() {
// We didn't do anything yet
assert_eq!(
ctx.ext.last_frame_output(),
&ExecReturnValue { flags: ReturnFlags::empty(), data: vec![] }
);

ctx.ext
.call(
Weight::zero(),
U256::zero(),
&CHARLIE_ADDR,
U256::zero(),
vec![],
true,
false,
)
.unwrap();
assert_eq!(
ctx.ext.last_frame_output(),
&ExecReturnValue { flags: ReturnFlags::REVERT, data: vec![70] }
);
}

Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: vec![127] })
});
let code_charlie = MockLoader::insert(Call, |ctx, _| {
// We didn't do anything yet
assert_eq!(
ctx.ext.last_frame_output(),
&ExecReturnValue { flags: ReturnFlags::empty(), data: vec![] }
);

assert!(ctx
.ext
.call(Weight::zero(), U256::zero(), &BOB_ADDR, U256::zero(), vec![99], true, false)
.is_ok());
assert_eq!(
ctx.ext.last_frame_output(),
&ExecReturnValue { flags: ReturnFlags::empty(), data: vec![127] }
);

Ok(ExecReturnValue { flags: ReturnFlags::REVERT, data: vec![70] })
});

ExtBuilder::default().build().execute_with(|| {
place_contract(&BOB, code_bob);
place_contract(&CHARLIE, code_charlie);
let origin = Origin::from_account_id(ALICE);
let mut storage_meter = storage::meter::Meter::new(&origin, 0, 0).unwrap();

let result = MockStack::run_call(
origin,
BOB_ADDR,
&mut GasMeter::<Test>::new(GAS_LIMIT),
&mut storage_meter,
0,
vec![0],
None,
);
assert_matches!(result, Ok(_));
});
}
}

0 comments on commit 4caa6a0

Please sign in to comment.