mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
send: refactor CreateTransaction flow to return a BResult<CTransactionRef>
This commit is contained in:
@@ -28,18 +28,18 @@ BOOST_FIXTURE_TEST_CASE(SubtractFee, TestChain100Setup)
|
||||
auto check_tx = [&wallet](CAmount leftover_input_amount) {
|
||||
CRecipient recipient{GetScriptForRawPubKey({}), 50 * COIN - leftover_input_amount, true /* subtract fee */};
|
||||
constexpr int RANDOM_CHANGE_POSITION = -1;
|
||||
bilingual_str error;
|
||||
CCoinControl coin_control;
|
||||
coin_control.m_feerate.emplace(10000);
|
||||
coin_control.fOverrideFeeRate = true;
|
||||
// We need to use a change type with high cost of change so that the leftover amount will be dropped to fee instead of added as a change output
|
||||
coin_control.m_change_type = OutputType::LEGACY;
|
||||
std::optional<CreatedTransactionResult> txr = CreateTransaction(*wallet, {recipient}, RANDOM_CHANGE_POSITION, error, coin_control);
|
||||
BOOST_CHECK(txr.has_value());
|
||||
BOOST_CHECK_EQUAL(txr->tx->vout.size(), 1);
|
||||
BOOST_CHECK_EQUAL(txr->tx->vout[0].nValue, recipient.nAmount + leftover_input_amount - txr->fee);
|
||||
BOOST_CHECK_GT(txr->fee, 0);
|
||||
return txr->fee;
|
||||
auto res = CreateTransaction(*wallet, {recipient}, RANDOM_CHANGE_POSITION, coin_control);
|
||||
BOOST_CHECK(res);
|
||||
const auto& txr = res.GetObj();
|
||||
BOOST_CHECK_EQUAL(txr.tx->vout.size(), 1);
|
||||
BOOST_CHECK_EQUAL(txr.tx->vout[0].nValue, recipient.nAmount + leftover_input_amount - txr.fee);
|
||||
BOOST_CHECK_GT(txr.fee, 0);
|
||||
return txr.fee;
|
||||
};
|
||||
|
||||
// Send full input amount to recipient, check that only nonzero fee is
|
||||
|
||||
Reference in New Issue
Block a user