mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 08:47:57 +00:00
break sp-api dependency cycle (#4352)
* move benches into tests, ignore non-passing doctests * Rename sr-api folder * Move test-primitives to primitives, use that for sp-api doctests
This commit is contained in:
committed by
Bastian Köcher
parent
f6f0f1cc16
commit
8721d98dd6
@@ -0,0 +1,128 @@
|
||||
// Copyright 2019 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/>.
|
||||
|
||||
use sp_api::{RuntimeApiInfo, decl_runtime_apis, impl_runtime_apis};
|
||||
|
||||
use sp_runtime::{traits::{GetNodeBlockType, Block as BlockT}, generic::BlockId};
|
||||
|
||||
use test_client::runtime::Block;
|
||||
use sp_blockchain::Result;
|
||||
|
||||
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
|
||||
/// trait are done by the `construct_runtime!` macro in a real runtime.
|
||||
pub struct Runtime {}
|
||||
impl GetNodeBlockType for Runtime {
|
||||
type NodeBlock = Block;
|
||||
}
|
||||
|
||||
decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
fn something_with_block(block: Block) -> Block;
|
||||
fn function_with_two_args(data: u64, block: Block);
|
||||
fn same_name();
|
||||
fn wild_card(_: u32);
|
||||
}
|
||||
|
||||
#[api_version(2)]
|
||||
pub trait ApiWithCustomVersion {
|
||||
fn same_name();
|
||||
#[changed_in(2)]
|
||||
fn same_name() -> String;
|
||||
}
|
||||
}
|
||||
|
||||
impl_runtime_apis! {
|
||||
impl self::Api<Block> for Runtime {
|
||||
fn test(_: u64) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn something_with_block(_: Block) -> Block {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn function_with_two_args(_: u64, _: Block) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn same_name() {}
|
||||
|
||||
fn wild_card(_: u32) {}
|
||||
}
|
||||
|
||||
impl self::ApiWithCustomVersion<Block> for Runtime {
|
||||
fn same_name() {}
|
||||
}
|
||||
|
||||
impl sp_api::Core<Block> for Runtime {
|
||||
fn version() -> sp_version::RuntimeVersion {
|
||||
unimplemented!()
|
||||
}
|
||||
fn execute_block(_: Block) {
|
||||
unimplemented!()
|
||||
}
|
||||
fn initialize_block(_: &<Block as BlockT>::Header) {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type TestClient = test_client::client::Client<
|
||||
test_client::Backend, test_client::Executor, Block, RuntimeApi
|
||||
>;
|
||||
|
||||
#[test]
|
||||
fn test_client_side_function_signature() {
|
||||
let _test: fn(&RuntimeApiImpl<TestClient>, &BlockId<Block>, u64) -> Result<()> =
|
||||
RuntimeApiImpl::<TestClient>::test;
|
||||
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]
|
||||
fn check_runtime_api_info() {
|
||||
assert_eq!(&Api::<Block, Error = ()>::ID, &runtime_decl_for_Api::ID);
|
||||
assert_eq!(Api::<Block, Error = ()>::VERSION, runtime_decl_for_Api::VERSION);
|
||||
assert_eq!(Api::<Block, Error = ()>::VERSION, 1);
|
||||
|
||||
assert_eq!(
|
||||
ApiWithCustomVersion::<Block, Error = ()>::VERSION,
|
||||
runtime_decl_for_ApiWithCustomVersion::VERSION,
|
||||
);
|
||||
assert_eq!(
|
||||
&ApiWithCustomVersion::<Block, Error = ()>::ID,
|
||||
&runtime_decl_for_ApiWithCustomVersion::ID,
|
||||
);
|
||||
assert_eq!(ApiWithCustomVersion::<Block, Error = ()>::VERSION, 2);
|
||||
}
|
||||
|
||||
fn check_runtime_api_versions_contains<T: RuntimeApiInfo + ?Sized>() {
|
||||
assert!(RUNTIME_API_VERSIONS.iter().any(|v| v == &(T::ID, T::VERSION)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn check_runtime_api_versions() {
|
||||
check_runtime_api_versions_contains::<dyn Api<Block, Error = ()>>();
|
||||
check_runtime_api_versions_contains::<dyn ApiWithCustomVersion<Block, Error = ()>>();
|
||||
check_runtime_api_versions_contains::<dyn sp_api::Core<Block, Error = ()>>();
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
// Copyright 2019 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/>.
|
||||
|
||||
use test_client::{
|
||||
prelude::*,
|
||||
DefaultTestClientBuilderExt, TestClientBuilder,
|
||||
runtime::{TestAPI, DecodeFails, Transfer, Header},
|
||||
};
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
traits::{ProvideRuntimeApi, Header as HeaderT, Hash as HashT},
|
||||
};
|
||||
use state_machine::{
|
||||
ExecutionStrategy, create_proof_check_backend,
|
||||
execution_proof_check_on_trie_backend,
|
||||
};
|
||||
|
||||
use consensus_common::SelectChain;
|
||||
use codec::Encode;
|
||||
|
||||
fn calling_function_with_strat(strat: ExecutionStrategy) {
|
||||
let client = TestClientBuilder::new().set_execution_strategy(strat).build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.info().chain.best_number);
|
||||
|
||||
assert_eq!(runtime_api.benchmark_add_one(&block_id, &1).unwrap(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn calling_native_runtime_function() {
|
||||
calling_function_with_strat(ExecutionStrategy::NativeWhenPossible);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn calling_wasm_runtime_function() {
|
||||
calling_function_with_strat(ExecutionStrategy::AlwaysWasm);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(
|
||||
expected =
|
||||
"Could not convert parameter `param` between node and runtime: DecodeFails always fails"
|
||||
)]
|
||||
fn calling_native_runtime_function_with_non_decodable_parameter() {
|
||||
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::NativeWhenPossible).build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.info().chain.best_number);
|
||||
runtime_api.fail_convert_parameter(&block_id, DecodeFails::new()).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Could not convert return value from runtime to node!")]
|
||||
fn calling_native_runtime_function_with_non_decodable_return_value() {
|
||||
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::NativeWhenPossible).build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.info().chain.best_number);
|
||||
runtime_api.fail_convert_return_value(&block_id).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn calling_native_runtime_signature_changed_function() {
|
||||
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::NativeWhenPossible).build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.info().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 = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::AlwaysWasm).build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.info().chain.best_number);
|
||||
|
||||
#[allow(deprecated)]
|
||||
let res = runtime_api.function_signature_changed_before_version_2(&block_id).unwrap();
|
||||
assert_eq!(&res, &[1, 2]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn calling_with_both_strategy_and_fail_on_wasm_should_return_error() {
|
||||
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.info().chain.best_number);
|
||||
assert!(runtime_api.fail_on_wasm(&block_id).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn calling_with_both_strategy_and_fail_on_native_should_work() {
|
||||
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.info().chain.best_number);
|
||||
assert_eq!(runtime_api.fail_on_native(&block_id).unwrap(), 1);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn calling_with_native_else_wasm_and_fail_on_wasm_should_work() {
|
||||
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::NativeElseWasm).build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.info().chain.best_number);
|
||||
assert_eq!(runtime_api.fail_on_wasm(&block_id).unwrap(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn calling_with_native_else_wasm_and_fail_on_native_should_work() {
|
||||
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::NativeElseWasm).build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.info().chain.best_number);
|
||||
assert_eq!(runtime_api.fail_on_native(&block_id).unwrap(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn use_trie_function() {
|
||||
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::AlwaysWasm).build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.info().chain.best_number);
|
||||
assert_eq!(runtime_api.use_trie(&block_id).unwrap(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn initialize_block_works() {
|
||||
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.info().chain.best_number);
|
||||
assert_eq!(runtime_api.get_block_number(&block_id).unwrap(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn initialize_block_is_called_only_once() {
|
||||
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.info().chain.best_number);
|
||||
assert_eq!(runtime_api.take_block_number(&block_id).unwrap(), Some(1));
|
||||
assert_eq!(runtime_api.take_block_number(&block_id).unwrap(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn initialize_block_is_skipped() {
|
||||
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Number(client.info().chain.best_number);
|
||||
assert!(runtime_api.without_initialize_block(&block_id).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record_proof_works() {
|
||||
let (client, longest_chain) = TestClientBuilder::new()
|
||||
.set_execution_strategy(ExecutionStrategy::Both)
|
||||
.build_with_longest_chain();
|
||||
|
||||
let block_id = BlockId::Number(client.info().chain.best_number);
|
||||
let storage_root = longest_chain.best_chain().unwrap().state_root().clone();
|
||||
|
||||
let transaction = Transfer {
|
||||
amount: 1000,
|
||||
nonce: 0,
|
||||
from: AccountKeyring::Alice.into(),
|
||||
to: Default::default(),
|
||||
}.into_signed_tx();
|
||||
|
||||
// Build the block and record proof
|
||||
let mut builder = client
|
||||
.new_block_at_with_proof_recording(&block_id, Default::default())
|
||||
.expect("Creates block builder");
|
||||
builder.push(transaction.clone()).unwrap();
|
||||
let (block, proof) = builder.bake_and_extract_proof().expect("Bake block");
|
||||
|
||||
let backend = create_proof_check_backend::<<<Header as HeaderT>::Hashing as HashT>::Hasher>(
|
||||
storage_root,
|
||||
proof.expect("Proof was generated"),
|
||||
).expect("Creates proof backend.");
|
||||
|
||||
// Use the proof backend to execute `execute_block`.
|
||||
let mut overlay = Default::default();
|
||||
let executor = NativeExecutor::<LocalExecutor>::new(WasmExecutionMethod::Interpreted, None);
|
||||
execution_proof_check_on_trie_backend(
|
||||
&backend,
|
||||
&mut overlay,
|
||||
&executor,
|
||||
"Core_execute_block",
|
||||
&block.encode(),
|
||||
).expect("Executes block while using the proof backend");
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2019 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/>.
|
||||
|
||||
use std::env;
|
||||
|
||||
#[rustversion::attr(not(stable), ignore)]
|
||||
#[test]
|
||||
fn ui() {
|
||||
// As trybuild is using `cargo check`, we don't need the real WASM binaries.
|
||||
env::set_var("BUILD_DUMMY_WASM_BINARY", "1");
|
||||
|
||||
let t = trybuild::TestCases::new();
|
||||
t.compile_fail("tests/ui/*.rs");
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(&self);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: `self` as argument not supported.
|
||||
--> $DIR/adding_self_parameter.rs:3:11
|
||||
|
|
||||
3 | fn test(&self);
|
||||
| ^
|
||||
@@ -0,0 +1,19 @@
|
||||
use sp_runtime::traits::GetNodeBlockType;
|
||||
use test_client::runtime::Block;
|
||||
|
||||
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
|
||||
/// trait are done by the `construct_runtime!` macro in a real runtime.
|
||||
struct Runtime {}
|
||||
impl GetNodeBlockType for Runtime {
|
||||
type NodeBlock = Block;
|
||||
}
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
#[changed_in(2)]
|
||||
fn test(data: u64);
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: `changed_in` version can not be greater than the `api_version`
|
||||
--> $DIR/changed_in_unknown_version.rs:14:3
|
||||
|
|
||||
14 | fn test(data: u64);
|
||||
| ^^
|
||||
@@ -0,0 +1,9 @@
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api<Block: BlockT> {
|
||||
fn test();
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,19 @@
|
||||
error: `Block: BlockT` generic parameter will be added automatically by the `decl_runtime_apis!` macro!
|
||||
--> $DIR/declaring_old_block.rs:4:16
|
||||
|
|
||||
4 | pub trait Api<Block: BlockT> {
|
||||
| ^^^^^
|
||||
|
||||
error: `Block: BlockT` generic parameter will be added automatically by the `decl_runtime_apis!` macro! If you try to use a different trait than the substrate `Block` trait, please rename it locally.
|
||||
--> $DIR/declaring_old_block.rs:4:23
|
||||
|
|
||||
4 | pub trait Api<Block: BlockT> {
|
||||
| ^^^^^^
|
||||
|
||||
warning: unused import: `sp_runtime::traits::Block as BlockT`
|
||||
--> $DIR/declaring_old_block.rs:1:5
|
||||
|
|
||||
1 | use sp_runtime::traits::Block as BlockT;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(unused_imports)]` on by default
|
||||
@@ -0,0 +1,9 @@
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api<B: BlockT> {
|
||||
fn test();
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,13 @@
|
||||
error: `Block: BlockT` generic parameter will be added automatically by the `decl_runtime_apis!` macro! If you try to use a different trait than the substrate `Block` trait, please rename it locally.
|
||||
--> $DIR/declaring_own_block_with_different_name.rs:4:19
|
||||
|
|
||||
4 | pub trait Api<B: BlockT> {
|
||||
| ^^^^^^
|
||||
|
||||
warning: unused import: `sp_runtime::traits::Block as BlockT`
|
||||
--> $DIR/declaring_own_block_with_different_name.rs:1:5
|
||||
|
|
||||
1 | use sp_runtime::traits::Block as BlockT;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(unused_imports)]` on by default
|
||||
@@ -0,0 +1,19 @@
|
||||
use sp_runtime::traits::GetNodeBlockType;
|
||||
use test_client::runtime::Block;
|
||||
|
||||
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
|
||||
/// trait are done by the `construct_runtime!` macro in a real runtime.
|
||||
struct Runtime {}
|
||||
impl GetNodeBlockType for Runtime {
|
||||
type NodeBlock = Block;
|
||||
}
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
sp_api::impl_runtime_apis! {}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: No api implementation given!
|
||||
--> $DIR/empty_impl_runtime_apis_call.rs:17:1
|
||||
|
|
||||
17 | sp_api::impl_runtime_apis! {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
|
||||
@@ -0,0 +1,35 @@
|
||||
use sp_runtime::traits::{GetNodeBlockType, Block as BlockT};
|
||||
use test_client::runtime::Block;
|
||||
|
||||
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
|
||||
/// trait are done by the `construct_runtime!` macro in a real runtime.
|
||||
struct Runtime {}
|
||||
impl GetNodeBlockType for Runtime {
|
||||
type NodeBlock = Block;
|
||||
}
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
sp_api::impl_runtime_apis! {
|
||||
impl self::Api<Block> for Runtime {
|
||||
fn test(data: String) {}
|
||||
}
|
||||
|
||||
impl sp_api::Core<Block> for Runtime {
|
||||
fn version() -> runtime_api::RuntimeVersion {
|
||||
unimplemented!()
|
||||
}
|
||||
fn execute_block(_: Block) {
|
||||
unimplemented!()
|
||||
}
|
||||
fn initialize_block(_: &<Block as BlockT>::Header) {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,70 @@
|
||||
error[E0433]: failed to resolve: use of undeclared type or module `runtime_api`
|
||||
--> $DIR/impl_incorrect_method_signature.rs:23:19
|
||||
|
|
||||
23 | fn version() -> runtime_api::RuntimeVersion {
|
||||
| ^^^^^^^^^^^ use of undeclared type or module `runtime_api`
|
||||
|
||||
error[E0053]: method `test` has an incompatible type for trait
|
||||
--> $DIR/impl_incorrect_method_signature.rs:19:17
|
||||
|
|
||||
13 | fn test(data: u64);
|
||||
| --- type in trait
|
||||
...
|
||||
19 | fn test(data: String) {}
|
||||
| ^^^^^^ expected u64, found struct `std::string::String`
|
||||
|
|
||||
= note: expected type `fn(u64)`
|
||||
found type `fn(std::string::String)`
|
||||
|
||||
error[E0053]: method `Api_test_runtime_api_impl` has an incompatible type for trait
|
||||
--> $DIR/impl_incorrect_method_signature.rs:17:1
|
||||
|
|
||||
11 | / sp_api::decl_runtime_apis! {
|
||||
12 | | pub trait Api {
|
||||
13 | | fn test(data: u64);
|
||||
14 | | }
|
||||
15 | | }
|
||||
| |_- type in trait
|
||||
16 |
|
||||
17 | sp_api::impl_runtime_apis! {
|
||||
| -^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| _expected u64, found struct `std::string::String`
|
||||
| |
|
||||
18 | | impl self::Api<Block> for Runtime {
|
||||
19 | | fn test(data: String) {}
|
||||
20 | | }
|
||||
... |
|
||||
32 | | }
|
||||
33 | | }
|
||||
| |_- in this macro invocation
|
||||
|
|
||||
= note: expected type `fn(&RuntimeApiImpl<RuntimeApiImplCall>, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u64, sp_runtime::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<u64>, std::vec::Vec<u8>) -> std::result::Result<sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::NativeOrEncoded<()>, <RuntimeApiImplCall as sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::CallRuntimeAt<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u64, sp_runtime::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>>::Error>`
|
||||
found type `fn(&RuntimeApiImpl<RuntimeApiImplCall>, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u64, sp_runtime::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<std::string::String>, std::vec::Vec<u8>) -> std::result::Result<sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::NativeOrEncoded<()>, <RuntimeApiImplCall as sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::CallRuntimeAt<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u64, sp_runtime::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>>::Error>`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/impl_incorrect_method_signature.rs:17:1
|
||||
|
|
||||
17 | / sp_api::impl_runtime_apis! {
|
||||
18 | | impl self::Api<Block> for Runtime {
|
||||
19 | | fn test(data: String) {}
|
||||
20 | | }
|
||||
... |
|
||||
32 | | }
|
||||
33 | | }
|
||||
| | ^
|
||||
| | |
|
||||
| |_expected u64, found struct `std::string::String`
|
||||
| in this macro invocation
|
||||
|
|
||||
= note: expected type `u64`
|
||||
found type `std::string::String`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/impl_incorrect_method_signature.rs:19:11
|
||||
|
|
||||
19 | fn test(data: String) {}
|
||||
| ^^^^ expected u64, found struct `std::string::String`
|
||||
|
|
||||
= note: expected type `u64`
|
||||
found type `std::string::String`
|
||||
@@ -0,0 +1,37 @@
|
||||
use sp_runtime::traits::GetNodeBlockType;
|
||||
use test_client::runtime::Block;
|
||||
|
||||
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
|
||||
/// trait are done by the `construct_runtime!` macro in a real runtime.
|
||||
struct Runtime {}
|
||||
impl GetNodeBlockType for Runtime {
|
||||
type NodeBlock = Block;
|
||||
}
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
mod second {
|
||||
use super::*;
|
||||
|
||||
decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test2(data: u64);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sp_api::impl_runtime_apis! {
|
||||
impl self::Api<Block> for Runtime {
|
||||
fn test(data: u64) {}
|
||||
}
|
||||
|
||||
impl second::Api<Block> for Runtime {
|
||||
fn test2(data: u64) {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,77 @@
|
||||
error: Two traits with the same name detected! The trait name is used to generate its ID. Please rename one trait at the declaration!
|
||||
--> $DIR/impl_two_traits_with_same_name.rs:32:15
|
||||
|
|
||||
32 | impl second::Api<Block> for Runtime {
|
||||
| ^^^
|
||||
|
||||
error: cannot find macro `decl_runtime_apis` in this scope
|
||||
--> $DIR/impl_two_traits_with_same_name.rs:20:2
|
||||
|
|
||||
20 | decl_runtime_apis! {
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0425]: cannot find function `test2_call_api_at` in `second::runtime_decl_for_Api`
|
||||
--> $DIR/impl_two_traits_with_same_name.rs:27:1
|
||||
|
|
||||
27 | / sp_api::impl_runtime_apis! {
|
||||
28 | | impl self::Api<Block> for Runtime {
|
||||
29 | | fn test(data: u64) {}
|
||||
30 | | }
|
||||
... |
|
||||
34 | | }
|
||||
35 | | }
|
||||
| | ^
|
||||
| | |
|
||||
| |_not found in `second::runtime_decl_for_Api`
|
||||
| in this macro invocation
|
||||
|
||||
error[E0425]: cannot find function `test2_native_call_generator` in `second::runtime_decl_for_Api`
|
||||
--> $DIR/impl_two_traits_with_same_name.rs:27:1
|
||||
|
|
||||
27 | / sp_api::impl_runtime_apis! {
|
||||
28 | | impl self::Api<Block> for Runtime {
|
||||
29 | | fn test(data: u64) {}
|
||||
30 | | }
|
||||
... |
|
||||
34 | | }
|
||||
35 | | }
|
||||
| | ^
|
||||
| | |
|
||||
| |_not found in `second::runtime_decl_for_Api`
|
||||
| in this macro invocation
|
||||
|
||||
error[E0576]: cannot find method or associated constant `test2` in `second::runtime_decl_for_Api::Api`
|
||||
--> $DIR/impl_two_traits_with_same_name.rs:33:6
|
||||
|
|
||||
33 | fn test2(data: u64) {}
|
||||
| ^^^^^ not found in `second::runtime_decl_for_Api::Api`
|
||||
|
||||
error[E0603]: module `runtime_decl_for_Api` is private
|
||||
--> $DIR/impl_two_traits_with_same_name.rs:27:1
|
||||
|
|
||||
27 | / sp_api::impl_runtime_apis! {
|
||||
28 | | impl self::Api<Block> for Runtime {
|
||||
29 | | fn test(data: u64) {}
|
||||
30 | | }
|
||||
... |
|
||||
34 | | }
|
||||
35 | | }
|
||||
| |_^
|
||||
|
||||
error[E0119]: conflicting implementations of trait `runtime_decl_for_Api::Api<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u64, sp_runtime::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>` for type `Runtime`:
|
||||
--> $DIR/impl_two_traits_with_same_name.rs:32:2
|
||||
|
|
||||
28 | impl self::Api<Block> for Runtime {
|
||||
| --------------------------------- first implementation here
|
||||
...
|
||||
32 | impl second::Api<Block> for Runtime {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Runtime`
|
||||
|
||||
error[E0119]: conflicting implementations of trait `Api<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u64, sp_runtime::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>` for type `RuntimeApiImpl<_>`:
|
||||
--> $DIR/impl_two_traits_with_same_name.rs:32:2
|
||||
|
|
||||
28 | impl self::Api<Block> for Runtime {
|
||||
| --------------------------------- first implementation here
|
||||
...
|
||||
32 | impl second::Api<Block> for Runtime {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `RuntimeApiImpl<_>`
|
||||
@@ -0,0 +1,8 @@
|
||||
sp_api::decl_runtime_apis! {
|
||||
#[api_version]
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,33 @@
|
||||
error: can't qualify macro invocation with `pub`
|
||||
--> $DIR/invalid_api_version.rs:1:1
|
||||
|
|
||||
1 | / sp_api::decl_runtime_apis! {
|
||||
2 | | #[api_version]
|
||||
3 | | pub trait Api {
|
||||
4 | | fn test(data: u64);
|
||||
5 | | }
|
||||
6 | | }
|
||||
| | ^ in this macro invocation
|
||||
| |_|
|
||||
|
|
||||
|
|
||||
= help: try adjusting the macro to put `pub` inside the invocation
|
||||
|
||||
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
|
||||
--> $DIR/invalid_api_version.rs:1:1
|
||||
|
|
||||
1 | / sp_api::decl_runtime_apis! {
|
||||
2 | | #[api_version]
|
||||
3 | | pub trait Api {
|
||||
4 | | fn test(data: u64);
|
||||
5 | | }
|
||||
6 | | }
|
||||
| | ^ in this macro invocation
|
||||
| |_|
|
||||
|
|
||||
|
||||
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
|
||||
--> $DIR/invalid_api_version.rs:2:4
|
||||
|
|
||||
2 | #[api_version]
|
||||
| ^^^^^^^^^^^
|
||||
@@ -0,0 +1,8 @@
|
||||
sp_api::decl_runtime_apis! {
|
||||
#[api_version("1")]
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,33 @@
|
||||
error: can't qualify macro invocation with `pub`
|
||||
--> $DIR/invalid_api_version_2.rs:1:1
|
||||
|
|
||||
1 | / sp_api::decl_runtime_apis! {
|
||||
2 | | #[api_version("1")]
|
||||
3 | | pub trait Api {
|
||||
4 | | fn test(data: u64);
|
||||
5 | | }
|
||||
6 | | }
|
||||
| | ^ in this macro invocation
|
||||
| |_|
|
||||
|
|
||||
|
|
||||
= help: try adjusting the macro to put `pub` inside the invocation
|
||||
|
||||
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
|
||||
--> $DIR/invalid_api_version_2.rs:1:1
|
||||
|
|
||||
1 | / sp_api::decl_runtime_apis! {
|
||||
2 | | #[api_version("1")]
|
||||
3 | | pub trait Api {
|
||||
4 | | fn test(data: u64);
|
||||
5 | | }
|
||||
6 | | }
|
||||
| | ^ in this macro invocation
|
||||
| |_|
|
||||
|
|
||||
|
||||
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
|
||||
--> $DIR/invalid_api_version_2.rs:2:4
|
||||
|
|
||||
2 | #[api_version("1")]
|
||||
| ^^^^^^^^^^^
|
||||
@@ -0,0 +1,8 @@
|
||||
sp_api::decl_runtime_apis! {
|
||||
#[api_version()]
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,33 @@
|
||||
error: can't qualify macro invocation with `pub`
|
||||
--> $DIR/invalid_api_version_3.rs:1:1
|
||||
|
|
||||
1 | / sp_api::decl_runtime_apis! {
|
||||
2 | | #[api_version()]
|
||||
3 | | pub trait Api {
|
||||
4 | | fn test(data: u64);
|
||||
5 | | }
|
||||
6 | | }
|
||||
| | ^ in this macro invocation
|
||||
| |_|
|
||||
|
|
||||
|
|
||||
= help: try adjusting the macro to put `pub` inside the invocation
|
||||
|
||||
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
|
||||
--> $DIR/invalid_api_version_3.rs:1:1
|
||||
|
|
||||
1 | / sp_api::decl_runtime_apis! {
|
||||
2 | | #[api_version()]
|
||||
3 | | pub trait Api {
|
||||
4 | | fn test(data: u64);
|
||||
5 | | }
|
||||
6 | | }
|
||||
| | ^ in this macro invocation
|
||||
| |_|
|
||||
|
|
||||
|
||||
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
|
||||
--> $DIR/invalid_api_version_3.rs:2:4
|
||||
|
|
||||
2 | #[api_version()]
|
||||
| ^^^^^^^^^^^
|
||||
@@ -0,0 +1,25 @@
|
||||
use sp_runtime::traits::GetNodeBlockType;
|
||||
use test_client::runtime::Block;
|
||||
|
||||
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
|
||||
/// trait are done by the `construct_runtime!` macro in a real runtime.
|
||||
struct Runtime {}
|
||||
impl GetNodeBlockType for Runtime {
|
||||
type NodeBlock = Block;
|
||||
}
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
sp_api::impl_runtime_apis! {
|
||||
impl self::Api for Runtime {
|
||||
fn test(data: u64) {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,11 @@
|
||||
error: Missing `Block` generic parameter.
|
||||
--> $DIR/missing_block_generic_parameter.rs:18:13
|
||||
|
|
||||
18 | impl self::Api for Runtime {
|
||||
| ^^^
|
||||
|
||||
error[E0107]: wrong number of type arguments: expected 1, found 0
|
||||
--> $DIR/missing_block_generic_parameter.rs:18:7
|
||||
|
|
||||
18 | impl self::Api for Runtime {
|
||||
| ^^^^^^^^^ expected 1 type argument
|
||||
@@ -0,0 +1,25 @@
|
||||
use sp_runtime::traits::GetNodeBlockType;
|
||||
use test_client::runtime::Block;
|
||||
|
||||
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
|
||||
/// trait are done by the `construct_runtime!` macro in a real runtime.
|
||||
struct Runtime {}
|
||||
impl GetNodeBlockType for Runtime {
|
||||
type NodeBlock = Block;
|
||||
}
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
sp_api::impl_runtime_apis! {
|
||||
impl Api<Block> for Runtime {
|
||||
fn test(data: u64) {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: The implemented trait has to be referenced with a path, e.g. `impl client::Core for Runtime`.
|
||||
--> $DIR/missing_path_for_trait.rs:18:7
|
||||
|
|
||||
18 | impl Api<Block> for Runtime {
|
||||
| ^^^
|
||||
@@ -0,0 +1,37 @@
|
||||
use sp_runtime::traits::{GetNodeBlockType, Block as BlockT};
|
||||
use test_client::runtime::Block;
|
||||
|
||||
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
|
||||
/// trait are done by the `construct_runtime!` macro in a real runtime.
|
||||
struct Runtime {}
|
||||
impl GetNodeBlockType for Runtime {
|
||||
type NodeBlock = Block;
|
||||
}
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
sp_api::impl_runtime_apis! {
|
||||
impl self::Api<Block> for Runtime {
|
||||
fn test(data: &u64) {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_api::Core<Block> for Runtime {
|
||||
fn version() -> runtime_api::RuntimeVersion {
|
||||
unimplemented!()
|
||||
}
|
||||
fn execute_block(_: Block) {
|
||||
unimplemented!()
|
||||
}
|
||||
fn initialize_block(_: &<Block as BlockT>::Header) {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
error[E0433]: failed to resolve: use of undeclared type or module `runtime_api`
|
||||
--> $DIR/type_reference_in_impl_runtime_apis_call.rs:25:19
|
||||
|
|
||||
25 | fn version() -> runtime_api::RuntimeVersion {
|
||||
| ^^^^^^^^^^^ use of undeclared type or module `runtime_api`
|
||||
|
||||
error[E0053]: method `test` has an incompatible type for trait
|
||||
--> $DIR/type_reference_in_impl_runtime_apis_call.rs:19:17
|
||||
|
|
||||
13 | fn test(data: u64);
|
||||
| --- type in trait
|
||||
...
|
||||
19 | fn test(data: &u64) {
|
||||
| ^^^^ expected u64, found &u64
|
||||
|
|
||||
= note: expected type `fn(u64)`
|
||||
found type `fn(&u64)`
|
||||
|
||||
error[E0053]: method `Api_test_runtime_api_impl` has an incompatible type for trait
|
||||
--> $DIR/type_reference_in_impl_runtime_apis_call.rs:17:1
|
||||
|
|
||||
11 | / sp_api::decl_runtime_apis! {
|
||||
12 | | pub trait Api {
|
||||
13 | | fn test(data: u64);
|
||||
14 | | }
|
||||
15 | | }
|
||||
| |_- type in trait
|
||||
16 |
|
||||
17 | sp_api::impl_runtime_apis! {
|
||||
| -^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| _expected u64, found &u64
|
||||
| |
|
||||
18 | | impl self::Api<Block> for Runtime {
|
||||
19 | | fn test(data: &u64) {
|
||||
20 | | unimplemented!()
|
||||
... |
|
||||
34 | | }
|
||||
35 | | }
|
||||
| |_- in this macro invocation
|
||||
|
|
||||
= note: expected type `fn(&RuntimeApiImpl<RuntimeApiImplCall>, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u64, sp_runtime::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<u64>, std::vec::Vec<u8>) -> std::result::Result<sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::NativeOrEncoded<()>, <RuntimeApiImplCall as sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::CallRuntimeAt<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u64, sp_runtime::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>>::Error>`
|
||||
found type `fn(&RuntimeApiImpl<RuntimeApiImplCall>, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u64, sp_runtime::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<&u64>, std::vec::Vec<u8>) -> std::result::Result<sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::NativeOrEncoded<()>, <RuntimeApiImplCall as sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::CallRuntimeAt<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u64, sp_runtime::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>>::Error>`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/type_reference_in_impl_runtime_apis_call.rs:17:1
|
||||
|
|
||||
17 | / sp_api::impl_runtime_apis! {
|
||||
18 | | impl self::Api<Block> for Runtime {
|
||||
19 | | fn test(data: &u64) {
|
||||
20 | | unimplemented!()
|
||||
... |
|
||||
34 | | }
|
||||
35 | | }
|
||||
| | ^
|
||||
| | |
|
||||
| |_expected u64, found &u64
|
||||
| in this macro invocation
|
||||
|
|
||||
= note: expected type `u64`
|
||||
found type `&u64`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/type_reference_in_impl_runtime_apis_call.rs:19:11
|
||||
|
|
||||
19 | fn test(data: &u64) {
|
||||
| ^^^^^^^
|
||||
| |
|
||||
| expected u64, found &u64
|
||||
| help: consider removing the borrow: `data`
|
||||
|
|
||||
= note: expected type `u64`
|
||||
found type `&u64`
|
||||
Reference in New Issue
Block a user