feat: initialize Kurdistan SDK - independent fork of Polkadot SDK
This commit is contained in:
@@ -0,0 +1,378 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use sp_api::{
|
||||
decl_runtime_apis, impl_runtime_apis, mock_impl_runtime_apis, ApiError, ApiExt, RuntimeApiInfo,
|
||||
};
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
|
||||
use substrate_test_runtime_client::runtime::{Block, Hash};
|
||||
|
||||
/// The declaration of the `Runtime` type is done by the `construct_runtime!` macro in a real
|
||||
/// runtime.
|
||||
pub struct Runtime {}
|
||||
|
||||
decl_runtime_apis! {
|
||||
#[deprecated]
|
||||
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;
|
||||
}
|
||||
|
||||
#[api_version(2)]
|
||||
pub trait ApiWithMultipleVersions {
|
||||
fn stable_one(data: u64);
|
||||
#[api_version(3)]
|
||||
fn new_one();
|
||||
#[api_version(4)]
|
||||
fn glory_one();
|
||||
}
|
||||
|
||||
pub trait ApiWithStagingMethod {
|
||||
fn stable_one(data: u64);
|
||||
#[api_version(99)]
|
||||
fn staging_one();
|
||||
}
|
||||
|
||||
pub trait ApiWithStagingAndVersionedMethods {
|
||||
fn stable_one(data: u64);
|
||||
#[api_version(2)]
|
||||
fn new_one();
|
||||
#[api_version(99)]
|
||||
fn staging_one();
|
||||
}
|
||||
|
||||
#[api_version(2)]
|
||||
pub trait ApiWithStagingAndChangedBase {
|
||||
fn stable_one(data: u64);
|
||||
fn new_one();
|
||||
#[api_version(99)]
|
||||
fn staging_one();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl_runtime_apis! {
|
||||
#[allow(deprecated)]
|
||||
impl self::Api<Block> for Runtime {
|
||||
fn test(_: u64) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
// Ensure that we accept `mut`
|
||||
fn something_with_block(mut _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() {}
|
||||
}
|
||||
|
||||
#[api_version(3)]
|
||||
impl self::ApiWithMultipleVersions<Block> for Runtime {
|
||||
fn stable_one(_: u64) {}
|
||||
|
||||
fn new_one() {}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "enable-staging-api", api_version(99))]
|
||||
impl self::ApiWithStagingMethod<Block> for Runtime {
|
||||
fn stable_one(_: u64) {}
|
||||
|
||||
#[cfg(feature = "enable-staging-api")]
|
||||
fn staging_one() { }
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "enable-staging-api", api_version(99))]
|
||||
#[api_version(2)]
|
||||
impl self::ApiWithStagingAndVersionedMethods<Block> for Runtime {
|
||||
fn stable_one(_: u64) {}
|
||||
fn new_one() {}
|
||||
|
||||
#[cfg(feature = "enable-staging-api")]
|
||||
fn staging_one() {}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "enable-staging-api", api_version(99))]
|
||||
impl self::ApiWithStagingAndChangedBase<Block> for Runtime {
|
||||
fn stable_one(_: u64) {}
|
||||
fn new_one() {}
|
||||
|
||||
#[cfg(feature = "enable-staging-api")]
|
||||
fn staging_one() {}
|
||||
}
|
||||
|
||||
impl sp_api::Core<Block> for Runtime {
|
||||
fn version() -> sp_version::RuntimeVersion {
|
||||
unimplemented!()
|
||||
}
|
||||
fn execute_block(_: <Block as BlockT>::LazyBlock) {
|
||||
unimplemented!()
|
||||
}
|
||||
fn initialize_block(_: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct MockApi {
|
||||
block: Option<Block>,
|
||||
}
|
||||
|
||||
mock_impl_runtime_apis! {
|
||||
#[allow(deprecated)]
|
||||
impl Api<Block> for MockApi {
|
||||
fn test(_: u64) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn something_with_block(&self, _: Block) -> Block {
|
||||
self.block.clone().unwrap()
|
||||
}
|
||||
|
||||
fn function_with_two_args(_: u64, _: Block) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[advanced]
|
||||
fn same_name(_: <Block as BlockT>::Hash) -> Result<(), ApiError> {
|
||||
Ok(().into())
|
||||
}
|
||||
|
||||
#[advanced]
|
||||
fn wild_card(at: <Block as BlockT>::Hash, _: u32) -> Result<(), ApiError> {
|
||||
if Hash::repeat_byte(0x0f) == at {
|
||||
// yeah
|
||||
Ok(().into())
|
||||
} else {
|
||||
Err((Box::from("Test error") as Box<dyn std::error::Error + Send + Sync>).into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ApiWithCustomVersion<Block> for MockApi {
|
||||
fn same_name() {}
|
||||
}
|
||||
}
|
||||
|
||||
type TestClient = substrate_test_runtime_client::client::Client<
|
||||
substrate_test_runtime_client::Backend,
|
||||
substrate_test_runtime_client::ExecutorDispatch,
|
||||
Block,
|
||||
RuntimeApi,
|
||||
>;
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn test_client_side_function_signature() {
|
||||
let _test: fn(
|
||||
&RuntimeApiImpl<Block, TestClient>,
|
||||
<Block as BlockT>::Hash,
|
||||
u64,
|
||||
) -> Result<(), ApiError> = RuntimeApiImpl::<Block, TestClient>::test;
|
||||
let _something_with_block: fn(
|
||||
&RuntimeApiImpl<Block, TestClient>,
|
||||
<Block as BlockT>::Hash,
|
||||
Block,
|
||||
) -> Result<Block, ApiError> = RuntimeApiImpl::<Block, TestClient>::something_with_block;
|
||||
|
||||
#[allow(deprecated)]
|
||||
let _same_name_before_version_2: fn(
|
||||
&RuntimeApiImpl<Block, TestClient>,
|
||||
<Block as BlockT>::Hash,
|
||||
) -> Result<String, ApiError> = RuntimeApiImpl::<Block, TestClient>::same_name_before_version_2;
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn check_runtime_api_info() {
|
||||
assert_eq!(&<dyn Api::<Block>>::ID, &runtime_decl_for_api::ID);
|
||||
assert_eq!(<dyn Api::<Block>>::VERSION, runtime_decl_for_api::VERSION);
|
||||
assert_eq!(<dyn Api::<Block>>::VERSION, 1);
|
||||
|
||||
assert_eq!(
|
||||
<dyn ApiWithCustomVersion::<Block>>::VERSION,
|
||||
runtime_decl_for_api_with_custom_version::VERSION,
|
||||
);
|
||||
assert_eq!(
|
||||
&<dyn ApiWithCustomVersion::<Block>>::ID,
|
||||
&runtime_decl_for_api_with_custom_version::ID,
|
||||
);
|
||||
assert_eq!(<dyn ApiWithCustomVersion::<Block>>::VERSION, 2);
|
||||
|
||||
// The stable version of the API
|
||||
assert_eq!(<dyn ApiWithMultipleVersions::<Block>>::VERSION, 2);
|
||||
|
||||
assert_eq!(<dyn ApiWithStagingMethod::<Block>>::VERSION, 1);
|
||||
assert_eq!(<dyn ApiWithStagingAndVersionedMethods::<Block>>::VERSION, 1);
|
||||
assert_eq!(<dyn ApiWithStagingAndChangedBase::<Block>>::VERSION, 2);
|
||||
}
|
||||
|
||||
fn check_runtime_api_versions_contains<T: RuntimeApiInfo + ?Sized>() {
|
||||
assert!(RUNTIME_API_VERSIONS.iter().any(|v| v == &(T::ID, T::VERSION)));
|
||||
}
|
||||
|
||||
fn check_staging_runtime_api_versions<T: RuntimeApiInfo + ?Sized>(_staging_ver: u32) {
|
||||
// Staging APIs should contain staging version if the feature is set...
|
||||
#[cfg(feature = "enable-staging-api")]
|
||||
assert!(RUNTIME_API_VERSIONS.iter().any(|v| v == &(T::ID, _staging_ver)));
|
||||
//... otherwise the base version should be set
|
||||
#[cfg(not(feature = "enable-staging-api"))]
|
||||
check_runtime_api_versions_contains::<dyn ApiWithStagingMethod<Block>>();
|
||||
}
|
||||
|
||||
#[allow(unused_assignments)]
|
||||
fn check_staging_multiver_runtime_api_versions<T: RuntimeApiInfo + ?Sized>(
|
||||
_staging_ver: u32,
|
||||
_stable_ver: u32,
|
||||
) {
|
||||
// Staging APIs should contain staging version if the feature is set...
|
||||
#[cfg(feature = "enable-staging-api")]
|
||||
assert!(RUNTIME_API_VERSIONS.iter().any(|v| v == &(T::ID, _staging_ver)));
|
||||
//... otherwise the base version should be set
|
||||
#[cfg(not(feature = "enable-staging-api"))]
|
||||
assert!(RUNTIME_API_VERSIONS.iter().any(|v| v == &(T::ID, _stable_ver)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn check_runtime_api_versions() {
|
||||
check_runtime_api_versions_contains::<dyn Api<Block>>();
|
||||
check_runtime_api_versions_contains::<dyn ApiWithCustomVersion<Block>>();
|
||||
assert!(RUNTIME_API_VERSIONS
|
||||
.iter()
|
||||
.any(|v| v == &(<dyn ApiWithMultipleVersions<Block>>::ID, 3)));
|
||||
|
||||
check_staging_runtime_api_versions::<dyn ApiWithStagingMethod<Block>>(99);
|
||||
check_staging_multiver_runtime_api_versions::<dyn ApiWithStagingAndVersionedMethods<Block>>(
|
||||
99, 2,
|
||||
);
|
||||
check_staging_runtime_api_versions::<dyn ApiWithStagingAndChangedBase<Block>>(99);
|
||||
|
||||
check_runtime_api_versions_contains::<dyn sp_api::Core<Block>>();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn mock_runtime_api_has_api() {
|
||||
let mock = MockApi { block: None };
|
||||
|
||||
assert!(mock.has_api::<dyn ApiWithCustomVersion<Block>>(Hash::default()).unwrap());
|
||||
assert!(mock.has_api::<dyn Api<Block>>(Hash::default()).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Calling deprecated methods is not supported by mocked runtime api.")]
|
||||
fn mock_runtime_api_panics_on_calling_old_version() {
|
||||
let mock = MockApi { block: None };
|
||||
|
||||
#[allow(deprecated)]
|
||||
let _ = mock.same_name_before_version_2(Hash::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn mock_runtime_api_works_with_advanced() {
|
||||
let mock = MockApi { block: None };
|
||||
|
||||
Api::<Block>::same_name(&mock, Hash::default()).unwrap();
|
||||
mock.wild_card(Hash::repeat_byte(0x0f), 1).unwrap();
|
||||
assert_eq!(
|
||||
"Test error".to_string(),
|
||||
mock.wild_card(Hash::repeat_byte(0x01), 1).unwrap_err().to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runtime_api_metadata_matches_version_implemented() {
|
||||
use sp_metadata_ir::InternalImplRuntimeApis;
|
||||
|
||||
let rt = Runtime {};
|
||||
let runtime_metadata = rt.runtime_metadata();
|
||||
|
||||
// Check that the metadata for some runtime API matches expectation.
|
||||
let assert_has_api_with_methods = |api_name: &str, api_methods: &[&str]| {
|
||||
let Some(api) = runtime_metadata.iter().find(|api| api.name == api_name) else {
|
||||
panic!("Can't find runtime API '{api_name}'");
|
||||
};
|
||||
if api.methods.len() != api_methods.len() {
|
||||
panic!(
|
||||
"Wrong number of methods in '{api_name}'; expected {} methods but got {}: {:?}",
|
||||
api_methods.len(),
|
||||
api.methods.len(),
|
||||
api.methods
|
||||
);
|
||||
}
|
||||
for expected_name in api_methods {
|
||||
if !api.methods.iter().any(|method| &method.name == expected_name) {
|
||||
panic!("Can't find API method '{expected_name}' in '{api_name}'");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
assert_has_api_with_methods("ApiWithCustomVersion", &["same_name"]);
|
||||
|
||||
assert_has_api_with_methods("ApiWithMultipleVersions", &["stable_one", "new_one"]);
|
||||
|
||||
assert_has_api_with_methods(
|
||||
"ApiWithStagingMethod",
|
||||
&[
|
||||
"stable_one",
|
||||
#[cfg(feature = "enable-staging-api")]
|
||||
"staging_one",
|
||||
],
|
||||
);
|
||||
|
||||
assert_has_api_with_methods(
|
||||
"ApiWithStagingAndVersionedMethods",
|
||||
&[
|
||||
"stable_one",
|
||||
"new_one",
|
||||
#[cfg(feature = "enable-staging-api")]
|
||||
"staging_one",
|
||||
],
|
||||
);
|
||||
|
||||
assert_has_api_with_methods(
|
||||
"ApiWithStagingAndChangedBase",
|
||||
&[
|
||||
"stable_one",
|
||||
"new_one",
|
||||
#[cfg(feature = "enable-staging-api")]
|
||||
"staging_one",
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::{
|
||||
panic::UnwindSafe,
|
||||
sync::{
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
Arc,
|
||||
},
|
||||
};
|
||||
|
||||
use sc_block_builder::BlockBuilderBuilder;
|
||||
use sp_api::{ApiExt, Core, ProvideRuntimeApi};
|
||||
use sp_externalities::{decl_extension, TransactionType};
|
||||
use sp_runtime::{
|
||||
traits::{HashingFor, Header as HeaderT},
|
||||
TransactionOutcome,
|
||||
};
|
||||
use sp_state_machine::{create_proof_check_backend, execution_proof_check_on_trie_backend};
|
||||
|
||||
use substrate_test_runtime_client::{
|
||||
prelude::*,
|
||||
runtime::{Block, Header, TestAPI, Transfer},
|
||||
DefaultTestClientBuilderExt, TestClient, TestClientBuilder,
|
||||
};
|
||||
|
||||
use codec::Encode;
|
||||
use sp_consensus::SelectChain;
|
||||
use substrate_test_runtime_client::sc_executor::WasmExecutor;
|
||||
|
||||
#[test]
|
||||
fn calling_runtime_function() {
|
||||
let client = TestClientBuilder::new().build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let best_hash = client.chain_info().best_hash;
|
||||
|
||||
assert_eq!(runtime_api.benchmark_add_one(best_hash, &1).unwrap(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn calling_native_runtime_signature_changed_function() {
|
||||
let client = TestClientBuilder::new().build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let best_hash = client.chain_info().best_hash;
|
||||
|
||||
assert_eq!(runtime_api.function_signature_changed(best_hash).unwrap(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn use_trie_function() {
|
||||
let client = TestClientBuilder::new().build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let best_hash = client.chain_info().best_hash;
|
||||
assert_eq!(runtime_api.use_trie(best_hash).unwrap(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn initialize_block_works() {
|
||||
let client = TestClientBuilder::new().build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let best_hash = client.chain_info().best_hash;
|
||||
runtime_api
|
||||
.initialize_block(
|
||||
best_hash,
|
||||
&Header::new(
|
||||
1,
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(runtime_api.get_block_number(best_hash).unwrap(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record_proof_works() {
|
||||
let (client, longest_chain) = TestClientBuilder::new().build_with_longest_chain();
|
||||
|
||||
let storage_root =
|
||||
*futures::executor::block_on(longest_chain.best_chain()).unwrap().state_root();
|
||||
|
||||
let runtime_code = sp_core::traits::RuntimeCode {
|
||||
code_fetcher: &sp_core::traits::WrappedRuntimeCode(
|
||||
client.code_at(client.chain_info().best_hash).unwrap().into(),
|
||||
),
|
||||
hash: vec![1],
|
||||
heap_pages: None,
|
||||
};
|
||||
|
||||
let transaction = Transfer {
|
||||
amount: 1000,
|
||||
nonce: 0,
|
||||
from: Sr25519Keyring::Alice.into(),
|
||||
to: Sr25519Keyring::Bob.into(),
|
||||
}
|
||||
.into_unchecked_extrinsic();
|
||||
|
||||
// Build the block and record proof
|
||||
let mut builder = BlockBuilderBuilder::new(&client)
|
||||
.on_parent_block(client.chain_info().best_hash)
|
||||
.with_parent_block_number(client.chain_info().best_number)
|
||||
.enable_proof_recording()
|
||||
.build()
|
||||
.unwrap();
|
||||
builder.push(transaction.clone()).unwrap();
|
||||
let (block, _, proof) = builder.build().expect("Bake block").into_inner();
|
||||
|
||||
let backend = create_proof_check_backend::<HashingFor<Block>>(
|
||||
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: WasmExecutor = WasmExecutor::builder().build();
|
||||
execution_proof_check_on_trie_backend(
|
||||
&backend,
|
||||
&mut overlay,
|
||||
&executor,
|
||||
"Core_execute_block",
|
||||
&block.encode(),
|
||||
&runtime_code,
|
||||
)
|
||||
.expect("Executes block while using the proof backend");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_runtime_api_with_multiple_arguments() {
|
||||
let client = TestClientBuilder::new().build();
|
||||
|
||||
let data = vec![1, 2, 4, 5, 6, 7, 8, 8, 10, 12];
|
||||
let best_hash = client.chain_info().best_hash;
|
||||
client
|
||||
.runtime_api()
|
||||
.test_multiple_arguments(best_hash, data.clone(), data.clone(), data.len() as u32)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disable_logging_works() {
|
||||
if std::env::var("RUN_TEST").is_ok() {
|
||||
sp_tracing::try_init_simple();
|
||||
|
||||
let mut builder = TestClientBuilder::new();
|
||||
builder.genesis_init_mut().set_wasm_code(
|
||||
substrate_test_runtime_client::runtime::wasm_binary_logging_disabled_unwrap().to_vec(),
|
||||
);
|
||||
|
||||
let client = builder.build();
|
||||
let runtime_api = client.runtime_api();
|
||||
runtime_api
|
||||
.do_trace_log(client.chain_info().genesis_hash)
|
||||
.expect("Logging should not fail");
|
||||
log::error!("Logging from native works");
|
||||
} else {
|
||||
let executable = std::env::current_exe().unwrap();
|
||||
let output = std::process::Command::new(executable)
|
||||
.env("RUN_TEST", "1")
|
||||
.env("RUST_LOG", "info")
|
||||
.args(&["--nocapture", "disable_logging_works"])
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
let output = dbg!(String::from_utf8(output.stderr).unwrap());
|
||||
assert!(!output.contains("Hey I'm runtime"));
|
||||
assert!(output.contains("Logging from native works"));
|
||||
}
|
||||
}
|
||||
|
||||
// Certain logic like the transaction handling is not unwind safe.
|
||||
//
|
||||
// Ensure that the type is not unwind safe!
|
||||
static_assertions::assert_not_impl_any!(<TestClient as ProvideRuntimeApi<_>>::Api: UnwindSafe);
|
||||
|
||||
#[derive(Default)]
|
||||
struct TransactionTesterInner {
|
||||
started: AtomicUsize,
|
||||
committed: AtomicUsize,
|
||||
rolled_back: AtomicUsize,
|
||||
}
|
||||
|
||||
decl_extension! {
|
||||
struct TransactionTester(Arc<TransactionTesterInner>);
|
||||
|
||||
impl TransactionTester {
|
||||
fn start_transaction(&mut self, ty: TransactionType) {
|
||||
assert_eq!(ty, TransactionType::Host);
|
||||
self.0.started.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
fn commit_transaction(&mut self, ty: TransactionType) {
|
||||
assert_eq!(ty, TransactionType::Host);
|
||||
self.0.committed.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
fn rollback_transaction(&mut self, ty: TransactionType) {
|
||||
assert_eq!(ty, TransactionType::Host);
|
||||
self.0.rolled_back.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ensure_transactional_works() {
|
||||
const KEY: &[u8] = b"test";
|
||||
|
||||
let client = TestClientBuilder::new().build();
|
||||
let best_hash = client.chain_info().best_hash;
|
||||
let transaction_tester = Arc::new(TransactionTesterInner::default());
|
||||
|
||||
let mut runtime_api = client.runtime_api();
|
||||
runtime_api.register_extension(TransactionTester(transaction_tester.clone()));
|
||||
runtime_api.execute_in_transaction(|api| {
|
||||
api.write_key_value(best_hash, KEY.to_vec(), vec![1, 2, 3], false).unwrap();
|
||||
|
||||
api.execute_in_transaction(|api| {
|
||||
api.write_key_value(best_hash, KEY.to_vec(), vec![1, 2, 3, 4], false).unwrap();
|
||||
|
||||
TransactionOutcome::Commit(())
|
||||
});
|
||||
|
||||
TransactionOutcome::Commit(())
|
||||
});
|
||||
|
||||
let changes = runtime_api
|
||||
.into_storage_changes(&client.state_at(best_hash).unwrap(), best_hash)
|
||||
.unwrap();
|
||||
assert_eq!(changes.main_storage_changes[0].1, Some(vec![1, 2, 3, 4]));
|
||||
|
||||
let mut runtime_api = client.runtime_api();
|
||||
runtime_api.register_extension(TransactionTester(transaction_tester.clone()));
|
||||
runtime_api.execute_in_transaction(|api| {
|
||||
assert!(api.write_key_value(best_hash, KEY.to_vec(), vec![1, 2, 3], true).is_err());
|
||||
|
||||
TransactionOutcome::Commit(())
|
||||
});
|
||||
|
||||
let changes = runtime_api
|
||||
.into_storage_changes(&client.state_at(best_hash).unwrap(), best_hash)
|
||||
.unwrap();
|
||||
assert_eq!(changes.main_storage_changes[0].1, Some(vec![1, 2, 3]));
|
||||
|
||||
let mut runtime_api = client.runtime_api();
|
||||
runtime_api.register_extension(TransactionTester(transaction_tester.clone()));
|
||||
runtime_api.execute_in_transaction(|api| {
|
||||
assert!(api.write_key_value(best_hash, KEY.to_vec(), vec![1, 2], true).is_err());
|
||||
|
||||
TransactionOutcome::Rollback(())
|
||||
});
|
||||
|
||||
let changes = runtime_api
|
||||
.into_storage_changes(&client.state_at(best_hash).unwrap(), best_hash)
|
||||
.unwrap();
|
||||
assert!(changes.main_storage_changes.is_empty());
|
||||
|
||||
assert_eq!(transaction_tester.started.load(Ordering::Relaxed), 4);
|
||||
assert_eq!(transaction_tester.committed.load(Ordering::Relaxed), 3);
|
||||
assert_eq!(transaction_tester.rolled_back.load(Ordering::Relaxed), 1);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#[rustversion::attr(not(stable), ignore)]
|
||||
#[cfg(not(feature = "disable-ui-tests"))]
|
||||
#[test]
|
||||
fn ui() {
|
||||
// Only run the ui tests when `RUN_UI_TESTS` is set.
|
||||
if std::env::var("RUN_UI_TESTS").is_err() {
|
||||
return;
|
||||
}
|
||||
|
||||
// As trybuild is using `cargo check`, we don't need the real WASM binaries.
|
||||
std::env::set_var("SKIP_WASM_BUILD", "1");
|
||||
|
||||
// Warnings are part of our UI.
|
||||
std::env::set_var("CARGO_ENCODED_RUSTFLAGS", "--deny=warnings");
|
||||
|
||||
let t = trybuild::TestCases::new();
|
||||
t.compile_fail("tests/ui/*.rs");
|
||||
t.pass("tests/ui/positive_cases/*.rs");
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(&self);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: `self` as argument not supported.
|
||||
--> tests/ui/adding_self_parameter.rs:20:11
|
||||
|
|
||||
20 | fn test(&self);
|
||||
| ^
|
||||
@@ -0,0 +1,30 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/// The declaration of the `Runtime` type is done by the `construct_runtime!` macro in a real
|
||||
/// runtime.
|
||||
struct Runtime {}
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
#[api_version(2)]
|
||||
pub trait Api {
|
||||
#[changed_in(2)]
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,6 @@
|
||||
error: There is no 'default' method with this name (without `changed_in` attribute).
|
||||
The 'default' method is used to call into the latest implementation.
|
||||
--> tests/ui/changed_in_no_default_method.rs:26:6
|
||||
|
|
||||
26 | fn test(data: u64);
|
||||
| ^^^^
|
||||
@@ -0,0 +1,30 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/// The declaration of the `Runtime` type is done by the `construct_runtime!` macro in a real
|
||||
/// runtime.
|
||||
struct Runtime {}
|
||||
|
||||
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`
|
||||
--> tests/ui/changed_in_unknown_version.rs:25:3
|
||||
|
|
||||
25 | fn test(data: u64);
|
||||
| ^^
|
||||
@@ -0,0 +1,24 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api<Block: BlockT> {
|
||||
fn test();
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,11 @@
|
||||
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.
|
||||
--> tests/ui/declaring_old_block.rs:19:23
|
||||
|
|
||||
19 | pub trait Api<Block: BlockT> {
|
||||
| ^^^^^^
|
||||
|
||||
error: `Block: BlockT` generic parameter will be added automatically by the `decl_runtime_apis!` macro!
|
||||
--> tests/ui/declaring_old_block.rs:19:16
|
||||
|
|
||||
19 | pub trait Api<Block: BlockT> {
|
||||
| ^^^^^
|
||||
@@ -0,0 +1,24 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api<B: BlockT> {
|
||||
fn test();
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
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.
|
||||
--> tests/ui/declaring_own_block_with_different_name.rs:19:19
|
||||
|
|
||||
19 | pub trait Api<B: BlockT> {
|
||||
| ^^^^^^
|
||||
@@ -0,0 +1,29 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
#[deprecated(unknown_kw = "test")]
|
||||
fn test();
|
||||
#[deprecated(since = 5)]
|
||||
fn test2();
|
||||
#[deprecated = 5]
|
||||
fn test3();
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,43 @@
|
||||
error: Invalid deprecation attribute: missing `note`
|
||||
help: the following are the possible correct uses
|
||||
|
|
||||
| #[deprecated = "reason"]
|
||||
|
|
||||
| #[deprecated(/*opt*/ since = "version", /*opt*/ note = "reason")]
|
||||
|
|
||||
| #[deprecated]
|
||||
|
|
||||
--> tests/ui/deprecation_info.rs:20:3
|
||||
|
|
||||
20 | #[deprecated(unknown_kw = "test")]
|
||||
| ^
|
||||
|
||||
error: malformed `deprecated` attribute input
|
||||
--> tests/ui/deprecation_info.rs:24:3
|
||||
|
|
||||
24 | #[deprecated = 5]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: the following are the possible correct uses
|
||||
|
|
||||
24 - #[deprecated = 5]
|
||||
24 + #[deprecated = "reason"]
|
||||
|
|
||||
24 - #[deprecated = 5]
|
||||
24 + #[deprecated(/*opt*/ since = "version", /*opt*/ note = "reason")]
|
||||
|
|
||||
24 - #[deprecated = 5]
|
||||
24 + #[deprecated]
|
||||
|
|
||||
|
||||
error[E0541]: unknown meta item 'unknown_kw'
|
||||
--> tests/ui/deprecation_info.rs:20:16
|
||||
|
|
||||
20 | #[deprecated(unknown_kw = "test")]
|
||||
| ^^^^^^^^^^^^^^^^^^^ expected one of `since`, `note`
|
||||
|
||||
error[E0565]: literal in `deprecated` value must be a string
|
||||
--> tests/ui/deprecation_info.rs:22:24
|
||||
|
|
||||
22 | #[deprecated(since = 5)]
|
||||
| ^
|
||||
@@ -0,0 +1,30 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/// The declaration of the `Runtime` type is done by the `construct_runtime!` macro in a real
|
||||
/// runtime.
|
||||
struct Runtime {}
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
sp_api::impl_runtime_apis! {}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,7 @@
|
||||
error: No api implementation given!
|
||||
--> tests/ui/empty_impl_runtime_apis_call.rs:28:1
|
||||
|
|
||||
28 | sp_api::impl_runtime_apis! {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in the macro `sp_api::impl_runtime_apis` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
@@ -0,0 +1,49 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use substrate_test_runtime_client::runtime::Block;
|
||||
|
||||
/// The declaration of the `Runtime` type is done by the `construct_runtime!` macro in a real
|
||||
/// runtime.
|
||||
struct Runtime {}
|
||||
|
||||
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() -> sp_api::RuntimeVersion {
|
||||
unimplemented!()
|
||||
}
|
||||
fn execute_block(_: <Block as BlockT>::LazyBlock) {
|
||||
unimplemented!()
|
||||
}
|
||||
fn initialize_block(_: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,66 @@
|
||||
error[E0603]: struct `RuntimeVersion` is private
|
||||
--> tests/ui/impl_incorrect_method_signature.rs:37:27
|
||||
|
|
||||
37 | fn version() -> sp_api::RuntimeVersion {
|
||||
| ^^^^^^^^^^^^^^ private struct
|
||||
|
|
||||
note: the struct `RuntimeVersion` is defined here
|
||||
--> $WORKSPACE/substrate/primitives/api/src/lib.rs
|
||||
|
|
||||
| use sp_version::RuntimeVersion;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
help: consider importing this struct instead
|
||||
|
|
||||
37 - fn version() -> sp_api::RuntimeVersion {
|
||||
37 + fn version() -> sp_version::RuntimeVersion {
|
||||
|
|
||||
help: import `RuntimeVersion` directly
|
||||
|
|
||||
37 - fn version() -> sp_api::RuntimeVersion {
|
||||
37 + fn version() -> sp_version::RuntimeVersion {
|
||||
|
|
||||
|
||||
error[E0053]: method `test` has an incompatible type for trait
|
||||
--> tests/ui/impl_incorrect_method_signature.rs:33:17
|
||||
|
|
||||
33 | fn test(data: String) {}
|
||||
| ^^^^^^ expected `u64`, found `std::string::String`
|
||||
|
|
||||
note: type in trait
|
||||
--> tests/ui/impl_incorrect_method_signature.rs:27:17
|
||||
|
|
||||
27 | fn test(data: u64);
|
||||
| ^^^
|
||||
= note: expected signature `fn(u64)`
|
||||
found signature `fn(std::string::String)`
|
||||
help: change the parameter type to match the trait
|
||||
|
|
||||
33 - fn test(data: String) {}
|
||||
33 + fn test(data: u64) {}
|
||||
|
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> tests/ui/impl_incorrect_method_signature.rs:33:11
|
||||
|
|
||||
31 | / sp_api::impl_runtime_apis! {
|
||||
32 | | impl self::Api<Block> for Runtime {
|
||||
33 | | fn test(data: String) {}
|
||||
| | ^^^^ expected `u64`, found `String`
|
||||
... |
|
||||
47 | | }
|
||||
| |_- arguments to this function are incorrect
|
||||
|
|
||||
note: associated function defined here
|
||||
--> tests/ui/impl_incorrect_method_signature.rs:27:6
|
||||
|
|
||||
27 | fn test(data: u64);
|
||||
| ^^^^ ----
|
||||
|
||||
error: unused variable: `data`
|
||||
--> tests/ui/impl_incorrect_method_signature.rs:33:11
|
||||
|
|
||||
33 | fn test(data: String) {}
|
||||
| ^^^^ help: if this is intentional, prefix it with an underscore: `_data`
|
||||
|
|
||||
= note: `-D unused-variables` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(unused_variables)]`
|
||||
@@ -0,0 +1,54 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use substrate_test_runtime_client::runtime::Block;
|
||||
|
||||
struct Runtime {}
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
#[api_version(2)]
|
||||
pub trait Api {
|
||||
fn test1();
|
||||
fn test2();
|
||||
#[api_version(3)]
|
||||
fn test3();
|
||||
}
|
||||
}
|
||||
|
||||
sp_api::impl_runtime_apis! {
|
||||
#[api_version(4)]
|
||||
impl self::Api<Block> for Runtime {
|
||||
fn test1() {}
|
||||
fn test2() {}
|
||||
fn test3() {}
|
||||
}
|
||||
|
||||
impl sp_api::Core<Block> for Runtime {
|
||||
fn version() -> sp_version::RuntimeVersion {
|
||||
unimplemented!()
|
||||
}
|
||||
fn execute_block(_: <Block as BlockT>::LazyBlock) {
|
||||
unimplemented!()
|
||||
}
|
||||
fn initialize_block(_: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,8 @@
|
||||
error[E0405]: cannot find trait `ApiV4` in module `self::runtime_decl_for_api`
|
||||
--> tests/ui/impl_missing_version.rs:35:13
|
||||
|
|
||||
25 | pub trait Api {
|
||||
| ------------- similarly named trait `ApiV2` defined here
|
||||
...
|
||||
35 | impl self::Api<Block> for Runtime {
|
||||
| ^^^ help: a trait with a similar name exists: `ApiV2`
|
||||
@@ -0,0 +1,47 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/// The declaration of the `Runtime` type is done by the `construct_runtime!` macro in a real
|
||||
/// runtime.
|
||||
struct Runtime {}
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused_imports)]
|
||||
mod second {
|
||||
sp_api::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,11 @@
|
||||
error: Two traits with the same name detected! The trait name is used to generate its ID. Please rename one trait at the declaration!
|
||||
--> tests/ui/impl_two_traits_with_same_name.rs:42:15
|
||||
|
|
||||
42 | impl second::Api<Block> for Runtime {
|
||||
| ^^^
|
||||
|
||||
error: First trait implementation.
|
||||
--> tests/ui/impl_two_traits_with_same_name.rs:38:13
|
||||
|
|
||||
38 | impl self::Api<Block> for Runtime {
|
||||
| ^^^
|
||||
@@ -0,0 +1,25 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
#[api_version]
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
|
||||
--> tests/ui/invalid_api_version_1.rs:19:2
|
||||
|
|
||||
19 | #[api_version]
|
||||
| ^
|
||||
@@ -0,0 +1,25 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
#[api_version("1")]
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
|
||||
--> tests/ui/invalid_api_version_2.rs:19:2
|
||||
|
|
||||
19 | #[api_version("1")]
|
||||
| ^
|
||||
@@ -0,0 +1,25 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
#[api_version()]
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
|
||||
--> tests/ui/invalid_api_version_3.rs:19:2
|
||||
|
|
||||
19 | #[api_version()]
|
||||
| ^
|
||||
@@ -0,0 +1,25 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
#[api_version("1")]
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
|
||||
--> tests/ui/invalid_api_version_4.rs:20:3
|
||||
|
|
||||
20 | #[api_version("1")]
|
||||
| ^
|
||||
@@ -0,0 +1,26 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
#[api_version(2)]
|
||||
pub trait Api {
|
||||
#[api_version(1)]
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,11 @@
|
||||
error: Method version `1` is older than (or equal to) trait version `2`.Methods can't define versions older than the trait version.
|
||||
--> tests/ui/method_ver_lower_than_trait_ver.rs:21:3
|
||||
|
|
||||
21 | #[api_version(1)]
|
||||
| ^
|
||||
|
||||
error: Trait version is set here.
|
||||
--> tests/ui/method_ver_lower_than_trait_ver.rs:19:2
|
||||
|
|
||||
19 | #[api_version(2)]
|
||||
| ^
|
||||
@@ -0,0 +1,36 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/// The declaration of the `Runtime` type is done by the `construct_runtime!` macro in a real
|
||||
/// runtime.
|
||||
struct Runtime {}
|
||||
|
||||
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,5 @@
|
||||
error: Missing `Block` generic parameter.
|
||||
--> tests/ui/missing_block_generic_parameter.rs:29:13
|
||||
|
|
||||
29 | impl self::Api for Runtime {
|
||||
| ^^^
|
||||
@@ -0,0 +1,36 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/// The declaration of the `Runtime` type is done by the `construct_runtime!` macro in a real
|
||||
/// runtime.
|
||||
struct Runtime {}
|
||||
|
||||
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`.
|
||||
--> tests/ui/missing_path_for_trait.rs:29:7
|
||||
|
|
||||
29 | impl Api<Block> for Runtime {
|
||||
| ^^^
|
||||
@@ -0,0 +1,53 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use substrate_test_runtime_client::runtime::Block;
|
||||
|
||||
struct Runtime {}
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
#[api_version(2)]
|
||||
pub trait Api {
|
||||
fn test1();
|
||||
fn test2();
|
||||
#[api_version(3)]
|
||||
fn test3();
|
||||
}
|
||||
}
|
||||
|
||||
sp_api::impl_runtime_apis! {
|
||||
#[api_version(3)]
|
||||
impl self::Api<Block> for Runtime {
|
||||
fn test1() {}
|
||||
fn test2() {}
|
||||
}
|
||||
|
||||
impl sp_api::Core<Block> for Runtime {
|
||||
fn version() -> sp_version::RuntimeVersion {
|
||||
unimplemented!()
|
||||
}
|
||||
fn execute_block(_: <Block as BlockT>::LazyBlock) {
|
||||
unimplemented!()
|
||||
}
|
||||
fn initialize_block(_: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,8 @@
|
||||
error[E0046]: not all trait items implemented, missing: `test3`
|
||||
--> tests/ui/missing_versioned_method.rs:35:2
|
||||
|
|
||||
29 | fn test3();
|
||||
| ----------- `test3` from trait
|
||||
...
|
||||
35 | impl self::Api<Block> for Runtime {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `test3` in implementation
|
||||
@@ -0,0 +1,56 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use substrate_test_runtime_client::runtime::Block;
|
||||
|
||||
struct Runtime {}
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
#[api_version(2)]
|
||||
pub trait Api {
|
||||
fn test1();
|
||||
fn test2();
|
||||
#[api_version(3)]
|
||||
fn test3();
|
||||
#[api_version(4)]
|
||||
fn test4();
|
||||
}
|
||||
}
|
||||
|
||||
sp_api::impl_runtime_apis! {
|
||||
#[api_version(4)]
|
||||
impl self::Api<Block> for Runtime {
|
||||
fn test1() {}
|
||||
fn test2() {}
|
||||
fn test4() {}
|
||||
}
|
||||
|
||||
impl sp_api::Core<Block> for Runtime {
|
||||
fn version() -> sp_version::RuntimeVersion {
|
||||
unimplemented!()
|
||||
}
|
||||
fn execute_block(_: <Block as BlockT>::LazyBlock) {
|
||||
unimplemented!()
|
||||
}
|
||||
fn initialize_block(_: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,8 @@
|
||||
error[E0046]: not all trait items implemented, missing: `test3`
|
||||
--> tests/ui/missing_versioned_method_multiple_vers.rs:37:2
|
||||
|
|
||||
29 | fn test3();
|
||||
| ----------- `test3` from trait
|
||||
...
|
||||
37 | impl self::Api<Block> for Runtime {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `test3` in implementation
|
||||
@@ -0,0 +1,38 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use substrate_test_runtime_client::runtime::Block;
|
||||
use sp_api::ApiError;
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test();
|
||||
}
|
||||
}
|
||||
|
||||
struct MockApi;
|
||||
|
||||
sp_api::mock_impl_runtime_apis! {
|
||||
impl Api<Block> for MockApi {
|
||||
#[advanced]
|
||||
fn test(&self, _: &Hash) -> Result<(), ApiError> {
|
||||
Ok(().into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,12 @@
|
||||
error: `Hash` needs to be taken by value and not by reference!
|
||||
--> tests/ui/mock_advanced_hash_by_reference.rs:29:1
|
||||
|
|
||||
29 | / sp_api::mock_impl_runtime_apis! {
|
||||
30 | | impl Api<Block> for MockApi {
|
||||
31 | | #[advanced]
|
||||
32 | | fn test(&self, _: &Hash) -> Result<(), ApiError> {
|
||||
... |
|
||||
36 | | }
|
||||
| |_^
|
||||
|
|
||||
= note: this error originates in the macro `sp_api::mock_impl_runtime_apis` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
@@ -0,0 +1,38 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use substrate_test_runtime_client::runtime::Block;
|
||||
use sp_api::ApiError;
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test();
|
||||
}
|
||||
}
|
||||
|
||||
struct MockApi;
|
||||
|
||||
sp_api::mock_impl_runtime_apis! {
|
||||
impl Api<Block> for MockApi {
|
||||
#[advanced]
|
||||
fn test(&self) -> Result<(), ApiError> {
|
||||
Ok(().into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: If using the `advanced` attribute, it is required that the function takes at least one argument, the `Hash`.
|
||||
--> tests/ui/mock_advanced_missing_hash.rs:32:3
|
||||
|
|
||||
32 | fn test(&self) -> Result<(), ApiError> {
|
||||
| ^^
|
||||
@@ -0,0 +1,42 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
struct Block2;
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
|
||||
pub trait Api2 {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
struct MockApi;
|
||||
|
||||
sp_api::mock_impl_runtime_apis! {
|
||||
impl Api<Block> for MockApi {
|
||||
fn test(data: u64) {}
|
||||
}
|
||||
|
||||
impl Api2<Block2> for MockApi {
|
||||
fn test(data: u64) {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,11 @@
|
||||
error: Block type should be the same between all runtime apis.
|
||||
--> tests/ui/mock_only_one_block_type.rs:37:12
|
||||
|
|
||||
37 | impl Api2<Block2> for MockApi {
|
||||
| ^^^^^^
|
||||
|
||||
error: First block type found here
|
||||
--> tests/ui/mock_only_one_block_type.rs:33:11
|
||||
|
|
||||
33 | impl Api<Block> for MockApi {
|
||||
| ^^^^^
|
||||
@@ -0,0 +1,41 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
|
||||
pub trait Api2 {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
struct MockApi;
|
||||
struct MockApi2;
|
||||
|
||||
sp_api::mock_impl_runtime_apis! {
|
||||
impl Api<Block> for MockApi {
|
||||
fn test(data: u64) {}
|
||||
}
|
||||
|
||||
impl Api2<Block> for MockApi2 {
|
||||
fn test(data: u64) {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,11 @@
|
||||
error: Self type should not change between runtime apis
|
||||
--> tests/ui/mock_only_one_self_type.rs:36:23
|
||||
|
|
||||
36 | impl Api2<Block> for MockApi2 {
|
||||
| ^^^^^^^^
|
||||
|
||||
error: First self type found here
|
||||
--> tests/ui/mock_only_one_self_type.rs:32:22
|
||||
|
|
||||
32 | impl Api<Block> for MockApi {
|
||||
| ^^^^^^^
|
||||
@@ -0,0 +1,37 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use substrate_test_runtime_client::runtime::Block;
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
fn test2(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
struct MockApi;
|
||||
|
||||
sp_api::mock_impl_runtime_apis! {
|
||||
impl Api<Block> for MockApi {
|
||||
fn test(self, data: u64) {}
|
||||
|
||||
fn test2(&mut self, data: u64) {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,46 @@
|
||||
error: Only `&self` is supported!
|
||||
--> tests/ui/mock_only_self_reference.rs:31:11
|
||||
|
|
||||
31 | fn test(self, data: u64) {}
|
||||
| ^^^^
|
||||
|
||||
error: Only `&self` is supported!
|
||||
--> tests/ui/mock_only_self_reference.rs:33:12
|
||||
|
|
||||
33 | fn test2(&mut self, data: u64) {}
|
||||
| ^
|
||||
|
||||
error[E0050]: method `test` has 2 parameters but the declaration in trait `Api::test` has 3
|
||||
--> tests/ui/mock_only_self_reference.rs:29:1
|
||||
|
|
||||
20 | / sp_api::decl_runtime_apis! {
|
||||
21 | | pub trait Api {
|
||||
22 | | fn test(data: u64);
|
||||
| |_________________________- trait requires 3 parameters
|
||||
...
|
||||
29 | / sp_api::mock_impl_runtime_apis! {
|
||||
30 | | impl Api<Block> for MockApi {
|
||||
31 | | fn test(self, data: u64) {}
|
||||
... |
|
||||
35 | | }
|
||||
| |_^ expected 3 parameters, found 2
|
||||
|
|
||||
= note: this error originates in the macro `sp_api::mock_impl_runtime_apis` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0050]: method `test2` has 2 parameters but the declaration in trait `Api::test2` has 3
|
||||
--> tests/ui/mock_only_self_reference.rs:29:1
|
||||
|
|
||||
20 | / sp_api::decl_runtime_apis! {
|
||||
21 | | pub trait Api {
|
||||
22 | | fn test(data: u64);
|
||||
23 | | fn test2(data: u64);
|
||||
| |__________________________- trait requires 3 parameters
|
||||
...
|
||||
29 | / sp_api::mock_impl_runtime_apis! {
|
||||
30 | | impl Api<Block> for MockApi {
|
||||
31 | | fn test(self, data: u64) {}
|
||||
... |
|
||||
35 | | }
|
||||
| |_^ expected 3 parameters, found 2
|
||||
|
|
||||
= note: this error originates in the macro `sp_api::mock_impl_runtime_apis` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
@@ -0,0 +1,26 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test() {
|
||||
println!("Hey, I'm a default implementation!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,8 @@
|
||||
error: A runtime API function cannot have a default implementation!
|
||||
--> tests/ui/no_default_implementation.rs:20:13
|
||||
|
|
||||
20 | fn test() {
|
||||
| ___________________^
|
||||
21 | | println!("Hey, I'm a default implementation!");
|
||||
22 | | }
|
||||
| |_________^
|
||||
@@ -0,0 +1,60 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use substrate_test_runtime_client::runtime::Block;
|
||||
|
||||
struct Runtime {}
|
||||
|
||||
pub trait CustomTrait: Encode + Decode + TypeInfo {}
|
||||
|
||||
#[derive(Encode, Decode, TypeInfo)]
|
||||
pub struct SomeImpl;
|
||||
impl CustomTrait for SomeImpl {}
|
||||
|
||||
#[derive(Encode, Decode, TypeInfo)]
|
||||
pub struct SomeOtherType<C: CustomTrait>(C);
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait Api<A> where A: CustomTrait {
|
||||
fn test() -> A;
|
||||
fn test2() -> SomeOtherType<A>;
|
||||
}
|
||||
}
|
||||
|
||||
sp_api::impl_runtime_apis! {
|
||||
impl self::Api<Block, SomeImpl> for Runtime {
|
||||
fn test() -> SomeImpl { SomeImpl }
|
||||
fn test2() -> SomeOtherType<SomeImpl> { SomeOtherType(SomeImpl) }
|
||||
}
|
||||
|
||||
impl sp_api::Core<Block> for Runtime {
|
||||
fn version() -> sp_version::RuntimeVersion {
|
||||
unimplemented!()
|
||||
}
|
||||
fn execute_block(_: <Block as BlockT>::LazyBlock) {
|
||||
unimplemented!()
|
||||
}
|
||||
fn initialize_block(_: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,55 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use substrate_test_runtime_client::runtime::Block;
|
||||
|
||||
struct Runtime {}
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
#[api_version(2)]
|
||||
pub trait Api {
|
||||
fn test1();
|
||||
fn test2();
|
||||
#[api_version(3)]
|
||||
fn test3();
|
||||
#[api_version(4)]
|
||||
fn test4();
|
||||
}
|
||||
}
|
||||
|
||||
sp_api::impl_runtime_apis! {
|
||||
#[api_version(2)]
|
||||
impl self::Api<Block> for Runtime {
|
||||
fn test1() {}
|
||||
fn test2() {}
|
||||
}
|
||||
|
||||
impl sp_api::Core<Block> for Runtime {
|
||||
fn version() -> sp_version::RuntimeVersion {
|
||||
unimplemented!()
|
||||
}
|
||||
fn execute_block(_: <Block as BlockT>::LazyBlock) {
|
||||
unimplemented!()
|
||||
}
|
||||
fn initialize_block(_: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,51 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use substrate_test_runtime_client::runtime::Block;
|
||||
|
||||
/// The declaration of the `Runtime` type is done by the `construct_runtime!` macro in a real
|
||||
/// runtime.
|
||||
struct Runtime {}
|
||||
|
||||
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() -> sp_api::RuntimeVersion {
|
||||
unimplemented!()
|
||||
}
|
||||
fn execute_block(_: <Block as BlockT>::LazyBlock) {
|
||||
unimplemented!()
|
||||
}
|
||||
fn initialize_block(_: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
error[E0603]: struct `RuntimeVersion` is private
|
||||
--> tests/ui/type_reference_in_impl_runtime_apis_call.rs:39:27
|
||||
|
|
||||
39 | fn version() -> sp_api::RuntimeVersion {
|
||||
| ^^^^^^^^^^^^^^ private struct
|
||||
|
|
||||
note: the struct `RuntimeVersion` is defined here
|
||||
--> $WORKSPACE/substrate/primitives/api/src/lib.rs
|
||||
|
|
||||
| use sp_version::RuntimeVersion;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
help: consider importing this struct instead
|
||||
|
|
||||
39 - fn version() -> sp_api::RuntimeVersion {
|
||||
39 + fn version() -> sp_version::RuntimeVersion {
|
||||
|
|
||||
help: import `RuntimeVersion` directly
|
||||
|
|
||||
39 - fn version() -> sp_api::RuntimeVersion {
|
||||
39 + fn version() -> sp_version::RuntimeVersion {
|
||||
|
|
||||
|
||||
error[E0053]: method `test` has an incompatible type for trait
|
||||
--> tests/ui/type_reference_in_impl_runtime_apis_call.rs:33:17
|
||||
|
|
||||
33 | fn test(data: &u64) {
|
||||
| ^^^^ expected `u64`, found `&u64`
|
||||
|
|
||||
note: type in trait
|
||||
--> tests/ui/type_reference_in_impl_runtime_apis_call.rs:27:17
|
||||
|
|
||||
27 | fn test(data: u64);
|
||||
| ^^^
|
||||
= note: expected signature `fn(_)`
|
||||
found signature `fn(&_)`
|
||||
help: change the parameter type to match the trait
|
||||
|
|
||||
33 - fn test(data: &u64) {
|
||||
33 + fn test(data: u64) {
|
||||
|
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> tests/ui/type_reference_in_impl_runtime_apis_call.rs:33:11
|
||||
|
|
||||
31 | / sp_api::impl_runtime_apis! {
|
||||
32 | | impl self::Api<Block> for Runtime {
|
||||
33 | | fn test(data: &u64) {
|
||||
| | ^^^^^^^ expected `u64`, found `&u64`
|
||||
34 | | unimplemented!()
|
||||
... |
|
||||
49 | | }
|
||||
| |_- arguments to this function are incorrect
|
||||
|
|
||||
note: associated function defined here
|
||||
--> tests/ui/type_reference_in_impl_runtime_apis_call.rs:27:6
|
||||
|
|
||||
27 | fn test(data: u64);
|
||||
| ^^^^ ----
|
||||
|
||||
error: unused variable: `data`
|
||||
--> tests/ui/type_reference_in_impl_runtime_apis_call.rs:33:11
|
||||
|
|
||||
33 | fn test(data: &u64) {
|
||||
| ^^^^ help: if this is intentional, prefix it with an underscore: `_data`
|
||||
|
|
||||
= note: `-D unused-variables` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(unused_variables)]`
|
||||
Reference in New Issue
Block a user