B1: plm_engine takes the modules without a database (ADR-59)
HD derivation (pure part), PSBT builder, Electrum client/merkle/quorum/scripthash, network profile, addresses and header checks move to plm_engine; the old stack imports them from there. A test forbids framework imports in the package. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c9784efa07
commit
3ee60a23da
87 files changed
+290
-260
No files matched your search
+12
-12
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
|
||||
from app.rounds.draw import (
|
||||
draw_winner,
|
||||
from plm_engine.draw import draw_winner
|
||||
from plm_engine.headers import (
|
||||
header_hex_to_block_hash,
|
||||
header_meets_its_own_target,
|
||||
header_prev_hash,
|
||||
@@ -58,7 +58,7 @@ def test_draw_seed_is_the_sha256_of_the_three_32_byte_values_read_big_endian():
|
||||
"""RND-17: the algorithm, written out here independently of the code under test."""
|
||||
import hashlib
|
||||
|
||||
from app.rounds.draw import draw_seed
|
||||
from plm_engine.draw import draw_seed
|
||||
|
||||
expected = int.from_bytes(
|
||||
hashlib.sha256(bytes.fromhex(_SEED) + bytes.fromhex(_BLOCK) + bytes.fromhex(_LIST_HASH)).digest(), "big"
|
||||
@@ -67,7 +67,7 @@ def test_draw_seed_is_the_sha256_of_the_three_32_byte_values_read_big_endian():
|
||||
|
||||
|
||||
def test_draw_seed_depends_on_all_three_inputs():
|
||||
from app.rounds.draw import draw_seed
|
||||
from plm_engine.draw import draw_seed
|
||||
|
||||
base = draw_seed(_SEED, _BLOCK, _LIST_HASH)
|
||||
assert draw_seed("12" * 32, _BLOCK, _LIST_HASH) != base # without the secret nobody can predict it
|
||||
@@ -76,7 +76,7 @@ def test_draw_seed_depends_on_all_three_inputs():
|
||||
|
||||
|
||||
def test_draw_winner_is_deterministic_and_within_range():
|
||||
from app.rounds.draw import draw_index, draw_seed
|
||||
from plm_engine.draw import draw_index, draw_seed
|
||||
|
||||
participants = ["addrA", "addrB", "addrC"]
|
||||
winner = draw_winner(participants, _SEED, _BLOCK, _LIST_HASH)
|
||||
@@ -99,7 +99,7 @@ def test_equal_odds_every_position_can_win():
|
||||
over 0..n-1 (checked over many seeds, not exactly)."""
|
||||
from collections import Counter
|
||||
|
||||
from app.rounds.draw import draw_index, draw_seed
|
||||
from plm_engine.draw import draw_index, draw_seed
|
||||
|
||||
wins = Counter(draw_index(draw_seed(f"{i:064x}", _BLOCK, _LIST_HASH), 4) for i in range(2000))
|
||||
assert set(wins) == {0, 1, 2, 3}
|
||||
@@ -109,13 +109,13 @@ def test_equal_odds_every_position_can_win():
|
||||
def test_server_seed_commitment_is_sha256_of_the_32_bytes():
|
||||
import hashlib
|
||||
|
||||
from app.rounds.draw import server_seed_commitment
|
||||
from plm_engine.draw import server_seed_commitment
|
||||
|
||||
assert server_seed_commitment(_SEED) == hashlib.sha256(bytes.fromhex(_SEED)).hexdigest()
|
||||
|
||||
|
||||
def test_new_server_seeds_are_32_random_bytes_in_hex():
|
||||
from app.rounds.draw import new_server_seed
|
||||
from plm_engine.draw import new_server_seed
|
||||
|
||||
seeds = {new_server_seed() for _ in range(20)}
|
||||
assert len(seeds) == 20
|
||||
@@ -126,7 +126,7 @@ def test_participants_hash_encodes_one_txid_vout_address_line_per_participant():
|
||||
"""RND-14: sha256 of `txid:vout:address\n` lines in draw_position order, UTF-8."""
|
||||
import hashlib
|
||||
|
||||
from app.rounds.draw import participants_hash
|
||||
from plm_engine.draw import participants_hash
|
||||
|
||||
rows = [("aa" * 32, 0, "plm1qfirst"), ("bb" * 32, 1, "plm1qsecond")]
|
||||
text = f"{'aa' * 32}:0:plm1qfirst\n{'bb' * 32}:1:plm1qsecond\n"
|
||||
@@ -139,7 +139,7 @@ def test_participants_hash_encodes_one_txid_vout_address_line_per_participant():
|
||||
|
||||
def test_pow_limit_is_the_mainnet_constant():
|
||||
"""B-74, ELC-11: PLM mainnet's `consensus.powLimit`, 00000000ffff…ffff."""
|
||||
from app.rounds import draw
|
||||
from plm_engine import headers as draw
|
||||
|
||||
assert draw.MAINNET_POW_LIMIT == int("00000000" + "ff" * 28, 16)
|
||||
assert draw.MAINNET_POW_LIMIT == (1 << 224) - 1
|
||||
@@ -152,7 +152,7 @@ def test_a_header_below_the_pow_limit_is_rejected_even_if_it_meets_its_own_targe
|
||||
powLimit in force it is rejected however its hash falls."""
|
||||
import struct
|
||||
|
||||
from app.rounds import draw
|
||||
from plm_engine import headers as draw
|
||||
|
||||
def build(nonce: int) -> str:
|
||||
return (
|
||||
@@ -167,7 +167,7 @@ def test_a_header_below_the_pow_limit_is_rejected_even_if_it_meets_its_own_targe
|
||||
|
||||
|
||||
def test_a_real_mainnet_header_passes_with_the_mainnet_pow_limit(monkeypatch):
|
||||
from app.rounds import draw
|
||||
from plm_engine import headers as draw
|
||||
|
||||
monkeypatch.setattr(draw, "POW_LIMIT", draw.MAINNET_POW_LIMIT)
|
||||
assert header_meets_its_own_target(_REAL_HEADER_HEX) is True
|
||||
Reference in new issue
Block a user