Make API backwards compatible with CC (#1697)

* Rework how a runtime api calls into the runtime

Now we generate a default implementation for each api call that calls
a generated method `method_runtime_api_impl`. This newly generated
method is the one that will be implemented by the `impl_runtime_apis`
macro in the runtime for the client side.

* Support `changed_in` to change runtime api function signatures

* Update documentation

* Fixes tests

* Implement checking the api version with a predicate

* Make the implementation backwards compatible with CC

* Update wasm files after merge

* Check for wasm runtime differences by building master and current branch

* Update spec_version and wasm files

* Fixes

* Revert my changes

* Remove `patch.crates-io` from test-runtime
This commit is contained in:
Bastian Köcher
2019-02-06 11:47:47 +01:00
committed by Gav Wood
parent 1ba7e35c18
commit 190393d476
25 changed files with 731 additions and 224 deletions
@@ -28,6 +28,8 @@ decl_runtime_apis! {
#[api_version(2)]
pub trait ApiWithCustomVersion {
fn same_name();
#[changed_in(2)]
fn same_name() -> String;
}
}
@@ -77,6 +79,11 @@ fn test_client_side_function_signature() {
let _something_with_block:
fn(&RuntimeApiImpl<TestClient>, &BlockId<Block>, Block) -> Result<Block> =
RuntimeApiImpl::<TestClient>::something_with_block;
#[allow(deprecated)]
let _same_name_before_version_2:
fn(&RuntimeApiImpl<TestClient>, &BlockId<Block>) -> Result<String> =
RuntimeApiImpl::<TestClient>::same_name_before_version_2;
}
#[test]
@@ -58,3 +58,23 @@ fn calling_native_runtime_function_with_non_decodable_return_value() {
let block_id = BlockId::Number(client.info().unwrap().chain.best_number);
runtime_api.fail_convert_return_value(&block_id).unwrap();
}
#[test]
fn calling_native_runtime_signature_changed_function() {
let client = test_client::new_with_api_execution_strat(ExecutionStrategy::NativeWhenPossible);
let runtime_api = client.runtime_api();
let block_id = BlockId::Number(client.info().unwrap().chain.best_number);
assert_eq!(runtime_api.function_signature_changed(&block_id).unwrap(), 1);
}
#[test]
fn calling_wasm_runtime_signature_changed_old_function() {
let client = test_client::new_with_api_execution_strat(ExecutionStrategy::AlwaysWasm);
let runtime_api = client.runtime_api();
let block_id = BlockId::Number(client.info().unwrap().chain.best_number);
#[allow(deprecated)]
let res = runtime_api.function_signature_changed_before_version_2(&block_id).unwrap();
assert_eq!(&res, &[1, 2]);
}