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
11 changes: 6 additions & 5 deletions host-spec/ae-hostapi.tm
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,12 @@
<item><verbatim|offset>: an u32 integer containing the offset beyond the
value should be read from.

<item><verbatim|result>: a pointer-size as defined in Definition
<reference|defn-runtime-pointer> indicating the SCALE encoded
<verbatim|Option> as defined in Definition <reference|defn-option-type>
containing the number of bytes written into the <verbatim|value_out>
buffer. Returns <verbatim|None> if the entry does not exists.
<item><verbatim|result>: a pointer-size (def.
<reference|defn-runtime-pointer>) pointing to a SCALE encoded
<verbatim|Option> (def. <reference|defn-option-type>) containing an
unsinged 32-bit interger representing the number of bytes left at
supplied <verbatim|offset>. Returns <verbatim|None> if the entry does not
exists.
</itemize>

<subsection|<verbatim|ext_storage_clear>>
Expand Down
4 changes: 2 additions & 2 deletions test/adapters/kagome/cmake/HunterConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

# Should point to the version of kagome to be tested (currently a custom fork with small fixes atop master)
hunter_config(kagome
URL https://github.com/soramitsu/kagome/archive/07536249ac2b1d5d5ee9b6d9455d01b815073304.tar.gz
SHA1 888f2c6e06442e3f8a460fa2a10d9f74c34d5891
URL https://github.com/soramitsu/kagome/archive/70e4719a81c69c8dc238187a98d1b077f54f0913.tar.gz
SHA1 a480c70af74b773a9c335a01e0deb85273b559ff
CMAKE_ARGS TESTING=OFF
)

Expand Down
20 changes: 10 additions & 10 deletions test/adapters/kagome/src/host_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void processHostApiCommands(const HostApiCommandArgs& args){
storage::processSetGet(args[0], args[1]);
});
router.addSubcommand("ext_storage_read_version_1", [](const std::vector<std::string>& args) {
throw NotImplemented(); // TODO not implemented
storage::processRead(args[0], args[1], std::stoul(args[2]), std::stoul(args[3]));
});
router.addSubcommand("ext_storage_clear_version_1", [](const std::vector<std::string>& args) {
storage::processClear(args[0], args[1]);
Expand All @@ -108,31 +108,31 @@ void processHostApiCommands(const HostApiCommandArgs& args){
});

// test child storage TODO: all not implemented
router.addSubcommand("ext_storage_child_set_version_1", [](const std::vector<std::string>& args) {
router.addSubcommand("ext_default_child_storage_set_version_1", [](const std::vector<std::string>& args) {
throw NotImplemented(); // TODO not implemented
});
router.addSubcommand("ext_storage_child_get_version_1", [](const std::vector<std::string>& args) {
router.addSubcommand("ext_default_child_storage_get_version_1", [](const std::vector<std::string>& args) {
throw NotImplemented(); // TODO not implemented
});
router.addSubcommand("ext_storage_child_read_version_1", [](const std::vector<std::string>& args) {
router.addSubcommand("ext_default_child_storage_read_version_1", [](const std::vector<std::string>& args) {
throw NotImplemented(); // TODO not implemented
});
router.addSubcommand("ext_storage_child_clear_version_1", [](const std::vector<std::string>& args) {
router.addSubcommand("ext_default_child_storage_clear_version_1", [](const std::vector<std::string>& args) {
throw NotImplemented(); // TODO not implemented
});
router.addSubcommand("ext_storage_child_storage_kill_version_1", [](const std::vector<std::string>& args) {
router.addSubcommand("ext_default_child_storage_storage_kill_version_1", [](const std::vector<std::string>& args) {
throw NotImplemented(); // TODO not implemented
});
router.addSubcommand("ext_storage_child_exists_version_1", [](const std::vector<std::string>& args) {
router.addSubcommand("ext_default_child_storage_exists_version_1", [](const std::vector<std::string>& args) {
throw NotImplemented(); // TODO not implemented
});
router.addSubcommand("ext_storage_child_clear_prefix_version_1", [](const std::vector<std::string>& args) {
router.addSubcommand("ext_default_child_storage_clear_prefix_version_1", [](const std::vector<std::string>& args) {
throw NotImplemented(); // TODO not implemented
});
router.addSubcommand("ext_storage_child_root_version_1", [](const std::vector<std::string>& args) {
router.addSubcommand("ext_default_child_storage_root_version_1", [](const std::vector<std::string>& args) {
throw NotImplemented(); // TODO not implemented
});
router.addSubcommand("ext_storage_child_next_key_version_1", [](const std::vector<std::string>& args) {
router.addSubcommand("ext_default_child_storage_next_key_version_1", [](const std::vector<std::string>& args) {
throw NotImplemented(); // TODO not implemented
});

Expand Down
38 changes: 38 additions & 0 deletions test/adapters/kagome/src/host_api/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "helpers.hpp"

#include <iostream>
#include <algorithm> // for min


namespace storage {
Expand Down Expand Up @@ -63,6 +64,43 @@ namespace storage {
std::cout << result.value().toString() << std::endl;
}

void processRead(
const std::string_view key,
const std::string_view value,
const uint32_t offset,
const uint32_t length
) {
helpers::RuntimeEnvironment environment;

// Check that key has not been set
auto result = environment.execute<helpers::MaybeBuffer>(
"rtm_ext_storage_read_version_1", key, offset, length
);

BOOST_ASSERT_MSG(!result, "Data exists");

// Add data to storage
environment.execute<void>("rtm_ext_storage_set_version_1", key, value);

// Retrieve data from storage
result = environment.execute<helpers::MaybeBuffer>(
"rtm_ext_storage_read_version_1", key, offset, length
);

// Check returned data
BOOST_ASSERT_MSG(result.has_value(), "No value");

if (offset < value.length()) {
auto expected_length = std::min(uint32_t(value.length() - offset), length);
auto expected_value = value.substr(offset, expected_length);

BOOST_ASSERT_MSG(result.value().toString() == expected_value, "Values are different");
} else {
BOOST_ASSERT_MSG(result.value().empty(), "Values are different");
}

std::cout << result.value().toString() << std::endl;
}

void processClear(const std::string_view key, const std::string_view value) {
helpers::RuntimeEnvironment environment;
Expand Down
8 changes: 8 additions & 0 deletions test/adapters/kagome/src/host_api/storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ namespace storage {
// executes ext_storage_set_version_1/ext_storage_get_version_1 test
void processSetGet(const std::string_view key, const std::string_view value);

// executes ext_storage_set_version_1/ext_storage_get_version_1 test
void processRead(
const std::string_view key,
const std::string_view value,
const uint32_t offset,
const uint32_t length
);

// executes ext_storage_clear_version_1 test
void processClear(const std::string_view key, const std::string_view value);

Expand Down
Loading