Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_keypool.py
Show First 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# import private key and fund it | # import private key and fund it | ||||
address = addr.pop() | address = addr.pop() | ||||
privkey = w1.dumpprivkey(address) | privkey = w1.dumpprivkey(address) | ||||
res = w2.importmulti( | res = w2.importmulti( | ||||
[{'scriptPubKey': {'address': address}, 'keys': [privkey], 'timestamp': 'now'}]) | [{'scriptPubKey': {'address': address}, 'keys': [privkey], 'timestamp': 'now'}]) | ||||
assert_equal(res[0]['success'], True) | assert_equal(res[0]['success'], True) | ||||
w1.walletpassphrase('test', 100) | w1.walletpassphrase('test', 100) | ||||
res = w1.sendtoaddress(address=address, amount=0.00010000) | res = w1.sendtoaddress(address=address, amount=100.00) | ||||
nodes[0].generate(1) | nodes[0].generate(1) | ||||
destination = addr.pop() | destination = addr.pop() | ||||
# Using a fee rate (10 sat / byte) well above the minimum relay rate | # Using a fee rate (10 sat / byte) well above the minimum relay rate | ||||
# creating a 5,000 sat transaction with change should not be possible | # creating a 5,000 sat transaction with change should not be possible | ||||
assert_raises_rpc_error(-4, | assert_raises_rpc_error(-4, | ||||
"Transaction needs a change address, but we can't generate it. Please call keypoolrefill first.", | "Transaction needs a change address, but we can't generate it. Please call keypoolrefill first.", | ||||
w2.walletcreatefundedpsbt, | w2.walletcreatefundedpsbt, | ||||
inputs=[], | inputs=[], | ||||
outputs=[{addr.pop(): 0.00005000}], | outputs=[{addr.pop(): 50.00}], | ||||
options={"subtractFeeFromOutputs": [0], | options={"subtractFeeFromOutputs": [0], | ||||
"feeRate": 0.00010}) | "feeRate": 100}) | ||||
# creating a 10,000 sat transaction without change, with a manual | # creating a 10,000 sat transaction without change, with a manual | ||||
# input, should still be possible | # input, should still be possible | ||||
res = w2.walletcreatefundedpsbt( | res = w2.walletcreatefundedpsbt( | ||||
inputs=w2.listunspent(), | inputs=w2.listunspent(), | ||||
outputs=[{destination: 0.00010000}], | outputs=[{destination: 100.00}], | ||||
options={"subtractFeeFromOutputs": [0], "feeRate": 0.00010}) | options={"subtractFeeFromOutputs": [0], "feeRate": 100}) | ||||
assert_equal("psbt" in res, True) | assert_equal("psbt" in res, True) | ||||
# creating a 10,000 sat transaction without change should still be | # creating a 10,000 sat transaction without change should still be | ||||
# possible | # possible | ||||
res = w2.walletcreatefundedpsbt( | res = w2.walletcreatefundedpsbt( | ||||
inputs=[], | inputs=[], | ||||
outputs=[{destination: 0.00010000}], | outputs=[{destination: 100.00}], | ||||
options={"subtractFeeFromOutputs": [0], "feeRate": 0.00010}) | options={"subtractFeeFromOutputs": [0], "feeRate": 100}) | ||||
assert_equal("psbt" in res, True) | assert_equal("psbt" in res, True) | ||||
# should work without subtractFeeFromOutputs if the exact fee is | # should work without subtractFeeFromOutputs if the exact fee is | ||||
# subtracted from the amount | # subtracted from the amount | ||||
res = w2.walletcreatefundedpsbt(inputs=[], | res = w2.walletcreatefundedpsbt(inputs=[], | ||||
outputs=[{destination: 0.00008000}], | outputs=[{destination: 80.00}], | ||||
options={"feeRate": 0.00010}) | options={"feeRate": 100}) | ||||
assert_equal("psbt" in res, True) | assert_equal("psbt" in res, True) | ||||
# dust change should be removed | # dust change should be removed | ||||
res = w2.walletcreatefundedpsbt(inputs=[], | res = w2.walletcreatefundedpsbt(inputs=[], | ||||
outputs=[{destination: 0.00007900}], | outputs=[{destination: 79.00}], | ||||
options={"feeRate": 0.00010}) | options={"feeRate": 100}) | ||||
assert_equal("psbt" in res, True) | assert_equal("psbt" in res, True) | ||||
# create a transaction without change at the maximum fee rate, such | # create a transaction without change at the maximum fee rate, such | ||||
# that the output is still spendable: | # that the output is still spendable: | ||||
res = w2.walletcreatefundedpsbt( | res = w2.walletcreatefundedpsbt( | ||||
inputs=[], | inputs=[], | ||||
outputs=[{destination: 0.00010000}], | outputs=[{destination: 100.00}], | ||||
options={"subtractFeeFromOutputs": [0], "feeRate": 0.0004949}) | options={"subtractFeeFromOutputs": [0], "feeRate": 494.90}) | ||||
assert_equal("psbt" in res, True) | assert_equal("psbt" in res, True) | ||||
assert_equal(res["fee"], Decimal("0.00009453")) | assert_equal(res["fee"], Decimal("94.53")) | ||||
# creating a 10,000 sat transaction with a manual change address should | # creating a 10,000 sat transaction with a manual change address should | ||||
# be possible | # be possible | ||||
res = w2.walletcreatefundedpsbt(inputs=[], | res = w2.walletcreatefundedpsbt(inputs=[], | ||||
outputs=[{destination: 0.00010000}], | outputs=[{destination: 100.00}], | ||||
options={"subtractFeeFromOutputs": [0], | options={"subtractFeeFromOutputs": [0], | ||||
"feeRate": 0.00010, | "feeRate": 100, | ||||
"changeAddress": addr.pop()}) | "changeAddress": addr.pop()}) | ||||
assert_equal("psbt" in res, True) | assert_equal("psbt" in res, True) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
KeyPoolTest().main() | KeyPoolTest().main() |