Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Add Integration Catchup Test #6989

Merged
merged 22 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cb98d8f
Added ability to configure nodes that are not launched immediately.
brianjohnson5972 Feb 22, 2019
328473c
Cleanup of scripts.
brianjohnson5972 Feb 22, 2019
5aa5835
Added config dir and data dir utils methods.
brianjohnson5972 Feb 25, 2019
50ea21f
Refactoring relaunch logic to allow for a general launch via a comman…
brianjohnson5972 Feb 26, 2019
7206f76
Fixed initialization of bios node and fixed merge error.
brianjohnson5972 Mar 6, 2019
5c71b5d
Fixed error in launchCmd refactor. GH #6727
brianjohnson5972 Mar 6, 2019
5f86a9d
Fixed errors from previous attempt to explicitly set parameters. GH #…
brianjohnson5972 Mar 6, 2019
b685215
Cleanup.
brianjohnson5972 Mar 9, 2019
87e9e61
Added support for adding true flag.
brianjohnson5972 Mar 9, 2019
a5ab5ba
Fixing logic for launching started and unstarted nodes.
brianjohnson5972 Mar 9, 2019
ef7b2aa
Fixed txn_test_gen_plugin to allow using different prefixes for the t…
brianjohnson5972 Mar 9, 2019
52ac578
Pulled out curl processing into its own function and added functions …
brianjohnson5972 Mar 9, 2019
277df3c
Fix error in variable substitution.
brianjohnson5972 Mar 12, 2019
3089f70
Add option to not load system contract. GH #6727
brianjohnson5972 Mar 12, 2019
0532e5c
Add test to ensure catchup lockup does not occur. GH #6727
brianjohnson5972 Mar 12, 2019
97f777b
Fixed launcher setup of unstarted nodes. GH #6727.
brianjohnson5972 Mar 23, 2019
dd4d3a4
Added python script handling for unstarted nodes. GH #6727.
brianjohnson5972 Mar 23, 2019
03c2eaa
Added starting up unstarted nodes and verifying catchup. GH #6727.
brianjohnson5972 Mar 23, 2019
fef0d2a
Changed api to return a json status to indicate what happened. GH #6727.
brianjohnson5972 Mar 23, 2019
640257e
Added nodeos_startup_catchup to long running tests. GH #6727.
brianjohnson5972 Mar 23, 2019
fcd01c8
Fixed interruptAndVerifyExitStatus to track that it was killed. GH #6…
brianjohnson5972 Mar 23, 2019
2790d66
Added catchup after relaunching the catchup node and refactored test …
brianjohnson5972 Mar 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 67 additions & 41 deletions plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ using namespace eosio::testing;

namespace eosio { namespace detail {
struct txn_test_gen_empty {};
struct txn_test_gen_status {
string status;
};
}}

FC_REFLECT(eosio::detail::txn_test_gen_empty, );
FC_REFLECT(eosio::detail::txn_test_gen_status, (status));

