mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-13 12:33:42 +02:00
commit
6e2d87990e
5 changed files with 72 additions and 8 deletions
|
|
@ -30,8 +30,9 @@ bool HasValidFee(const CTransaction& tx) {
|
|||
CAmount fee = 0;
|
||||
if (tx.vout[i].IsFee()) {
|
||||
fee = tx.vout[i].nValue.GetAmount();
|
||||
if (fee == 0 || !MoneyRange(fee))
|
||||
if (fee == 0 || !MoneyRange(fee)) {
|
||||
return false;
|
||||
}
|
||||
totalFee[tx.vout[i].nAsset.GetAsset()] += fee;
|
||||
if (!MoneyRange(totalFee)) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1322,11 +1322,14 @@ static bool CreateTransactionInternal(
|
|||
|
||||
// Add fee output.
|
||||
if (g_con_elementsmode) {
|
||||
CTxOut fee(::policyAsset, 0, CScript());
|
||||
assert(fee.IsFee());
|
||||
txNew.vout.push_back(fee);
|
||||
if (blind_details) {
|
||||
blind_details->o_pubkeys.push_back(CPubKey());
|
||||
// only create fee output if non-zero fee
|
||||
if (coin_selection_params.m_effective_feerate > CFeeRate()) {
|
||||
CTxOut fee(::policyAsset, 0, CScript());
|
||||
assert(fee.IsFee());
|
||||
txNew.vout.push_back(fee);
|
||||
if (blind_details) {
|
||||
blind_details->o_pubkeys.push_back(CPubKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
assert(nChangePosInOut != -1);
|
||||
|
|
@ -1448,7 +1451,6 @@ static bool CreateTransactionInternal(
|
|||
txNew = tx_blinded; // sigh, `fillBlindDetails` may have modified txNew
|
||||
// Update the change position to the new tx
|
||||
change_position = txNew.vout.begin() + nChangePosInOut;
|
||||
|
||||
int ret = BlindTransaction(blind_details->i_amount_blinds, blind_details->i_asset_blinds, blind_details->i_assets, blind_details->i_amounts, blind_details->o_amount_blinds, blind_details->o_asset_blinds, blind_details->o_pubkeys, issuance_asset_keys, issuance_token_keys, tx_blinded);
|
||||
assert(ret != -1);
|
||||
if (ret != blind_details->num_to_blind) {
|
||||
|
|
|
|||
|
|
@ -3024,7 +3024,7 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
|
|||
|
||||
if (args.IsArgSet("-mintxfee")) {
|
||||
std::optional<CAmount> min_tx_fee = ParseMoney(args.GetArg("-mintxfee", ""));
|
||||
if (!min_tx_fee || min_tx_fee.value() == 0) {
|
||||
if (!min_tx_fee) {
|
||||
error = AmountErrMsg("mintxfee", args.GetArg("-mintxfee", ""));
|
||||
return nullptr;
|
||||
} else if (min_tx_fee.value() > HIGH_TX_FEE_PER_KB) {
|
||||
|
|
|
|||
|
|
@ -356,6 +356,7 @@ BASE_SCRIPTS = [
|
|||
'feature_coinstatsindex.py --legacy-wallet',
|
||||
'feature_coinstatsindex.py --descriptors',
|
||||
'wallet_orphanedreward.py',
|
||||
'wallet_send_zero_fee.py',
|
||||
'wallet_timelock.py',
|
||||
'p2p_node_network_limited.py',
|
||||
'p2p_permissions.py',
|
||||
|
|
|
|||
60
test/functional/wallet_send_zero_fee.py
Executable file
60
test/functional/wallet_send_zero_fee.py
Executable file
|
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2017-2020 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
from decimal import Decimal
|
||||
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
)
|
||||
|
||||
class WalletTest(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 3
|
||||
self.extra_args = [[
|
||||
"-blindedaddresses=1",
|
||||
"-minrelaytxfee=0",
|
||||
"-blockmintxfee=0",
|
||||
"-mintxfee=0",
|
||||
]] * self.num_nodes
|
||||
|
||||
def skip_test_if_missing_module(self):
|
||||
self.skip_if_no_wallet()
|
||||
|
||||
def run_test(self):
|
||||
# initial state when setup_clean_chain is False
|
||||
assert_equal(self.nodes[0].getbalance(), {'bitcoin': Decimal('1250')})
|
||||
assert_equal(self.nodes[1].getbalance(), {'bitcoin': Decimal('1250')})
|
||||
assert_equal(self.nodes[2].getbalance(), {'bitcoin': Decimal('1250')})
|
||||
assert_equal(self.nodes[0].getblockchaininfo()["blocks"], 200)
|
||||
|
||||
self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 10)
|
||||
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 20)
|
||||
self.generate(self.nodes[0], 1)
|
||||
assert_equal(self.nodes[0].getblockchaininfo()["blocks"], 201)
|
||||
assert_equal(self.nodes[0].getbalance(), {'bitcoin': Decimal('1269.99897200')})
|
||||
assert_equal(self.nodes[1].getbalance(), {'bitcoin': Decimal('1260')})
|
||||
assert_equal(self.nodes[2].getbalance(), {'bitcoin': Decimal('1270')})
|
||||
|
||||
# send a zero fee_rate transaction, which should not add a fee output
|
||||
addr = self.nodes[1].getnewaddress()
|
||||
txid = self.nodes[0].sendtoaddress(address=addr, amount=1, fee_rate=0)
|
||||
tx = self.nodes[0].getrawtransaction(txid, 2)
|
||||
# there should be no fees
|
||||
assert "bitcoin" not in tx["fee"]
|
||||
assert_equal(tx["fee"], {})
|
||||
# and no fee output
|
||||
assert_equal(len(tx["vout"]),2)
|
||||
for output in tx["vout"]:
|
||||
assert output["scriptPubKey"]["type"] != "fee"
|
||||
|
||||
self.generate(self.nodes[0], 1)
|
||||
assert_equal(self.nodes[0].getblockchaininfo()["blocks"], 202)
|
||||
|
||||
assert_equal(self.nodes[0].getbalance(), {'bitcoin': Decimal('1318.99897200')})
|
||||
assert_equal(self.nodes[1].getbalance(), {'bitcoin': Decimal('1261')})
|
||||
assert_equal(self.nodes[2].getbalance(), {'bitcoin': Decimal('1270')})
|
||||
|
||||
if __name__ == '__main__':
|
||||
WalletTest().main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue