Skip to content

Commit

Permalink
Addressing peer review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
oschwaldp-oci committed Feb 13, 2023
1 parent 239fa1f commit f25de1b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
18 changes: 9 additions & 9 deletions tests/trx_generator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ int main(int argc, char** argv) {
const uint16_t generator_id_max = 960;
variables_map vmap;
options_description cli("Transaction Generator command line options.");
uint16_t gen_id;
uint16_t gen_id = 0;
string chain_id_in;
string contract_owner_acct;
string accts;
string p_keys;
int64_t trx_expr;
uint32_t gen_duration;
uint32_t target_tps;
int64_t trx_expr = 3600;
uint32_t gen_duration = 60;
uint32_t target_tps = 1;
string lib_id_str;
int64_t spinup_time_us;
uint32_t max_lag_per;
int64_t max_lag_duration_us;
int64_t spinup_time_us = 1000000;
uint32_t max_lag_per = 5;
int64_t max_lag_duration_us = 1000000;
string log_dir_in;
bool stop_on_trx_failed;
std::string peer_endpoint;
unsigned short port;
std::string peer_endpoint = "127.0.0.1";
unsigned short port = 9876;

bool transaction_specified = false;
std::string abi_file_path_in;
Expand Down
25 changes: 13 additions & 12 deletions tests/trx_generator/trx_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ namespace eosio::testing {
signed_transaction_w_signer trx_generator_base::create_trx_w_actions_and_signer(std::vector<action> acts, const fc::crypto::private_key& priv_key, uint64_t& nonce_prefix, uint64_t& nonce, const fc::microseconds& trx_expiration, const chain_id_type& chain_id, const block_id_type& last_irr_block_id) {
signed_transaction trx;
set_transaction_headers(trx, last_irr_block_id, trx_expiration);
for (auto act:acts) {
trx.actions.push_back(act);
for (auto& act : acts) {
trx.actions.emplace_back(std::move(act));
}
trx.context_free_actions.emplace_back(action({}, config::null_account_name, name("nonce"),
fc::raw::pack(std::to_string(nonce_prefix) + ":" + std::to_string(++nonce) + ":" +
Expand All @@ -44,23 +44,24 @@ namespace eosio::testing {
std::vector<signed_transaction_w_signer> trxs;
trxs.reserve(2 * action_pairs_vector.size());

for (action_pair_w_keys ap: action_pairs_vector) {
for (const action_pair_w_keys& ap : action_pairs_vector) {
trxs.emplace_back(create_trx_w_actions_and_signer({ap._first_act}, ap._first_act_priv_key, nonce_prefix, nonce, trx_expiration, chain_id, last_irr_block_id));
trxs.emplace_back(create_trx_w_actions_and_signer({ap._second_act}, ap._second_act_priv_key, nonce_prefix, nonce, trx_expiration, chain_id, last_irr_block_id));
}

return trxs;
}

void trx_generator_base::update_resign_transaction(signed_transaction& trx, fc::crypto::private_key priv_key, uint64_t& nonce_prefix, uint64_t& nonce, const fc::microseconds& trx_expiration, const chain_id_type& chain_id, const block_id_type& last_irr_block_id) {
void trx_generator_base::update_resign_transaction(signed_transaction& trx, const fc::crypto::private_key& priv_key, uint64_t& nonce_prefix, uint64_t& nonce, const fc::microseconds& trx_expiration,
const chain_id_type& chain_id, const block_id_type& last_irr_block_id) {
trx.context_free_actions.clear();
trx.context_free_actions.emplace_back(action({}, config::null_account_name, name("nonce"), fc::raw::pack(std::to_string(nonce_prefix) + ":" + std::to_string(++nonce) + ":" + fc::time_point::now().time_since_epoch().count())));
set_transaction_headers(trx, last_irr_block_id, trx_expiration);
trx.signatures.clear();
trx.sign(priv_key, chain_id);
}

chain::bytes transfer_trx_generator::make_transfer_data(const chain::name& from, const chain::name& to, const chain::asset& quantity, const std::string&& memo) {
chain::bytes transfer_trx_generator::make_transfer_data(const chain::name& from, const chain::name& to, const chain::asset& quantity, const std::string& memo) {
return fc::raw::pack<chain::name>(from, to, quantity, memo);
}

Expand All @@ -81,7 +82,7 @@ namespace eosio::testing {
ilog("create_initial_transfer_actions: creating transfer from ${acctB} to ${acctA}", ("acctB", accounts.at(j))("acctA", accounts.at(i)));
action act_b_to_a = make_transfer_action(contract_owner_account, accounts.at(j), accounts.at(i), asset::from_string("1.0000 CUR"), salt);

actions_pairs_vector.push_back(action_pair_w_keys(act_a_to_b, act_b_to_a, priv_keys.at(i), priv_keys.at(j)));
actions_pairs_vector.emplace_back(action_pair_w_keys(act_a_to_b, act_b_to_a, priv_keys.at(i), priv_keys.at(j)));
}
}
ilog("create_initial_transfer_actions: total action pairs created: ${pairs}", ("pairs", actions_pairs_vector.size()));
Expand All @@ -99,9 +100,9 @@ namespace eosio::testing {

vector<name> transfer_trx_generator::get_accounts(const vector<string>& account_str_vector) {
vector<name> acct_name_list;
for (string account_name: account_str_vector) {
for (const string& account_name : account_str_vector) {
ilog("get_account about to try to create name for ${acct}", ("acct", account_name));
acct_name_list.push_back(eosio::chain::name(account_name));
acct_name_list.emplace_back(eosio::chain::name(account_name));
}
return acct_name_list;
}
Expand All @@ -110,7 +111,7 @@ namespace eosio::testing {
vector<fc::crypto::private_key> key_list;
for (const string& private_key: priv_key_str_vector) {
ilog("get_private_keys about to try to create private_key for ${key} : gen key ${newKey}", ("key", private_key)("newKey", fc::crypto::private_key(private_key)));
key_list.push_back(fc::crypto::private_key(private_key));
key_list.emplace_back(fc::crypto::private_key(private_key));
}
return key_list;
}
Expand Down Expand Up @@ -166,7 +167,7 @@ namespace eosio::testing {
void trx_generator::locate_key_words_in_action_mvo(std::vector<std::string>& acct_gen_fields_out, fc::mutable_variant_object& action_mvo, const std::string& key_word) {
for (const mutable_variant_object::entry& e: action_mvo) {
if (e.value().get_type() == fc::variant::string_type && e.value() == key_word) {
acct_gen_fields_out.push_back(e.key());
acct_gen_fields_out.emplace_back(e.key());
} else if (e.value().get_type() == fc::variant::object_type) {
auto inner_mvo = fc::mutable_variant_object(e.value());
locate_key_words_in_action_mvo(acct_gen_fields_out, inner_mvo, key_word);
Expand Down Expand Up @@ -205,11 +206,11 @@ namespace eosio::testing {
}
}

void trx_generator::update_resign_transaction(signed_transaction& trx, fc::crypto::private_key priv_key, uint64_t& nonce_prefix, uint64_t& nonce, const fc::microseconds& trx_expiration, const chain_id_type& chain_id, const block_id_type& last_irr_block_id) {
void trx_generator::update_resign_transaction(signed_transaction& trx, const fc::crypto::private_key& priv_key, uint64_t& nonce_prefix, uint64_t& nonce, const fc::microseconds& trx_expiration, const chain_id_type& chain_id, const block_id_type& last_irr_block_id) {
trx.actions.clear();
update_actions();
for (const auto& act: _actions) {
trx.actions.push_back(act);
trx.actions.emplace_back(act);
}
trx_generator_base::update_resign_transaction(trx, priv_key, nonce_prefix, nonce, trx_expiration, chain_id, last_irr_block_id);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/trx_generator/trx_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace eosio::testing {

virtual ~trx_generator_base() = default;

virtual void update_resign_transaction(eosio::chain::signed_transaction& trx, fc::crypto::private_key priv_key, uint64_t& nonce_prefix, uint64_t& nonce,
virtual void update_resign_transaction(eosio::chain::signed_transaction& trx, const fc::crypto::private_key& priv_key, uint64_t& nonce_prefix, uint64_t& nonce,
const fc::microseconds& trx_expiration, const eosio::chain::chain_id_type& chain_id, const eosio::chain::block_id_type& last_irr_block_id);

void push_transaction(p2p_trx_provider& provider, signed_transaction_w_signer& trx, uint64_t& nonce_prefix,
Expand Down Expand Up @@ -152,7 +152,7 @@ namespace eosio::testing {
std::vector<fc::crypto::private_key> get_private_keys(const std::vector<std::string>& priv_key_str_vector);

std::vector<signed_transaction_w_signer> create_initial_transfer_transactions(const std::vector<action_pair_w_keys>& action_pairs_vector, uint64_t& nonce_prefix, uint64_t& nonce, const fc::microseconds& trx_expiration, const eosio::chain::chain_id_type& chain_id, const eosio::chain::block_id_type& last_irr_block_id);
eosio::chain::bytes make_transfer_data(const eosio::chain::name& from, const eosio::chain::name& to, const eosio::chain::asset& quantity, const std::string&& memo);
eosio::chain::bytes make_transfer_data(const eosio::chain::name& from, const eosio::chain::name& to, const eosio::chain::asset& quantity, const std::string& memo);
auto make_transfer_action(eosio::chain::name account, eosio::chain::name from, eosio::chain::name to, eosio::chain::asset quantity, std::string memo);
std::vector<action_pair_w_keys> create_initial_transfer_actions(const std::string& salt, const uint64_t& period, const eosio::chain::name& contract_owner_account,
const std::vector<eosio::chain::name>& accounts, const std::vector<fc::crypto::private_key>& priv_keys);
Expand Down Expand Up @@ -184,7 +184,7 @@ namespace eosio::testing {
void update_key_word_fields_in_action(std::vector<std::string>& acct_gen_fields, fc::mutable_variant_object& action_mvo, const std::string& key_word);

void update_actions();
virtual void update_resign_transaction(eosio::chain::signed_transaction& trx, fc::crypto::private_key priv_key, uint64_t& nonce_prefix, uint64_t& nonce,
virtual void update_resign_transaction(eosio::chain::signed_transaction& trx, const fc::crypto::private_key& priv_key, uint64_t& nonce_prefix, uint64_t& nonce,
const fc::microseconds& trx_expiration, const eosio::chain::chain_id_type& chain_id, const eosio::chain::block_id_type& last_irr_block_id);

fc::variant json_from_file_or_string(const std::string& file_or_str, fc::json::parse_type ptype = fc::json::parse_type::legacy_parser);
Expand Down

0 comments on commit f25de1b

Please sign in to comment.