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

Commit

Permalink
Ref #123: More testing
Browse files Browse the repository at this point in the history
Test that a fully validated transaction to transfer money requires the
linked authority, or a parent, but not a child.
  • Loading branch information
nathanielhourt committed Aug 15, 2017
1 parent c69cd8d commit 94f2268
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/common/database_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ types::PublicKey testing_blockchain::get_block_signing_key(const types::AccountN
return get_database().get<producer_object, by_owner>(producerName).signing_key;
}

void testing_blockchain::sign_transaction(SignedTransaction& trx) {
void testing_blockchain::sign_transaction(SignedTransaction& trx) const {
auto GetAuthority = [this](const types::AccountPermission& permission) {
auto key = boost::make_tuple(permission.account, permission.permission);
return db.get<permission_object, by_owner>(key).auth;
Expand Down
2 changes: 1 addition & 1 deletion tests/common/database_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class testing_blockchain : public chain_controller {
PublicKey get_block_signing_key(const AccountName& producerName);

/// @brief Attempt to sign the provided transaction using the keys available to the testing_fixture
void sign_transaction(SignedTransaction& trx);
void sign_transaction(SignedTransaction& trx) const;

/// @brief Override push_transaction to apply testing policies
/// If transactions are being held for review, transaction will be held after testing policies are applied
Expand Down
30 changes: 30 additions & 0 deletions tests/tests/native_contract_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ BOOST_FIXTURE_TEST_CASE(auth_tests, testing_fixture) {
BOOST_FIXTURE_TEST_CASE(auth_links, testing_fixture) { try {
Make_Blockchain(chain);
Make_Account(chain, alice);
Make_Account(chain, bob);
chain.produce_blocks();

Make_Key(spending);
Expand All @@ -506,6 +507,35 @@ BOOST_FIXTURE_TEST_CASE(auth_links, testing_fixture) { try {
BOOST_CHECK_EQUAL(obj->message_type, "transfer");
}

Transfer_Asset(chain, inita, alice, Asset(1000));
chain.set_auto_sign_transactions(false);
chain.set_skip_transaction_signature_checking(false);
chain.set_hold_transactions_for_review(true);

Transfer_Asset(chain, alice, bob, Asset(10));
BOOST_CHECK_THROW(chain.review_transaction([&chain](SignedTransaction& trx, auto) {
trx.messages.front().authorization = {{"alice", "scud"}};
chain.sign_transaction(trx);
return true;
}), tx_irrelevant_auth);
chain.review_transaction([&chain](SignedTransaction& trx, auto) {
trx.messages.front().authorization = {{"alice", "spending"}};
trx.signatures.clear();
chain.sign_transaction(trx);
return true;
});
chain.review_transaction([&chain](SignedTransaction& trx, auto) {
trx.messages.front().authorization = {{"alice", "active"}};
trx.signatures.clear();
chain.sign_transaction(trx);
return true;
});

BOOST_CHECK_EQUAL(chain.get_liquid_balance("bob"), Asset(20));

chain.set_skip_transaction_signature_checking(true);
chain.set_hold_transactions_for_review(false);

Unlink_Authority(chain, alice, eos, "transfer");
BOOST_CHECK_NE(
(chain_db.find<permission_link_object, by_message_type>(boost::make_tuple("alice", "eos", "transfer"))),
Expand Down

0 comments on commit 94f2268

Please sign in to comment.