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

Add multi-sig recovery tests. stat-291 #1466

Merged
merged 2 commits into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be an "up-port" of the method call that used to only exist for recovery tests.

In the context of recovery tests using the "owner" permission level makes sense however, in most other cases that seems to be a mis-use as the concept of "owner" is that it is very rarely used.

It seems this was done to make the missing_multi_sigs tests case more concise but as that could be done with the "Active" permission level and the push_reqauth that already existed with a few more keys strokes maybe we should keep this "owner" bomb in the recover tester?

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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while more concise, this does change the semantics by signing with the "owner" key/permission instead of the active.

We should probably just leave the exploded version that was in place before


produce_block();
produce_block();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix whitespace

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