Skip to content

Commit

Permalink
moved tests, fixed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jmjatlanta committed Oct 23, 2018
1 parent 673ac2b commit f523ad6
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 112 deletions.
4 changes: 2 additions & 2 deletions libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,10 @@ class database_api
bool verify_authority( const signed_transaction& trx )const;

/**
* @brief Verify that the public keys have enough authority to authorize a transaction
* @brief Verify that the public keys have enough authority to approve an operation
* @param account_name_or_id the account to check
* @param signers the public keys
* @return true if the passed in keys have enough authority to authorize a transaction
* @return true if the passed in keys have enough authority to approve an operation
*/
bool verify_account_authority( const string& account_name_or_id, const flat_set<public_key_type>& signers )const;

Expand Down
110 changes: 110 additions & 0 deletions tests/tests/database_api_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,4 +831,114 @@ BOOST_AUTO_TEST_CASE( get_transaction_hex )

} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE(verify_account_authority)
{
try {

ACTORS( (nathan) );
graphene::app::database_api db_api(db);

// good keys
flat_set<public_key_type> public_keys;
public_keys.emplace(nathan_public_key);
BOOST_CHECK(db_api.verify_account_authority( "nathan", public_keys));

// bad keys
flat_set<public_key_type> bad_public_keys;
bad_public_keys.emplace(public_key_type("BTS6MkMxwBjFWmcDjXRoJ4mW9Hd4LCSPwtv9tKG1qYW5Kgu4AhoZy"));
BOOST_CHECK(!db_api.verify_account_authority( "nathan", bad_public_keys));

} FC_LOG_AND_RETHROW()
}

BOOST_AUTO_TEST_CASE( any_two_of_three )
{
try {
fc::ecc::private_key nathan_key1 = fc::ecc::private_key::regenerate(fc::digest("key1"));
fc::ecc::private_key nathan_key2 = fc::ecc::private_key::regenerate(fc::digest("key2"));
fc::ecc::private_key nathan_key3 = fc::ecc::private_key::regenerate(fc::digest("key3"));
const account_object& nathan = create_account("nathan", nathan_key1.get_public_key() );
fund(nathan);
graphene::app::database_api db_api(db);

try {
account_update_operation op;
op.account = nathan.id;
op.active = authority(2, public_key_type(nathan_key1.get_public_key()), 1,
public_key_type(nathan_key2.get_public_key()), 1, public_key_type(nathan_key3.get_public_key()), 1);
op.owner = *op.active;
trx.operations.push_back(op);
sign(trx, nathan_key1);
PUSH_TX( db, trx, database::skip_transaction_dupe_check );
trx.clear();
} FC_CAPTURE_AND_RETHROW ((nathan.active))

// two keys should work
{
flat_set<public_key_type> public_keys;
public_keys.emplace(nathan_key1.get_public_key());
public_keys.emplace(nathan_key2.get_public_key());
BOOST_CHECK(db_api.verify_account_authority("nathan", public_keys));
}

// the other two keys should work
{
flat_set<public_key_type> public_keys;
public_keys.emplace(nathan_key2.get_public_key());
public_keys.emplace(nathan_key3.get_public_key());
BOOST_CHECK(db_api.verify_account_authority("nathan", public_keys));
}

// just one key should not work
{
flat_set<public_key_type> public_keys;
public_keys.emplace(nathan_key1.get_public_key());
BOOST_CHECK(!db_api.verify_account_authority("nathan", public_keys));
}
} catch (fc::exception& e) {
edump((e.to_detail_string()));
throw;
}
}

BOOST_AUTO_TEST_CASE( verify_authority_multiple_accounts )
{
try {
ACTORS( (nathan) (alice) (bob) );

graphene::app::database_api db_api(db);

try {
account_update_operation op;
op.account = nathan.id;
op.active = authority(3, nathan_public_key, 1, alice.id, 1, bob.id, 1);
op.owner = *op.active;
trx.operations.push_back(op);
sign(trx, nathan_private_key);
PUSH_TX( db, trx, database::skip_transaction_dupe_check );
trx.clear();
} FC_CAPTURE_AND_RETHROW ((nathan.active))

// requires 3 signatures
{
flat_set<public_key_type> public_keys;
public_keys.emplace(nathan_public_key);
public_keys.emplace(alice_public_key);
public_keys.emplace(bob_public_key);
BOOST_CHECK(db_api.verify_account_authority("nathan", public_keys));
}

// only 2 signatures given
{
flat_set<public_key_type> public_keys;
public_keys.emplace(nathan_public_key);
public_keys.emplace(bob_public_key);
BOOST_CHECK(!db_api.verify_account_authority("nathan", public_keys));
}
} catch (fc::exception& e) {
edump((e.to_detail_string()));
throw;
}
}

