Fix sp-api handling of multiple arguments (#6484)

With the switch to `decode_all_with_depth_limit` we silently broken
support for functions with multiple arguments. The old generated code
tried to decode each parameter separately, which does not play well with
`decode_all`.

This pr adds a test to ensure that this does not happen again and fixes
the bug by decoding everything at once by wrapping it into tuples.
This commit is contained in:
Bastian Köcher
2020-06-23 13:46:16 +02:00
committed by GitHub
parent 63793c8b97
commit 6647a42a67
3 changed files with 35 additions and 11 deletions
+16
View File
@@ -313,6 +313,9 @@ cfg_if! {
fn test_ecdsa_crypto() -> (ecdsa::AppSignature, ecdsa::AppPublic);
/// Run various tests against storage.
fn test_storage();
/// Test that ensures that we can call a function that takes multiple
/// arguments.
fn test_multiple_arguments(data: Vec<u8>, other: Vec<u8>, num: u32);
}
}
} else {
@@ -359,6 +362,9 @@ cfg_if! {
fn test_ecdsa_crypto() -> (ecdsa::AppSignature, ecdsa::AppPublic);
/// Run various tests against storage.
fn test_storage();
/// Test that ensures that we can call a function that takes multiple
/// arguments.
fn test_multiple_arguments(data: Vec<u8>, other: Vec<u8>, num: u32);
}
}
}
@@ -641,6 +647,11 @@ cfg_if! {
test_read_storage();
test_read_child_storage();
}
fn test_multiple_arguments(data: Vec<u8>, other: Vec<u8>, num: u32) {
assert_eq!(&data[..], &other[..]);
assert_eq!(data.len(), num as usize);
}
}
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
@@ -862,6 +873,11 @@ cfg_if! {
test_read_storage();
test_read_child_storage();
}
fn test_multiple_arguments(data: Vec<u8>, other: Vec<u8>, num: u32) {
assert_eq!(&data[..], &other[..]);
assert_eq!(data.len(), num as usize);
}
}
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {