mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 17:11:02 +00:00
contracts: Replace cargo feature unstable-interface with config (#12787)
* Replace cargo feature with config * Update frame/contracts/proc-macro/src/lib.rs Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
This commit is contained in:
committed by
GitHub
parent
ec064e5edf
commit
edce3ead3b
@@ -36,7 +36,7 @@ use crate::{
|
||||
};
|
||||
use codec::{Decode, Encode, MaxEncodedLen};
|
||||
use frame_support::dispatch::{DispatchError, DispatchResult};
|
||||
use sp_core::crypto::UncheckedFrom;
|
||||
use sp_core::{crypto::UncheckedFrom, Get};
|
||||
use sp_runtime::RuntimeDebug;
|
||||
use sp_std::prelude::*;
|
||||
#[cfg(test)]
|
||||
@@ -218,7 +218,7 @@ where
|
||||
let module = Module::new(&engine, code)?;
|
||||
let mut store = Store::new(&engine, host_state);
|
||||
let mut linker = Linker::new();
|
||||
E::define(&mut store, &mut linker)?;
|
||||
E::define(&mut store, &mut linker, T::UnsafeUnstableInterface::get())?;
|
||||
let memory = Memory::new(&mut store, MemoryType::new(memory.0, Some(memory.1))?).expect(
|
||||
"The limits defined in our `Schedule` limit the amount of memory well below u32::MAX; qed",
|
||||
);
|
||||
@@ -627,10 +627,17 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn execute<E: BorrowMut<MockExt>>(wat: &str, input_data: Vec<u8>, mut ext: E) -> ExecResult {
|
||||
fn execute_internal<E: BorrowMut<MockExt>>(
|
||||
wat: &str,
|
||||
input_data: Vec<u8>,
|
||||
mut ext: E,
|
||||
unstable_interface: bool,
|
||||
) -> ExecResult {
|
||||
type RuntimeConfig = <MockExt as Ext>::T;
|
||||
RuntimeConfig::set_unstable_interface(unstable_interface);
|
||||
let wasm = wat::parse_str(wat).unwrap();
|
||||
let schedule = crate::Schedule::default();
|
||||
let executable = PrefabWasmModule::<<MockExt as Ext>::T>::from_code(
|
||||
let executable = PrefabWasmModule::<RuntimeConfig>::from_code(
|
||||
wasm,
|
||||
&schedule,
|
||||
ALICE,
|
||||
@@ -641,6 +648,19 @@ mod tests {
|
||||
executable.execute(ext.borrow_mut(), &ExportedFunction::Call, input_data)
|
||||
}
|
||||
|
||||
fn execute<E: BorrowMut<MockExt>>(wat: &str, input_data: Vec<u8>, ext: E) -> ExecResult {
|
||||
execute_internal(wat, input_data, ext, false)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "runtime-benchmarks"))]
|
||||
fn execute_with_unstable<E: BorrowMut<MockExt>>(
|
||||
wat: &str,
|
||||
input_data: Vec<u8>,
|
||||
ext: E,
|
||||
) -> ExecResult {
|
||||
execute_internal(wat, input_data, ext, true)
|
||||
}
|
||||
|
||||
const CODE_TRANSFER: &str = r#"
|
||||
(module
|
||||
;; seal_transfer(
|
||||
@@ -741,7 +761,6 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "unstable-interface")]
|
||||
fn contract_delegate_call() {
|
||||
const CODE: &str = r#"
|
||||
(module
|
||||
@@ -2274,7 +2293,6 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable-interface")]
|
||||
const CODE_CALL_RUNTIME: &str = r#"
|
||||
(module
|
||||
(import "seal0" "call_runtime" (func $call_runtime (param i32 i32) (result i32)))
|
||||
@@ -2311,7 +2329,6 @@ mod tests {
|
||||
"#;
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "unstable-interface")]
|
||||
fn call_runtime_works() {
|
||||
let call =
|
||||
RuntimeCall::System(frame_system::Call::remark { remark: b"Hello World".to_vec() });
|
||||
@@ -2323,7 +2340,6 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "unstable-interface")]
|
||||
fn call_runtime_panics_on_invalid_call() {
|
||||
let mut ext = MockExt::default();
|
||||
let result = execute(CODE_CALL_RUNTIME, vec![0x42], &mut ext);
|
||||
@@ -2586,7 +2602,6 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "unstable-interface")]
|
||||
fn take_storage_works() {
|
||||
const CODE: &str = r#"
|
||||
(module
|
||||
@@ -2822,7 +2837,6 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "unstable-interface")]
|
||||
fn caller_is_origin_works() {
|
||||
const CODE_CALLER_IS_ORIGIN: &str = r#"
|
||||
;; This runs `caller_is_origin` check on zero account address
|
||||
@@ -2894,7 +2908,6 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "unstable-interface")]
|
||||
fn reentrance_count_works() {
|
||||
const CODE: &str = r#"
|
||||
(module
|
||||
@@ -2927,7 +2940,6 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "unstable-interface")]
|
||||
fn account_reentrance_count_works() {
|
||||
const CODE: &str = r#"
|
||||
(module
|
||||
@@ -2958,4 +2970,24 @@ mod tests {
|
||||
let mut mock_ext = MockExt::default();
|
||||
execute(CODE, vec![], &mut mock_ext).unwrap();
|
||||
}
|
||||
|
||||
/// This test check that an unstable interface cannot be deployed. In case of runtime
|
||||
/// benchmarks we always allow unstable interfaces. This is why this test does not
|
||||
/// work when this feature is enabled.
|
||||
#[cfg(not(feature = "runtime-benchmarks"))]
|
||||
#[test]
|
||||
fn cannot_deploy_unstable() {
|
||||
const CANNT_DEPLOY_UNSTABLE: &str = r#"
|
||||
(module
|
||||
(import "seal0" "reentrance_count" (func $reentrance_count (result i32)))
|
||||
(func (export "call"))
|
||||
(func (export "deploy"))
|
||||
)
|
||||
"#;
|
||||
assert_err!(
|
||||
execute(CANNT_DEPLOY_UNSTABLE, vec![], MockExt::default()),
|
||||
<Error<Test>>::CodeRejected,
|
||||
);
|
||||
assert_ok!(execute_with_unstable(CANNT_DEPLOY_UNSTABLE, vec![], MockExt::default()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user