MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / run_test

Method run_test

test/functional/rpc_psbt.py:65–284  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

63 connect_nodes_bi(self.nodes, 0, 2)
64
65 def run_test(self):
66 # Create and fund a raw tx for sending 10 BTC
67 psbtx1 = self.nodes[0].walletcreatefundedpsbt([], {self.nodes[2].getnewaddress():10})['psbt']
68
69 # Node 1 should not be able to add anything to it but still return the psbtx same as before
70 psbtx = self.nodes[1].walletprocesspsbt(psbtx1)['psbt']
71 assert_equal(psbtx1, psbtx)
72
73 # Sign the transaction and send
74 signed_tx = self.nodes[0].walletprocesspsbt(psbtx)['psbt']
75 final_tx = self.nodes[0].finalizepsbt(signed_tx)['hex']
76 self.nodes[0].sendrawtransaction(final_tx)
77
78 # Create p2sh, p2wpkh, and p2wsh addresses
79 pubkey0 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())['pubkey']
80 pubkey1 = self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress())['pubkey']
81 pubkey2 = self.nodes[2].getaddressinfo(self.nodes[2].getnewaddress())['pubkey']
82 p2sh = self.nodes[1].addmultisigaddress(2, [pubkey0, pubkey1, pubkey2], "", "legacy")['address']
83 p2wsh = self.nodes[1].addmultisigaddress(2, [pubkey0, pubkey1, pubkey2], "", "bech32")['address']
84 p2sh_p2wsh = self.nodes[1].addmultisigaddress(2, [pubkey0, pubkey1, pubkey2], "", "p2sh-segwit")['address']
85 p2wpkh = self.nodes[1].getnewaddress("", "bech32")
86 p2pkh = self.nodes[1].getnewaddress("", "legacy")
87 p2sh_p2wpkh = self.nodes[1].getnewaddress("", "p2sh-segwit")
88
89 # fund those addresses
90 rawtx = self.nodes[0].createrawtransaction([], {p2sh:10, p2wsh:10, p2wpkh:10, p2sh_p2wsh:10, p2sh_p2wpkh:10, p2pkh:10})
91 rawtx = self.nodes[0].fundrawtransaction(rawtx, {"changePosition":3})
92 signed_tx = self.nodes[0].signrawtransactionwithwallet(rawtx['hex'])['hex']
93 txid = self.nodes[0].sendrawtransaction(signed_tx)
94 self.nodes[0].generate(6)
95 self.sync_all()
96
97 # Find the output pos
98 p2sh_pos = -1
99 p2wsh_pos = -1
100 p2wpkh_pos = -1
101 p2pkh_pos = -1
102 p2sh_p2wsh_pos = -1
103 p2sh_p2wpkh_pos = -1
104 decoded = self.nodes[0].decoderawtransaction(signed_tx)
105 for out in decoded['vout']:
106 if out['scriptPubKey']['addresses'][0] == p2sh:
107 p2sh_pos = out['n']
108 elif out['scriptPubKey']['addresses'][0] == p2wsh:
109 p2wsh_pos = out['n']
110 elif out['scriptPubKey']['addresses'][0] == p2wpkh:
111 p2wpkh_pos = out['n']
112 elif out['scriptPubKey']['addresses'][0] == p2sh_p2wsh:
113 p2sh_p2wsh_pos = out['n']
114 elif out['scriptPubKey']['addresses'][0] == p2sh_p2wpkh:
115 p2sh_p2wpkh_pos = out['n']
116 elif out['scriptPubKey']['addresses'][0] == p2pkh:
117 p2pkh_pos = out['n']
118
119 # spend single key from node 1
120 rawtx = self.nodes[1].walletcreatefundedpsbt([{"txid":txid,"vout":p2wpkh_pos},{"txid":txid,"vout":p2sh_p2wpkh_pos},{"txid":txid,"vout":p2pkh_pos}], {self.nodes[1].getnewaddress():29.99})['psbt']
121 walletprocesspsbt_out = self.nodes[1].walletprocesspsbt(rawtx)
122 assert_equal(walletprocesspsbt_out['complete'], True)

Callers

nothing calls this directly

Calls 8

test_utxo_conversionMethod · 0.95
assert_equalFunction · 0.90
assert_raises_rpc_errorFunction · 0.90
find_outputFunction · 0.90
sync_allMethod · 0.80
joinMethod · 0.80
formatMethod · 0.80
get_wallet_rpcMethod · 0.80

Tested by

no test coverage detected