Merge bitcoin/bitcoin#23312: tests: reduce feature_segwit.py usage of the legacy wallet
e9ade032f3tests: Add feature_segwit.py --descriptors to test_runner.py (Andrew Chow)ae6cbcc909tests: restrict feature_segwit legacy wallet import tests (Andrew Chow)1d13c44a4ctests: Use descriptors for feature_segwit multisig setup (Andrew Chow) Pull request description: `feature_segwit.py` has tests for some legacy wallet behavior, but otherwise does not really need the legacy wallet. Those parts now require `--legacy-wallet` to be provided (as with other legacy wallet tests). Other parts of the test are changed to work with descriptor wallets as well. ACKs for top commit: lsilva01: tACKe9ade03Tree-SHA512: 4ae76a4d2a8d318e7f8ad4c984748e3cdd67ed00359fcd798a08492ed9399b1d01be88c9ebea3d6c996fbe190cf41708a15c98f088f0cb5c47d6d00fff258944
This commit is contained in:
2 files changed
+36
-4
No files matched your search
@@ -17,6 +17,7 @@ from test_framework.blocktools import (
|
|||||||
send_to_witness,
|
send_to_witness,
|
||||||
witness_script,
|
witness_script,
|
||||||
)
|
)
|
||||||
|
from test_framework.descriptors import descsum_create
|
||||||
from test_framework.messages import (
|
from test_framework.messages import (
|
||||||
COIN,
|
COIN,
|
||||||
COutPoint,
|
COutPoint,
|
||||||
@@ -49,6 +50,9 @@ from test_framework.util import (
|
|||||||
assert_raises_rpc_error,
|
assert_raises_rpc_error,
|
||||||
try_rpc,
|
try_rpc,
|
||||||
)
|
)
|
||||||
|
from test_framework.wallet_util import (
|
||||||
|
get_generate_key,
|
||||||
|
)
|
||||||
|
|
||||||
NODE_0 = 0
|
NODE_0 = 0
|
||||||
NODE_2 = 2
|
NODE_2 = 2
|
||||||
@@ -142,13 +146,39 @@ class SegWitTest(BitcoinTestFramework):
|
|||||||
p2sh_ids = [] # p2sh_ids[NODE][TYPE] is an array of txids that spend to P2WPKH (TYPE=0) or P2WSH (TYPE=1) scripts to an address for NODE embedded in p2sh
|
p2sh_ids = [] # p2sh_ids[NODE][TYPE] is an array of txids that spend to P2WPKH (TYPE=0) or P2WSH (TYPE=1) scripts to an address for NODE embedded in p2sh
|
||||||
wit_ids = [] # wit_ids[NODE][TYPE] is an array of txids that spend to P2WPKH (TYPE=0) or P2WSH (TYPE=1) scripts to an address for NODE via bare witness
|
wit_ids = [] # wit_ids[NODE][TYPE] is an array of txids that spend to P2WPKH (TYPE=0) or P2WSH (TYPE=1) scripts to an address for NODE via bare witness
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
newaddress = self.nodes[i].getnewaddress()
|
key = get_generate_key()
|
||||||
self.pubkey.append(self.nodes[i].getaddressinfo(newaddress)["pubkey"])
|
self.pubkey.append(key.pubkey)
|
||||||
|
|
||||||
multiscript = CScript([OP_1, bytes.fromhex(self.pubkey[-1]), OP_1, OP_CHECKMULTISIG])
|
multiscript = CScript([OP_1, bytes.fromhex(self.pubkey[-1]), OP_1, OP_CHECKMULTISIG])
|
||||||
p2sh_ms_addr = self.nodes[i].addmultisigaddress(1, [self.pubkey[-1]], '', 'p2sh-segwit')['address']
|
p2sh_ms_addr = self.nodes[i].createmultisig(1, [self.pubkey[-1]], 'p2sh-segwit')['address']
|
||||||
bip173_ms_addr = self.nodes[i].addmultisigaddress(1, [self.pubkey[-1]], '', 'bech32')['address']
|
bip173_ms_addr = self.nodes[i].createmultisig(1, [self.pubkey[-1]], 'bech32')['address']
|
||||||
assert_equal(p2sh_ms_addr, script_to_p2sh_p2wsh(multiscript))
|
assert_equal(p2sh_ms_addr, script_to_p2sh_p2wsh(multiscript))
|
||||||
assert_equal(bip173_ms_addr, script_to_p2wsh(multiscript))
|
assert_equal(bip173_ms_addr, script_to_p2wsh(multiscript))
|
||||||
|
|
||||||
|
p2sh_ms_desc = descsum_create(f"sh(wsh(multi(1,{key.privkey})))")
|
||||||
|
bip173_ms_desc = descsum_create(f"wsh(multi(1,{key.privkey}))")
|
||||||
|
assert_equal(self.nodes[i].deriveaddresses(p2sh_ms_desc)[0], p2sh_ms_addr)
|
||||||
|
assert_equal(self.nodes[i].deriveaddresses(bip173_ms_desc)[0], bip173_ms_addr)
|
||||||
|
|
||||||
|
sh_wpkh_desc = descsum_create(f"sh(wpkh({key.privkey}))")
|
||||||
|
wpkh_desc = descsum_create(f"wpkh({key.privkey})")
|
||||||
|
assert_equal(self.nodes[i].deriveaddresses(sh_wpkh_desc)[0], key.p2sh_p2wpkh_addr)
|
||||||
|
assert_equal(self.nodes[i].deriveaddresses(wpkh_desc)[0], key.p2wpkh_addr)
|
||||||
|
|
||||||
|
if self.options.descriptors:
|
||||||
|
res = self.nodes[i].importdescriptors([
|
||||||
|
{"desc": p2sh_ms_desc, "timestamp": "now"},
|
||||||
|
{"desc": bip173_ms_desc, "timestamp": "now"},
|
||||||
|
{"desc": sh_wpkh_desc, "timestamp": "now"},
|
||||||
|
{"desc": wpkh_desc, "timestamp": "now"},
|
||||||
|
])
|
||||||
|
else:
|
||||||
|
# The nature of the legacy wallet is that this import results in also adding all of the necessary scripts
|
||||||
|
res = self.nodes[i].importmulti([
|
||||||
|
{"desc": p2sh_ms_desc, "timestamp": "now"},
|
||||||
|
])
|
||||||
|
assert all([r["success"] for r in res])
|
||||||
|
|
||||||
p2sh_ids.append([])
|
p2sh_ids.append([])
|
||||||
wit_ids.append([])
|
wit_ids.append([])
|
||||||
for _ in range(2):
|
for _ in range(2):
|
||||||
@@ -311,6 +341,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||||||
# Mine a block to clear the gbt cache again.
|
# Mine a block to clear the gbt cache again.
|
||||||
self.generate(self.nodes[0], 1)
|
self.generate(self.nodes[0], 1)
|
||||||
|
|
||||||
|
if not self.options.descriptors:
|
||||||
self.log.info("Verify behaviour of importaddress and listunspent")
|
self.log.info("Verify behaviour of importaddress and listunspent")
|
||||||
|
|
||||||
# Some public keys to be used later
|
# Some public keys to be used later
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ BASE_SCRIPTS = [
|
|||||||
'p2p_compactblocks.py',
|
'p2p_compactblocks.py',
|
||||||
'p2p_compactblocks_blocksonly.py',
|
'p2p_compactblocks_blocksonly.py',
|
||||||
'feature_segwit.py --legacy-wallet',
|
'feature_segwit.py --legacy-wallet',
|
||||||
|
'feature_segwit.py --descriptors',
|
||||||
# vv Tests less than 2m vv
|
# vv Tests less than 2m vv
|
||||||
'wallet_basic.py --legacy-wallet',
|
'wallet_basic.py --legacy-wallet',
|
||||||
'wallet_basic.py --descriptors',
|
'wallet_basic.py --descriptors',
|
||||||
|
|||||||
Reference in new issue
Block a user