aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2015-11-30 12:18:13 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2015-11-30 12:18:20 +0100
commita7751824ce8a7e1cc5511794516fe674bc3eaa3c (patch)
tree00ba888f51a1b92674751bcb78bca7df68c72195
parent6fc287f2df548497c1ced1abe64b303f500cad15 (diff)
parentfa506c0c9b3928843704c666909c0b0c5af2f9a0 (diff)
Merge pull request #7103
fa506c0 [wallet] Add rpc tests to verify fee calculations (MarcoFalke) 4b89f01 Default fPayAtLeastCustomFee to false (Ryan Havar)
-rw-r--r--qa/rpc-tests/test_framework/util.py3
-rwxr-xr-xqa/rpc-tests/wallet.py39
-rw-r--r--src/wallet/wallet.cpp2
3 files changed, 31 insertions, 13 deletions
diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py
index 30dd5de585..d9d5129f21 100644
--- a/qa/rpc-tests/test_framework/util.py
+++ b/qa/rpc-tests/test_framework/util.py
@@ -67,6 +67,9 @@ def check_json_precision():
if satoshis != 2000000000000003:
raise RuntimeError("JSON encode/decode loses precision")
+def count_bytes(hex_string):
+ return len(bytearray.fromhex(hex_string))
+
def sync_blocks(rpc_connections, wait=1):
"""
Wait until everybody has the same block count
diff --git a/qa/rpc-tests/wallet.py b/qa/rpc-tests/wallet.py
index f9ec6f429b..6f6bc31895 100755
--- a/qa/rpc-tests/wallet.py
+++ b/qa/rpc-tests/wallet.py
@@ -24,6 +24,17 @@ from test_framework.util import *
class WalletTest (BitcoinTestFramework):
+ def check_fee_amount(self, curr_balance, balance_with_fee, fee_per_byte, tx_size):
+ """Return curr_balance after asserting the fee was in range"""
+ fee = balance_with_fee - curr_balance
+ target_fee = fee_per_byte * tx_size
+ if fee < target_fee:
+ raise AssertionError("Fee of %s BTC too low! (Should be %s BTC)"%(str(fee), str(target_fee)))
+ # allow the node's estimation to be at most 2 bytes off
+ if fee > fee_per_byte * (tx_size + 2):
+ raise AssertionError("Fee of %s BTC too high! (Should be %s BTC)"%(str(fee), str(target_fee)))
+ return curr_balance
+
def setup_chain(self):
print("Initializing test directory "+self.options.tmpdir)
initialize_chain_clean(self.options.tmpdir, 4)
@@ -104,33 +115,37 @@ class WalletTest (BitcoinTestFramework):
# Send 10 BTC normal
address = self.nodes[0].getnewaddress("test")
- self.nodes[2].settxfee(Decimal('0.001'))
+ fee_per_byte = Decimal('0.001') / 1000
+ self.nodes[2].settxfee(fee_per_byte * 1000)
txid = self.nodes[2].sendtoaddress(address, 10, "", "", False)
self.nodes[2].generate(1)
self.sync_all()
- assert_equal(self.nodes[2].getbalance(), Decimal('89.99900000'))
- assert_equal(self.nodes[0].getbalance(), Decimal('10.00000000'))
+ node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal('90'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))
+ assert_equal(self.nodes[0].getbalance(), Decimal('10'))
# Send 10 BTC with subtract fee from amount
txid = self.nodes[2].sendtoaddress(address, 10, "", "", True)
self.nodes[2].generate(1)
self.sync_all()
- assert_equal(self.nodes[2].getbalance(), Decimal('79.99900000'))
- assert_equal(self.nodes[0].getbalance(), Decimal('19.99900000'))
+ node_2_bal -= Decimal('10')
+ assert_equal(self.nodes[2].getbalance(), node_2_bal)
+ node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), Decimal('20'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))
# Sendmany 10 BTC
txid = self.nodes[2].sendmany('from1', {address: 10}, 0, "", [])
self.nodes[2].generate(1)
self.sync_all()
- assert_equal(self.nodes[2].getbalance(), Decimal('69.99800000'))
- assert_equal(self.nodes[0].getbalance(), Decimal('29.99900000'))
+ node_0_bal += Decimal('10')
+ node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), node_2_bal - Decimal('10'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))
+ assert_equal(self.nodes[0].getbalance(), node_0_bal)
# Sendmany 10 BTC with subtract fee from amount
txid = self.nodes[2].sendmany('from1', {address: 10}, 0, "", [address])
self.nodes[2].generate(1)
self.sync_all()
- assert_equal(self.nodes[2].getbalance(), Decimal('59.99800000'))
- assert_equal(self.nodes[0].getbalance(), Decimal('39.99800000'))
+ node_2_bal -= Decimal('10')
+ assert_equal(self.nodes[2].getbalance(), node_2_bal)
+ node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), node_0_bal + Decimal('10'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))
# Test ResendWalletTransactions:
# Create a couple of transactions, then start up a fourth
@@ -191,14 +206,14 @@ class WalletTest (BitcoinTestFramework):
txObjNotBroadcasted = self.nodes[0].gettransaction(txIdNotBroadcasted)
self.nodes[1].generate(1) #mine a block, tx should not be in there
self.sync_all()
- assert_equal(self.nodes[2].getbalance(), Decimal('59.99800000')); #should not be changed because tx was not broadcasted
+ assert_equal(self.nodes[2].getbalance(), node_2_bal); #should not be changed because tx was not broadcasted
#now broadcast from another node, mine a block, sync, and check the balance
self.nodes[1].sendrawtransaction(txObjNotBroadcasted['hex'])
self.nodes[1].generate(1)
self.sync_all()
txObjNotBroadcasted = self.nodes[0].gettransaction(txIdNotBroadcasted)
- assert_equal(self.nodes[2].getbalance(), Decimal('61.99800000')); #should not be
+ assert_equal(self.nodes[2].getbalance(), node_2_bal + Decimal('2')); #should not be
#create another tx
txIdNotBroadcasted = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2);
@@ -216,7 +231,7 @@ class WalletTest (BitcoinTestFramework):
sync_blocks(self.nodes)
#tx should be added to balance because after restarting the nodes tx should be broadcastet
- assert_equal(self.nodes[2].getbalance(), Decimal('63.99800000')); #should not be
+ assert_equal(self.nodes[2].getbalance(), node_2_bal + Decimal('4')); #should not be
#send a tx with value in a string (PR#6380 +)
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "2")
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 69b163ebc9..b062226dd9 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -41,7 +41,7 @@ CAmount maxTxFee = DEFAULT_TRANSACTION_MAXFEE;
unsigned int nTxConfirmTarget = DEFAULT_TX_CONFIRM_TARGET;
bool bSpendZeroConfChange = DEFAULT_SPEND_ZEROCONF_CHANGE;
bool fSendFreeTransactions = DEFAULT_SEND_FREE_TRANSACTIONS;
-bool fPayAtLeastCustomFee = true;
+bool fPayAtLeastCustomFee = false;
/**
* Fees smaller than this (in satoshi) are considered zero fee (for transaction creation)