Adapt test framework to Palladium consensus rules

This commit is contained in:
2026-02-05 13:29:25 +01:00
parent f94645004a
commit ba4446842d
4 changed files with 37 additions and 21 deletions

View File

@@ -11,10 +11,10 @@ from .util import hex_str_to_bytes
from . import segwit_addr from . import segwit_addr
ADDRESS_BCRT1_UNSPENDABLE = 'bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3xueyj' ADDRESS_BCRT1_UNSPENDABLE = 'rplm1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqaggqfu'
ADDRESS_BCRT1_UNSPENDABLE_DESCRIPTOR = 'addr(bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3xueyj)#juyq9d97' ADDRESS_BCRT1_UNSPENDABLE_DESCRIPTOR = 'addr(rplm1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqaggqfu)#vxcupvkx'
# Coins sent to this address can be spent with a witness stack of just OP_TRUE # Coins sent to this address can be spent with a witness stack of just OP_TRUE
ADDRESS_BCRT1_P2WSH_OP_TRUE = 'bcrt1qft5p2uhsdcdc3l2ua4ap5qqfg4pjaqlp250x7us7a8qqhrxrxfsqseac85' ADDRESS_BCRT1_P2WSH_OP_TRUE = 'rplm1qft5p2uhsdcdc3l2ua4ap5qqfg4pjaqlp250x7us7a8qqhrxrxfsquhfp26'
class AddressType(enum.Enum): class AddressType(enum.Enum):
@@ -45,12 +45,12 @@ def byte_to_base58(b, version):
def keyhash_to_p2pkh(hash, main = False): def keyhash_to_p2pkh(hash, main = False):
assert len(hash) == 20 assert len(hash) == 20
version = 0 if main else 111 version = 55 if main else 127
return byte_to_base58(hash, version) return byte_to_base58(hash, version)
def scripthash_to_p2sh(hash, main = False): def scripthash_to_p2sh(hash, main = False):
assert len(hash) == 20 assert len(hash) == 20
version = 5 if main else 196 version = 5 if main else 115
return byte_to_base58(hash, version) return byte_to_base58(hash, version)
def key_to_p2pkh(key, main = False): def key_to_p2pkh(key, main = False):
@@ -72,7 +72,7 @@ def program_to_witness(version, program, main = False):
assert 0 <= version <= 16 assert 0 <= version <= 16
assert 2 <= len(program) <= 40 assert 2 <= len(program) <= 40
assert version > 0 or len(program) in [20, 32] assert version > 0 or len(program) in [20, 32]
return segwit_addr.encode("bc" if main else "bcrt", version, program) return segwit_addr.encode("plm" if main else "rplm", version, program)
def script_to_p2wsh(script, main = False): def script_to_p2wsh(script, main = False):
script = check_script(script) script = check_script(script)

View File

