forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wallet test: Add test for subtract fee from recipient behavior
Behavior might have recently changed in bitcoin#17331 (it is not clear) but not noticed because there is no test coverage. This adds test coverage for current subtract from recipient behavior without changing it.
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) 2021 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <policy/fees.h> | ||
#include <validation.h> | ||
#include <wallet/coincontrol.h> | ||
#include <wallet/test/util.h> | ||
#include <wallet/test/wallet_test_fixture.h> | ||
|
||
#include <boost/test/unit_test.hpp> | ||
|
||
BOOST_FIXTURE_TEST_SUITE(spend_tests, WalletTestingSetup) | ||
|
||
BOOST_FIXTURE_TEST_CASE(SubtractFee, TestChain100Setup) | ||
{ | ||
CChain& cchain = m_node.chainman->ActiveChain(); | ||
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); | ||
auto wallet = CreateSyncedWallet(*m_node.chain, cchain, coinbaseKey); | ||
|
||
// Check subtract from recipient transaction equal to coinbase amount does | ||
// not create change output. | ||
CRecipient recipient{GetScriptForRawPubKey({}), 50 * COIN, true /* subtract fee */}; | ||
CTransactionRef tx; | ||
CAmount fee; | ||
int change_pos = -1; | ||
bilingual_str error; | ||
CCoinControl coin_control; | ||
FeeCalculation fee_calc; | ||
BOOST_CHECK(wallet->CreateTransaction({recipient}, tx, fee, change_pos, error, coin_control, fee_calc)); | ||
BOOST_CHECK_EQUAL(tx->vout.size(), 1); | ||
BOOST_CHECK_EQUAL(tx->vout[0].nValue, recipient.nAmount - fee); | ||
tx.reset(); | ||
|
||
// Check subtract from recipient transaction slightly less than coinbase | ||
// amount also does not create change output and pays extra dust amount to | ||
// recipient instead of miner | ||
const CAmount dust_amount = 123; | ||
const CAmount expected_fee = fee; | ||
recipient.nAmount -= dust_amount; | ||
BOOST_CHECK(wallet->CreateTransaction({recipient}, tx, fee, change_pos, error, coin_control, fee_calc)); | ||
BOOST_CHECK_EQUAL(tx->vout.size(), 1); | ||
BOOST_CHECK_EQUAL(tx->vout[0].nValue, recipient.nAmount - fee + dust_amount); | ||
BOOST_CHECK_EQUAL(fee, expected_fee); | ||
tx.reset(); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |