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 3.7k
5380 support iteration over scopes & tables in cleos #5486
Merged
+211
−1
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -2033,6 +2033,23 @@ int main( int argc, char** argv ) { | |
<< std::endl; | ||
}); | ||
|
||
auto getScope = get->add_subcommand( "scope", localized("Retrieve a list of scopes and tables owned by a contract"), false); | ||
getScope->add_option( "contract", code, localized("The contract who owns the table") )->required(); | ||
getScope->add_option( "-t,--table", table, localized("The name of the table as filter") ); | ||
getScope->add_option( "-l,--limit", limit, localized("The maximum number of rows to return") ); | ||
getScope->add_option( "-L,--lower", lower, localized("lower bound of scope") ); | ||
getScope->add_option( "-U,--upper", upper, localized("upper bound of scope") ); | ||
getScope->set_callback([&] { | ||
auto result = call(get_table_by_scope_func, fc::mutable_variant_object("code",code) | ||
("table",table) | ||
("lower_bound",lower) | ||
("upper_bound",upper) | ||
("limit",limit) | ||
); | ||
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. It would be nice to have some tests for this and the other get table functionality. Not required for this PR, but something to do when you have some time. 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. agree. let me make some tests for "get table" related functionality. |
||
std::cout << fc::json::to_pretty_string(result) | ||
<< std::endl; | ||
}); | ||
|
||
// currency accessors | ||
// get currency balance | ||
string symbol; | ||
|
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,124 @@ | ||
#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 <asserter/asserter.wast.hpp> | ||
#include <asserter/asserter.abi.hpp> | ||
|
||
#include <stltest/stltest.wast.hpp> | ||
#include <stltest/stltest.abi.hpp> | ||
|
||
#include <eosio.system/eosio.system.wast.hpp> | ||
#include <eosio.system/eosio.system.abi.hpp> | ||
|
||
#include <eosio.token/eosio.token.wast.hpp> | ||
#include <eosio.token/eosio.token.abi.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_tests) | ||
|
||
BOOST_FIXTURE_TEST_CASE( get_scope_test, TESTER ) try { | ||
produce_blocks(2); | ||
|
||
create_accounts({ N(eosio.token), N(eosio.ram), N(eosio.ramfee), N(eosio.stake), | ||
N(eosio.bpay), N(eosio.vpay), N(eosio.saving), N(eosio.names) }); | ||
|
||
std::vector<account_name> accs{N(inita), N(initb), N(initc), N(initd)}; | ||
create_accounts(accs); | ||
produce_block(); | ||
|
||
set_code( N(eosio.token), eosio_token_wast ); | ||
set_abi( N(eosio.token), eosio_token_abi ); | ||
produce_blocks(1); | ||
|
||
// create currency | ||
auto act = mutable_variant_object() | ||
("issuer", "eosio") | ||
("maximum_supply", eosio::chain::asset::from_string("1000000000.0000 SYS")); | ||
push_action(N(eosio.token), N(create), N(eosio.token), act ); | ||
|
||
// issue | ||
for (account_name a: accs) { | ||
push_action( N(eosio.token), N(issue), "eosio", mutable_variant_object() | ||
("to", name(a) ) | ||
("quantity", eosio::chain::asset::from_string("999.0000 SYS") ) | ||
("memo", "") | ||
); | ||
} | ||
produce_blocks(1); | ||
|
||
// iterate over scope | ||
eosio::chain_apis::read_only plugin(*(this->control), fc::microseconds(INT_MAX)); | ||
eosio::chain_apis::read_only::get_table_by_scope_params param{N(eosio.token), N(accounts), "inita", "", 10}; | ||
eosio::chain_apis::read_only::get_table_by_scope_result result = plugin.read_only::get_table_by_scope(param); | ||
|
||
BOOST_REQUIRE_EQUAL(4, result.rows.size()); | ||
BOOST_REQUIRE_EQUAL("", result.more); | ||
if (result.rows.size() >= 4) { | ||
BOOST_REQUIRE_EQUAL(name(N(eosio.token)), result.rows[0].code); | ||
BOOST_REQUIRE_EQUAL(name(N(inita)), result.rows[0].scope); | ||
BOOST_REQUIRE_EQUAL(name(N(accounts)), result.rows[0].table); | ||
BOOST_REQUIRE_EQUAL(name(N(eosio)), result.rows[0].payer); | ||
BOOST_REQUIRE_EQUAL(1, result.rows[0].count); | ||
|
||
BOOST_REQUIRE_EQUAL(name(N(initb)), result.rows[1].scope); | ||
BOOST_REQUIRE_EQUAL(name(N(initc)), result.rows[2].scope); | ||
BOOST_REQUIRE_EQUAL(name(N(initd)), result.rows[3].scope); | ||
} | ||
|
||
param.lower_bound = "initb"; | ||
param.upper_bound = "initd"; | ||
result = plugin.read_only::get_table_by_scope(param); | ||
BOOST_REQUIRE_EQUAL(2, result.rows.size()); | ||
BOOST_REQUIRE_EQUAL("", result.more); | ||
if (result.rows.size() >= 2) { | ||
BOOST_REQUIRE_EQUAL(name(N(initb)), result.rows[0].scope); | ||
BOOST_REQUIRE_EQUAL(name(N(initc)), result.rows[1].scope); | ||
} | ||
|
||
param.limit = 1; | ||
result = plugin.read_only::get_table_by_scope(param); | ||
BOOST_REQUIRE_EQUAL(1, result.rows.size()); | ||
BOOST_REQUIRE_EQUAL("initc", result.more); | ||
|
||
param.table = name(0); | ||
result = plugin.read_only::get_table_by_scope(param); | ||
BOOST_REQUIRE_EQUAL(1, result.rows.size()); | ||
BOOST_REQUIRE_EQUAL("initc", result.more); | ||
|
||
param.table = N(invalid); | ||
result = plugin.read_only::get_table_by_scope(param); | ||
BOOST_REQUIRE_EQUAL(0, result.rows.size()); | ||
BOOST_REQUIRE_EQUAL("", result.more); | ||
|
||
} FC_LOG_AND_RETHROW() /// get_scope_test | ||
|
||
BOOST_AUTO_TEST_SUITE_END() | ||
|
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.
This line is a bug!
If I pass '313313313313' to lower_bound, then it's 313313313313 (0x48F2EDC221), SHOULD be 1749138884762583600 (0x1846308C6118C230)
1111111.bank is 595056260428703488 (0x084210842039A700)
313313313313 < N(1111111.bank) < N(313313313313)
You can reproduce BUG by:
`
cleos -u https://mainnet.meet.one --print-request get scope eosio.token -t accounts -l 1 -L 313313313313
REQUEST:
POST /v1/chain/get_table_by_scope HTTP/1.0
Host: mainnet.meet.one
content-length: 118
Accept: /
Connection: close
{
"code": "eosio.token",
"table": "accounts",
"lower_bound": "313313313313",
"upper_bound": "",
"limit": 1
}
{
"rows": [{
"code": "eosio.token",
"scope": "1111111.bank",
"table": "accounts",
"payer": "1111111.bank",
"count": 1
}
],
"more": "111111111111"
}
`
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.
This is not a bug. The value of scope will be read as uint64_t first, then be read as account_name if failed to be read as uint64_t, as for different contracts the meaning of scopes may defer. If you want to read it as account_name always, you need to use
cleos -u https://mainnet.meet.one --print-request get scope eosio.token -t accounts -l 1 -L " 313313313313"