Skip to content

Commit 6a7c40b

Browse files
author
MarcoFalke
committed
Merge #15888: QA: Add wallet_implicitsegwit to test the ability to transform keys between address types
a6f6f77 QA: Add wallet_implicitsegwit to test the ability to transform keys between address types (Luke Dashjr) Pull request description: This makes sure the wallet recognises payments to keys via address types they weren't created with. While we don't *want* this behaviour, it might make sense to explicitly test that it works until we remove it. ACKs for top commit: adamjonas: utACK a6f6f77 Tree-SHA512: b208405729277e9ce06eb772b45e8d1683c4dc5703754448b8f19a590b37522abd7bb46d4dbd41513b3d46d7f9e8769ce4f15fa4114be600f31a1ebbc1157840
2 parents 0e6cae0 + a6f6f77 commit 6a7c40b

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
'mining_basic.py',
182182
'wallet_bumpfee.py',
183183
'wallet_bumpfee_totalfee_deprecation.py',
184+
'wallet_implicitsegwit.py',
184185
'rpc_named_arguments.py',
185186
'wallet_listsinceblock.py',
186187
'p2p_leak.py',
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2019 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+
"""Test the wallet implicit segwit feature."""
6+
7+
import test_framework.address as address
8+
from test_framework.test_framework import BitcoinTestFramework
9+
10+
# TODO: Might be nice to test p2pk here too
11+
address_types = ('legacy', 'bech32', 'p2sh-segwit')
12+
13+
def key_to_address(key, address_type):
14+
if address_type == 'legacy':
15+
return address.key_to_p2pkh(key)
16+
elif address_type == 'p2sh-segwit':
17+
return address.key_to_p2sh_p2wpkh(key)
18+
elif address_type == 'bech32':
19+
return address.key_to_p2wpkh(key)
20+
21+
def send_a_to_b(receive_node, send_node):
22+
keys = {}
23+
for a in address_types:
24+
a_address = receive_node.getnewaddress(address_type=a)
25+
pubkey = receive_node.getaddressinfo(a_address)['pubkey']
26+
keys[a] = pubkey
27+
for b in address_types:
28+
b_address = key_to_address(pubkey, b)
29+
send_node.sendtoaddress(address=b_address, amount=1)
30+
return keys
31+
32+
def check_implicit_transactions(implicit_keys, implicit_node):
33+
# The implicit segwit node allows conversion all possible ways
34+
txs = implicit_node.listtransactions(None, 99999)
35+
for a in address_types:
36+
pubkey = implicit_keys[a]
37+
for b in address_types:
38+
b_address = key_to_address(pubkey, b)
39+
assert(('receive', b_address) in tuple((tx['category'], tx['address']) for tx in txs))
40+
41+
class ImplicitSegwitTest(BitcoinTestFramework):
42+
def set_test_params(self):
43+
self.num_nodes = 2
44+
45+
def skip_test_if_missing_module(self):
46+
self.skip_if_no_wallet()
47+
48+
def run_test(self):
49+
self.log.info("Manipulating addresses and sending transactions to all variations")
50+
implicit_keys = send_a_to_b(self.nodes[0], self.nodes[1])
51+
52+
self.sync_all()
53+
54+
self.log.info("Checking that transactions show up correctly without a restart")
55+
check_implicit_transactions(implicit_keys, self.nodes[0])
56+
57+
self.log.info("Checking that transactions still show up correctly after a restart")
58+
self.restart_node(0)
59+
self.restart_node(1)
60+
61+
check_implicit_transactions(implicit_keys, self.nodes[0])
62+
63+
if __name__ == '__main__':
64+
ImplicitSegwitTest().main()

0 commit comments

Comments
 (0)