diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 8e35f06e15828e62543964c9799f7fb5aaaeab70..992970db73b0373bfaaf40c2c4a88c1bce56a157 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -184,7 +184,7 @@ void testing_blockchain::sign_transaction(SignedTransaction& trx) { trx.sign(fixture.get_private_key(key), chain_id_type{}); } -ProcessedTransaction testing_blockchain::push_transaction(SignedTransaction trx, uint32_t skip_flags) { +fc::optional testing_blockchain::push_transaction(SignedTransaction trx, uint32_t skip_flags) { if (skip_trx_sigs) skip_flags |= chain_controller::skip_transaction_signatures; @@ -192,6 +192,10 @@ ProcessedTransaction testing_blockchain::push_transaction(SignedTransaction trx, sign_transaction(trx); } + if (hold_for_review) { + review_storage = std::make_pair(trx, skip_flags); + return {}; + } return chain_controller::push_transaction(trx, skip_flags); } diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index fd6d95603cb0812983111ebdcb100d07c94aa9dc..fa0893802c7f68eb1bc386e14b32ee867e542b9e 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -183,7 +183,18 @@ public: void sign_transaction(SignedTransaction& trx); /// @brief Override push_transaction to apply testing policies - ProcessedTransaction push_transaction(SignedTransaction trx, uint32_t skip_flags = 0); + /// If transactions are being held for review, transaction will be held after testing policies are applied + fc::optional push_transaction(SignedTransaction trx, uint32_t skip_flags = 0); + /// @brief Review and optionally push last held transaction + /// @tparam F A callable with signature `bool f(SignedTransaction&, uint32_t&)` + /// @param reviewer Callable which inspects and potentially alters the held transaction and skip flags, and returns + /// whether it should be pushed or not + template + fc::optional review_transaction(F&& reviewer) { + if (reviewer(review_storage.first, review_storage.second)) + return chain_controller::push_transaction(review_storage.first, review_storage.second); + return {}; + } /// @brief Set whether testing_blockchain::push_transaction checks signatures by default /// @param skip_sigs If true, push_transaction will skip signature checks; otherwise, no changes will be made @@ -194,12 +205,18 @@ public: void set_auto_sign_transactions(bool auto_sign) { auto_sign_trxs = auto_sign; } + /// @brief Set whether testing_blockchain::push_transaction holds transactions for review or not + void set_hold_transactions_for_review(bool hold_trxs) { + hold_for_review = hold_trxs; + } protected: chainbase::database& db; testing_fixture& fixture; + std::pair review_storage; bool skip_trx_sigs = true; bool auto_sign_trxs = false; + bool hold_for_review = false; }; using boost::signals2::scoped_connection;