Skip to content

Commit

Permalink
wallet: add sendtoaddress/sendmany explicit fee rate coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatack committed Oct 28, 2020
1 parent 44e7bfa commit dd341e6
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions test/functional/wallet_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ def run_test(self):
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, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))

self.log.info("Test sendmany")

# Sendmany 10 BTC
txid = self.nodes[2].sendmany('', {address: 10}, 0, "", [])
self.nodes[2].generate(1)
Expand All @@ -226,7 +228,7 @@ def run_test(self):
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, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))

# Sendmany with explicit fee (BTC/kB)
self.log.info("Test case-insensitive explicit fee rate (sendmany as BTC/kB)")
# Throw if no conf_target provided
assert_raises_rpc_error(-8, "Selected estimate_mode bTc/kB requires a fee rate to be specified in conf_target",
self.nodes[2].sendmany,
Expand All @@ -252,7 +254,7 @@ def run_test(self):
node_0_bal += Decimal('10')
assert_equal(self.nodes[0].getbalance(), node_0_bal)

# Sendmany with explicit fee (SAT/B)
self.log.info("Test case-insensitive explicit fee rate (sendmany as sat/B)")
# Throw if no conf_target provided
assert_raises_rpc_error(-8, "Selected estimate_mode sat/b requires a fee rate to be specified in conf_target",
self.nodes[2].sendmany,
Expand Down Expand Up @@ -280,6 +282,12 @@ def run_test(self):
node_0_bal += Decimal('10')
assert_equal(self.nodes[0].getbalance(), node_0_bal)

# Test setting explicit fee rate just below the minimum.
for unit, fee_rate in {"BTC/kB": 0.00000999, "sat/B": 0.99999999}.items():
self.log.info("Test sendmany raises 'fee rate too low' if conf_target {} and estimate_mode {} are passed".format(fee_rate, unit))
assert_raises_rpc_error(-6, "Fee rate (0.00000999 BTC/kB) is lower than the minimum fee rate setting (0.00001000 BTC/kB)",
self.nodes[2].sendmany, amounts={address: 10}, estimate_mode=unit, conf_target=fee_rate)

self.start_node(3, self.nodes[3].extra_args)
connect_nodes(self.nodes[0], 3)
self.sync_all()
Expand Down Expand Up @@ -413,8 +421,7 @@ def run_test(self):
self.nodes[0].generate(1)
self.sync_all(self.nodes[0:3])

# send with explicit btc/kb fee
self.log.info("test explicit fee (sendtoaddress as btc/kb)")
self.log.info("Test case-insensitive explicit fee rate (sendtoaddress as BTC/kB)")
self.nodes[0].generate(1)
self.sync_all(self.nodes[0:3])
prebalance = self.nodes[2].getbalance()
Expand Down Expand Up @@ -447,9 +454,9 @@ def run_test(self):
fee = prebalance - postbalance - Decimal('1')
assert_fee_amount(fee, tx_size, Decimal('0.00002500'))

# send with explicit sat/b fee
self.sync_all(self.nodes[0:3])
self.log.info("test explicit fee (sendtoaddress as sat/b)")

self.log.info("Test case-insensitive explicit fee rate (sendtoaddress as sat/B)")
self.nodes[0].generate(1)
prebalance = self.nodes[2].getbalance()
assert prebalance > 2
Expand Down Expand Up @@ -481,6 +488,12 @@ def run_test(self):
fee = prebalance - postbalance - Decimal('1')
assert_fee_amount(fee, tx_size, Decimal('0.00002000'))

# Test setting explicit fee rate just below the minimum.
for unit, fee_rate in {"BTC/kB": 0.00000999, "sat/B": 0.99999999}.items():
self.log.info("Test sendtoaddress raises 'fee rate too low' if conf_target {} and estimate_mode {} are passed".format(fee_rate, unit))
assert_raises_rpc_error(-6, "Fee rate (0.00000999 BTC/kB) is lower than the minimum fee rate setting (0.00001000 BTC/kB)",
self.nodes[2].sendtoaddress, address=address, amount=1, estimate_mode=unit, conf_target=fee_rate)

# 2. Import address from node2 to node1
self.nodes[1].importaddress(address_to_import)

Expand Down

0 comments on commit dd341e6

Please sign in to comment.