|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright (c) 2015-2016 The Bitcoin Core developers |
| 3 | +# Distributed under the MIT software license, see the accompanying |
| 4 | +# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 5 | + |
| 6 | +# |
| 7 | +# Test new Litecoin multisig prefix functionality. |
| 8 | +# |
| 9 | + |
| 10 | +from test_framework.test_framework import BitcoinTestFramework |
| 11 | +from test_framework.util import * |
| 12 | +import decimal |
| 13 | + |
| 14 | +class ScriptAddress2Test(BitcoinTestFramework): |
| 15 | + def __init__(self): |
| 16 | + super().__init__() |
| 17 | + self.num_nodes = 3 |
| 18 | + self.setup_clean_chain = False |
| 19 | + |
| 20 | + def setup_network(self): |
| 21 | + self.nodes = self.start_nodes(self.num_nodes, self.options.tmpdir) |
| 22 | + connect_nodes(self.nodes[1], 0) |
| 23 | + connect_nodes(self.nodes[2], 0) |
| 24 | + self.is_network_split = False |
| 25 | + self.sync_all() |
| 26 | + |
| 27 | + def run_test(self): |
| 28 | + cnt = self.nodes[0].getblockcount() |
| 29 | + |
| 30 | + # Mine some blocks |
| 31 | + self.nodes[1].generate(100) |
| 32 | + self.sync_all() |
| 33 | + if (self.nodes[0].getblockcount() != cnt + 100): |
| 34 | + raise AssertionError("Failed to mine 100 blocks") |
| 35 | + |
| 36 | + addr = self.nodes[0].getnewaddress() |
| 37 | + addr2 = self.nodes[0].getnewaddress() |
| 38 | + multisig_addr = self.nodes[0].addmultisigaddress(2, [addr, addr2], "multisigaccount") |
| 39 | + assert_equal(multisig_addr[0], 'Q') |
| 40 | + |
| 41 | + # Send to a new multisig address |
| 42 | + txid = self.nodes[1].sendtoaddress(multisig_addr, 1) |
| 43 | + block = self.nodes[1].generate(3) |
| 44 | + self.sync_all() |
| 45 | + tx = self.nodes[2].getrawtransaction(txid, 1) |
| 46 | + dest_addrs = [tx["vout"][0]['scriptPubKey']['addresses'][0], |
| 47 | + tx["vout"][1]['scriptPubKey']['addresses'][0]] |
| 48 | + assert(multisig_addr in dest_addrs) |
| 49 | + |
| 50 | + # Spend from the new multisig address |
| 51 | + addr3 = self.nodes[1].getnewaddress() |
| 52 | + txid = self.nodes[0].sendfrom("multisigaccount", addr3, 0.8) |
| 53 | + block = self.nodes[0].generate(2) |
| 54 | + self.sync_all() |
| 55 | + assert(self.nodes[0].getbalance("multisigaccount", 1) < 0.2) |
| 56 | + assert(self.nodes[1].listtransactions()[-1]['address'] == addr3) |
| 57 | + |
| 58 | + # Send to an old multisig address. The api addmultisigaddress |
| 59 | + # can only generate a new address so we manually compute |
| 60 | + # multisig_addr_old beforehand using an old client. |
| 61 | + priv_keys = ["cU7eeLPKzXeKMeZvnEJhvZZ3tLqVF3XGeo1BbM8dnbmV7pP3Qg89", |
| 62 | + "cTw7mRhSvTfzqCt6MFgBoTBqwBpYu2rWugisXcwjv4cAASh3iqPt"] |
| 63 | + |
| 64 | + addrs = ["mj6gNGRXPXrD69R5ApjcsDerZGrYKSfb6v", |
| 65 | + "mqET4JA3L7P7FoUjUP3F6m6YsLpCkyzzou"] |
| 66 | + |
| 67 | + self.nodes[0].importprivkey(priv_keys[0]) |
| 68 | + self.nodes[0].importprivkey(priv_keys[1]) |
| 69 | + |
| 70 | + multisig_addr_new = self.nodes[0].addmultisigaddress(2, addrs, "multisigaccount2") |
| 71 | + assert_equal(multisig_addr_new, "QZ974ZrPrmqMmm1PSVp4m8YEgo3bCQZBbe") |
| 72 | + multisig_addr_old = "2N5nLwYz9qfnGdaFLpPn3gS6oYQbmLTWPjq" |
| 73 | + |
| 74 | + ## Let's send to the old address. We can then find it in the |
| 75 | + ## new address with the new client. So basically the old |
| 76 | + ## address and the new one are the same thing. |
| 77 | + txid = self.nodes[1].sendtoaddress(multisig_addr_old, 1) |
| 78 | + block = self.nodes[1].generate(1) |
| 79 | + self.sync_all() |
| 80 | + tx = self.nodes[2].getrawtransaction(txid, 1) |
| 81 | + dest_addrs = [tx["vout"][0]['scriptPubKey']['addresses'][0], |
| 82 | + tx["vout"][1]['scriptPubKey']['addresses'][0]] |
| 83 | + assert(multisig_addr_new in dest_addrs) |
| 84 | + assert(multisig_addr_old not in dest_addrs) |
| 85 | + |
| 86 | + # Spend from the new multisig address |
| 87 | + addr4 = self.nodes[1].getnewaddress() |
| 88 | + txid = self.nodes[0].sendfrom("multisigaccount2", addr4, 0.8) |
| 89 | + block = self.nodes[0].generate(2) |
| 90 | + self.sync_all() |
| 91 | + assert(self.nodes[0].getbalance("multisigaccount2", 1) < 0.2) |
| 92 | + assert(self.nodes[1].listtransactions()[-1]['address'] == addr4) |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | +if __name__ == '__main__': |
| 97 | + ScriptAddress2Test().main() |
0 commit comments