This repository was archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 289
add an example for kv test #979
Merged
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4714640
add kvtests
vzqzhang 3cd684d
truncate a long string when printing
vzqzhang c7d1707
remove tabs
vzqzhang 0587f19
change the project name in readme
vzqzhang 43fbb7d
change the key in kv table to string
vzqzhang d5412f6
set kv parameters
vzqzhang 87ccd02
set kv parameters in the constructor
vzqzhang 6025836
the table is deployed to account eosio
vzqzhang a652b25
fix an error
vzqzhang b8aac55
cut off long string in assertion
vzqzhang 8d532ae
change the maximum value size to be multiplication of 1024
vzqzhang 58e0514
rename the example
vzqzhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
include(ExternalProject) | ||
# if no cdt root is given use default path | ||
if(EOSIO_CDT_ROOT STREQUAL "" OR NOT EOSIO_CDT_ROOT) | ||
find_package(eosio.cdt) | ||
endif() | ||
|
||
ExternalProject_Add( | ||
kvtest_project | ||
SOURCE_DIR ${CMAKE_SOURCE_DIR}/src | ||
BINARY_DIR ${CMAKE_BINARY_DIR}/kvtest | ||
CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${EOSIO_CDT_ROOT}/lib/cmake/eosio.cdt/EosioWasmToolchain.cmake | ||
UPDATE_COMMAND "" | ||
PATCH_COMMAND "" | ||
TEST_COMMAND "" | ||
INSTALL_COMMAND "" | ||
BUILD_ALWAYS 1 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- kv_addr_book Project --- | ||
|
||
--backing-store chainbase -- How to Build with CMake and Make -- | ||
- cd into the 'build' directory | ||
- run the command 'cmake .. -DEOSIO_CONTRACTS_ROOT=/path/to//eosio.contracts' | ||
- run the command 'make' | ||
|
||
- After build - | ||
- The built smart contract is under the 'kvtest' directory in the 'build' directory | ||
- You can then do a 'set contract' action with 'cleos' and point to the './build/kvtest' directory | ||
|
||
- Additions to CMake should be done to the CMakeLists.txt in the './src' directory and not in the top level CMakeLists.txt | ||
|
||
- After build - | ||
- The built smart contract is in the 'build' directory | ||
- You can then do a 'set contract' action with 'cleos' and point to the 'build' directory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h1 class="contract"> hi </h1> | ||
|
||
Stub for hi action's ricardian contract |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
project(kvtest) | ||
|
||
set(EOSIO_WASM_OLD_BEHAVIOR "Off") | ||
find_package(eosio.cdt) | ||
|
||
add_contract( kvtest kvtest kvtest.cpp ) | ||
target_ricardian_directory( kvtest ${CMAKE_SOURCE_DIR}/../ricardian ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include <eosio/eosio.hpp> | ||
#include <eosio/asset.hpp> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have to include this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I used eosio::check in the code. |
||
|
||
using namespace eosio; | ||
|
||
struct kvtest_record { | ||
uint64_t id; | ||
std::string data; | ||
}; | ||
|
||
class [[eosio::contract]] kvtest : public contract { | ||
struct [[eosio::table]] kvtest_table : eosio::kv::table<kvtest_record, "kvtest"_n> { | ||
KV_NAMED_INDEX("by.id", id); | ||
kvtest_table(name contract) { init(contract, id); } | ||
}; | ||
|
||
public: | ||
using contract::contract; | ||
|
||
[[eosio::action]] | ||
void smalltest() { | ||
require_auth(_self); | ||
kvtest_table table{"kvtest"_n}; | ||
|
||
uint64_t id = 1; | ||
std::string data = "test"; | ||
|
||
for (; id < 5000; ++id) { | ||
table.put({id, data + std::to_string(id)}, get_self()); | ||
} | ||
|
||
for (id = 1; id < 5000; ++id) { | ||
auto itr = table. id.find(id); | ||
if (itr != table.id.end()) { | ||
std::string val = itr.value().data; | ||
eosio::check(val.compare(data + std::to_string(id)), "The value for the key " + std::to_string(id) + " is " + val); | ||
} | ||
} | ||
} | ||
|
||
[[eosio::action]] | ||
void largetest() { | ||
require_auth(_self); | ||
kvtest_table table{"kvtest"_n}; | ||
|
||
std::string data = std::string(8 * 1024 * 1024, 't'); | ||
|
||
uint64_t id = 1; | ||
for (; id < 200; ++id) | ||
table.put({id, std::to_string(id) + data}, get_self()); | ||
|
||
for (id = 1; id < 200; ++id) { | ||
auto itr = table.id.find(id); | ||
if (itr != table.id.end()) { | ||
std::string val = itr.value().data; | ||
eosio::check(val.compare(data + std::to_string(id)), "The value for the key " + std::to_string(id) + " is " + val.substr(0, 10) + "..."); | ||
} | ||
} | ||
} | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong project name?