diff --git a/libraries/testing/include/eosio/testing/tester.hpp b/libraries/testing/include/eosio/testing/tester.hpp index 8e61b459dcd..3e93137deee 100644 --- a/libraries/testing/include/eosio/testing/tester.hpp +++ b/libraries/testing/include/eosio/testing/tester.hpp @@ -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& auths, const vector& 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 ); diff --git a/libraries/testing/tester.cpp b/libraries/testing/tester.cpp index d6bcd4e452c..7d9199e0ffe 100644 --- a/libraries/testing/tester.cpp +++ b/libraries/testing/tester.cpp @@ -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{{from, config::owner_name}}, + {get_private_key(from, role)}); + } else { + return push_reqauth(from, vector{{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({ diff --git a/tests/chain_tests/auth_tests.cpp b/tests/chain_tests/auth_tests.cpp index 23dd41a7e50..4b40952301a 100644 --- a/tests/chain_tests/auth_tests.cpp +++ b/tests/chain_tests/auth_tests.cpp @@ -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(); diff --git a/tests/chain_tests/recovery_tests.cpp b/tests/chain_tests/recovery_tests.cpp index beca2214db8..fc0ef648dd5 100644 --- a/tests/chain_tests/recovery_tests.cpp +++ b/tests/chain_tests/recovery_tests.cpp @@ -1,7 +1,6 @@ #include #include - using namespace eosio; using namespace eosio::chain; using namespace eosio::chain::contracts; @@ -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{{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(); @@ -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(); @@ -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(); @@ -173,5 +200,4 @@ BOOST_FIXTURE_TEST_CASE( test_recovery_bad_creator, recov_tester ) try { } FC_LOG_AND_RETHROW() - BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/tests/misc_tests.cpp b/tests/tests/misc_tests.cpp index 50e7c2fa448..22199c65857 100644 --- a/tests/tests/misc_tests.cpp +++ b/tests/tests/misc_tests.cpp @@ -17,7 +17,6 @@ #include using namespace eosio::chain; - namespace eosio { using namespace chain; @@ -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