@@ -22,6 +22,7 @@ from . import coverage
from .test_node import TestNode from .test_node import TestNode
from .mininode import NetworkThread from .mininode import NetworkThread
from .util import ( from .util import (
COINBASE_MATURITY,
MAX_NODES, MAX_NODES,
PortSeed, PortSeed,
assert_equal, assert_equal,
@@ -340,8 +341,9 @@ class PalladiumTestFramework(metaclass=PalladiumTestMetaClass):
self.start_nodes() self.start_nodes()
self.import_deterministic_coinbase_privkeys() self.import_deterministic_coinbase_privkeys()
if not self.setup_clean_chain: if not self.setup_clean_chain:
target_blocks = max(199, COINBASE_MATURITY + 99)
for n in self.nodes: for n in self.nodes:
assert_equal(n.getblockchaininfo()["blocks"], 199) assert_equal(n.getblockchaininfo()["blocks"], target_blocks)
# To ensure that all nodes are out of IBD, the most recent block # To ensure that all nodes are out of IBD, the most recent block
# must have a timestamp not too old (see IsInitialBlockDownload()). # must have a timestamp not too old (see IsInitialBlockDownload()).
self.log.debug('Generate a block with current time') self.log.debug('Generate a block with current time')
@@ -350,7 +352,7 @@ class PalladiumTestFramework(metaclass=PalladiumTestMetaClass):
for n in self.nodes: for n in self.nodes:
n.submitblock(block) n.submitblock(block)
chain_info = n.getblockchaininfo() chain_info = n.getblockchaininfo()
assert_equal(chain_info["blocks"], 200) assert_equal(chain_info["blocks"], target_blocks + 1)
assert_equal(chain_info["initialblockdownload"], False) assert_equal(chain_info["initialblockdownload"], False)
def import_deterministic_coinbase_privkeys(self): def import_deterministic_coinbase_privkeys(self):
@@ -567,6 +569,17 @@ class PalladiumTestFramework(metaclass=PalladiumTestMetaClass):
assert_equal(self.nodes[CACHE_NODE_ID].getblockchaininfo()["blocks"], 199) assert_equal(self.nodes[CACHE_NODE_ID].getblockchaininfo()["blocks"], 199)
# Ensure enough blocks for 25 mature coinbase outputs per node with
# the current COINBASE_MATURITY.
target_blocks = COINBASE_MATURITY + 99
current_blocks = self.nodes[CACHE_NODE_ID].getblockchaininfo()["blocks"]
if current_blocks < target_blocks:
self.nodes[CACHE_NODE_ID].generatetoaddress(
nblocks=target_blocks - current_blocks,
address=TestNode.PRIV_KEYS[0].address,
)
assert_equal(self.nodes[CACHE_NODE_ID].getblockchaininfo()["blocks"], target_blocks)
# Shut it down, and clean up cache directories: # Shut it down, and clean up cache directories:
self.stop_nodes() self.stop_nodes()
self.nodes = [] self.nodes = []

View File

@@ -129,18 +129,18 @@ class TestNode():
AddressKeyPair = collections.namedtuple('AddressKeyPair', ['address', 'key']) AddressKeyPair = collections.namedtuple('AddressKeyPair', ['address', 'key'])
PRIV_KEYS = [ PRIV_KEYS = [
# address , privkey # address , privkey
AddressKeyPair('mjTkW3DjgyZck4KbiRusZsqTgaYTxdSz6z', 'cVpF924EspNh8KjYsfhgY96mmxvT6DgdWiTYMtMjuM74hJaU5psW'), AddressKeyPair('tAsQFmzM3rydpzYz79EyKtC3kefZPwJ22b', 'es6LHbpdgH2tibwqit1yGvcZkv8tSv2G7nRdK9uFm1ATCbkfhTsC'),
AddressKeyPair('msX6jQXvxiNhx3Q62PKeLPrhrqZQdSimTg', 'cUxsWyKyZ9MAQTaAhUQWJmBbSvHMwSmuv59KgxQV7oZQU3PXN3KE'), AddressKeyPair('tJvkV9JYKbnj2ydUR6ek6QDHvugVyvrFTe', 'erExfZ6NMc1MzjnTYgio3YhPRsVoJ97YX97QeDwzyTcnyLZTYrRj'),
AddressKeyPair('mnonCMyH9TmAsSj3M59DsbH8H63U3RKoFP', 'cTrh7dkEAeJd6b3MRX9bZK8eRmNqVCMH3LSUkE3dSFDyzjU38QxK'), AddressKeyPair('tEDRx6jtWMBBxNxRjnUKdbdiMAAZTfqoK3', 'eq8nGDWcy6xpgsFeGjTtJ6eSQibGqtgueQQZhVb9HuHNW2cvHy91'),
AddressKeyPair('mqJupas8Dt2uestQDvV2NH3RU8uZh2dqQR', 'cVuKKa7gbehEQvVq717hYcbE9Dqmq7KEBKqWgWrYBa2CKKrhtRim'), AddressKeyPair('tGiZaKdjamSvjp7ncdp88HQ1YD2f1C77T4', 'esBQU9t5Q7MS1Ci7xDRzHQ728B4DBoernPobdnQ43E5apd6ZWLD4'),
AddressKeyPair('msYac7Rvd5ywm6pEmkjyxhbCDKqWsVeYws', 'cQDCBuKcjanpXDpCqacNSjYfxeQj8G6CAtH1Dsk3cXyqLNC4RPuh'), AddressKeyPair('tJxEMrCXyyPxr33dAU55ihwnHPxcLZT1Zc', 'emVHLV61Y3T27W2VgnvfBX4TwbdAUxRpmxF6B9HZUC3DqfQ3YdYj'),
AddressKeyPair('n2rnuUnwLgXqf9kk2kjvVm8R5BZK1yxQBi', 'cQakmfPSLSqKHyMFGwAqKHgWUiofJCagVGhiB4KCainaeCSxeyYq'), AddressKeyPair('tUGSfDZYhZwrk5z8RU52FmV19FgQQzooLk', 'emrqvF9q8uVWtFZY89V845CJTg26etvK6Lfo8KriSNqy9Vde1ffx'),
AddressKeyPair('myzuPxRwsf3vvGzEuzPfK9Nf2RfwauwYe6', 'cQMpDLJwA8DBe9NcQbdoSb1BhmFxVjWD5gRyrLZCtpuF9Zi3a9RK'), AddressKeyPair('tRQZ9hCZEYTx1DDdJhim59jF6Vo2xoVGxU', 'emduMv5KxasPERauFox6BNWygiUPrRqqgkQ4oc6ikUxdervBtscg'),
AddressKeyPair('mumwTaMtbxEPUswmLBBN3vM9oGRtGBrys8', 'cSXmRKXVcoouhNNVpcNKFfxsTsToY5pvB9DVsFksF1ENunTzRKsy'), AddressKeyPair('tMBbDK8VxqeQZpB9itWTovhjsLYygD7aoj', 'eoorZuHtRGU7HeanfpgbzTUfSpgEtnAYnDBapXJP6fHmR5hFSSVJ'),
AddressKeyPair('mpV7aGShMkJCZgbW7F6iZgrvuPHjZjH9qg', 'cSoXt6tm3pqy43UMabY6eUTmR3eSUYFtB2iNQDGgb3VUnRsQys2k'), AddressKeyPair('tFtmL1DJidiDecptVxRpKhDWyTQq1kpKC2', 'ep5d2gf9rHWAeKgeRorPPFyZPzrsqEbWn6gTMUpCShYsHj9jdh6J'),
AddressKeyPair('mq4fBNdckGtvY2mijd9am7DRsbRB4KjUkf', 'cN55daf1HotwBAgAKWVgDcoppmUNDtQSfb7XLutTLeAgVc3u8hik'), AddressKeyPair('tGUJw7QE7AJwcy178LUgX7a1wfYGLovPCg', 'ejMAnARQ6GZ8mStTAioxxQKcoigoaak5Gf5cJBRyCJE4zuDbsZTo'),
AddressKeyPair('mpFAHDjX7KregM3rVotdXzQmkbwtbQEnZ6', 'cT7qK7g1wkYEMvKowd2ZrX1E5f6JQ7TM246UfqbCiyF7kZhorpX3'), AddressKeyPair('tFep2xW8UDGfmHHEtXDjHzmMpg4z1XutqA', 'epPvThSQkDCRxCY6nqLrbJX24cJjkonyd84Zd78iadJWFrw5QduY'),
AddressKeyPair('mzRe8QZMfGi58KyWCse2exxEFry2sfF2Y7', 'cPiRWE8KMjTRxH1MWkPerhfoHFn5iHPWVK5aPqjW8NxmdwenFinJ'), AddressKeyPair('tRqHt9Ky2A86DGCtbay8QyJpKw68EQDTqq', 'ekzWeotiAC7dYZDeMxhwbVBbGCzX4yj96P3fM7H1z32A9EsSH3gr'),
] ]
def get_deterministic_priv_key(self): def get_deterministic_priv_key(self):

View File

@@ -22,6 +22,9 @@ from io import BytesIO
logger = logging.getLogger("TestFramework.utils") logger = logging.getLogger("TestFramework.utils")
# Palladium consensus parameters for functional tests.
COINBASE_MATURITY = 120
# Assert functions # Assert functions
################## ##################
@@ -501,7 +504,7 @@ def random_transaction(nodes, amount, min_fee, fee_increment, fee_variants):
# Helper to create at least "count" utxos # Helper to create at least "count" utxos
# Pass in a fee that is sufficient for relay and mining new transactions. # Pass in a fee that is sufficient for relay and mining new transactions.
def create_confirmed_utxos(fee, node, count): def create_confirmed_utxos(fee, node, count):
to_generate = int(0.5 * count) + 101 to_generate = int(0.5 * count) + COINBASE_MATURITY + 1
while to_generate > 0: while to_generate > 0:
node.generate(min(25, to_generate)) node.generate(min(25, to_generate))
to_generate -= 25 to_generate -= 25