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:
Nikolay Volf
2020-03-23 07:09:05 -07:00
committed by GitHub
parent fe68d6fd8c
commit 4d3557d5a1
22 changed files with 556 additions and 104 deletions
@@ -21,7 +21,7 @@
use sp_runtime_interface::runtime_interface;
#[cfg(not(feature = "std"))]
use sp_std::{vec, vec::Vec, mem, convert::TryFrom};
use sp_std::{prelude::*, mem, convert::TryFrom};
use sp_core::{sr25519::Public, wasm_export_functions};
@@ -103,6 +103,15 @@ pub trait TestApi {
fn get_and_return_i128(val: i128) -> i128 {
val
}
fn test_versionning(&self, data: u32) -> bool {
data == 42 || data == 50
}
#[version(2)]
fn test_versionning(&self, data: u32) -> bool {
data == 42
}
}
/// This function is not used, but we require it for the compiler to include `sp-io`.
@@ -231,4 +240,14 @@ wasm_export_functions! {
}
assert_eq!(0, len);
}
fn test_versionning_works() {
// we fix new api to accept only 42 as a proper input
// as opposed to sp-runtime-interface-test-wasm-deprecated::test_api::verify_input
// which accepted 42 and 50.
assert!(test_api::test_versionning(42));
assert!(!test_api::test_versionning(50));
assert!(!test_api::test_versionning(102));
}
}