Skip to content

Commit

Permalink
Add multi-sig recovery tests. Cleanup misc_tests and enable it.
Browse files Browse the repository at this point in the history
  • Loading branch information
cijujohn committed Feb 23, 2018
1 parent f255ea6 commit 75dedbb
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 206 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
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ set( CMAKE_CXX_STANDARD 14 )
include_directories("${CMAKE_BINARY_DIR}/contracts")
include_directories("${CMAKE_SOURCE_DIR}/contracts")

file(GLOB UNIT_TESTS "chain_tests/*.cpp" "api_tests/*.cpp" "tests/abi_tests.cpp" "tests/database_tests.cpp")
file(GLOB UNIT_TESTS "chain_tests/*.cpp" "api_tests/*.cpp" "tests/abi_tests.cpp" "tests/database_tests.cpp" "tests/misc_tests.cpp")

#if(WASM_TOOLCHAIN)
# file(GLOB WASM_UNIT_TESTS "wasm_tests/*.cpp")
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()
Loading

0 comments on commit 75dedbb

Please sign in to comment.