Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_psbt.py
Show All 18 Lines | |||||
# Create one-input, one-output, no-fee transaction: | # Create one-input, one-output, no-fee transaction: | ||||
class PSBTTest(BitcoinTestFramework): | class PSBTTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = False | self.setup_clean_chain = False | ||||
self.num_nodes = 3 | self.num_nodes = 3 | ||||
# TODO: remove -txindex. Currently required for getrawtransaction call. | |||||
self.extra_args = [["-txindex"], ["-txindex"], ["-txindex"]] | |||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_wallet() | self.skip_if_no_wallet() | ||||
def run_test(self): | def run_test(self): | ||||
# Create and fund a raw tx for sending 10 BTC | # Create and fund a raw tx for sending 10 BTC | ||||
psbtx1 = self.nodes[0].walletcreatefundedpsbt( | psbtx1 = self.nodes[0].walletcreatefundedpsbt( | ||||
[], {self.nodes[2].getnewaddress(): 10})['psbt'] | [], {self.nodes[2].getnewaddress(): 10})['psbt'] | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
new_psbt = self.nodes[0].converttopsbt(rawtx['hex']) | new_psbt = self.nodes[0].converttopsbt(rawtx['hex']) | ||||
self.nodes[0].decodepsbt(new_psbt) | self.nodes[0].decodepsbt(new_psbt) | ||||
# Create outputs to nodes 1 and 2 | # Create outputs to nodes 1 and 2 | ||||
node1_addr = self.nodes[1].getnewaddress() | node1_addr = self.nodes[1].getnewaddress() | ||||
node2_addr = self.nodes[2].getnewaddress() | node2_addr = self.nodes[2].getnewaddress() | ||||
txid1 = self.nodes[0].sendtoaddress(node1_addr, 13) | txid1 = self.nodes[0].sendtoaddress(node1_addr, 13) | ||||
txid2 = self.nodes[0].sendtoaddress(node2_addr, 13) | txid2 = self.nodes[0].sendtoaddress(node2_addr, 13) | ||||
self.nodes[0].generate(6) | blockhash = self.nodes[0].generate(6)[0] | ||||
self.sync_all() | self.sync_all() | ||||
vout1 = find_output(self.nodes[1], txid1, 13) | vout1 = find_output(self.nodes[1], txid1, 13, blockhash=blockhash) | ||||
vout2 = find_output(self.nodes[2], txid2, 13) | vout2 = find_output(self.nodes[2], txid2, 13, blockhash=blockhash) | ||||
# Create a psbt spending outputs from nodes 1 and 2 | # Create a psbt spending outputs from nodes 1 and 2 | ||||
psbt_orig = self.nodes[0].createpsbt([{"txid": txid1, "vout": vout1}, { | psbt_orig = self.nodes[0].createpsbt([{"txid": txid1, "vout": vout1}, { | ||||
"txid": txid2, "vout": vout2}], {self.nodes[0].getnewaddress(): 25.999}) | "txid": txid2, "vout": vout2}], {self.nodes[0].getnewaddress(): 25.999}) | ||||
# Update psbts, should only have data for one input and not the other | # Update psbts, should only have data for one input and not the other | ||||
psbt1 = self.nodes[1].walletprocesspsbt(psbt_orig)['psbt'] | psbt1 = self.nodes[1].walletprocesspsbt(psbt_orig)['psbt'] | ||||
psbt1_decoded = self.nodes[0].decodepsbt(psbt1) | psbt1_decoded = self.nodes[0].decodepsbt(psbt1) | ||||
▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
assert_raises_rpc_error(-8, | assert_raises_rpc_error(-8, | ||||
"At least two PSBTs are required to join PSBTs.", self.nodes[1].joinpsbts, []) | "At least two PSBTs are required to join PSBTs.", self.nodes[1].joinpsbts, []) | ||||
assert_raises_rpc_error(-8, | assert_raises_rpc_error(-8, | ||||
"At least two PSBTs are required to join PSBTs.", self.nodes[1].joinpsbts, [psbt2]) | "At least two PSBTs are required to join PSBTs.", self.nodes[1].joinpsbts, [psbt2]) | ||||
# Newly created PSBT needs UTXOs and updating | # Newly created PSBT needs UTXOs and updating | ||||
addr = self.nodes[1].getnewaddress("") | addr = self.nodes[1].getnewaddress("") | ||||
txid = self.nodes[0].sendtoaddress(addr, 7) | txid = self.nodes[0].sendtoaddress(addr, 7) | ||||
self.nodes[0].generate(6) | blockhash = self.nodes[0].generate(6)[0] | ||||
self.sync_all() | self.sync_all() | ||||
vout = find_output(self.nodes[0], txid, 7) | vout = find_output(self.nodes[0], txid, 7, blockhash=blockhash) | ||||
psbt = self.nodes[1].createpsbt([{"txid": txid, "vout": vout}], { | psbt = self.nodes[1].createpsbt([{"txid": txid, "vout": vout}], { | ||||
self.nodes[0].getnewaddress(""): Decimal('6.999')}) | self.nodes[0].getnewaddress(""): Decimal('6.999')}) | ||||
analyzed = self.nodes[0].analyzepsbt(psbt) | analyzed = self.nodes[0].analyzepsbt(psbt) | ||||
assert not analyzed['inputs'][0]['has_utxo'] and not analyzed['inputs'][0][ | assert not analyzed['inputs'][0]['has_utxo'] and not analyzed['inputs'][0][ | ||||
'is_final'] and analyzed['inputs'][0]['next'] == 'updater' and analyzed['next'] == 'updater' | 'is_final'] and analyzed['inputs'][0]['next'] == 'updater' and analyzed['next'] == 'updater' | ||||
# After update with wallet, only needs signing | # After update with wallet, only needs signing | ||||
updated = self.nodes[1].walletprocesspsbt( | updated = self.nodes[1].walletprocesspsbt( | ||||
Show All 17 Lines |