Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Update initialize tests for latest rust stable #5971

Merged
merged 6 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions frame/support/test/tests/reserved_keyword/on_initialize.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@ error: Invalid call fn name: `on_finalize`, name is reserved and doesn't match e
--> $DIR/on_initialize.rs:31:1
|
31 | reserved!(on_finalize on_initialize on_runtime_upgrade offchain_worker deposit_event);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: Invalid call fn name: `on_initialize`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword.
--> $DIR/on_initialize.rs:31:1
|
31 | reserved!(on_finalize on_initialize on_runtime_upgrade offchain_worker deposit_event);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: Invalid call fn name: `on_runtime_upgrade`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword.
--> $DIR/on_initialize.rs:31:1
|
31 | reserved!(on_finalize on_initialize on_runtime_upgrade offchain_worker deposit_event);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: Invalid call fn name: `offchain_worker`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword.
--> $DIR/on_initialize.rs:31:1
|
31 | reserved!(on_finalize on_initialize on_runtime_upgrade offchain_worker deposit_event);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: Invalid call fn name: `deposit_event`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword.
--> $DIR/on_initialize.rs:31:1
|
31 | reserved!(on_finalize on_initialize on_runtime_upgrade offchain_worker deposit_event);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ error: No api implementation given!
--> $DIR/empty_impl_runtime_apis_call.rs:17:1
|
17 | sp_api::impl_runtime_apis! {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,11 @@ error[E0053]: method `Api_test_runtime_api_impl` has an incompatible type for tr
| |_- 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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found struct `std::string::String`
|
= note: expected fn pointer `fn(&RuntimeApiImpl<__SR_API_BLOCK__, RuntimeApiImplCall>, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId<__SR_API_BLOCK__>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<u64>, std::vec::Vec<_>) -> std::result::Result<_, _>`
found fn pointer `fn(&RuntimeApiImpl<__SR_API_BLOCK__, RuntimeApiImplCall>, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId<__SR_API_BLOCK__>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<std::string::String>, std::vec::Vec<_>) -> std::result::Result<_, _>`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
--> $DIR/impl_incorrect_method_signature.rs:17:1
Expand All @@ -46,10 +37,9 @@ error[E0308]: mismatched types
... |
32 | | }
33 | | }
| | ^
| | |
| |_expected `u64`, found struct `std::string::String`
| in this macro invocation
| |_^ expected `u64`, found struct `std::string::String`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
--> $DIR/impl_incorrect_method_signature.rs:19:11
Expand Down
6 changes: 2 additions & 4 deletions primitives/api/test/tests/ui/mock_only_one_error_type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ error[E0277]: the trait bound `u32: std::convert::From<std::string::String>` is
... |
26 | | }
27 | | }
| | ^
| | |
| |_the trait `std::convert::From<std::string::String>` is not implemented for `u32`
| in this macro invocation
| |_^ the trait `std::convert::From<std::string::String>` is not implemented for `u32`
|
= help: the following implementations were found:
<u32 as std::convert::From<bool>>
<u32 as std::convert::From<char>>
<u32 as std::convert::From<h2::frame::reason::Reason>>
<u32 as std::convert::From<h2::frame::reason::Reason>>
and 18 others
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
26 changes: 4 additions & 22 deletions primitives/api/test/tests/ui/mock_only_self_reference.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,11 @@ error[E0053]: method `Api_test_runtime_api_impl` has an incompatible type for tr
| |_- type in trait
...
12 | sp_api::mock_impl_runtime_apis! {
| -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| _expected `u64`, found `()`
| |
13 | | impl Api<Block> for MockApi {
14 | | fn test(self, data: u64) {}
15 | |
16 | | fn test2(&mut self, data: u64) {}
17 | | }
18 | | }
| |_- in this macro invocation
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found `()`
|
= note: expected fn pointer `fn(&MockApi, &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<_>) -> std::result::Result<_, _>`
found fn pointer `fn(&MockApi, &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::vec::Vec<_>) -> std::result::Result<_, _>`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0053]: method `Api_test2_runtime_api_impl` has an incompatible type for trait
--> $DIR/mock_only_self_reference.rs:12:1
Expand All @@ -49,17 +40,8 @@ error[E0053]: method `Api_test2_runtime_api_impl` has an incompatible type for t
| |_- type in trait
...
12 | sp_api::mock_impl_runtime_apis! {
| -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| _expected `u64`, found `()`
| |
13 | | impl Api<Block> for MockApi {
14 | | fn test(self, data: u64) {}
15 | |
16 | | fn test2(&mut self, data: u64) {}
17 | | }
18 | | }
| |_- in this macro invocation
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found `()`
|
= note: expected fn pointer `fn(&MockApi, &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<_>) -> std::result::Result<_, _>`
found fn pointer `fn(&MockApi, &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::vec::Vec<_>) -> std::result::Result<_, _>`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,11 @@ error[E0053]: method `Api_test_runtime_api_impl` has an incompatible type for tr
| |_- 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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found `&u64`
|
= note: expected fn pointer `fn(&RuntimeApiImpl<__SR_API_BLOCK__, RuntimeApiImplCall>, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId<__SR_API_BLOCK__>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<u64>, std::vec::Vec<_>) -> std::result::Result<_, _>`
found fn pointer `fn(&RuntimeApiImpl<__SR_API_BLOCK__, RuntimeApiImplCall>, &sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::BlockId<__SR_API_BLOCK__>, sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ExecutionContext, std::option::Option<&u64>, std::vec::Vec<_>) -> std::result::Result<_, _>`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
--> $DIR/type_reference_in_impl_runtime_apis_call.rs:17:1
Expand All @@ -46,10 +37,9 @@ error[E0308]: mismatched types
... |
34 | | }
35 | | }
| | ^
| | |
| |_expected `u64`, found `&u64`
| in this macro invocation
| |_^ expected `u64`, found `&u64`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
--> $DIR/type_reference_in_impl_runtime_apis_call.rs:19:11
Expand Down
28 changes: 15 additions & 13 deletions primitives/runtime-interface/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ use std::{collections::HashSet, sync::{Arc, Mutex}};

