Skip to content

Commit

Permalink
Tests for funding with external inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
achow101 committed Oct 29, 2019
1 parent 07ad7e3 commit e96d6e5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/functional/rpc_fundrawtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def run_test(self):
self.test_option_feerate()
self.test_address_reuse()
self.test_option_subtract_fee_from_outputs()
self.test_external_inputs()

def test_change_position(self):
# ensure that setting changePosition in fundraw with an exact match is handled properly
Expand Down Expand Up @@ -778,5 +779,21 @@ def test_option_subtract_fee_from_outputs(self):
# the total subtracted from the outputs is equal to the fee
assert_equal(share[0] + share[2] + share[3], result[0]['fee'])

def test_external_inputs(self):
ext_utxo = self.nodes[0].listunspent()[0]
addr_info = self.nodes[0].getaddressinfo(ext_utxo['address'])

# An external input without solving data should result in an error
raw_tx = self.nodes[2].createrawtransaction([{"txid": ext_utxo['txid'], "vout": ext_utxo['vout']}], {self.nodes[0].getnewaddress(): 10 + ext_utxo['amount']})
assert_raises_rpc_error(-4, "Missing solving data for estimating transaction size", self.nodes[2].fundrawtransaction, raw_tx)

# But funding should work when the solving data is provided
funded_tx = self.nodes[2].fundrawtransaction(raw_tx, {}, False, {"pubkeys": [addr_info['pubkey']]})
signed_tx = self.nodes[2].signrawtransactionwithwallet(funded_tx['hex'])
assert not signed_tx['complete']
signed_tx = self.nodes[0].signrawtransactionwithwallet(signed_tx['hex'])
assert signed_tx['complete']
self.nodes[0].sendrawtransaction(signed_tx['hex'])

if __name__ == '__main__':
RawTransactionsTest().main()
16 changes: 16 additions & 0 deletions test/functional/rpc_psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,5 +416,21 @@ def test_psbt_input_keys(psbt_input, keys):
analyzed = self.nodes[0].analyzepsbt(signed)
assert analyzed['inputs'][0]['has_utxo'] and analyzed['inputs'][0]['is_final'] and analyzed['next'] == 'extractor'

# Test that we can fund psbts with external inputs specified
ext_utxo = self.nodes[0].listunspent()[0]
addr_info = self.nodes[0].getaddressinfo(ext_utxo['address'])

# An external input without solving data should result in an error
assert_raises_rpc_error(-4, "Missing solving data for estimating transaction size", self.nodes[1].walletcreatefundedpsbt, [{"txid": ext_utxo['txid'], "vout": ext_utxo['vout']}], {self.nodes[0].getnewaddress(): 10 + ext_utxo['amount']})

# But funding should work when the solving data is provided
psbt = self.nodes[1].walletcreatefundedpsbt([{"txid": ext_utxo['txid'], "vout": ext_utxo['vout']}], {self.nodes[0].getnewaddress(): 10 + ext_utxo['amount']}, 0, {}, False, {"pubkeys": [addr_info['pubkey']]})
signed = self.nodes[1].walletprocesspsbt(psbt['psbt'])
assert not signed['complete']
signed = self.nodes[0].walletprocesspsbt(signed['psbt'])
assert signed['complete']
tx = self.nodes[0].finalizepsbt(signed['psbt'])
self.nodes[0].sendrawtransaction(tx['hex'])

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

0 comments on commit e96d6e5

Please sign in to comment.