mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 18:07:58 +00:00
Versioning for #[runtime-interface] (#5328)
* versionned runtime-interface * use only one additional wasm blob * alter docs * formatting, naming and docs * add comment for test * version duplicate err * RuntimeInterfaceItem -> RuntimeInterfaceFunction< * test naming * version checking * remove spaces * Update primitives/runtime-interface/proc-macro/src/runtime_interface/bare_function_interface.rs Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * remove sanity checks and reduce coverage * add doc comment Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Tests for the runtime interface traits and proc macros.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use sp_core::wasm_export_functions;
|
||||
use sp_runtime_interface::runtime_interface;
|
||||
|
||||
// Include the WASM binary
|
||||
#[cfg(feature = "std")]
|
||||
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
|
||||
/// This function is not used, but we require it for the compiler to include `sp-io`.
|
||||
/// `sp-io` is required for its panic and oom handler.
|
||||
#[no_mangle]
|
||||
pub fn import_sp_io() {
|
||||
sp_io::misc::print_utf8(&[]);
|
||||
}
|
||||
|
||||
#[runtime_interface]
|
||||
pub trait TestApi {
|
||||
fn test_versionning(&self, _data: u32) -> bool {
|
||||
// should not be called
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
wasm_export_functions! {
|
||||
fn test_versionning_works() {
|
||||
// old api allows only 42 and 50
|
||||
assert!(test_api::test_versionning(42));
|
||||
assert!(test_api::test_versionning(50));
|
||||
|
||||
assert!(!test_api::test_versionning(142));
|
||||
assert!(!test_api::test_versionning(0));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user