Skip to content
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
7 changes: 3 additions & 4 deletions core/extensions/impl/storage_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,16 @@ namespace kagome::extensions {
runtime::WasmSpan key_pos,
runtime::WasmSpan value_out,
runtime::WasmOffset offset) {
static constexpr runtime::WasmSpan kErrorSpan = -1;

auto [key_ptr, key_size] = runtime::WasmResult(key_pos);
auto [value_ptr, value_size] = runtime::WasmResult(value_out);

auto key = memory_->loadN(key_ptr, key_size);
boost::optional<uint32_t> res{boost::none};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It initializes with none in ctor by def, i suppose.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but making it explicit improves readability I suppose

if (auto data = get(key, offset, value_size)) {
memory_->storeBuffer(value_ptr, data.value());
return runtime::WasmResult(0, data.value().size()).combine();
res = value_size;
}
return kErrorSpan;
return memory_->storeBuffer(scale::encode(res).value());
}

void StorageExtension::ext_set_storage(const runtime::WasmPointer key_data,
Expand Down
10 changes: 8 additions & 2 deletions test/core/extensions/storage_extension_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ TEST_P(OutcomeParameterizedTest, StorageReadTest) {
WasmResult value(42, 41);
Buffer value_data(8, 'v');
WasmOffset offset = 0;
EXPECT_OUTCOME_TRUE(encoded_opt_val_size, kagome::scale::encode(boost::make_optional(value.length)));
WasmSpan res_wasm_span = 1337;

// expect key loaded, than data stored
EXPECT_CALL(*memory_, loadN(key.address, key.length))
Expand All @@ -446,9 +448,13 @@ TEST_P(OutcomeParameterizedTest, StorageReadTest) {
EXPECT_CALL(*trie_batch_, get(key_data)).WillOnce(Return(value_data));
EXPECT_CALL(*memory_,
storeBuffer(value.address, gsl::span<const uint8_t>(value_data)));
EXPECT_CALL(*memory_,
storeBuffer(gsl::span<const uint8_t>(encoded_opt_val_size)))
.WillOnce(Return(res_wasm_span));

storage_extension_->ext_storage_read_version_1(
key.combine(), value.combine(), offset);
ASSERT_EQ(res_wasm_span,
storage_extension_->ext_storage_read_version_1(
key.combine(), value.combine(), offset));
}

INSTANTIATE_TEST_CASE_P(Instance,
Expand Down