Skip to content

Commit

Permalink
Merge pull request EOSIO#1466 from cj-oci/accountRecoveryTest-dawn291
Browse files Browse the repository at this point in the history
Add multi-sig recovery tests. stat-291
  • Loading branch information
b1bart authored Feb 26, 2018
2 parents b07081e + 734879f commit 356a8c2
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 35 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 @@ -45,6 +45,7 @@ namespace eosio { namespace testing {
void create_account( account_name name, account_name creator = config::system_account_name, bool multisig = false );

transaction_trace push_reqauth( account_name from, const vector<permission_level>& auths, const vector<private_key_type>& keys );
transaction_trace push_reqauth(account_name from, string role, bool multi_sig = false);
transaction_trace push_nonce( account_name from, const string& v = "blah" );
transaction_trace transfer( account_name from, account_name to, asset amount, string memo, account_name currency );
transaction_trace transfer( account_name from, account_name to, string amount, string memo, account_name currency );
Expand Down
10 changes: 10 additions & 0 deletions libraries/testing/tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ namespace eosio { namespace testing {
return push_transaction( trx );
}

transaction_trace base_tester::push_reqauth(account_name from, string role, bool multi_sig) {
if (!multi_sig) {
return push_reqauth(from, vector<permission_level>{{from, config::owner_name}},
{get_private_key(from, role)});
} else {
return push_reqauth(from, vector<permission_level>{{from, config::owner_name}},
{get_private_key(from, role), get_private_key( config::system_account_name, "active" )} );
}
}

transaction_trace base_tester::push_nonce(account_name from, const string& v) {
variant pretty_trx = fc::mutable_variant_object()
("actions", fc::variants({
Expand Down
17 changes: 15 additions & 2 deletions tests/chain_tests/auth_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,26 @@ BOOST_FIXTURE_TEST_CASE( missing_sigs, tester ) { try {
produce_block();

BOOST_REQUIRE_THROW( push_reqauth( N(alice), {permission_level{N(alice), config::active_name}}, {} ), tx_missing_sigs );
auto trace = push_reqauth(N(alice), {permission_level{N(alice), config::active_name}}, { get_private_key(N(alice), "active") } );
auto trace = push_reqauth(N(alice), "owner");

produce_block();
produce_block();
BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trace.id));

} FC_LOG_AND_RETHROW() } /// missing_sigs

BOOST_FIXTURE_TEST_CASE( missing_multi_sigs, tester ) { try {
produce_block();
create_account(N(alice), config::system_account_name, true);
produce_block();

BOOST_REQUIRE_THROW(push_reqauth(N(alice), "owner"), tx_missing_sigs); // without multisig
auto trace = push_reqauth(N(alice), "owner", true); // with multisig

produce_block();
BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trace.id));

} FC_LOG_AND_RETHROW() } /// missing_multi_sigs

BOOST_FIXTURE_TEST_CASE( missing_auths, tester ) { try {
create_accounts( {N(alice), N(bob)} );
produce_block();
Expand Down
50 changes: 38 additions & 12 deletions tests/chain_tests/recovery_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <boost/test/unit_test.hpp>
#include <eosio/testing/tester.hpp>


using namespace eosio;
using namespace eosio::chain;
using namespace eosio::chain::contracts;
Expand Down Expand Up @@ -35,18 +34,46 @@ auto make_vetorecovery(const tester &t, account_name account, permission_name ve
return trx;
}

struct recov_tester : public tester {
transaction_trace push_reqauth(account_name from, string role) {
return tester::push_reqauth(from, vector<permission_level>{{from, config::owner_name}}, {get_private_key(from, role)} );
}
};



BOOST_AUTO_TEST_SUITE(recovery_tests)

BOOST_FIXTURE_TEST_CASE( test_recovery_multisig_owner, tester ) try {
produce_blocks(1000);
create_account(N(alice), config::system_account_name, true);
produce_block();

BOOST_REQUIRE_THROW(push_reqauth(N(alice), "owner"), tx_missing_sigs); // requires multisig authorization
push_reqauth(N(alice), "owner", true);
produce_block();

fc::time_point expected_recovery(fc::seconds(control->head_block_time().sec_since_epoch()) +fc::days(30));

transaction_id_type recovery_txid;
{
signed_transaction trx = make_postrecovery(*this, N(alice), "owner.recov");
auto trace = push_transaction(trx);
BOOST_REQUIRE_EQUAL(trace.deferred_transactions.size(), 1);
recovery_txid = trace.deferred_transactions.front().id();
produce_block();
BOOST_REQUIRE_EQUAL(chain_has_transaction(trx.id()), true);
}

auto skip_time = expected_recovery - control->head_block_time() - fc::milliseconds(config::block_interval_ms);
produce_block(skip_time);
control->push_deferred_transactions(true);
auto last_old_nonce_id = push_reqauth(N(alice), "owner", true).id;
produce_block();
control->push_deferred_transactions(true);

BOOST_REQUIRE_EQUAL(chain_has_transaction(last_old_nonce_id), true);
BOOST_REQUIRE_THROW(push_reqauth(N(alice), "owner", true), tx_missing_sigs);
auto first_new_nonce_id = push_reqauth(N(alice), "owner.recov").id;
produce_block();
BOOST_REQUIRE_EQUAL(chain_has_transaction(first_new_nonce_id), true);

BOOST_FIXTURE_TEST_CASE( test_recovery_owner, recov_tester ) try {
} FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE( test_recovery_owner, tester ) try {
produce_blocks(1000);
create_account(N(alice));
produce_block();
Expand Down Expand Up @@ -79,7 +106,7 @@ BOOST_FIXTURE_TEST_CASE( test_recovery_owner, recov_tester ) try {

} FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE( test_recovery_owner_veto, recov_tester ) try {
BOOST_FIXTURE_TEST_CASE( test_recovery_owner_veto, tester ) try {
produce_blocks(1000);
create_account(N(alice));
produce_block();
Expand Down Expand Up @@ -121,7 +148,7 @@ BOOST_FIXTURE_TEST_CASE( test_recovery_owner_veto, recov_tester ) try {

} FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE( test_recovery_bad_creator, recov_tester ) try {
BOOST_FIXTURE_TEST_CASE( test_recovery_bad_creator, tester ) try {
produce_blocks(1000);
create_account(N(alice), config::system_account_name, true);
produce_block();
Expand Down Expand Up @@ -173,5 +200,4 @@ BOOST_FIXTURE_TEST_CASE( test_recovery_bad_creator, recov_tester ) try {

} FC_LOG_AND_RETHROW()


BOOST_AUTO_TEST_SUITE_END()
35 changes: 14 additions & 21 deletions tests/tests/misc_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <boost/test/unit_test.hpp>

using namespace eosio::chain;

namespace eosio
{
using namespace chain;
Expand All @@ -28,27 +27,21 @@ BOOST_AUTO_TEST_SUITE(misc_tests)
/// Test processing of unbalanced strings
BOOST_AUTO_TEST_CASE(json_from_string_test)
{
bool exc_found = false;
try
{
auto val = fc::json::from_string("{\"}");
}
catch (...)
{
exc_found = true;
}
BOOST_CHECK_EQUAL(exc_found, true);
bool exc_found = false;
try {
auto val = fc::json::from_string("{\"}");
} catch(...) {
exc_found = true;
}
BOOST_CHECK_EQUAL(exc_found, true);

exc_found = false;
try
{
auto val = fc::json::from_string("{\"block_num_or_id\":5");
}
catch (...)
{
exc_found = true;
}
BOOST_CHECK_EQUAL(exc_found, true);
exc_found = false;
try {
auto val = fc::json::from_string("{\"block_num_or_id\":5");
} catch(...) {
exc_found = true;
}
BOOST_CHECK_EQUAL(exc_found, true);
}

/// Test calculation of median values of blockchain operation properties
Expand Down

0 comments on commit 356a8c2

Please sign in to comment.