From 94f226819df55432a70f5eed9e62140941e6b84e Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Tue, 15 Aug 2017 14:38:41 -0500 Subject: [PATCH] Ref #123: More testing Test that a fully validated transaction to transfer money requires the linked authority, or a parent, but not a child. --- tests/common/database_fixture.cpp | 2 +- tests/common/database_fixture.hpp | 2 +- tests/tests/native_contract_tests.cpp | 30 +++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 992970db73b..650c8d6cf86 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -166,7 +166,7 @@ types::PublicKey testing_blockchain::get_block_signing_key(const types::AccountN return get_database().get(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(key).auth; diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index fa0893802c7..5f0e997091b 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -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 diff --git a/tests/tests/native_contract_tests.cpp b/tests/tests/native_contract_tests.cpp index 90067a06c8b..93e63a2cc1c 100644 --- a/tests/tests/native_contract_tests.cpp +++ b/tests/tests/native_contract_tests.cpp @@ -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); @@ -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(boost::make_tuple("alice", "eos", "transfer"))),