Litecoin: Multisig code testing

pull/751/head
Adrian Gallagher 6 years ago
parent c7c4806e7a
commit e16dd76732
No known key found for this signature in database
GPG Key ID: FE3348877809386C

@ -18,13 +18,15 @@ import random
from segwit_addr import bech32_encode, decode_segwit_address, convertbits, CHARSET, Encoding
# key types
PUBKEY_ADDRESS = 0
PUBKEY_ADDRESS = 48
SCRIPT_ADDRESS = 5
SCRIPT_ADDRESS2 = 50
PUBKEY_ADDRESS_TEST = 111
SCRIPT_ADDRESS_TEST = 196
SCRIPT_ADDRESS_TEST2 = 58
PUBKEY_ADDRESS_REGTEST = 111
SCRIPT_ADDRESS_REGTEST = 196
PRIVKEY = 128
PRIVKEY = 176
PRIVKEY_TEST = 239
PRIVKEY_REGTEST = 239
@ -54,8 +56,10 @@ templates = [
# None = N/A
((PUBKEY_ADDRESS,), 20, (), (False, 'main', None, None), pubkey_prefix, pubkey_suffix),
((SCRIPT_ADDRESS,), 20, (), (False, 'main', None, None), script_prefix, script_suffix),
((SCRIPT_ADDRESS2,), 20, (), (False, 'main', None, None), script_prefix, script_suffix),
((PUBKEY_ADDRESS_TEST,), 20, (), (False, 'test', None, None), pubkey_prefix, pubkey_suffix),
((SCRIPT_ADDRESS_TEST,), 20, (), (False, 'test', None, None), script_prefix, script_suffix),
((SCRIPT_ADDRESS_TEST2,), 20, (), (False, 'test', None, None), script_prefix, script_suffix),
((PUBKEY_ADDRESS_TEST,), 20, (), (False, 'signet', None, None), pubkey_prefix, pubkey_suffix),
((SCRIPT_ADDRESS_TEST,), 20, (), (False, 'signet', None, None), script_prefix, script_suffix),
((PUBKEY_ADDRESS_REGTEST,), 20, (), (False, 'regtest', None, None), pubkey_prefix, pubkey_suffix),
@ -72,42 +76,42 @@ templates = [
# templates for valid bech32 sequences
bech32_templates = [
# hrp, version, witprog_size, metadata, encoding, output_prefix
('bc', 0, 20, (False, 'main', None, True), Encoding.BECH32, p2wpkh_prefix),
('bc', 0, 32, (False, 'main', None, True), Encoding.BECH32, p2wsh_prefix),
('bc', 1, 32, (False, 'main', None, True), Encoding.BECH32M, p2tr_prefix),
('bc', 2, 2, (False, 'main', None, True), Encoding.BECH32M, (OP_2, 2)),
('tb', 0, 20, (False, 'test', None, True), Encoding.BECH32, p2wpkh_prefix),
('tb', 0, 32, (False, 'test', None, True), Encoding.BECH32, p2wsh_prefix),
('tb', 1, 32, (False, 'test', None, True), Encoding.BECH32M, p2tr_prefix),
('tb', 3, 16, (False, 'test', None, True), Encoding.BECH32M, (OP_3, 16)),
('tb', 0, 20, (False, 'signet', None, True), Encoding.BECH32, p2wpkh_prefix),
('tb', 0, 32, (False, 'signet', None, True), Encoding.BECH32, p2wsh_prefix),
('tb', 1, 32, (False, 'signet', None, True), Encoding.BECH32M, p2tr_prefix),
('tb', 3, 32, (False, 'signet', None, True), Encoding.BECH32M, (OP_3, 32)),
('bcrt', 0, 20, (False, 'regtest', None, True), Encoding.BECH32, p2wpkh_prefix),
('bcrt', 0, 32, (False, 'regtest', None, True), Encoding.BECH32, p2wsh_prefix),
('bcrt', 1, 32, (False, 'regtest', None, True), Encoding.BECH32M, p2tr_prefix),
('bcrt', 16, 40, (False, 'regtest', None, True), Encoding.BECH32M, (OP_16, 40))
('ltc', 0, 20, (False, 'main', None, True), Encoding.BECH32, p2wpkh_prefix),
('ltc', 0, 32, (False, 'main', None, True), Encoding.BECH32, p2wsh_prefix),
('ltc', 1, 32, (False, 'main', None, True), Encoding.BECH32M, p2tr_prefix),
('ltc', 2, 2, (False, 'main', None, True), Encoding.BECH32M, (OP_2, 2)),
('tltc', 0, 20, (False, 'test', None, True), Encoding.BECH32, p2wpkh_prefix),
('tltc', 0, 32, (False, 'test', None, True), Encoding.BECH32, p2wsh_prefix),
('tltc', 1, 32, (False, 'test', None, True), Encoding.BECH32M, p2tr_prefix),
('tltc', 3, 16, (False, 'test', None, True), Encoding.BECH32M, (OP_3, 16)),
('tltc', 0, 20, (False, 'signet', None, True), Encoding.BECH32, p2wpkh_prefix),
('tltc', 0, 32, (False, 'signet', None, True), Encoding.BECH32, p2wsh_prefix),
('tltc', 1, 32, (False, 'signet', None, True), Encoding.BECH32M, p2tr_prefix),
('tltc', 3, 32, (False, 'signet', None, True), Encoding.BECH32M, (OP_3, 32)),
('rltc', 0, 20, (False, 'regtest', None, True), Encoding.BECH32, p2wpkh_prefix),
('rltc', 0, 32, (False, 'regtest', None, True), Encoding.BECH32, p2wsh_prefix),
('rltc', 1, 32, (False, 'regtest', None, True), Encoding.BECH32M, p2tr_prefix),
('rltc', 16, 40, (False, 'regtest', None, True), Encoding.BECH32M, (OP_16, 40))
]
# templates for invalid bech32 sequences
bech32_ng_templates = [
# hrp, version, witprog_size, encoding, invalid_bech32, invalid_checksum, invalid_char
('tc', 0, 20, Encoding.BECH32, False, False, False),
('bt', 1, 32, Encoding.BECH32M, False, False, False),
('tb', 17, 32, Encoding.BECH32M, False, False, False),
('bcrt', 3, 1, Encoding.BECH32M, False, False, False),
('bc', 15, 41, Encoding.BECH32M, False, False, False),
('tb', 0, 16, Encoding.BECH32, False, False, False),
('bcrt', 0, 32, Encoding.BECH32, True, False, False),
('bc', 0, 16, Encoding.BECH32, True, False, False),
('tb', 0, 32, Encoding.BECH32, False, True, False),
('bcrt', 0, 20, Encoding.BECH32, False, False, True),
('bc', 0, 20, Encoding.BECH32M, False, False, False),
('tb', 0, 32, Encoding.BECH32M, False, False, False),
('bcrt', 0, 20, Encoding.BECH32M, False, False, False),
('bc', 1, 32, Encoding.BECH32, False, False, False),
('tb', 2, 16, Encoding.BECH32, False, False, False),
('bcrt', 16, 20, Encoding.BECH32, False, False, False),
('tltc', 17, 32, Encoding.BECH32M, False, False, False),
('rltc', 3, 1, Encoding.BECH32M, False, False, False),
('ltc', 15, 41, Encoding.BECH32M, False, False, False),
('tltc', 0, 16, Encoding.BECH32, False, False, False),
('rltc', 0, 32, Encoding.BECH32, True, False, False),
('ltc', 0, 16, Encoding.BECH32, True, False, False),
('tltc', 0, 32, Encoding.BECH32, False, True, False),
('rltc', 0, 20, Encoding.BECH32, False, False, True),
('ltc', 0, 20, Encoding.BECH32M, False, False, False),
('tltc', 0, 32, Encoding.BECH32M, False, False, False),
('rltc', 0, 20, Encoding.BECH32M, False, False, False),
('ltc', 1, 32, Encoding.BECH32, False, False, False),
('tltc', 2, 16, Encoding.BECH32, False, False, False),
('rltc', 16, 20, Encoding.BECH32, False, False, False),
]
def is_valid(v):
@ -127,7 +131,7 @@ def is_valid(v):
def is_valid_bech32(v):
'''Check vector v for bech32 validity'''
for hrp in ['bc', 'tb', 'bcrt']:
for hrp in ['ltc', 'tltc', 'rltc']:
if decode_segwit_address(hrp, v) != (None, None):
return True
return False

@ -42,7 +42,7 @@ class DeriveaddressesTest(BitcoinTestFramework):
assert_raises_rpc_error(-8, "Range should be greater or equal than 0", self.nodes[0].deriveaddresses, descsum_create("wpkh(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/1/*)"), [-1, 0])
combo_descriptor = descsum_create("combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/1/0)")
assert_equal(self.nodes[0].deriveaddresses(combo_descriptor), ["mtfUoUax9L4tzXARpw1oTGxWyoogp52KhJ", "mtfUoUax9L4tzXARpw1oTGxWyoogp52KhJ", address, "2NDvEwGfpEqJWfybzpKPHF2XH3jwoQV3D7x"])
assert_equal(self.nodes[0].deriveaddresses(combo_descriptor), ["mtfUoUax9L4tzXARpw1oTGxWyoogp52KhJ", "mtfUoUax9L4tzXARpw1oTGxWyoogp52KhJ", address, "QhH14HY4FwMbpAN3SRRJKixiC8PdFg8qpP"])
hardened_without_privkey_descriptor = descsum_create("wpkh(tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1'/1/0)")
assert_raises_rpc_error(-5, "Cannot derive script without private keys", self.nodes[0].deriveaddresses, hardened_without_privkey_descriptor)

@ -70,7 +70,7 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
if addr.startswith('m') or addr.startswith('n'):
# P2PKH address
found_legacy_addr += 1
elif addr.startswith('2'):
elif addr.startswith('Q'):
# P2SH-segwit address
found_p2sh_segwit_addr += 1
elif addr.startswith('rltc1'):

@ -16,8 +16,8 @@ from test_framework.util import (
class ScriptAddress2Test(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 3
self.setup_clean_chain = False
self.extra_args = [['-addresstype=legacy', '-deprecatedrpc=accounts'], [], []]
self.setup_clean_chain = True
self.extra_args = [['-addresstype=legacy', '-deprecatedrpc=accounts', '-txindex=1'], [], ['-txindex=1']]
def setup_network(self, split=False):
self.setup_nodes()
@ -45,19 +45,19 @@ class ScriptAddress2Test(BitcoinTestFramework):
# Send to a new multisig address
txid = self.nodes[1].sendtoaddress(multisig_addr, 1)
self.nodes[1].generate(3)
self.nodes[1].generate(101)
self.sync_all()
tx = self.nodes[2].getrawtransaction(txid, 1)
tx = self.nodes[0].getrawtransaction(txid, 1)
dest_addrs = [tx["vout"][0]['scriptPubKey']['addresses'][0],
tx["vout"][1]['scriptPubKey']['addresses'][0]]
assert(multisig_addr in dest_addrs)
# Spend from the new multisig address
addr3 = self.nodes[1].getnewaddress()
txid = self.nodes[0].sendfrom("multisigaccount", addr3, 0.8)
txid = self.nodes[0].sendtoaddress(addr3, 0.8)
self.nodes[0].generate(2)
self.sync_all()
assert(self.nodes[0].getbalance("multisigaccount", 1) < 0.2)
assert(self.nodes[0].getbalance("*", 1) < 0.2)
assert(self.nodes[1].listtransactions()[-1]['address'] == addr3)
# Send to an old multisig address. The api addmultisigaddress
@ -91,10 +91,10 @@ class ScriptAddress2Test(BitcoinTestFramework):
# Spend from the new multisig address
addr4 = self.nodes[1].getnewaddress()
txid = self.nodes[0].sendfrom("multisigaccount2", addr4, 0.8)
txid = self.nodes[0].sendtoaddress(addr4, 0.8)
self.nodes[0].generate(2)
self.sync_all()
assert(self.nodes[0].getbalance("multisigaccount2", 1) < 0.2)
assert(self.nodes[0].getbalance("*", 1) < 0.4)
assert(self.nodes[1].listtransactions()[-1]['address'] == addr4)
if __name__ == '__main__':

Loading…
Cancel
Save