namespace eosio {

Expand All @@ -53,8 +57,8 @@ using io_work_t = boost::asio::executor_work_guard<boost::asio::io_context::exec

#define INVOKE_V_R_R_R(api_handle, call_name, in_param0, in_param1, in_param2) \
const auto& vs = fc::json::json::from_string(body).as<fc::variants>(); \
api_handle->call_name(vs.at(0).as<in_param0>(), vs.at(1).as<in_param1>(), vs.at(2).as<in_param2>()); \
eosio::detail::txn_test_gen_empty result;
auto status = api_handle->call_name(vs.at(0).as<in_param0>(), vs.at(1).as<in_param1>(), vs.at(2).as<in_param2>()); \
eosio::detail::txn_test_gen_status result = { status };

#define INVOKE_V_R_R(api_handle, call_name, in_param0, in_param1) \
const auto& vs = fc::json::json::from_string(body).as<fc::variants>(); \
Expand Down Expand Up @@ -101,6 +105,9 @@ struct txn_test_gen_plugin_impl {
uint16_t thread_pool_size;
optional<boost::asio::thread_pool> thread_pool;
std::shared_ptr<boost::asio::high_resolution_timer> timer;
name newaccountA;
name newaccountB;
name newaccountT;

void push_next_transaction(const std::shared_ptr<std::vector<signed_transaction>>& trxs, const std::function<void(const fc::exception_ptr&)>& next ) {
chain_plugin& cp = app().get_plugin<chain_plugin>();
Expand All @@ -127,13 +134,11 @@ struct txn_test_gen_plugin_impl {
}

void create_test_accounts(const std::string& init_name, const std::string& init_priv_key, const std::function<void(const fc::exception_ptr&)>& next) {
ilog("create_test_accounts");
std::vector<signed_transaction> trxs;
trxs.reserve(2);

try {
name newaccountA("txn.test.a");
name newaccountB("txn.test.b");
name newaccountC("txn.test.t");
name creator(init_name);

abi_def currency_abi_def = fc::json::from_string(contracts::eosio_token_abi().data()).as<abi_def>();
Expand Down Expand Up @@ -170,73 +175,85 @@ struct txn_test_gen_plugin_impl {

trx.actions.emplace_back(vector<chain::permission_level>{{creator,"active"}}, newaccount{creator, newaccountB, owner_auth, active_auth});
}
//create "txn.test.t" account
//create "T" account
{
auto owner_auth = eosio::chain::authority{1, {{txn_text_receiver_C_pub_key, 1}}, {}};
auto active_auth = eosio::chain::authority{1, {{txn_text_receiver_C_pub_key, 1}}, {}};

trx.actions.emplace_back(vector<chain::permission_level>{{creator,"active"}}, newaccount{creator, newaccountC, owner_auth, active_auth});
trx.actions.emplace_back(vector<chain::permission_level>{{creator,"active"}}, newaccount{creator, newaccountT, owner_auth, active_auth});
}

trx.expiration = cc.head_block_time() + fc::seconds(30);
trx.expiration = cc.head_block_time() + fc::seconds(180);
trx.set_reference_block(cc.head_block_id());
trx.sign(creator_priv_key, chainid);
trxs.emplace_back(std::move(trx));
}

//set txn.test.t contract to eosio.token & initialize it
//set newaccountT contract to eosio.token & initialize it
{
signed_transaction trx;

vector<uint8_t> wasm = contracts::eosio_token_wasm();

setcode handler;
handler.account = newaccountC;
handler.account = newaccountT;
handler.code.assign(wasm.begin(), wasm.end());

trx.actions.emplace_back( vector<chain::permission_level>{{newaccountC,"active"}}, handler);
trx.actions.emplace_back( vector<chain::permission_level>{{newaccountT,"active"}}, handler);

{
setabi handler;
handler.account = newaccountC;
handler.account = newaccountT;
handler.abi = fc::raw::pack(json::from_string(contracts::eosio_token_abi().data()).as<abi_def>());
trx.actions.emplace_back( vector<chain::permission_level>{{newaccountC,"active"}}, handler);
trx.actions.emplace_back( vector<chain::permission_level>{{newaccountT,"active"}}, handler);
}

{
action act;
act.account = N(txn.test.t);
act.account = newaccountT;
act.name = N(create);
act.authorization = vector<permission_level>{{newaccountC,config::active_name}};
act.data = eosio_token_serializer.variant_to_binary("create", fc::json::from_string("{\"issuer\":\"txn.test.t\",\"maximum_supply\":\"1000000000.0000 CUR\"}}"), abi_serializer_max_time);
act.authorization = vector<permission_level>{{newaccountT,config::active_name}};
act.data = eosio_token_serializer.variant_to_binary("create",
fc::json::from_string(fc::format_string("{\"issuer\":\"${issuer}\",\"maximum_supply\":\"1000000000.0000 CUR\"}}",
fc::mutable_variant_object()("issuer",newaccountT.to_string()))),
abi_serializer_max_time);
trx.actions.push_back(act);
}
{
action act;
act.account = N(txn.test.t);
act.account = newaccountT;
act.name = N(issue);
act.authorization = vector<permission_level>{{newaccountC,config::active_name}};
act.data = eosio_token_serializer.variant_to_binary("issue", fc::json::from_string("{\"to\":\"txn.test.t\",\"quantity\":\"60000.0000 CUR\",\"memo\":\"\"}"), abi_serializer_max_time);
act.authorization = vector<permission_level>{{newaccountT,config::active_name}};
act.data = eosio_token_serializer.variant_to_binary("issue",
fc::json::from_string(fc::format_string("{\"to\":\"${to}\",\"quantity\":\"60000.0000 CUR\",\"memo\":\"\"}",
fc::mutable_variant_object()("to",newaccountT.to_string()))),
abi_serializer_max_time);
trx.actions.push_back(act);
}
{
action act;
act.account = N(txn.test.t);
act.account = newaccountT;
act.name = N(transfer);
act.authorization = vector<permission_level>{{newaccountC,config::active_name}};
act.data = eosio_token_serializer.variant_to_binary("transfer", fc::json::from_string("{\"from\":\"txn.test.t\",\"to\":\"txn.test.a\",\"quantity\":\"20000.0000 CUR\",\"memo\":\"\"}"), abi_serializer_max_time);
act.authorization = vector<permission_level>{{newaccountT,config::active_name}};
act.data = eosio_token_serializer.variant_to_binary("transfer",
fc::json::from_string(fc::format_string("{\"from\":\"${from}\",\"to\":\"${to}\",\"quantity\":\"20000.0000 CUR\",\"memo\":\"\"}",
fc::mutable_variant_object()("from",newaccountT.to_string())("to",newaccountA.to_string()))),
abi_serializer_max_time);
trx.actions.push_back(act);
}
{
action act;
act.account = N(txn.test.t);
act.account = newaccountT;
act.name = N(transfer);
act.authorization = vector<permission_level>{{newaccountC,config::active_name}};
act.data = eosio_token_serializer.variant_to_binary("transfer", fc::json::from_string("{\"from\":\"txn.test.t\",\"to\":\"txn.test.b\",\"quantity\":\"20000.0000 CUR\",\"memo\":\"\"}"), abi_serializer_max_time);
act.authorization = vector<permission_level>{{newaccountT,config::active_name}};
act.data = eosio_token_serializer.variant_to_binary("transfer",
fc::json::from_string(fc::format_string("{\"from\":\"${from}\",\"to\":\"${to}\",\"quantity\":\"20000.0000 CUR\",\"memo\":\"\"}",
fc::mutable_variant_object()("from",newaccountT.to_string())("to",newaccountB.to_string()))),
abi_serializer_max_time);
trx.actions.push_back(act);
}

trx.expiration = cc.head_block_time() + fc::seconds(30);
trx.expiration = cc.head_block_time() + fc::seconds(180);
trx.set_reference_block(cc.head_block_id());
trx.max_net_usage_words = 5000;
trx.sign(txn_test_receiver_C_priv_key, chainid);
Expand All @@ -250,36 +267,38 @@ struct txn_test_gen_plugin_impl {
push_transactions(std::move(trxs), next);
}

void start_generation(const std::string& salt, const uint64_t& period, const uint64_t& batch_size) {
string start_generation(const std::string& salt, const uint64_t& period, const uint64_t& batch_size) {
ilog("Starting transaction test plugin");
if(running)
throw fc::exception(fc::invalid_operation_exception_code);
return "start_generation already running";
if(period < 1 || period > 2500)
throw fc::exception(fc::invalid_operation_exception_code);
return "period must be between 1 and 2500";
if(batch_size < 1 || batch_size > 250)
throw fc::exception(fc::invalid_operation_exception_code);
return "batch_size must be between 1 and 250";
if(batch_size & 1)
throw fc::exception(fc::invalid_operation_exception_code);
return "batch_size must be even";
ilog("Starting transaction test plugin valid");

running = true;

controller& cc = app().get_plugin<chain_plugin>().chain();
auto abi_serializer_max_time = app().get_plugin<chain_plugin>().get_abi_serializer_max_time();
abi_serializer eosio_token_serializer{fc::json::from_string(contracts::eosio_token_abi().data()).as<abi_def>(), abi_serializer_max_time};
//create the actions here
act_a_to_b.account = N(txn.test.t);
act_a_to_b.account = newaccountT;
act_a_to_b.name = N(transfer);
act_a_to_b.authorization = vector<permission_level>{{name("txn.test.a"),config::active_name}};
act_a_to_b.data = eosio_token_serializer.variant_to_binary("transfer",
fc::json::from_string(fc::format_string("{\"from\":\"txn.test.a\",\"to\":\"txn.test.b\",\"quantity\":\"1.0000 CUR\",\"memo\":\"${l}\"}",
fc::mutable_variant_object()("l", salt))),
act_a_to_b.authorization = vector<permission_level>{{newaccountA,config::active_name}};
act_a_to_b.data = eosio_token_serializer.variant_to_binary("transfer",
fc::json::from_string(fc::format_string("{\"from\":\"${from}\",\"to\":\"${to}\",\"quantity\":\"1.0000 CUR\",\"memo\":\"${l}\"}",
fc::mutable_variant_object()("from",newaccountA.to_string())("to",newaccountB.to_string())("l", salt))),
abi_serializer_max_time);

act_b_to_a.account = N(txn.test.t);
act_b_to_a.account = newaccountT;
act_b_to_a.name = N(transfer);
act_b_to_a.authorization = vector<permission_level>{{name("txn.test.b"),config::active_name}};
act_b_to_a.data = eosio_token_serializer.variant_to_binary("transfer",
fc::json::from_string(fc::format_string("{\"from\":\"txn.test.b\",\"to\":\"txn.test.a\",\"quantity\":\"1.0000 CUR\",\"memo\":\"${l}\"}",
fc::mutable_variant_object()("l", salt))),
act_b_to_a.authorization = vector<permission_level>{{newaccountB,config::active_name}};
act_b_to_a.data = eosio_token_serializer.variant_to_binary("transfer",
fc::json::from_string(fc::format_string("{\"from\":\"${from}\",\"to\":\"${to}\",\"quantity\":\"1.0000 CUR\",\"memo\":\"${l}\"}",
fc::mutable_variant_object()("from",newaccountB.to_string())("to",newaccountA.to_string())("l", salt))),
abi_serializer_max_time);

timer_timeout = period;
Expand All @@ -299,6 +318,7 @@ struct txn_test_gen_plugin_impl {
boost::asio::post( *gen_ioc, [this]() {
arm_timer(boost::asio::high_resolution_timer::clock_type::now());
});
return "success";
}

void arm_timer(boost::asio::high_resolution_timer::time_point s) {
Expand Down Expand Up @@ -371,6 +391,7 @@ struct txn_test_gen_plugin_impl {
next(e.dynamic_copy_exception());
}

ilog("send ${c} transactions", ("c",trxs.size()));
push_transactions(std::move(trxs), next);
}

Expand Down Expand Up @@ -414,6 +435,7 @@ void txn_test_gen_plugin::set_program_options(options_description&, options_desc
cfg.add_options()
("txn-reference-block-lag", bpo::value<int32_t>()->default_value(0), "Lag in number of blocks from the head block when selecting the reference block for transactions (-1 means Last Irreversible Block)")
("txn-test-gen-threads", bpo::value<uint16_t>()->default_value(2), "Number of worker threads in txn_test_gen thread pool")
("txn-test-gen-account-prefix", bpo::value<string>()->default_value("txn.test."), "Prefix to use for accounts generated and used by this plugin")
;
}

Expand All @@ -422,6 +444,10 @@ void txn_test_gen_plugin::plugin_initialize(const variables_map& options) {
my.reset( new txn_test_gen_plugin_impl );
my->txn_reference_block_lag = options.at( "txn-reference-block-lag" ).as<int32_t>();
my->thread_pool_size = options.at( "txn-test-gen-threads" ).as<uint16_t>();
const std::string thread_pool_account_prefix = options.at( "txn-test-gen-account-prefix" ).as<std::string>();
my->newaccountA = thread_pool_account_prefix + "a";
my->newaccountB = thread_pool_account_prefix + "b";
my->newaccountT = thread_pool_account_prefix + "t";
EOS_ASSERT( my->thread_pool_size > 0, chain::plugin_config_exception,
"txn-test-gen-threads ${num} must be greater than 0", ("num", my->thread_pool_size) );
} FC_LOG_AND_RETHROW()
Expand Down
Loading