提交 a2ea69a1 编写于 作者: N Nathan Hourt

Update test framework, add review_transaction

This adds a way to review and potentially alter a transaction generated
by the test framework, prior to pushing it.
上级 7f1080a7
......@@ -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<ProcessedTransaction> 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);
}
......
......@@ -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<ProcessedTransaction> 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<typename F>
fc::optional<ProcessedTransaction> 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<SignedTransaction, uint32_t> review_storage;
bool skip_trx_sigs = true;
bool auto_sign_trxs = false;
bool hold_for_review = false;
};
using boost::signals2::scoped_connection;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册