forked from AntelopeIO/cdt
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref AntelopeIO#97/AntelopeIO#98: Add unit test
Create a unit test for a table with a name primary key. The new test fails to build before the commits in PReq AntelopeIO#98, but passes when those commits are included.
- Loading branch information
1 parent
9e8385b
commit faa9747
Showing
4 changed files
with
71 additions
and
0 deletions.
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
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,32 @@ | ||
#include <boost/test/unit_test.hpp> | ||
#include <eosio/testing/tester.hpp> | ||
#include <eosio/chain/abi_serializer.hpp> | ||
|
||
#include <Runtime/Runtime.h> | ||
|
||
#include <fc/variant_object.hpp> | ||
|
||
#include <contracts.hpp> | ||
|
||
using namespace eosio; | ||
using namespace eosio::testing; | ||
using namespace eosio::chain; | ||
using namespace fc; | ||
|
||
using mvo = fc::mutable_variant_object; | ||
|
||
BOOST_AUTO_TEST_SUITE(name_pk_tests_suite) | ||
|
||
BOOST_FIXTURE_TEST_CASE( name_pk_tests, tester ) try { | ||
create_accounts( { "test"_n } ); | ||
produce_block(); | ||
|
||
set_code( "test"_n, contracts::name_pk_tests_wasm() ); | ||
set_abi( "test"_n, contracts::name_pk_tests_abi().data() ); | ||
|
||
produce_blocks(); | ||
push_action("test"_n, "write"_n, "test"_n, mvo()); | ||
push_action("test"_n, "read"_n, "test"_n, mvo()); | ||
} FC_LOG_AND_RETHROW() | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |
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
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,35 @@ | ||
// Verifies that a table with name-typed primary key works | ||
|
||
#include <eosio/multi_index.hpp> | ||
#include <eosio/contract.hpp> | ||
|
||
struct [[eosio::table]] name_table { | ||
eosio::name pk; | ||
int num; | ||
|
||
auto primary_key() const { return pk; } | ||
}; | ||
using name_table_idx = eosio::multi_index<"name.pk"_n, name_table>; | ||
|
||
class [[eosio::contract]] name_pk_tests : public eosio::contract { | ||
public: | ||
using eosio::contract::contract; | ||
|
||
[[eosio::action]] void write() { | ||
name_table_idx table(get_self(), 0); | ||
table.emplace(get_self(), [](auto& row) { | ||
row.pk = "alice"_n; | ||
row.num = 2; | ||
}); | ||
table.emplace(get_self(), [](auto& row) { | ||
row.pk = "bob"_n; | ||
row.num = 1; | ||
}); | ||
} | ||
|
||
[[eosio::action]] void read() { | ||
name_table_idx table(get_self(), 0); | ||
eosio::check(table.get("alice"_n).num == 2, "num mismatch"); | ||
eosio::check(table.get("bob"_n).num == 1, "num mismatch"); | ||
} | ||
}; |