diff --git a/adapters/substrate/src/host_api/child_storage.rs b/adapters/substrate/src/host_api/child_storage.rs index def553ff..db4422ab 100644 --- a/adapters/substrate/src/host_api/child_storage.rs +++ b/adapters/substrate/src/host_api/child_storage.rs @@ -44,6 +44,37 @@ pub fn ext_default_child_storage_get_version_1(rtm: Runtime, input: ParsedInput) ext_default_child_storage_set_version_1(rtm, input) } +pub fn ext_default_child_storage_set_version_1_invalid_child_key(mut rtm: Runtime, input: ParsedInput) { + // Parse inputs + let child_key = input.get(0); + // Skipping index `1` + let key = input.get(2); + let value = input.get(3); + + // Set NON-child key/value + let _ = rtm.call("rtm_ext_storage_set_version_1", &(key, value).encode()); + + // Get NON-child value + let res = rtm + .call_and_decode::<Option<Vec<u8>>>("rtm_ext_storage_get_version_1", &key.encode()) + .unwrap(); + assert_eq!(res, value); + + // Try to get child value from NON-child key + let res = rtm.call_and_decode::<Option<Vec<u8>>>( + "rtm_ext_default_child_storage_get_version_1", + &(key, key).encode(), + ); + assert!(res.is_none()); + + // Try to get child value from NON-child key (note that `child_key` does not exist) + let res = rtm.call_and_decode::<Option<Vec<u8>>>( + "rtm_ext_default_child_storage_get_version_1", + &(child_key, key).encode(), + ); + assert!(res.is_none()); +} + pub fn ext_default_child_storage_read_version_1(mut rtm: Runtime, input: ParsedInput) { // Parse inputs let child_key1 = input.get(0); diff --git a/adapters/substrate/src/host_api/mod.rs b/adapters/substrate/src/host_api/mod.rs index db1d7851..e12f1a19 100644 --- a/adapters/substrate/src/host_api/mod.rs +++ b/adapters/substrate/src/host_api/mod.rs @@ -79,6 +79,8 @@ pub fn process_subcommand(matches: &ArgMatches) { "ext_storage_append_version_1" => storage::ext_storage_append_version_1(rtm, input), "ext_storage_root_version_1" => storage::ext_storage_root_version_1(rtm, input), "ext_storage_next_key_version_1" => storage::ext_storage_next_key_version_1(rtm, input), + "ext_storage_set_version_1_try_fetch_child_key" => storage::ext_storage_set_version_1_try_fetch_child_key(rtm, input), + "ext_storage_set_version_1_try_set_child_key" => storage::ext_storage_set_version_1_try_set_child_key(rtm, input), // child storage api "ext_default_child_storage_set_version_1" => { @@ -87,6 +89,9 @@ pub fn process_subcommand(matches: &ArgMatches) { "ext_default_child_storage_get_version_1" => { child_storage::ext_default_child_storage_get_version_1(rtm, input) } + "ext_default_child_storage_set_version_1_invalid_child_key" => { + child_storage::ext_default_child_storage_set_version_1_invalid_child_key(rtm, input) + } "ext_default_child_storage_read_version_1" => { child_storage::ext_default_child_storage_read_version_1(rtm, input) } diff --git a/adapters/substrate/src/host_api/storage.rs b/adapters/substrate/src/host_api/storage.rs index 55c68ca2..fe1a88ca 100644 --- a/adapters/substrate/src/host_api/storage.rs +++ b/adapters/substrate/src/host_api/storage.rs @@ -282,3 +282,70 @@ pub fn ext_storage_next_key_version_1(mut rtm: Runtime, input: ParsedInput) { assert!(res.is_none()); } } + +pub fn ext_storage_set_version_1_try_fetch_child_key(mut rtm: Runtime, input: ParsedInput) { + // Parse inputs + let child_key = input.get(0); + // Skipping index `1` + let key = input.get(2); + let value = input.get(3); + + // Set child key/value + let _ = rtm.call( + "rtm_ext_default_child_storage_set_version_1", + &(child_key, key, value).encode(), + ); + + // Get child value + let res = rtm + .call_and_decode::<Option<Vec<u8>>>( + "rtm_ext_default_child_storage_get_version_1", + &(child_key, key).encode(), + ) + .unwrap(); + assert_eq!(res, value); + + // Try to get value of child storage key itself (must fail). + let res = rtm + .call_and_decode::<Option<Vec<u8>>>("rtm_ext_storage_get_version_1", &child_key.encode()); + assert!(res.is_none()); + + // Try to read value of child storage key itself (must fail). + let res = rtm.call_and_decode::<Option<Vec<u8>>>( + "rtm_ext_storage_read_version_1", + &(child_key, 0, value.len() as u32).encode(), + ); + assert!(res.is_none()); +} + +pub fn ext_storage_set_version_1_try_set_child_key(mut rtm: Runtime, input: ParsedInput) { + // Parse inputs + let child_key = input.get(0); + // Skipping index `1` + let key = input.get(2); + let value = input.get(3); + + // Set child key/value + let _ = rtm.call( + "rtm_ext_default_child_storage_set_version_1", + &(child_key, key, value).encode(), + ); + + // Set NON-child key/value with identitcal key (DROPPED) + let _ = rtm.call("rtm_ext_storage_set_version_1", &(child_key, vec![1]).encode()); + + // Try to get (dropped) value. + let res = rtm + .call_and_decode::<Option<Vec<u8>>>("rtm_ext_storage_get_version_1", &child_key.encode()); + assert!(res.is_none()); + + // Get child value (must not be destroyed) + let res = rtm + .call_and_decode::<Option<Vec<u8>>>( + "rtm_ext_default_child_storage_get_version_1", + &(child_key, key).encode(), + ) + .unwrap(); + + assert_eq!(res, value); +} diff --git a/fixtures/host-api/HostApiFunctions.jl b/fixtures/host-api/HostApiFunctions.jl index 0664db4b..af57b0ce 100644 --- a/fixtures/host-api/HostApiFunctions.jl +++ b/fixtures/host-api/HostApiFunctions.jl @@ -28,8 +28,11 @@ module HostApiFunctions const child_key_value = [ "ext_default_child_storage_set_version_1", "ext_default_child_storage_get_version_1", + "ext_default_child_storage_set_version_1_invalid_child_key", "ext_default_child_storage_clear_version_1", - "ext_default_child_storage_exists_version_1" + "ext_default_child_storage_exists_version_1", + "ext_storage_set_version_1_try_fetch_child_key", + "ext_storage_set_version_1_try_set_child_key" ] const child_prefix_key_value_key_value = [ diff --git a/fixtures/host-api/HostApiOutputs.jl b/fixtures/host-api/HostApiOutputs.jl index 3b2ae1de..72aada28 100644 --- a/fixtures/host-api/HostApiOutputs.jl +++ b/fixtures/host-api/HostApiOutputs.jl @@ -189,6 +189,17 @@ module HostApiOutputs "value-added\n", "Reactive\n", "secondary\n", + # ext_default_child_storage_set_version_1_invalid_child_key + nothing, + nothing, + nothing, + nothing, + nothing, + nothing, + nothing, + nothing, + nothing, + nothing, # ext_default_child_storage_clear_version_1 nothing, nothing, @@ -211,6 +222,28 @@ module HostApiOutputs "true\n", "true\n", "true\n", + # ext_storage_set_version_1_try_fetch_child_key + nothing, + nothing, + nothing, + nothing, + nothing, + nothing, + nothing, + nothing, + nothing, + nothing, + # ext_storage_set_version_1_try_set_child_key + nothing, + nothing, + nothing, + nothing, + nothing, + nothing, + nothing, + nothing, + nothing, + nothing, ] const child_prefix_key_value_key_value = [ diff --git a/hosts/gossamer b/hosts/gossamer index 3a471d91..8105cd41 160000 --- a/hosts/gossamer +++ b/hosts/gossamer @@ -1 +1 @@ -Subproject commit 3a471d91f61c1ba10022ff11403b9cebb71c8666 +Subproject commit 8105cd4112c9593089541f12e5f5008f3499a8bc diff --git a/hosts/kagome b/hosts/kagome index d21d9c8e..102768a2 160000 --- a/hosts/kagome +++ b/hosts/kagome @@ -1 +1 @@ -Subproject commit d21d9c8e22fe33eb2960340d33398483743569d1 +Subproject commit 102768a28551704fd5faf16aeef7a22387cd1505 diff --git a/hosts/substrate b/hosts/substrate index bf54653f..4c3166cc 160000 --- a/hosts/substrate +++ b/hosts/substrate @@ -1 +1 @@ -Subproject commit bf54653f93025c61680b28dac41e251b50c6fded +Subproject commit 4c3166ccdf0c80be592752c78e5210287ddbec6d