Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_psbt.py
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
psbtx = self.nodes[1].walletprocesspsbt(psbtx1)['psbt'] | psbtx = self.nodes[1].walletprocesspsbt(psbtx1)['psbt'] | ||||
assert_equal(psbtx1, psbtx) | assert_equal(psbtx1, psbtx) | ||||
# Sign the transaction and send | # Sign the transaction and send | ||||
signed_tx = self.nodes[0].walletprocesspsbt(psbtx)['psbt'] | signed_tx = self.nodes[0].walletprocesspsbt(psbtx)['psbt'] | ||||
final_tx = self.nodes[0].finalizepsbt(signed_tx)['hex'] | final_tx = self.nodes[0].finalizepsbt(signed_tx)['hex'] | ||||
self.nodes[0].sendrawtransaction(final_tx) | self.nodes[0].sendrawtransaction(final_tx) | ||||
# Create p2sh, p2pkh addresses | # Get pubkeys | ||||
pubkey0 = self.nodes[0].getaddressinfo( | pubkey0 = self.nodes[0].getaddressinfo( | ||||
self.nodes[0].getnewaddress())['pubkey'] | self.nodes[0].getnewaddress())['pubkey'] | ||||
pubkey1 = self.nodes[1].getaddressinfo( | pubkey1 = self.nodes[1].getaddressinfo( | ||||
self.nodes[1].getnewaddress())['pubkey'] | self.nodes[1].getnewaddress())['pubkey'] | ||||
pubkey2 = self.nodes[2].getaddressinfo( | pubkey2 = self.nodes[2].getaddressinfo( | ||||
self.nodes[2].getnewaddress())['pubkey'] | self.nodes[2].getnewaddress())['pubkey'] | ||||
p2sh = self.nodes[1].addmultisigaddress( | |||||
# Setup watchonly wallets | |||||
self.nodes[2].createwallet( | |||||
wallet_name='wmulti', | |||||
disable_private_keys=True) | |||||
wmulti = self.nodes[2].get_wallet_rpc('wmulti') | |||||
# Create all the addresses | |||||
p2sh = wmulti.addmultisigaddress( | |||||
2, [pubkey0, pubkey1, pubkey2], "")['address'] | 2, [pubkey0, pubkey1, pubkey2], "")['address'] | ||||
if not self.options.descriptors: | |||||
wmulti.importaddress(p2sh) | |||||
p2pkh = self.nodes[1].getnewaddress("") | p2pkh = self.nodes[1].getnewaddress("") | ||||
# fund those addresses | # fund those addresses | ||||
rawtx = self.nodes[0].createrawtransaction([], {p2sh: 10, p2pkh: 10}) | rawtx = self.nodes[0].createrawtransaction([], {p2sh: 10, p2pkh: 10}) | ||||
rawtx = self.nodes[0].fundrawtransaction(rawtx, {"changePosition": 0}) | rawtx = self.nodes[0].fundrawtransaction(rawtx, {"changePosition": 0}) | ||||
signed_tx = self.nodes[0].signrawtransactionwithwallet(rawtx['hex'])[ | signed_tx = self.nodes[0].signrawtransactionwithwallet(rawtx['hex'])[ | ||||
'hex'] | 'hex'] | ||||
txid = self.nodes[0].sendrawtransaction(signed_tx) | txid = self.nodes[0].sendrawtransaction(signed_tx) | ||||
Show All 15 Lines | def run_test(self): | ||||
self.nodes[1].getnewaddress(): 9.99})['psbt'] | self.nodes[1].getnewaddress(): 9.99})['psbt'] | ||||
walletprocesspsbt_out = self.nodes[1].walletprocesspsbt(rawtx) | walletprocesspsbt_out = self.nodes[1].walletprocesspsbt(rawtx) | ||||
assert_equal(walletprocesspsbt_out['complete'], True) | assert_equal(walletprocesspsbt_out['complete'], True) | ||||
self.nodes[1].sendrawtransaction( | self.nodes[1].sendrawtransaction( | ||||
self.nodes[1].finalizepsbt(walletprocesspsbt_out['psbt'])['hex']) | self.nodes[1].finalizepsbt(walletprocesspsbt_out['psbt'])['hex']) | ||||
# feeRate of 0.1 BCH / KB produces a total fee slightly below -maxtxfee | # feeRate of 0.1 BCH / KB produces a total fee slightly below -maxtxfee | ||||
res = self.nodes[1].walletcreatefundedpsbt( | res = self.nodes[1].walletcreatefundedpsbt( | ||||
[ | inputs=[{"txid": txid, "vout": p2sh_pos}], | ||||
{ | outputs={self.nodes[1].getnewaddress(): 9.99}, | ||||
"txid": txid, "vout": p2sh_pos}, { | locktime=0, | ||||
"txid": txid, "vout": p2pkh_pos}], { | options={"feeRate": 0.1, "add_inputs": True}) | ||||
self.nodes[1].getnewaddress(): 29.99}, 0, { | |||||
"feeRate": 0.1, "add_inputs": True}) | |||||
assert_approx(res["fee"], 0.065, 0.005) | assert_approx(res["fee"], 0.065, 0.005) | ||||
# feeRate of 10 BCH / KB produces a total fee well above -maxtxfee | # feeRate of 10 BCH / KB produces a total fee well above -maxtxfee | ||||
# previously this was silently capped at -maxtxfee | # previously this was silently capped at -maxtxfee | ||||
assert_raises_rpc_error(-4, | assert_raises_rpc_error( | ||||
-4, | |||||
"Fee exceeds maximum configured by -maxtxfee", | "Fee exceeds maximum configured by -maxtxfee", | ||||
self.nodes[1].walletcreatefundedpsbt, | self.nodes[1].walletcreatefundedpsbt, | ||||
[{"txid": txid, | [{"txid": txid, "vout": p2sh_pos}, | ||||
"vout": p2sh_pos}, | {"txid": txid, "vout": p2pkh_pos}], | ||||
{"txid": txid, | |||||
"vout": p2pkh_pos}], | |||||
{self.nodes[1].getnewaddress(): 29.99}, | {self.nodes[1].getnewaddress(): 29.99}, | ||||
0, | 0, | ||||
{"feeRate": 10, | {"feeRate": 10, "add_inputs": True}) | ||||
"add_inputs": True}) | assert_raises_rpc_error( | ||||
assert_raises_rpc_error(-4, | -4, | ||||
"Fee exceeds maximum configured by -maxtxfee", | "Fee exceeds maximum configured by -maxtxfee", | ||||
self.nodes[1].walletcreatefundedpsbt, | self.nodes[1].walletcreatefundedpsbt, | ||||
[{"txid": txid, | [{"txid": txid, "vout": p2sh_pos}, | ||||
"vout": p2sh_pos}, | {"txid": txid, "vout": p2pkh_pos}], | ||||
{"txid": txid, | |||||
"vout": p2pkh_pos}], | |||||
{self.nodes[1].getnewaddress(): 1}, | {self.nodes[1].getnewaddress(): 1}, | ||||
0, | 0, | ||||
{"feeRate": 10, | {"feeRate": 10, "add_inputs": False}) | ||||
"add_inputs": False}) | |||||
# partially sign multisig things with node 1 | # partially sign multisig things with node 1 | ||||
psbtx = self.nodes[1].walletcreatefundedpsbt([{"txid": txid, "vout": p2sh_pos}], { | psbtx = wmulti.walletcreatefundedpsbt( | ||||
self.nodes[1].getnewaddress(): 9.99})['psbt'] | inputs=[ | ||||
{ | |||||
"txid": txid, "vout": p2sh_pos}], outputs={ | |||||
self.nodes[1].getnewaddress(): 9.99}, options={ | |||||
'changeAddress': self.nodes[1].getrawchangeaddress()})['psbt'] | |||||
walletprocesspsbt_out = self.nodes[1].walletprocesspsbt(psbtx) | walletprocesspsbt_out = self.nodes[1].walletprocesspsbt(psbtx) | ||||
psbtx = walletprocesspsbt_out['psbt'] | psbtx = walletprocesspsbt_out['psbt'] | ||||
assert_equal(walletprocesspsbt_out['complete'], False) | assert_equal(walletprocesspsbt_out['complete'], False) | ||||
# Unload wmulti, we don't need it anymore | |||||
wmulti.unloadwallet() | |||||
# partially sign with node 2. This should be complete and sendable | # partially sign with node 2. This should be complete and sendable | ||||
walletprocesspsbt_out = self.nodes[2].walletprocesspsbt(psbtx) | walletprocesspsbt_out = self.nodes[2].walletprocesspsbt(psbtx) | ||||
assert_equal(walletprocesspsbt_out['complete'], True) | assert_equal(walletprocesspsbt_out['complete'], True) | ||||
self.nodes[2].sendrawtransaction( | self.nodes[2].sendrawtransaction( | ||||
self.nodes[2].finalizepsbt(walletprocesspsbt_out['psbt'])['hex']) | self.nodes[2].finalizepsbt(walletprocesspsbt_out['psbt'])['hex']) | ||||
# check that walletprocesspsbt fails to decode a non-psbt | # check that walletprocesspsbt fails to decode a non-psbt | ||||
rawtx = self.nodes[1].createrawtransaction([{"txid": txid, "vout": p2pkh_pos}], { | rawtx = self.nodes[1].createrawtransaction([{"txid": txid, "vout": p2pkh_pos}], { | ||||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Creator Tests | # Creator Tests | ||||
for creator in creators: | for creator in creators: | ||||
created_tx = self.nodes[0].createpsbt( | created_tx = self.nodes[0].createpsbt( | ||||
creator['inputs'], creator['outputs']) | creator['inputs'], creator['outputs']) | ||||
assert_equal(created_tx, creator['result']) | assert_equal(created_tx, creator['result']) | ||||
# Signer tests | # Signer tests | ||||
for i, signer in enumerate(signers): | for i, signer in enumerate(signers): | ||||
self.nodes[2].createwallet("wallet{}".format(i)) | self.nodes[2].createwallet(wallet_name="wallet{}".format(i)) | ||||
wrpc = self.nodes[2].get_wallet_rpc("wallet{}".format(i)) | wrpc = self.nodes[2].get_wallet_rpc("wallet{}".format(i)) | ||||
for key in signer['privkeys']: | for key in signer['privkeys']: | ||||
wrpc.importprivkey(key) | wrpc.importprivkey(key) | ||||
signed_tx = wrpc.walletprocesspsbt(signer['psbt'])['psbt'] | signed_tx = wrpc.walletprocesspsbt(signer['psbt'])['psbt'] | ||||
assert_equal(signed_tx, signer['result']) | assert_equal(signed_tx, signer['result']) | ||||
# Combiner test | # Combiner test | ||||
for combiner in combiners: | for combiner in combiners: | ||||
▲ Show 20 Lines • Show All 164 Lines • Show Last 20 Lines |