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
+6 -6
View File
@@ -31,14 +31,14 @@ where
#[cfg(feature = "bench-pvm-interpreter")]
{
let contract = contract(p.clone());
let (state, mut instance, export) = revive_benchmarks::prepare_pvm(
let (transaction, mut instance, export) = revive_benchmarks::prepare_pvm(
&contract.pvm_runtime,
&contract.calldata,
contract.calldata,
polkavm::BackendKind::Interpreter,
);
group.bench_with_input(BenchmarkId::new("PVMInterpreter", l), p, |b, _| {
b.iter(|| {
revive_integration::mock_runtime::call(state.clone(), &mut instance, export);
transaction.clone().call_on(&mut instance, export);
});
});
}
@@ -46,14 +46,14 @@ where
#[cfg(feature = "bench-pvm")]
{
let contract = contract(p.clone());
let (state, mut instance, export) = revive_benchmarks::prepare_pvm(
let (transaction, mut instance, export) = revive_benchmarks::prepare_pvm(
&contract.pvm_runtime,
&contract.calldata,
contract.calldata,
polkavm::BackendKind::Compiler,
);
group.bench_with_input(BenchmarkId::new("PVM", l), p, |b, _| {
b.iter(|| {
revive_integration::mock_runtime::call(state.clone(), &mut instance, export);
transaction.clone().call_on(&mut instance, export);
});
});
}
+6 -5
View File
@@ -1,19 +1,20 @@
use polkavm::{BackendKind, Config, Engine, ExportIndex, Instance, SandboxKind};
use revive_integration::mock_runtime;
use revive_integration::mock_runtime::State;
use revive_integration::mock_runtime::{self, TransactionBuilder};
use revive_integration::mock_runtime::{State, Transaction};
pub fn prepare_pvm(
code: &[u8],
input: &[u8],
input: Vec<u8>,
backend: BackendKind,
) -> (State, Instance<State>, ExportIndex) {
) -> (TransactionBuilder, Instance<Transaction>, ExportIndex) {
let mut config = Config::new();
config.set_backend(Some(backend));
config.set_sandbox(Some(SandboxKind::Linux));
let (instance, export_index) = mock_runtime::prepare(code, Some(config));
let transaction = State::default().transaction().calldata(input);
(State::new(input.to_vec()), instance, export_index)
(transaction, instance, export_index)
}
pub fn instantiate_engine(backend: BackendKind) -> Engine {