Contracts: Reuse module when validating (#3789)

Reuse wasmi Module when validating.
Prepare the code for 0.32 and the addition of Module::new_unchecked
This commit is contained in:
PG Herveou
2024-04-10 20:56:51 +02:00
committed by GitHub
parent cd010925e1
commit 1da8d12dd1
6 changed files with 719 additions and 655 deletions
+15 -1
View File
@@ -34,7 +34,7 @@ use crate::{
primitives::CodeUploadReturnValue,
storage::DeletionQueueManager,
tests::test_utils::{get_contract, get_contract_checked},
wasm::{Determinism, ReturnErrorCode as RuntimeReturnCode},
wasm::{Determinism, LoadingMode, ReturnErrorCode as RuntimeReturnCode},
weights::WeightInfo,
Array, BalanceOf, Code, CodeHash, CodeInfoOf, CollectEvents, Config, ContractInfo,
ContractInfoOf, DebugInfo, DefaultAddressGenerator, DeletionQueueCounter, Error, HoldReason,
@@ -1102,6 +1102,20 @@ fn delegate_call() {
});
}
#[test]
fn track_check_uncheck_module_call() {
let (wasm, code_hash) = compile_module::<Test>("dummy").unwrap();
ExtBuilder::default().build().execute_with(|| {
let _ = <Test as Config>::Currency::set_balance(&ALICE, 1_000_000);
Contracts::bare_upload_code(ALICE, wasm, None, Determinism::Enforced).unwrap();
builder::bare_instantiate(Code::Existing(code_hash)).build_and_unwrap_result();
});
// It should have recorded 1 `Checked` for the upload and 1 `Unchecked` for the instantiate.
let record = crate::wasm::tracker::LOADED_MODULE.with(|stack| stack.borrow().clone());
assert_eq!(record, vec![LoadingMode::Checked, LoadingMode::Unchecked]);
}
#[test]
fn transfer_expendable_cannot_kill_account() {
let (wasm, _code_hash) = compile_module::<Test>("dummy").unwrap();