Skip to content

Commit 9eb325d

Browse files
committed
[QA] Add test for fundrawtransactions new reserveChangeKey option
1 parent 9aa4e6a commit 9eb325d

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

qa/rpc-tests/fundrawtransaction.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ def run_test(self):
651651
assert_equal(len(self.nodes[3].listunspent(1)), 1)
652652

653653
inputs = []
654-
outputs = {self.nodes[2].getnewaddress() : 1}
654+
outputs = {self.nodes[3].getnewaddress() : 1}
655655
rawtx = self.nodes[3].createrawtransaction(inputs, outputs)
656656
result = self.nodes[3].fundrawtransaction(rawtx) # uses min_relay_tx_fee (set by settxfee)
657657
result2 = self.nodes[3].fundrawtransaction(rawtx, {"feeRate": 2*min_relay_tx_fee})
@@ -660,6 +660,32 @@ def run_test(self):
660660
assert_fee_amount(result2['fee'], count_bytes(result2['hex']), 2 * result_fee_rate)
661661
assert_fee_amount(result3['fee'], count_bytes(result3['hex']), 10 * result_fee_rate)
662662

663+
#############################
664+
# Test address reuse option #
665+
#############################
666+
667+
result3 = self.nodes[3].fundrawtransaction(rawtx, {"reserveChangeKey": False})
668+
res_dec = self.nodes[0].decoderawtransaction(result3["hex"])
669+
changeaddress = ""
670+
for out in res_dec['vout']:
671+
if out['value'] > 1.0:
672+
changeaddress += out['scriptPubKey']['addresses'][0]
673+
assert(changeaddress != "")
674+
nextaddr = self.nodes[3].getnewaddress()
675+
# frt should not have removed the key from the keypool
676+
assert(changeaddress == nextaddr)
677+
678+
result3 = self.nodes[3].fundrawtransaction(rawtx)
679+
res_dec = self.nodes[0].decoderawtransaction(result3["hex"])
680+
changeaddress = ""
681+
for out in res_dec['vout']:
682+
if out['value'] > 1.0:
683+
changeaddress += out['scriptPubKey']['addresses'][0]
684+
assert(changeaddress != "")
685+
nextaddr = self.nodes[3].getnewaddress()
686+
# Now the change address key should be removed from the keypool
687+
assert(changeaddress != nextaddr)
688+
663689
######################################
664690
# Test subtractFeeFromOutputs option #
665691
######################################

0 commit comments

Comments
 (0)