extend mock runtime to allow executing constructors and cross contract calls

Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
xermicus
2024-05-13 13:50:35 +02:00
parent 0e90317488
commit 02055c73bb
16 changed files with 544 additions and 218 deletions
+10 -8
View File
@@ -1,5 +1,7 @@
use cases::Contract;
use mock_runtime::State;
use mock_runtime::{CallOutput, State};
use crate::mock_runtime::ReturnFlags;
pub mod cases;
pub mod mock_runtime;
@@ -73,15 +75,15 @@ pub fn compile_blob_with_options(
hex::decode(bytecode).expect("hex encoding should always be valid")
}
pub fn assert_success(contract: Contract, differential: bool) -> State {
let (mut instance, export) = mock_runtime::prepare(&contract.pvm_runtime, None);
let state = mock_runtime::call(State::new(contract.calldata.clone()), &mut instance, export);
assert_eq!(state.output.flags, 0);
pub fn assert_success(contract: &Contract, differential: bool) -> (State, CallOutput) {
let (state, output) = contract.execute();
assert_eq!(output.flags, ReturnFlags::Success);
if differential {
let evm = revive_differential::prepare(contract.evm_runtime, contract.calldata);
assert_eq!(state.output.data.clone(), revive_differential::execute(evm));
let evm =
revive_differential::prepare(contract.evm_runtime.clone(), contract.calldata.clone());
assert_eq!(output.data.clone(), revive_differential::execute(evm));
}
state
(state, output)
}