BOOST_AUTO_TEST_SUITE_END()
111 changes: 1 addition & 110 deletions tests/tests/wallet_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,115 +76,6 @@ BOOST_FIXTURE_TEST_SUITE(wallet_tests, database_fixture)

} FC_LOG_AND_RETHROW()
}

BOOST_AUTO_TEST_CASE(verify_account_authority) {
try {

ACTORS( (nathan) );
graphene::app::database_api db_api(db);

// good keys
flat_set<public_key_type> public_keys;
public_keys.emplace(nathan_public_key);
BOOST_CHECK(db_api.verify_account_authority( "nathan", public_keys));

// bad keys
flat_set<public_key_type> bad_public_keys;
bad_public_keys.emplace(public_key_type("BTS6MkMxwBjFWmcDjXRoJ4mW9Hd4LCSPwtv9tKG1qYW5Kgu4AhoZy"));
BOOST_CHECK(!db_api.verify_account_authority( "nathan", bad_public_keys));

} FC_LOG_AND_RETHROW()
}

BOOST_AUTO_TEST_CASE( any_two_of_three )
{
try {
fc::ecc::private_key nathan_key1 = fc::ecc::private_key::regenerate(fc::digest("key1"));
fc::ecc::private_key nathan_key2 = fc::ecc::private_key::regenerate(fc::digest("key2"));
fc::ecc::private_key nathan_key3 = fc::ecc::private_key::regenerate(fc::digest("key3"));
const account_object& nathan = create_account("nathan", nathan_key1.get_public_key() );
fund(nathan);
graphene::app::database_api db_api(db);

try {
account_update_operation op;
op.account = nathan.id;
op.active = authority(2, public_key_type(nathan_key1.get_public_key()), 1,
public_key_type(nathan_key2.get_public_key()), 1, public_key_type(nathan_key3.get_public_key()), 1);
op.owner = *op.active;
trx.operations.push_back(op);
sign(trx, nathan_key1);
PUSH_TX( db, trx, database::skip_transaction_dupe_check );
trx.clear();
} FC_CAPTURE_AND_RETHROW ((nathan.active))

// two keys should work
{
flat_set<public_key_type> public_keys;
public_keys.emplace(nathan_key1.get_public_key());
public_keys.emplace(nathan_key2.get_public_key());
BOOST_CHECK(db_api.verify_account_authority("nathan", public_keys));
}

// the other two keys should work
{
flat_set<public_key_type> public_keys;
public_keys.emplace(nathan_key2.get_public_key());
public_keys.emplace(nathan_key3.get_public_key());
BOOST_CHECK(db_api.verify_account_authority("nathan", public_keys));
}

// just one key should not work
{
flat_set<public_key_type> public_keys;
public_keys.emplace(nathan_key1.get_public_key());
BOOST_CHECK(!db_api.verify_account_authority("nathan", public_keys));
}
} catch (fc::exception& e) {
edump((e.to_detail_string()));
throw;
}
}

BOOST_AUTO_TEST_CASE( verify_authority_multiple_accounts )
{
try {
ACTORS( (nathan) (alice) (bob) );

graphene::app::database_api db_api(db);

try {
account_update_operation op;
op.account = nathan.id;
op.active = authority(3, nathan_public_key, 1, alice.id, 1, bob.id, 1);
op.owner = *op.active;
trx.operations.push_back(op);
sign(trx, nathan_private_key);
PUSH_TX( db, trx, database::skip_transaction_dupe_check );
trx.clear();
} FC_CAPTURE_AND_RETHROW ((nathan.active))

// requires 3 signatures
{
flat_set<public_key_type> public_keys;
public_keys.emplace(nathan_public_key);
public_keys.emplace(alice_public_key);
public_keys.emplace(bob_public_key);
BOOST_CHECK(db_api.verify_account_authority("nathan", public_keys));
}

// only 2 signatures given
{
flat_set<public_key_type> public_keys;
public_keys.emplace(nathan_public_key);
public_keys.emplace(bob_public_key);
BOOST_CHECK(!db_api.verify_account_authority("nathan", public_keys));
}
} catch (fc::exception& e) {
edump((e.to_detail_string()));
throw;
}
}


BOOST_AUTO_TEST_SUITE_END()

0 comments on commit f523ad6

Please sign in to comment.