use super::super::{
Config, HeapPages, HostVm, HostVmPrototype, StorageProofSizeBehavior, vm::ExecHint,
};
use super::with_core_version_custom_sections;
fn run_to_finished(module_bytes: Vec<u8>) {
for exec_hint in ExecHint::available_engines() {
let proto = HostVmPrototype::new(Config {
allow_unresolved_imports: false,
exec_hint,
heap_pages: HeapPages::new(1024),
module: &module_bytes,
})
.unwrap();
let mut vm = HostVm::from(
proto
.run(
"test",
StorageProofSizeBehavior::proof_recording_disabled(),
b"",
)
.unwrap(),
);
loop {
match vm {
HostVm::ReadyToRun(r) => vm = r.run(),
HostVm::Finished(_) => break,
other => panic!("unexpected HostVm state: {:?}", other),
}
}
}
}
#[test]
fn ext_transaction_index_index_consumes_three_i32_params() {
let module_bytes = with_core_version_custom_sections(
wat::parse_str(
r#"
(module
(import "env" "memory" (memory 16))
(import "env" "ext_transaction_index_index_version_1"
(func $tx_index (param i32 i32 i32)))
(global (export "__heap_base") i32 (i32.const 1024))
(func (export "test") (param i32 i32) (result i64)
i32.const 7 ;; extrinsic_index
i32.const 128 ;; content_size
i32.const 0 ;; content_hash_ptr (points at 32 zero bytes)
call $tx_index
i64.const 0))
"#,
)
.unwrap(),
);
run_to_finished(module_bytes);
}
#[test]
fn ext_transaction_index_renew_consumes_i32_and_hash_pointer() {
let module_bytes = with_core_version_custom_sections(
wat::parse_str(
r#"
(module
(import "env" "memory" (memory 16))
(import "env" "ext_transaction_index_renew_version_1"
(func $tx_renew (param i32 i32)))
(global (export "__heap_base") i32 (i32.const 1024))
(func (export "test") (param i32 i32) (result i64)
i32.const 3 ;; extrinsic_index
i32.const 0 ;; content_hash_ptr
call $tx_renew
i64.const 0))
"#,
)
.unwrap(),
);
run_to_finished(module_bytes);
}