2019-04-25 09:44:00 +02:00
|
|
|
#!/usr/bin/env python3
|
2022-12-25 00:49:50 +01:00
|
|
|
# Copyright (c) 2019-2022 The Bitcoin Core developers
|
2019-04-25 09:44:00 +02:00
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
"""Test the wallet implicit segwit feature."""
|
|
|
|
|
|
|
|
import test_framework.address as address
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
|
|
|
|
|
|
# TODO: Might be nice to test p2pk here too
|
|
|
|
address_types = ('legacy', 'bech32', 'p2sh-segwit')
|
|
|
|
|
|
|
|
def key_to_address(key, address_type):
|
|
|
|
if address_type == 'legacy':
|
|
|
|
return address.key_to_p2pkh(key)
|
|
|
|
elif address_type == 'p2sh-segwit':
|
|
|
|
return address.key_to_p2sh_p2wpkh(key)
|
|
|
|
elif address_type == 'bech32':
|
|
|
|
return address.key_to_p2wpkh(key)
|
|
|
|
|
|
|
|
def send_a_to_b(receive_node, send_node):
|
|
|
|
keys = {}
|
|
|
|
for a in address_types:
|
|
|
|
a_address = receive_node.getnewaddress(address_type=a)
|
|
|
|
pubkey = receive_node.getaddressinfo(a_address)['pubkey']
|
|
|
|
keys[a] = pubkey
|
|
|
|
for b in address_types:
|
|
|
|
b_address = key_to_address(pubkey, b)
|
|
|
|
send_node.sendtoaddress(address=b_address, amount=1)
|
|
|
|
return keys
|
|
|
|
|
|
|
|
def check_implicit_transactions(implicit_keys, implicit_node):
|
|
|
|
# The implicit segwit node allows conversion all possible ways
|
|
|
|
txs = implicit_node.listtransactions(None, 99999)
|
|
|
|
for a in address_types:
|
|
|
|
pubkey = implicit_keys[a]
|
|
|
|
for b in address_types:
|
|
|
|
b_address = key_to_address(pubkey, b)
|
2022-10-04 15:18:42 +02:00
|
|
|
assert ('receive', b_address) in tuple((tx['category'], tx['address']) for tx in txs)
|
2019-04-25 09:44:00 +02:00
|
|
|
|
|
|
|
class ImplicitSegwitTest(BitcoinTestFramework):
|
2022-11-09 12:53:13 +01:00
|
|
|
def add_options(self, parser):
|
|
|
|
self.add_wallet_options(parser, descriptors=False)
|
|
|
|
|
2019-04-25 09:44:00 +02:00
|
|
|
def set_test_params(self):
|
|
|
|
self.num_nodes = 2
|
2019-12-06 15:37:49 +01:00
|
|
|
self.supports_cli = False
|
2019-04-25 09:44:00 +02:00
|
|
|
|
|
|
|
def skip_test_if_missing_module(self):
|
|
|
|
self.skip_if_no_wallet()
|
|
|
|
|
|
|
|
def run_test(self):
|
|
|
|
self.log.info("Manipulating addresses and sending transactions to all variations")
|
|
|
|
implicit_keys = send_a_to_b(self.nodes[0], self.nodes[1])
|
|
|
|
|
|
|
|
self.sync_all()
|
|
|
|
|
|
|
|
self.log.info("Checking that transactions show up correctly without a restart")
|
|
|
|
check_implicit_transactions(implicit_keys, self.nodes[0])
|
|
|
|
|
|
|
|
self.log.info("Checking that transactions still show up correctly after a restart")
|
|
|
|
self.restart_node(0)
|
|
|
|
self.restart_node(1)
|
|
|
|
|
|
|
|
check_implicit_transactions(implicit_keys, self.nodes[0])
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2024-07-16 23:05:14 +02:00
|
|
|
ImplicitSegwitTest(__file__).main()
|