-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #520 from eosnetworkfoundation/fix_get_table_rows_…
…by_seckey [3.2] Fix eosio::name conversion in get_table_rows_by_seckey
- Loading branch information
Showing
10 changed files
with
256 additions
and
6 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
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,98 @@ | ||
#include <boost/test/unit_test.hpp> | ||
#include <boost/algorithm/string/predicate.hpp> | ||
|
||
#include <eosio/testing/tester.hpp> | ||
#include <eosio/chain/abi_serializer.hpp> | ||
#include <eosio/chain/wasm_eosio_constraints.hpp> | ||
#include <eosio/chain/resource_limits.hpp> | ||
#include <eosio/chain/exceptions.hpp> | ||
#include <eosio/chain/wast_to_wasm.hpp> | ||
#include <eosio/chain_plugin/chain_plugin.hpp> | ||
|
||
#include <contracts.hpp> | ||
|
||
#include <fc/io/fstream.hpp> | ||
|
||
#include <Runtime/Runtime.h> | ||
|
||
#include <fc/variant_object.hpp> | ||
#include <fc/io/json.hpp> | ||
|
||
#include <array> | ||
#include <utility> | ||
|
||
#ifdef NON_VALIDATING_TEST | ||
#define TESTER tester | ||
#else | ||
#define TESTER validating_tester | ||
#endif | ||
|
||
using namespace eosio; | ||
using namespace eosio::chain; | ||
using namespace eosio::testing; | ||
using namespace fc; | ||
|
||
BOOST_AUTO_TEST_SUITE(get_table_seckey_tests) | ||
|
||
BOOST_FIXTURE_TEST_CASE( get_table_next_key_test, TESTER ) try { | ||
create_account("test"_n); | ||
|
||
// setup contract and abi | ||
set_code( "test"_n, contracts::get_table_seckey_test_wasm() ); | ||
set_abi( "test"_n, contracts::get_table_seckey_test_abi().data() ); | ||
produce_block(); | ||
|
||
chain_apis::read_only plugin(*(this->control), {}, fc::microseconds::maximum(), {}, {}); | ||
chain_apis::read_only::get_table_rows_params params = []{ | ||
chain_apis::read_only::get_table_rows_params params{}; | ||
params.json=true; | ||
params.code="test"_n; | ||
params.scope="test"; | ||
params.limit=1; | ||
return params; | ||
}(); | ||
|
||
params.table = "numobjs"_n; | ||
|
||
|
||
// name secondary key type | ||
push_action("test"_n, "addnumobj"_n, "test"_n, mutable_variant_object()("input", 2)("nm", "a")); | ||
push_action("test"_n, "addnumobj"_n, "test"_n, mutable_variant_object()("input", 5)("nm", "b")); | ||
push_action("test"_n, "addnumobj"_n, "test"_n, mutable_variant_object()("input", 7)("nm", "c")); | ||
|
||
params.table = "numobjs"_n; | ||
params.key_type = "name"; | ||
params.limit = 10; | ||
params.index_position = "6"; | ||
params.lower_bound = "a"; | ||
params.upper_bound = "a"; | ||
auto res_nm = plugin.get_table_rows(params); | ||
BOOST_REQUIRE(res_nm.rows.size() == 1); | ||
|
||
params.lower_bound = "a"; | ||
params.upper_bound = "b"; | ||
res_nm = plugin.get_table_rows(params); | ||
BOOST_REQUIRE(res_nm.rows.size() == 2); | ||
|
||
params.lower_bound = "a"; | ||
params.upper_bound = "c"; | ||
res_nm = plugin.get_table_rows(params); | ||
BOOST_REQUIRE(res_nm.rows.size() == 3); | ||
|
||
push_action("test"_n, "addnumobj"_n, "test"_n, mutable_variant_object()("input", 8)("nm", "1111")); | ||
push_action("test"_n, "addnumobj"_n, "test"_n, mutable_variant_object()("input", 9)("nm", "2222")); | ||
push_action("test"_n, "addnumobj"_n, "test"_n, mutable_variant_object()("input", 10)("nm", "3333")); | ||
|
||
params.lower_bound = "1111"; | ||
params.upper_bound = "3333"; | ||
res_nm = plugin.get_table_rows(params); | ||
BOOST_REQUIRE(res_nm.rows.size() == 3); | ||
|
||
params.lower_bound = "2222"; | ||
params.upper_bound = "3333"; | ||
res_nm = plugin.get_table_rows(params); | ||
BOOST_REQUIRE(res_nm.rows.size() == 2); | ||
|
||
} FC_LOG_AND_RETHROW() /// get_table_next_key_test | ||
|
||
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
6 changes: 6 additions & 0 deletions
6
unittests/test-contracts/get_table_seckey_test/CMakeLists.txt
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,6 @@ | ||
if( EOSIO_COMPILE_TEST_CONTRACTS ) | ||
add_contract( get_table_seckey_test get_table_seckey_test get_table_seckey_test.cpp ) | ||
else() | ||
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/get_table_seckey_test.wasm ${CMAKE_CURRENT_BINARY_DIR}/get_table_seckey_test.wasm COPYONLY ) | ||
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/get_table_seckey_test.abi ${CMAKE_CURRENT_BINARY_DIR}/get_table_seckey_test.abi COPYONLY ) | ||
endif() |
71 changes: 71 additions & 0 deletions
71
unittests/test-contracts/get_table_seckey_test/get_table_seckey_test.abi
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,71 @@ | ||
{ | ||
"____comment": "This file was generated with eosio-abigen. DO NOT EDIT ", | ||
"version": "eosio::abi/1.2", | ||
"types": [], | ||
"structs": [ | ||
{ | ||
"name": "addnumobj", | ||
"base": "", | ||
"fields": [ | ||
{ | ||
"name": "input", | ||
"type": "uint64" | ||
}, | ||
{ | ||
"name": "nm", | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "numobj", | ||
"base": "", | ||
"fields": [ | ||
{ | ||
"name": "key", | ||
"type": "uint64" | ||
}, | ||
{ | ||
"name": "sec64", | ||
"type": "uint64" | ||
}, | ||
{ | ||
"name": "sec128", | ||
"type": "uint128" | ||
}, | ||
{ | ||
"name": "secdouble", | ||
"type": "float64" | ||
}, | ||
{ | ||
"name": "secldouble", | ||
"type": "float128" | ||
}, | ||
{ | ||
"name": "nm", | ||
"type": "name" | ||
} | ||
] | ||
} | ||
], | ||
"actions": [ | ||
{ | ||
"name": "addnumobj", | ||
"type": "addnumobj", | ||
"ricardian_contract": "" | ||
} | ||
], | ||
"tables": [ | ||
{ | ||
"name": "numobjs", | ||
"type": "numobj", | ||
"index_type": "i64", | ||
"key_names": [], | ||
"key_types": [] | ||
} | ||
], | ||
"kv_tables": {}, | ||
"ricardian_clauses": [], | ||
"variants": [], | ||
"action_results": [] | ||
} |
18 changes: 18 additions & 0 deletions
18
unittests/test-contracts/get_table_seckey_test/get_table_seckey_test.cpp
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,18 @@ | ||
/** | ||
* @file | ||
* @copyright defined in eos/LICENSE | ||
*/ | ||
#include "get_table_seckey_test.hpp" | ||
|
||
|
||
void get_table_seckey_test::addnumobj(uint64_t input, std::string nm) { | ||
numobjs numobjs_table( _self, _self.value ); | ||
numobjs_table.emplace(_self, [&](auto &obj) { | ||
obj.key = numobjs_table.available_primary_key(); | ||
obj.sec64 = input; | ||
obj.sec128 = input; | ||
obj.secdouble = input; | ||
obj.secldouble = input; | ||
obj.nm = name(nm); | ||
}); | ||
} |
43 changes: 43 additions & 0 deletions
43
unittests/test-contracts/get_table_seckey_test/get_table_seckey_test.hpp
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,43 @@ | ||
/** | ||
* @file | ||
* @copyright defined in eos/LICENSE | ||
*/ | ||
#pragma once | ||
|
||
#include <eosio/eosio.hpp> | ||
#include <eosio/crypto.hpp> | ||
|
||
using namespace eosio; | ||
|
||
class [[eosio::contract]] get_table_seckey_test : public eosio::contract { | ||
public: | ||
using eosio::contract::contract; | ||
|
||
// Number object | ||
struct [[eosio::table]] numobj { | ||
uint64_t key; | ||
uint64_t sec64; | ||
uint128_t sec128; | ||
double secdouble; | ||
long double secldouble; | ||
name nm; | ||
|
||
uint64_t primary_key() const { return key; } | ||
uint64_t sec64_key() const { return sec64; } | ||
uint128_t sec128_key() const { return sec128; } | ||
double secdouble_key() const { return secdouble; } | ||
long double secldouble_key() const { return secldouble; } | ||
uint64_t name_key() const { return nm.value; } | ||
}; | ||
|
||
typedef eosio::multi_index< "numobjs"_n, numobj, | ||
indexed_by<"bysec1"_n, const_mem_fun<numobj, uint64_t, &numobj::sec64_key>>, | ||
indexed_by<"bysec2"_n, const_mem_fun<numobj, uint128_t, &numobj::sec128_key>>, | ||
indexed_by<"bysec3"_n, const_mem_fun<numobj, double, &numobj::secdouble_key>>, | ||
indexed_by<"bysec4"_n, const_mem_fun<numobj, long double, &numobj::secldouble_key>>, | ||
indexed_by<"byname"_n, const_mem_fun<numobj, uint64_t, &numobj::name_key>> | ||
> numobjs; | ||
|
||
[[eosio::action]] | ||
void addnumobj(uint64_t input, std::string nm); | ||
}; |
Binary file added
BIN
+38.8 KB
unittests/test-contracts/get_table_seckey_test/get_table_seckey_test.wasm
Binary file not shown.