Skip to content

Commit 429a7cf

Browse files
author
MarcoFalke
committed
Merge #15831: test: Add test that addmultisigaddress fails for watchonly addresses
fab6a0a test: Add test that addmultisigaddress fails for watchonly addresses (MarcoFalke) fad81d8 test: Fixup creatmultisig documentation and whitespace (MarcoFalke) Pull request description: Just to make sure this is not regressed on accidentally in the future ACKs for commit fab6a0: jonatack: ACK bitcoin/bitcoin@fab6a0a Tree-SHA512: bf8dcbc752f8910902a995e55ce486621156aa01f112990344815c4aab980298dfecc108e78245a8986a00c3871338ad16fc818a1bce9dfc6b37b9c88851e39d
2 parents e2b5fde + fab6a0a commit 429a7cf

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

test/functional/rpc_createmultisig.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
#!/usr/bin/env python3
2-
# Copyright (c) 2015-2018 The Bitcoin Core developers
2+
# Copyright (c) 2015-2019 The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5-
"""Test transaction signing using the signrawtransaction* RPCs."""
5+
"""Test multisig RPCs"""
66

77
from test_framework.test_framework import BitcoinTestFramework
8+
from test_framework.util import (
9+
assert_raises_rpc_error,
10+
)
811
import decimal
912

13+
1014
class RpcCreateMultiSigTest(BitcoinTestFramework):
1115
def set_test_params(self):
1216
self.setup_clean_chain = True
@@ -17,29 +21,40 @@ def skip_test_if_missing_module(self):
1721

1822
def get_keys(self):
1923
node0, node1, node2 = self.nodes
20-
self.add = [node1.getnewaddress() for _ in range(self.nkeys)]
21-
self.pub = [node1.getaddressinfo(a)["pubkey"] for a in self.add]
22-
self.priv = [node1.dumpprivkey(a) for a in self.add]
24+
add = [node1.getnewaddress() for _ in range(self.nkeys)]
25+
self.pub = [node1.getaddressinfo(a)["pubkey"] for a in add]
26+
self.priv = [node1.dumpprivkey(a) for a in add]
2327
self.final = node2.getnewaddress()
2428

2529
def run_test(self):
26-
node0,node1,node2 = self.nodes
30+
node0, node1, node2 = self.nodes
2731

28-
# 50 BTC each, rest will be 25 BTC each
32+
self.check_addmultisigaddress_errors()
33+
34+
self.log.info('Generating blocks ...')
2935
node0.generate(149)
3036
self.sync_all()
3137

3238
self.moved = 0
33-
for self.nkeys in [3,5]:
34-
for self.nsigs in [2,3]:
39+
for self.nkeys in [3, 5]:
40+
for self.nsigs in [2, 3]:
3541
for self.output_type in ["bech32", "p2sh-segwit", "legacy"]:
3642
self.get_keys()
3743
self.do_multisig()
3844

3945
self.checkbalances()
4046

47+
def check_addmultisigaddress_errors(self):
48+
self.log.info('Check that addmultisigaddress fails when the private keys are missing')
49+
addresses = [self.nodes[1].getnewaddress(address_type='legacy') for _ in range(2)]
50+
assert_raises_rpc_error(-5, 'no full public key for address', lambda: self.nodes[0].addmultisigaddress(nrequired=1, keys=addresses))
51+
for a in addresses:
52+
# Importing all addresses should not change the result
53+
self.nodes[0].importaddress(a)
54+
assert_raises_rpc_error(-5, 'no full public key for address', lambda: self.nodes[0].addmultisigaddress(nrequired=1, keys=addresses))
55+
4156
def checkbalances(self):
42-
node0,node1,node2 = self.nodes
57+
node0, node1, node2 = self.nodes
4358
node0.generate(100)
4459
self.sync_all()
4560

@@ -49,13 +64,13 @@ def checkbalances(self):
4964

5065
height = node0.getblockchaininfo()["blocks"]
5166
assert 150 < height < 350
52-
total = 149*50 + (height-149-100)*25
67+
total = 149 * 50 + (height - 149 - 100) * 25
5368
assert bal1 == 0
5469
assert bal2 == self.moved
55-
assert bal0+bal1+bal2 == total
70+
assert bal0 + bal1 + bal2 == total
5671

5772
def do_multisig(self):
58-
node0,node1,node2 = self.nodes
73+
node0, node1, node2 = self.nodes
5974

6075
msig = node2.createmultisig(self.nsigs, self.pub, self.output_type)
6176
madd = msig["address"]
@@ -74,7 +89,7 @@ def do_multisig(self):
7489
txid = node0.sendtoaddress(madd, 40)
7590

7691
tx = node0.getrawtransaction(txid, True)
77-
vout = [v["n"] for v in tx["vout"] if madd in v["scriptPubKey"].get("addresses",[])]
92+
vout = [v["n"] for v in tx["vout"] if madd in v["scriptPubKey"].get("addresses", [])]
7893
assert len(vout) == 1
7994
vout = vout[0]
8095
scriptPubKey = tx["vout"][vout]["scriptPubKey"]["hex"]
@@ -86,7 +101,7 @@ def do_multisig(self):
86101
outval = value - decimal.Decimal("0.00001000")
87102
rawtx = node2.createrawtransaction([{"txid": txid, "vout": vout}], [{self.final: outval}])
88103

89-
rawtx2 = node2.signrawtransactionwithkey(rawtx, self.priv[0:self.nsigs-1], prevtxs)
104+
rawtx2 = node2.signrawtransactionwithkey(rawtx, self.priv[0:self.nsigs - 1], prevtxs)
90105
rawtx3 = node2.signrawtransactionwithkey(rawtx2["hex"], [self.priv[-1]], prevtxs)
91106

92107
self.moved += outval
@@ -97,5 +112,6 @@ def do_multisig(self):
97112
txinfo = node0.getrawtransaction(tx, True, blk)
98113
self.log.info("n/m=%d/%d %s size=%d vsize=%d weight=%d" % (self.nsigs, self.nkeys, self.output_type, txinfo["size"], txinfo["vsize"], txinfo["weight"]))
99114

115+
100116
if __name__ == '__main__':
101117
RpcCreateMultiSigTest().main()

0 commit comments

Comments
 (0)