Skip to content

Commit f7e1fb6

Browse files
committed
blind: add functional test that attempting to spend more than 256 inputs fails "gracefully"
1 parent ba538cb commit f7e1fb6

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/functional/rpc_fundrawtransaction.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def run_test(self):
9595
self.test_address_reuse()
9696
self.test_option_subtract_fee_from_outputs()
9797
self.test_subtract_fee_with_presets()
98+
self.test_surjectionproof_many_inputs()
9899

99100
def test_change_position(self):
100101
"""Ensure setting changePosition in fundraw with an exact match is handled properly."""
@@ -953,5 +954,33 @@ def test_subtract_fee_with_presets(self):
953954
signedtx = self.nodes[0].signrawtransactionwithwallet(blindedtx)
954955
self.nodes[0].sendrawtransaction(signedtx['hex'])
955956

957+
def test_surjectionproof_many_inputs(self):
958+
self.log.info("Test fundrawtx with more than 256 inputs")
959+
960+
self.nodes[0].createwallet("surjection")
961+
wallet = self.nodes[0].get_wallet_rpc(self.default_wallet_name)
962+
recipient = self.nodes[0].get_wallet_rpc("surjection")
963+
964+
# Make 500 0.1 BTC outputs...
965+
for j in range(0, 10):
966+
outputs = {}
967+
for i in range(0, 50):
968+
outputs[recipient.getnewaddress()] = 0.1
969+
wallet.sendmany("", outputs)
970+
self.nodes[0].generate(10)
971+
972+
# ...and try to send them all in one transaction
973+
# This should fail but we should not see an assertation failure.
974+
rawtx = recipient.createrawtransaction([], {wallet.getnewaddress(): 49.99})
975+
assert_raises_rpc_error(-4, "Unable to blind the transaction properly. This should not happen.", recipient.fundrawtransaction, rawtx)
976+
977+
# Try to send them across two transactions. This should succeed.
978+
rawtx = recipient.createrawtransaction([], {wallet.getnewaddress(): 24.99})
979+
for i in range(0, 2):
980+
fundedtx = recipient.fundrawtransaction(rawtx)
981+
blindedtx = recipient.blindrawtransaction(fundedtx['hex'])
982+
signedtx = recipient.signrawtransactionwithwallet(blindedtx)
983+
self.nodes[0].sendrawtransaction(signedtx['hex'])
984+
956985
if __name__ == '__main__':
957986
RawTransactionsTest().main()

0 commit comments

Comments
 (0)