aboutsummaryrefslogtreecommitdiff
path: root/test/functional/rpc_psbt.py
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2018-07-31 17:58:01 -0700
committerAndrew Chow <achow101-github@achow101.com>2019-02-16 11:51:02 -0500
commit540729ef4bf1b6c6da1ec795e441d2ce56a9a58b (patch)
treef7984f7df6df66f36b45a8d9a0fc52b5edd10963 /test/functional/rpc_psbt.py
parent77542cf2a5f8abb97dd46f782c1b0199cc062033 (diff)
Implement analyzepsbt RPC and tests
Diffstat (limited to 'test/functional/rpc_psbt.py')
-rwxr-xr-xtest/functional/rpc_psbt.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py
index f1538b34a8..9a79a7ee43 100755
--- a/test/functional/rpc_psbt.py
+++ b/test/functional/rpc_psbt.py
@@ -5,8 +5,9 @@
"""Test the Partially Signed Transaction RPCs.
"""
+from decimal import Decimal
from test_framework.test_framework import BitcoinTestFramework
-from test_framework.util import assert_equal, assert_raises_rpc_error, find_output, disconnect_nodes, connect_nodes_bi, sync_blocks
+from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes_bi, disconnect_nodes, find_output, sync_blocks
import json
import os
@@ -339,6 +340,29 @@ class PSBTTest(BitcoinTestFramework):
joined_decoded = self.nodes[0].decodepsbt(joined)
assert len(joined_decoded['inputs']) == 4 and len(joined_decoded['outputs']) == 2 and "final_scriptwitness" not in joined_decoded['inputs'][3] and "final_scriptSig" not in joined_decoded['inputs'][3]
+ # Newly created PSBT needs UTXOs and updating
+ addr = self.nodes[1].getnewaddress("", "p2sh-segwit")
+ txid = self.nodes[0].sendtoaddress(addr, 7)
+ addrinfo = self.nodes[1].getaddressinfo(addr)
+ self.nodes[0].generate(6)
+ self.sync_all()
+ vout = find_output(self.nodes[0], txid, 7)
+ psbt = self.nodes[1].createpsbt([{"txid":txid, "vout":vout}], {self.nodes[0].getnewaddress("", "p2sh-segwit"):Decimal('6.999')})
+ analyzed = self.nodes[0].analyzepsbt(psbt)
+ assert not analyzed['inputs'][0]['has_utxo'] and not analyzed['inputs'][0]['is_final'] and analyzed['inputs'][0]['next'] == 'updater' and analyzed['next'] == 'updater'
+
+ # After update with wallet, only needs signing
+ updated = self.nodes[1].walletprocesspsbt(psbt, False, 'ALL', True)['psbt']
+ analyzed = self.nodes[0].analyzepsbt(updated)
+ assert analyzed['inputs'][0]['has_utxo'] and not analyzed['inputs'][0]['is_final'] and analyzed['inputs'][0]['next'] == 'signer' and analyzed['next'] == 'signer' and analyzed['inputs'][0]['missing']['signatures'][0] == addrinfo['embedded']['witness_program']
+
+ # Check fee and size things
+ assert analyzed['fee'] == Decimal('0.001') and analyzed['estimated_vsize'] == 134 and analyzed['estimated_feerate'] == '0.00746268 BTC/kB'
+
+ # After signing and finalizing, needs extracting
+ signed = self.nodes[1].walletprocesspsbt(updated)['psbt']
+ analyzed = self.nodes[0].analyzepsbt(signed)
+ assert analyzed['inputs'][0]['has_utxo'] and analyzed['inputs'][0]['is_final'] and analyzed['next'] == 'extractor'
if __name__ == '__main__':
PSBTTest().main()