mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 01:27:56 +00:00
Give more information why conversion between native and runtime failed (#3720)
* Give more information why conversion between native and runtime failed This adds the SCALE error description to the error when the conversion between native and runtime failed. * Fixes tests
This commit is contained in:
@@ -72,7 +72,7 @@ where
|
||||
Result<NativeOrEncoded<R>, Self::Error>
|
||||
) -> Result<NativeOrEncoded<R>, Self::Error>,
|
||||
R: Encode + Decode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, &'static str> + UnwindSafe,
|
||||
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
|
||||
>(
|
||||
&self,
|
||||
initialize_block_fn: IB,
|
||||
@@ -104,7 +104,7 @@ where
|
||||
Result<NativeOrEncoded<R>, Self::Error>
|
||||
) -> Result<NativeOrEncoded<R>, Self::Error>,
|
||||
R: Encode + Decode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, &'static str> + UnwindSafe,
|
||||
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
|
||||
>(&self,
|
||||
state: &S,
|
||||
overlay: &mut OverlayedChanges,
|
||||
@@ -234,7 +234,7 @@ where
|
||||
Result<NativeOrEncoded<R>, Self::Error>
|
||||
) -> Result<NativeOrEncoded<R>, Self::Error>,
|
||||
R: Encode + Decode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, &'static str> + UnwindSafe,
|
||||
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
|
||||
>(
|
||||
&self,
|
||||
initialize_block_fn: IB,
|
||||
@@ -342,7 +342,7 @@ where
|
||||
Result<NativeOrEncoded<R>, Self::Error>
|
||||
) -> Result<NativeOrEncoded<R>, Self::Error>,
|
||||
R: Encode + Decode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, &'static str> + UnwindSafe,
|
||||
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
|
||||
>(&self,
|
||||
state: &S,
|
||||
changes: &mut OverlayedChanges,
|
||||
|
||||
@@ -1419,7 +1419,7 @@ impl<B, E, Block, RA> CallRuntimeAt<Block> for Client<B, E, Block, RA> where
|
||||
fn call_api_at<
|
||||
'a,
|
||||
R: Encode + Decode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, &'static str> + UnwindSafe,
|
||||
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
|
||||
C: CoreApi<Block>,
|
||||
>(
|
||||
&self,
|
||||
|
||||
@@ -99,7 +99,7 @@ impl<Block, B, Local> CallExecutor<Block, Blake2Hasher> for
|
||||
Result<NativeOrEncoded<R>, Self::Error>
|
||||
) -> Result<NativeOrEncoded<R>, Self::Error>,
|
||||
R: Encode + Decode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, &'static str> + UnwindSafe,
|
||||
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
|
||||
>(
|
||||
&self,
|
||||
initialize_block_fn: IB,
|
||||
@@ -160,7 +160,7 @@ impl<Block, B, Local> CallExecutor<Block, Blake2Hasher> for
|
||||
Result<NativeOrEncoded<R>, Self::Error>
|
||||
) -> Result<NativeOrEncoded<R>, Self::Error>,
|
||||
R: Encode + Decode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, &'static str> + UnwindSafe,
|
||||
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
|
||||
>(&self,
|
||||
_state: &S,
|
||||
_changes: &mut OverlayedChanges,
|
||||
@@ -334,7 +334,7 @@ mod tests {
|
||||
Result<NativeOrEncoded<R>, Self::Error>
|
||||
) -> Result<NativeOrEncoded<R>, Self::Error>,
|
||||
R: Encode + Decode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, &'static str> + UnwindSafe,
|
||||
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
|
||||
>(
|
||||
&self,
|
||||
_initialize_block_fn: IB,
|
||||
@@ -364,7 +364,7 @@ mod tests {
|
||||
Result<NativeOrEncoded<R>, Self::Error>
|
||||
) -> Result<NativeOrEncoded<R>, Self::Error>,
|
||||
R: Encode + Decode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, &'static str> + UnwindSafe,
|
||||
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
|
||||
>(&self,
|
||||
_state: &S,
|
||||
_overlay: &mut OverlayedChanges,
|
||||
|
||||
@@ -136,7 +136,7 @@ pub trait CallRuntimeAt<Block: BlockT> {
|
||||
fn call_api_at<
|
||||
'a,
|
||||
R: Encode + Decode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, &'static str> + UnwindSafe,
|
||||
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
|
||||
C: Core<Block>,
|
||||
>(
|
||||
&self,
|
||||
|
||||
@@ -126,7 +126,7 @@ impl<D: NativeExecutionDispatch> CodeExecutor<Blake2Hasher> for NativeExecutor<D
|
||||
<
|
||||
E: Externalities<Blake2Hasher>,
|
||||
R:Decode + Encode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, &'static str> + UnwindSafe
|
||||
NC: FnOnce() -> result::Result<R, String> + UnwindSafe
|
||||
>(
|
||||
&self,
|
||||
ext: &mut E,
|
||||
|
||||
@@ -193,7 +193,7 @@ pub trait CodeExecutor<H: Hasher>: Sized + Send + Sync {
|
||||
fn call<
|
||||
E: Externalities<H>,
|
||||
R: codec::Codec + PartialEq,
|
||||
NC: FnOnce() -> Result<R, &'static str> + UnwindSafe,
|
||||
NC: FnOnce() -> Result<R, String> + UnwindSafe,
|
||||
>(
|
||||
&self,
|
||||
ext: &mut E,
|
||||
|
||||
@@ -188,11 +188,11 @@ fn generate_native_call_generators(decl: &ItemTrait) -> Result<TokenStream> {
|
||||
fn convert_between_block_types
|
||||
<I: #crate_::runtime_api::Encode, R: #crate_::runtime_api::Decode>(
|
||||
input: &I, error_desc: &'static str,
|
||||
) -> ::std::result::Result<R, &'static str>
|
||||
) -> std::result::Result<R, String>
|
||||
{
|
||||
<R as #crate_::runtime_api::Decode>::decode(
|
||||
&mut &#crate_::runtime_api::Encode::encode(input)[..]
|
||||
).map_err(|_| error_desc)
|
||||
&mut &#crate_::runtime_api::Encode::encode(input)[..],
|
||||
).map_err(|e| format!("{} {}", error_desc, e.what()))
|
||||
}
|
||||
));
|
||||
|
||||
@@ -203,13 +203,13 @@ fn generate_native_call_generators(decl: &ItemTrait) -> Result<TokenStream> {
|
||||
let fn_name = generate_native_call_generator_fn_name(&fn_.ident);
|
||||
let output = return_type_replace_block_with_node_block(fn_.decl.output.clone());
|
||||
let output_ty = return_type_extract_type(&output);
|
||||
let output = quote!( ::std::result::Result<#output_ty, &'static str> );
|
||||
let output = quote!( std::result::Result<#output_ty, String> );
|
||||
|
||||
// Every type that is using the `Block` generic parameter, we need to encode/decode,
|
||||
// to make it compatible between the runtime/node.
|
||||
let conversions = params.iter().filter(|v| type_is_using_block(&v.1)).map(|(n, t, _)| {
|
||||
let name_str = format!(
|
||||
"Could not convert parameter `{}` between node and runtime!", quote!(#n)
|
||||
"Could not convert parameter `{}` between node and runtime:", quote!(#n)
|
||||
);
|
||||
quote!(
|
||||
let #n: #t = convert_between_block_types(&#n, #name_str)?;
|
||||
@@ -398,7 +398,7 @@ fn generate_call_api_at_calls(decl: &ItemTrait) -> Result<TokenStream> {
|
||||
#[cfg(any(feature = "std", test))]
|
||||
pub fn #fn_name<
|
||||
R: #crate_::runtime_api::Encode + #crate_::runtime_api::Decode + PartialEq,
|
||||
NC: FnOnce() -> ::std::result::Result<R, &'static str> + ::std::panic::UnwindSafe,
|
||||
NC: FnOnce() -> std::result::Result<R, String> + std::panic::UnwindSafe,
|
||||
Block: #crate_::runtime_api::BlockT,
|
||||
T: #crate_::runtime_api::CallRuntimeAt<Block>,
|
||||
C: #crate_::runtime_api::Core<Block>,
|
||||
|
||||
@@ -282,7 +282,7 @@ fn generate_runtime_api_base_structures(impls: &[ItemImpl]) -> Result<TokenStrea
|
||||
impl<C: #crate_::runtime_api::CallRuntimeAt<#block>> #crate_::runtime_api::ApiExt<#block>
|
||||
for RuntimeApiImpl<C>
|
||||
{
|
||||
fn map_api_result<F: FnOnce(&Self) -> ::std::result::Result<R, E>, R, E>(
|
||||
fn map_api_result<F: FnOnce(&Self) -> std::result::Result<R, E>, R, E>(
|
||||
&self,
|
||||
map_call: F
|
||||
) -> ::std::result::Result<R, E> where Self: Sized {
|
||||
|
||||
@@ -50,7 +50,10 @@ fn calling_wasm_runtime_function() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Could not convert parameter `param` between node and runtime!")]
|
||||
#[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();
|
||||
|
||||
@@ -250,7 +250,7 @@ impl<'a, B, H, N, T, O, Exec> StateMachine<'a, B, H, N, T, O, Exec> where
|
||||
Option<ChangesTrieTransaction<H, N>>,
|
||||
) where
|
||||
R: Decode + Encode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, &'static str> + UnwindSafe,
|
||||
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
|
||||
{
|
||||
let mut externalities = ext::Ext::new(
|
||||
self.overlay,
|
||||
@@ -295,7 +295,7 @@ impl<'a, B, H, N, T, O, Exec> StateMachine<'a, B, H, N, T, O, Exec> where
|
||||
on_consensus_failure: Handler,
|
||||
) -> (CallResult<R, Exec::Error>, Option<(B::Transaction, H::Out)>, Option<ChangesTrieTransaction<H, N>>) where
|
||||
R: Decode + Encode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, &'static str> + UnwindSafe,
|
||||
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
|
||||
Handler: FnOnce(
|
||||
CallResult<R, Exec::Error>,
|
||||
CallResult<R, Exec::Error>
|
||||
@@ -334,7 +334,7 @@ impl<'a, B, H, N, T, O, Exec> StateMachine<'a, B, H, N, T, O, Exec> where
|
||||
orig_prospective: OverlayedChangeSet,
|
||||
) -> (CallResult<R, Exec::Error>, Option<(B::Transaction, H::Out)>, Option<ChangesTrieTransaction<H, N>>) where
|
||||
R: Decode + Encode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, &'static str> + UnwindSafe,
|
||||
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
|
||||
{
|
||||
let (result, was_native, storage_delta, changes_delta) = self.execute_aux(
|
||||
compute_tx,
|
||||
@@ -374,7 +374,7 @@ impl<'a, B, H, N, T, O, Exec> StateMachine<'a, B, H, N, T, O, Exec> where
|
||||
Option<ChangesTrieTransaction<H, N>>,
|
||||
), Box<dyn Error>> where
|
||||
R: Decode + Encode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, &'static str> + UnwindSafe,
|
||||
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
|
||||
Handler: FnOnce(
|
||||
CallResult<R, Exec::Error>,
|
||||
CallResult<R, Exec::Error>,
|
||||
@@ -753,7 +753,7 @@ mod tests {
|
||||
impl<H: Hasher> CodeExecutor<H> for DummyCodeExecutor {
|
||||
type Error = u8;
|
||||
|
||||
fn call<E: Externalities<H>, R: Encode + Decode + PartialEq, NC: FnOnce() -> result::Result<R, &'static str>>(
|
||||
fn call<E: Externalities<H>, R: Encode + Decode + PartialEq, NC: FnOnce() -> result::Result<R, String>>(
|
||||
&self,
|
||||
ext: &mut E,
|
||||
_method: &str,
|
||||
|
||||
Reference in New Issue
Block a user