test: Fixup creatmultisig documentation and whitespace

pull/764/head
MarcoFalke 6 years ago
parent 78295e97b8
commit fad81d870a
No known key found for this signature in database
GPG Key ID: CE2B75697E69A548

@ -1,12 +1,13 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Copyright (c) 2015-2018 The Bitcoin Core developers # Copyright (c) 2015-2019 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying # Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test transaction signing using the signrawtransaction* RPCs.""" """Test multisig RPCs"""
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
import decimal import decimal
class RpcCreateMultiSigTest(BitcoinTestFramework): class RpcCreateMultiSigTest(BitcoinTestFramework):
def set_test_params(self): def set_test_params(self):
self.setup_clean_chain = True self.setup_clean_chain = True
@ -17,21 +18,21 @@ class RpcCreateMultiSigTest(BitcoinTestFramework):
def get_keys(self): def get_keys(self):
node0, node1, node2 = self.nodes node0, node1, node2 = self.nodes
self.add = [node1.getnewaddress() for _ in range(self.nkeys)] add = [node1.getnewaddress() for _ in range(self.nkeys)]
self.pub = [node1.getaddressinfo(a)["pubkey"] for a in self.add] self.pub = [node1.getaddressinfo(a)["pubkey"] for a in add]
self.priv = [node1.dumpprivkey(a) for a in self.add] self.priv = [node1.dumpprivkey(a) for a in add]
self.final = node2.getnewaddress() self.final = node2.getnewaddress()
def run_test(self): def run_test(self):
node0,node1,node2 = self.nodes node0, node1, node2 = self.nodes
# 50 BTC each, rest will be 25 BTC each # 50 BTC each, rest will be 25 BTC each
node0.generate(149) node0.generate(149)
self.sync_all() self.sync_all()
self.moved = 0 self.moved = 0
for self.nkeys in [3,5]: for self.nkeys in [3, 5]:
for self.nsigs in [2,3]: for self.nsigs in [2, 3]:
for self.output_type in ["bech32", "p2sh-segwit", "legacy"]: for self.output_type in ["bech32", "p2sh-segwit", "legacy"]:
self.get_keys() self.get_keys()
self.do_multisig() self.do_multisig()
@ -39,7 +40,7 @@ class RpcCreateMultiSigTest(BitcoinTestFramework):
self.checkbalances() self.checkbalances()
def checkbalances(self): def checkbalances(self):
node0,node1,node2 = self.nodes node0, node1, node2 = self.nodes
node0.generate(100) node0.generate(100)
self.sync_all() self.sync_all()
@ -49,13 +50,13 @@ class RpcCreateMultiSigTest(BitcoinTestFramework):
height = node0.getblockchaininfo()["blocks"] height = node0.getblockchaininfo()["blocks"]
assert 150 < height < 350 assert 150 < height < 350
total = 149*50 + (height-149-100)*25 total = 149 * 50 + (height - 149 - 100) * 25
assert bal1 == 0 assert bal1 == 0
assert bal2 == self.moved assert bal2 == self.moved
assert bal0+bal1+bal2 == total assert bal0 + bal1 + bal2 == total
def do_multisig(self): def do_multisig(self):
node0,node1,node2 = self.nodes node0, node1, node2 = self.nodes
msig = node2.createmultisig(self.nsigs, self.pub, self.output_type) msig = node2.createmultisig(self.nsigs, self.pub, self.output_type)
madd = msig["address"] madd = msig["address"]
@ -74,7 +75,7 @@ class RpcCreateMultiSigTest(BitcoinTestFramework):
txid = node0.sendtoaddress(madd, 40) txid = node0.sendtoaddress(madd, 40)
tx = node0.getrawtransaction(txid, True) tx = node0.getrawtransaction(txid, True)
vout = [v["n"] for v in tx["vout"] if madd in v["scriptPubKey"].get("addresses",[])] vout = [v["n"] for v in tx["vout"] if madd in v["scriptPubKey"].get("addresses", [])]
assert len(vout) == 1 assert len(vout) == 1
vout = vout[0] vout = vout[0]
scriptPubKey = tx["vout"][vout]["scriptPubKey"]["hex"] scriptPubKey = tx["vout"][vout]["scriptPubKey"]["hex"]
@ -86,7 +87,7 @@ class RpcCreateMultiSigTest(BitcoinTestFramework):
outval = value - decimal.Decimal("0.00001000") outval = value - decimal.Decimal("0.00001000")
rawtx = node2.createrawtransaction([{"txid": txid, "vout": vout}], [{self.final: outval}]) rawtx = node2.createrawtransaction([{"txid": txid, "vout": vout}], [{self.final: outval}])
rawtx2 = node2.signrawtransactionwithkey(rawtx, self.priv[0:self.nsigs-1], prevtxs) rawtx2 = node2.signrawtransactionwithkey(rawtx, self.priv[0:self.nsigs - 1], prevtxs)
rawtx3 = node2.signrawtransactionwithkey(rawtx2["hex"], [self.priv[-1]], prevtxs) rawtx3 = node2.signrawtransactionwithkey(rawtx2["hex"], [self.priv[-1]], prevtxs)
self.moved += outval self.moved += outval
@ -97,5 +98,6 @@ class RpcCreateMultiSigTest(BitcoinTestFramework):
txinfo = node0.getrawtransaction(tx, True, blk) txinfo = node0.getrawtransaction(tx, True, blk)
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"])) 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"]))
if __name__ == '__main__': if __name__ == '__main__':
RpcCreateMultiSigTest().main() RpcCreateMultiSigTest().main()

Loading…
Cancel
Save