Skip to content

Commit

Permalink
Add a test that selects too large if BnB is used
Browse files Browse the repository at this point in the history
If BnB is used, the test will fail because the transaction is too large.
  • Loading branch information
achow101 committed Nov 30, 2020
1 parent 3e69939 commit 3201572
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/functional/rpc_fundrawtransaction.py
Expand Up @@ -94,6 +94,7 @@ def run_test(self):
self.test_address_reuse()
self.test_option_subtract_fee_from_outputs()
self.test_subtract_fee_with_presets()
self.test_transaction_too_large()

def test_change_position(self):
"""Ensure setting changePosition in fundraw with an exact match is handled properly."""
Expand Down Expand Up @@ -907,5 +908,25 @@ def test_subtract_fee_with_presets(self):
signedtx = self.nodes[0].signrawtransactionwithwallet(fundedtx['hex'])
self.nodes[0].sendrawtransaction(signedtx['hex'])

def test_transaction_too_large(self):
self.log.info("Test fundrawtx where BnB solution would result in a too large transaction, but Knapsack would not")

self.nodes[0].createwallet("large")
wallet = self.nodes[0].get_wallet_rpc(self.default_wallet_name)
recipient = self.nodes[0].get_wallet_rpc("large")
outputs = {}
rawtx = recipient.createrawtransaction([], {wallet.getnewaddress(): 147.99899260})

# Make 1500 0.1 BTC outputs
# The amount that we target for funding is in the BnB range when these outputs are used.
# However if these outputs are selected, the transaction will end up being too large, so it shouldn't use BnB and instead fallback to Knapsack
for i in range(0, 1500):
outputs[recipient.getnewaddress()] = 0.1
wallet.sendmany("", outputs)
self.nodes[0].generate(10)

# Currently, the only solution is to select most of the coins just made, however this will result in a transaction that is too large
assert_raises_rpc_error(-4, "Transaction too large", recipient.fundrawtransaction ,rawtx)

if __name__ == '__main__':
RawTransactionsTest().main()

0 comments on commit 3201572

Please sign in to comment.