Skip to content

Commit

Permalink
Merge pull request #2368 from AntelopeIO/get_row_by_id
Browse files Browse the repository at this point in the history
IF: Add get_row_by_id to libtester
  • Loading branch information
linh2931 authored Apr 2, 2024
2 parents 8c03a62 + 755da1a commit 548641d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions libraries/testing/include/eosio/testing/tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ namespace eosio { namespace testing {
const account_name& account ) const;

vector<char> get_row_by_account( name code, name scope, name table, const account_name& act ) const;
vector<char> get_row_by_id( name code, name scope, name table, uint64_t id ) const;

map<account_name, block_id_type> get_last_produced_block_map()const { return last_produced_block; };
void set_last_produced_block_map( const map<account_name, block_id_type>& lpb ) { last_produced_block = lpb; }
Expand Down
10 changes: 6 additions & 4 deletions libraries/testing/tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1047,8 +1047,11 @@ namespace eosio { namespace testing {
return asset(result, asset_symbol);
}


vector<char> base_tester::get_row_by_account( name code, name scope, name table, const account_name& act ) const {
return get_row_by_id( code, scope, table, act.to_uint64_t() );
}

vector<char> base_tester::get_row_by_id( name code, name scope, name table, uint64_t id ) const {
vector<char> data;
const auto& db = control->db();
const auto* t_id = db.find<chain::table_id_object, chain::by_code_scope_table>( boost::make_tuple( code, scope, table ) );
Expand All @@ -1059,8 +1062,8 @@ namespace eosio { namespace testing {

const auto& idx = db.get_index<chain::key_value_index, chain::by_scope_primary>();

auto itr = idx.lower_bound( boost::make_tuple( t_id->id, act.to_uint64_t() ) );
if ( itr == idx.end() || itr->t_id != t_id->id || act.to_uint64_t() != itr->primary_key ) {
auto itr = idx.lower_bound( boost::make_tuple( t_id->id, id ) );
if ( itr == idx.end() || itr->t_id != t_id->id || id != itr->primary_key ) {
return data;
}

Expand All @@ -1069,7 +1072,6 @@ namespace eosio { namespace testing {
return data;
}


vector<uint8_t> base_tester::to_uint8_vector(const string& s) {
vector<uint8_t> v(s.size());
copy(s.begin(), s.end(), v.begin());
Expand Down

0 comments on commit 548641d

Please sign in to comment.