type TestExternalities = sp_state_machine::TestExternalities<sp_runtime::traits::BlakeTwo256, u64>;

fn call_wasm_method<HF: HostFunctionsT>(binary: &[u8], method: &str) -> TestExternalities {
fn call_wasm_method_with_result<HF: HostFunctionsT>(
binary: &[u8],
method: &str,
) -> Result<TestExternalities, String> {
let mut ext = TestExternalities::default();
let mut ext_ext = ext.ext();
let mut host_functions = HF::host_functions();
Expand All @@ -50,9 +53,13 @@ fn call_wasm_method<HF: HostFunctionsT>(binary: &[u8], method: &str) -> TestExte
&[],
&mut ext_ext,
sp_core::traits::MissingHostFunctions::Disallow,
).expect(&format!("Executes `{}`", method));
).map_err(|e| format!("Failed to execute `{}`: {}", method, e))?;

ext
Ok(ext)
}

fn call_wasm_method<HF: HostFunctionsT>(binary: &[u8], method: &str) -> TestExternalities {
call_wasm_method_with_result::<HF>(binary, method).unwrap()
}

#[test]
Expand Down Expand Up @@ -94,20 +101,15 @@ fn test_return_input_public_key() {
}

#[test]
#[should_panic(
expected = "Instantiation: Export ext_test_api_return_input_version_1 not found"
)]
fn host_function_not_found() {
call_wasm_method::<()>(&WASM_BINARY[..], "test_return_data");
let err = call_wasm_method_with_result::<()>(&WASM_BINARY[..], "test_return_data").unwrap_err();

assert!(err.contains("Instantiation: Export "));
assert!(err.contains(" not found"));
}

#[test]
#[should_panic(
expected =
"Executes `test_invalid_utf8_data_should_return_an_error`: \
\"Trap: Trap { kind: Host(FunctionExecution(\\\"ext_test_api_invalid_utf8_data_version_1\\\", \
\\\"Invalid utf8 data provided\\\")) }\""
)]
#[should_panic(expected = "Invalid utf8 data provided")]
fn test_invalid_utf8_data_should_return_an_error() {
call_wasm_method::<HostFunctions>(&WASM_BINARY[..], "test_invalid_utf8_data_should_return_an_error");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ error: `PassByEnum` only supports enums as input type.
|
3 | #[derive(PassByEnum)]
| ^^^^^^^^^^
|
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ error: `PassByEnum` only supports unit variants.
|
3 | #[derive(PassByEnum)]
| ^^^^^^^^^^
|
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ error: Only newtype/one field structs are supported by `PassByInner`!
|
3 | #[derive(PassByInner)]
| ^^^^^^^^^^^
|
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)