Periodic scheduler (configurable round duration) that closes a round only once all broadcast bets confirm, waits for the next block after closing, draws a winner via block-hash-seeded modulo over participants ordered by broadcast time, triggers the 70/30 payout, and only opens the next round once that payout confirms. Draw logic is isolated in draw.py as a deliberately simple, replaceable component. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
import pytest
|
|
|
|
from app.rounds.draw import draw_winner, header_hex_to_block_hash
|
|
|
|
|
|
def test_header_hex_to_block_hash_matches_known_mainnet_block():
|
|
# Real PLM mainnet block 477486: header from blockchain.block.header, hash
|
|
# cross-checked against the blockhash reported by blockchain.transaction.get
|
|
# for a tx confirmed in that block.
|
|
header_hex = (
|
|
"0020ed30fbc39ee45200d10214f5107c5f36e7bf753032fd1d3279810c170000000000"
|
|
"009a4ea723f732be4c538f3a2490837dd6560103d73ece606aa7d578a66700447b28875"
|
|
"e6a47a61b1ad8012582"
|
|
)
|
|
known_block_hash = "00000000000008788b55ade13b74d54ceffda9e54315b802411be1ca65064e86"
|
|
assert header_hex_to_block_hash(header_hex) == known_block_hash
|
|
|
|
|
|
def test_draw_winner_is_deterministic_and_within_range():
|
|
participants = ["addrA", "addrB", "addrC"]
|
|
block_hash = "00" * 31 + "05" # seed = 5, index = 5 % 3 = 2
|
|
assert draw_winner(participants, block_hash) == "addrC"
|
|
|
|
|
|
def test_draw_winner_single_participant_always_wins():
|
|
block_hash = "ff" * 32
|
|
assert draw_winner(["only"], block_hash) == "only"
|
|
|
|
|
|
def test_draw_winner_raises_on_empty_participants():
|
|
with pytest.raises(ValueError):
|
|
draw_winner([], "00" * 32)
|