B6: atomic UTXO reservation, bet signed by the worker and saved before broadcast, broadcast verdicts (BET-30..33)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
davideandClaude Sonnet 5.5 committed 2026-11-16 16:18:34 +01:00
1 parent 2acd4ccd1c
commit feff993584
25 files changed
+995 -53

No files matched your search

+375
View File
@@ -0,0 +1,375 @@
"""B6 — a real bet: reservation, signing in the worker, broadcast verdicts: BET-30..BET-33, TX-20, TX-26, ARC-72, ARC-78."""
import json
import os
import subprocess
import sys
from datetime import timedelta
from pathlib import Path
from uuid import uuid4
import pytest
from django.contrib.auth import get_user_model
from django.utils import timezone
from embit.transaction import Transaction
from plm_engine.electrum.client import ElectrumEndpoint, ElectrumRpcError
from plm_engine.psbt_builder import DUST_LIMIT_SATS
from apps.lottery import bets, chain, keys, reservation
from apps.lottery.balances import balance_of
from apps.lottery.electrum_chain import ElectrumChain, Outcome, Verdict
from apps.lottery.errors import LedgerError
from apps.lottery.ledger import ChainLedger, get_ledger
from apps.lottery.models import (
AuditEntry, ChainTransaction, Deposit, Movement, Participation, Round, Utxo,
)
ROOT = Path(__file__).resolve().parents[2]
User = get_user_model()
PLM = 100_000_000
BET = 10 * PLM
pytestmark = pytest.mark.django_db
ledger = ChainLedger()
@pytest.fixture
def world(settings, tmp_path):
"""A real master key: the public part configured as the web has it, the private part as the worker has it."""
settings.LEDGER_BACKEND = "chain"
settings.PLM_ACCOUNT_XPUB = keys.generate_keys(tmp_path / "keys", settings.PLM_PROFILE)
settings.PLM_MASTER_KEY_FILE = str(tmp_path / "keys" / "master.key")
settings.PLM_KEY_ENCRYPTION_KEY_FILE = str(tmp_path / "keys" / "master.encryption.key")
settings.PROCESS_ROLE = "worker"
return settings
def make_round():
round_ = Round.objects.create(opened_at=timezone.now() - timedelta(seconds=30), bet_amount_sats=BET)
round_.pool_address = chain.derive_pool_address(round_.pk)
round_.save(update_fields=["pool_address"])
return round_
_counter = iter(range(1, 10_000))
def fund(user, amount, *, credited=True):
"""A deposit the scan has already registered: a coin of the player's own address."""
address = chain.assign_deposit_address(user).address
n = next(_counter)
utxo = Utxo.objects.create(txid=f"{n:064x}", vout=0, amount_sats=amount, address=address, user=user, confirmed_height=100)
movement = Movement.objects.create(
user=user, kind="deposit", status="confirmed" if credited else "pending", amount_sats=amount,
confirmed_at=timezone.now() if credited else None)
Deposit.objects.create(user=user, utxo=utxo, movement=movement, status="credited" if credited else "detected",
credited_at=timezone.now() if credited else None)
return utxo
def player(name="mario", funds=3 * BET):
user = User.objects.create_user(name, password="x" * 12)
if funds:
fund(user, funds)
return user
def bet(user, round_):
return ledger.place_bet(user, round_.pk, request_id=uuid4())
# --- BET-30: admission and reservation ----------------------------------------------------------------------
def test_a_bet_reserves_its_coins_and_takes_the_quota_from_the_balance(world):
user, round_ = player(), make_round()
result = bet(user, round_)
tx = ChainTransaction.objects.get()
assert (tx.kind, tx.status, tx.current_txid) == ("bet", "building", None)
assert list(tx.reserved_utxos.values_list("amount_sats", flat=True)) == [3 * BET]
assert result.obj.status == "pending" and balance_of(user).spendable_sats == 2 * BET
def test_a_reserved_coin_is_not_offered_again(world):
user, round_ = player(funds=BET + 2 * PLM), make_round()
bet(user, round_)
assert not reservation.spendable(user).exists()
def test_waiting_deposits_are_not_spendable(world):
user, round_ = player(funds=0), make_round()
fund(user, 2 * BET, credited=False)
with pytest.raises(LedgerError) as refused:
bet(user, round_)
assert refused.value.code == "balance_pending_confirmation" and not ChainTransaction.objects.exists()
def test_a_balance_that_leaves_no_change_is_refused_with_the_documented_code(world):
user, round_ = player(funds=BET), make_round()
with pytest.raises(LedgerError) as refused:
bet(user, round_)
assert refused.value.code == "balance_leaves_no_change"
assert not ChainTransaction.objects.exists() and not Utxo.objects.filter(reserved_by__isnull=False).exists()
def test_not_enough_money_is_refused(world):
user, round_ = player(funds=PLM), make_round()
with pytest.raises(LedgerError) as refused:
bet(user, round_)
assert refused.value.code == "insufficient_balance"
def test_the_same_request_is_one_bet(world):
user, round_ = player(), make_round()
key = uuid4()
first = ledger.place_bet(user, round_.pk, request_id=key)
again = ledger.place_bet(user, round_.pk, request_id=key)
assert again.replayed and again.obj == first.obj and ChainTransaction.objects.count() == 1
def test_a_second_bet_in_the_round_is_refused_and_reserves_nothing(world):
user, round_ = player(), make_round()
bet(user, round_)
with pytest.raises(LedgerError) as refused:
bet(user, round_)
assert refused.value.code == "already_betting" and ChainTransaction.objects.count() == 1
def test_the_chain_ledger_does_not_pretend_what_is_not_there_yet(world):
with pytest.raises(LedgerError):
ledger.deposit(player(), PLM)
with pytest.raises(NotImplementedError):
ledger.pay_winner(1)
assert isinstance(get_ledger(), ChainLedger)
_SETUP = """
import django, json
django.setup()
from uuid import uuid4
from django.contrib.auth import get_user_model
from django.utils import timezone
from apps.lottery import chain
from apps.lottery.models import Utxo, Deposit, Movement
user = get_user_model().objects.create_user('mario', password='x'*12)
address = chain.assign_deposit_address(user).address
utxo = Utxo.objects.create(txid='ab'*32, vout=0, amount_sats=3_000_000_000, address=address, user=user, confirmed_height=1)
m = Movement.objects.create(user=user, kind='deposit', status='confirmed', amount_sats=3_000_000_000, confirmed_at=timezone.now())
Deposit.objects.create(user=user, utxo=utxo, movement=m, status='credited', credited_at=timezone.now())
"""
_RACE = """
import django, json
django.setup()
from django.contrib.auth import get_user_model
from apps.lottery import reservation
from apps.lottery.models import ChainTransaction
user = get_user_model().objects.get(username='mario')
tx = ChainTransaction.objects.create(kind='bet', user=user)
try:
reservation.reserve_for(user, 1_000_000_000, tx)
print(json.dumps('won'))
except Exception as exc:
print(json.dumps(type(exc).__name__))
"""
def test_two_requests_never_reserve_the_same_coin(tmp_path, settings):
"""ARC-72: six processes want the one coin of a player at once; exactly one gets it."""
env = {"PATH": os.environ["PATH"], "PYTHONPATH": str(ROOT), "DJANGO_SECRET_KEY": "k" * 60,
"DJANGO_DB_PATH": str(tmp_path / "site.sqlite3"), "DJANGO_SETTINGS_MODULE": "config.settings",
"PLM_ACCOUNT_XPUB": keys.generate_keys(tmp_path / "keys", settings.PLM_PROFILE)}
subprocess.run([sys.executable, "manage.py", "migrate", "--noinput", "-v", "0"], cwd=ROOT, env=env, check=True)
subprocess.run([sys.executable, "-c", _SETUP], cwd=ROOT, env=env, check=True)
procs = [subprocess.Popen([sys.executable, "-c", _RACE], cwd=ROOT, env=env, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, text=True) for _ in range(6)]
outputs = [p.communicate(timeout=120) for p in procs]
assert all(p.returncode == 0 for p in procs), [o[1] for o in outputs]
results = [json.loads(o[0].strip().splitlines()[-1]) for o in outputs]
assert results.count("won") == 1 and results.count("InsufficientFundsError") == 5, results
# --- BET-31: signing in the worker, saved before it is sent ---------------------------------------------------
def test_without_the_signing_key_nothing_is_signed(world):
user, round_ = player(), make_round()
bet(user, round_)
world.PROCESS_ROLE = "web"
assert bets.sign_pending() == 0
tx = ChainTransaction.objects.get()
assert tx.current_txid is None and not tx.versions.exists()
def test_the_stake_in_the_pool_is_the_quota_minus_the_fee(world):
user, round_ = player(), make_round()
bet(user, round_)
assert bets.sign_pending() == 1
tx = ChainTransaction.objects.get()
participation = Participation.objects.get()
parsed = Transaction.parse(bytes.fromhex(tx.raw_hex))
assert tx.current_txid == parsed.txid().hex() and tx.versions.get().txid == tx.current_txid
assert participation.bet_txid == tx.current_txid and participation.bet_vout == 0
pool_out, change_out = parsed.vout
assert pool_out.value == participation.bet_amount_sats < BET # the fee comes out of the stake (BET-04)
assert pool_out.value + (BET - pool_out.value) == BET
assert change_out.value == 3 * BET - BET and change_out.value >= DUST_LIMIT_SATS
assert pool_out.script_pubkey.address(world.PLM_PROFILE.embit) == round_.pool_address
assert [(i.txid.hex(), i.vout) for i in parsed.vin] == [(u.txid, u.vout) for u in tx.reserved_utxos.all()]
assert AuditEntry.objects.filter(action="bet_signed").count() == 1
def test_a_signed_transaction_is_not_signed_twice(world):
user, round_ = player(), make_round()
bet(user, round_)
assert bets.sign_pending() == 1 and bets.sign_pending() == 0
assert ChainTransaction.objects.get().versions.count() == 1
# --- BET-32: verdicts ------------------------------------------------------------------------------------------
class ScriptedChain:
"""What `broadcast_pending` asks of the network: a verdict per call."""
def __init__(self, *verdicts):
self.verdicts, self.sent = list(verdicts), []
async def broadcast(self, raw, txid):
self.sent.append(txid)
return self.verdicts.pop(0) if self.verdicts else Verdict(Outcome.ACCEPTED, "")
def placed_and_signed(world):
user, round_ = player(), make_round()
bet(user, round_)
bets.sign_pending()
return user, round_, ChainTransaction.objects.get()
def test_the_transaction_is_saved_before_it_is_broadcast(world):
user, round_, tx = placed_and_signed(world)
assert tx.status == "building" and tx.current_txid and tx.versions.exists() # nothing was sent yet
class Crashing:
async def broadcast(self, raw, txid):
raise RuntimeError("the process died here")
with pytest.raises(RuntimeError):
bets.broadcast_pending(Crashing())
tx.refresh_from_db()
assert tx.status == "building" and tx.versions.count() == 1 # saved, still unsent: the next pass sends it
def test_an_accepted_broadcast_makes_the_bet_pending(world):
user, round_, tx = placed_and_signed(world)
assert bets.broadcast_pending(ScriptedChain())["accepted"] == 1
tx.refresh_from_db()
assert tx.status == "pending" and tx.broadcast_at is not None
assert AuditEntry.objects.filter(action="bet_broadcast").exists()
assert bets.broadcast_pending(ScriptedChain()) == {"accepted": 0, "refused": 0, "uncertain": 0} # not sent again
def test_a_proven_refusal_frees_the_coins(world):
user, round_, tx = placed_and_signed(world)
assert bets.broadcast_pending(ScriptedChain(Verdict(Outcome.REFUSED, "bad-txns-inputs-missingorspent")))["refused"] == 1
tx.refresh_from_db()
assert tx.status == "failed" and "missingorspent" in tx.failure_reason and tx.failed_at
assert Participation.objects.get().status == "rejected"
assert Movement.objects.get(kind="bet").status == "failed"
assert reservation.spendable(user).count() == 1 and balance_of(user).spendable_sats == 3 * BET
assert AuditEntry.objects.filter(action="bet_refused").exists()
def test_an_uncertain_broadcast_frees_nothing_and_is_retried(world):
user, round_, tx = placed_and_signed(world)
assert bets.broadcast_pending(ScriptedChain(Verdict(Outcome.UNCERTAIN, "timeout")))["uncertain"] == 1
tx.refresh_from_db()
assert tx.status == "building" and tx.reserved_utxos.count() == 1 and not reservation.spendable(user).exists()
retry = ScriptedChain()
assert bets.broadcast_pending(retry)["accepted"] == 1 and retry.sent == [tx.current_txid] # the same transaction
tx.refresh_from_db()
assert tx.status == "pending" and tx.versions.count() == 1
def test_an_outcome_is_not_written_over_a_changed_row(world):
user, round_, tx = placed_and_signed(world)
other = "ee" * 32
assert bets._settle(tx.pk, other, Verdict(Outcome.ACCEPTED, ""), timezone.now()) is False # another txid (an RBF meanwhile)
ChainTransaction.objects.filter(pk=tx.pk).update(status="pending")
assert bets._settle(tx.pk, tx.current_txid, Verdict(Outcome.REFUSED, "late"), timezone.now()) is False
tx.refresh_from_db()
assert tx.status == "pending" and tx.reserved_utxos.count() == 1
# --- the verdict as the network phase reaches it ---------------------------------------------------------------
class Server:
def __init__(self, name, *, broadcast=None, knows=None):
self.name, self.broadcast_error, self.knows = name, broadcast, knows # knows: True / False / None (silent)
self.sent = []
class FakeClient:
def __init__(self, server):
self.s = server
async def connect(self):
pass
async def close(self):
pass
async def broadcast(self, raw):
self.s.sent.append(raw)
if self.s.broadcast_error is not None:
raise self.s.broadcast_error
return "txid"
async def get_transaction(self, txid, verbose=False):
if self.s.knows is True:
return "00"
if self.s.knows is False:
raise ElectrumRpcError({"code": 2, "message": "No such mempool or blockchain transaction"})
raise OSError("timeout")
def network(*servers, allow_no_quorum=False):
by_endpoint = {ElectrumEndpoint(s.name, 1, False): s for s in servers}
from plm_engine.network import REGTEST
return ElectrumChain(list(by_endpoint), REGTEST, allow_no_quorum, lambda e: FakeClient(by_endpoint[e]))
async def test_a_plain_acceptance_is_fanned_out_to_the_others():
servers = [Server("a"), Server("b"), Server("c")]
verdict = await network(*servers).broadcast("00ff", "tx")
assert verdict.outcome is Outcome.ACCEPTED and [len(s.sent) for s in servers] == [1, 1, 1]
async def test_already_known_counts_as_accepted():
refusal = ElectrumRpcError({"code": -26, "message": "txn-already-in-mempool"})
verdict = await network(Server("a", broadcast=refusal), Server("b"), Server("c")).broadcast("00ff", "tx")
assert verdict.outcome is Outcome.ACCEPTED
async def test_a_refusal_that_another_server_contradicts_is_an_acceptance():
refusal = ElectrumRpcError({"code": 1, "message": "weird wording"})
servers = [Server("a", broadcast=refusal, knows=False), Server("b", knows=True), Server("c", knows=False)]
assert (await network(*servers).broadcast("00ff", "tx")).outcome is Outcome.ACCEPTED
async def test_a_refusal_every_server_confirms_is_a_refusal():
refusal = ElectrumRpcError({"code": 1, "message": "bad-txns-inputs-missingorspent"})
servers = [Server("a", broadcast=refusal, knows=False), Server("b", knows=False), Server("c", knows=False)]
verdict = await network(*servers).broadcast("00ff", "tx")
assert verdict.outcome is Outcome.REFUSED and "missingorspent" in verdict.reason
async def test_a_refusal_the_others_cannot_confirm_is_only_uncertain():
refusal = ElectrumRpcError({"code": 1, "message": "bad-txns-inputs-missingorspent"})
servers = [Server("a", broadcast=refusal, knows=False), Server("b", knows=None), Server("c", knows=None)]
assert (await network(*servers).broadcast("00ff", "tx")).outcome is Outcome.UNCERTAIN
async def test_a_timeout_is_uncertain_and_never_a_refusal():
servers = [Server("a", broadcast=OSError("timeout")), Server("b"), Server("c")]
assert (await network(*servers).broadcast("00ff", "tx")).outcome is Outcome.UNCERTAIN
+10 -5
View File
@@ -89,14 +89,19 @@ def test_a_coinbase_needs_120(player):
assert scan(fake)["credited"] == 1
def test_our_own_transactions_need_one(player):
def test_the_change_of_our_own_transactions_is_spendable_but_never_a_deposit(player):
"""BET-30: the stake was taken from the balance when the bet was placed; its change coming back must not be credited."""
user, address = player
tx = ChainTransaction.objects.create(kind="withdrawal", user=user)
tx = ChainTransaction.objects.create(kind="bet", user=user)
chain.register_version(tx, TXID, "00")
fake = FakeChain()
fake.entries[address] = [coin(height=1000)] # one confirmation
fake.verified = {(TXID, 0)}
assert scan(fake)["credited"] == 1
assert scan(fake) == {"detected": 0, "credited": 0, "orphaned": 0, "reinstated": 0}
utxo = Utxo.objects.get()
assert utxo.user == user and utxo.confirmed_height == 1000 and not Deposit.objects.exists()
assert not Movement.objects.exists() and balance_of(user).spendable_sats == 0
scan(fake) # and once only
assert Utxo.objects.count() == 1
def test_dust_and_mempool_coins_are_ignored(player):
@@ -217,7 +222,7 @@ def test_the_operator_changes_the_threshold_from_the_admin_and_it_is_audited(cli
client.force_login(admin)
config = LotteryConfig.get()
data = {f: getattr(config, f) for f in ("fee_address", "bet_amount_sats", "round_duration_seconds", "round_cooldown_seconds",
"draw_confirmations", "deposit_confirmations", "max_round_pool_sats")}
"draw_confirmations", "deposit_confirmations", "max_round_pool_sats", "fee_rate_sat_vb")}
data["deposit_confirmations"] = 3
assert client.post("/admin/lottery/lotteryconfig/1/change/", data).status_code == 302
assert LotteryConfig.get().deposit_confirmations == 3
+3 -2
View File
@@ -420,8 +420,9 @@ def test_unknown_network_or_ledger_is_refused(env):
def test_get_ledger_follows_the_configuration(settings):
assert isinstance(get_ledger(), SimulatedLedger)
settings.LEDGER_BACKEND = "chain"
with pytest.raises(NotImplementedError):
get_ledger()
from apps.lottery.ledger import ChainLedger
assert isinstance(get_ledger(), ChainLedger)
# --- real concurrency: separate processes on one SQLite file -----------------------------------
+8 -3
View File
@@ -104,15 +104,20 @@ def test_a_round_copies_its_rules_when_it_opens(t0):
assert (round_.draw_confirmations, round_.cooldown_seconds, round_.fee_address) == (5, 11, "rplm1fee")
def test_a_real_ledger_needs_a_fee_address_to_open_a_round(settings, t0):
"""ADR-29: a round that cannot pay its commission is not opened. The simulated ledger needs none."""
def test_a_real_ledger_needs_a_fee_address_to_open_a_round(settings, t0, tmp_path):
"""ADR-29: a round that cannot pay its commission is not opened. The simulated ledger needs none. A real one
also derives the round's pool address from the public key (DAT-60), so it needs that configured."""
from apps.lottery import keys
assert lifecycle.rounds_can_open(LotteryConfig.get())
settings.LEDGER_BACKEND = "chain"
settings.PLM_ACCOUNT_XPUB = keys.generate_keys(tmp_path / "keys", settings.PLM_PROFILE)
assert lifecycle.open_new_round_if_needed(t0) is None
config = LotteryConfig.get()
config.fee_address = "rplm1fee"
config.save()
assert lifecycle.open_new_round_if_needed(t0) is not None
opened = lifecycle.open_new_round_if_needed(t0)
assert opened is not None and opened.pool_address.startswith("rplm1") # its own address, from the public key
def test_the_pause_after_the_round_stops_only_the_next_one(t0):
+104
View File
@@ -0,0 +1,104 @@
"""B6 — a real bet on the local regtest: deposit, reservation, signature by the worker, broadcast to the node,
the change coming back, and the verdict of a refused transaction (BET-30..BET-33, DEP-22, TX-04)."""
import asyncio
import time
from datetime import timedelta
from uuid import uuid4
import pytest
from django.contrib.auth import get_user_model
from django.utils import timezone
from embit.transaction import Transaction
from plm_engine.electrum.client import ElectrumEndpoint
from plm_engine.network import REGTEST
from apps.lottery import bets, chain, deposits, keys
from apps.lottery.balances import balance_of
from apps.lottery.electrum_chain import ElectrumChain, Outcome
from apps.lottery.ledger import ChainLedger
from apps.lottery.models import ChainTransaction, Deposit, Movement, Participation, Round, Utxo
pytestmark = pytest.mark.django_db
PLM = 100_000_000
BET = 10 * PLM
@pytest.fixture
def network(electrum_endpoint):
host, port = electrum_endpoint
return ElectrumChain([ElectrumEndpoint(host, port, False)], REGTEST, allow_no_quorum=True)
@pytest.fixture
def funded_player(settings, tmp_path, regtest_node, electrum_endpoint, network):
"""A player whose 30 PLM deposit has been through 6 confirmations and the scan."""
settings.LEDGER_BACKEND = "chain"
settings.PLM_ACCOUNT_XPUB = keys.generate_keys(tmp_path / "keys", settings.PLM_PROFILE)
settings.PLM_MASTER_KEY_FILE = str(tmp_path / "keys" / "master.key")
settings.PLM_KEY_ENCRYPTION_KEY_FILE = str(tmp_path / "keys" / "master.encryption.key")
settings.PROCESS_ROLE = "worker"
user = get_user_model().objects.create_user("giocatore", password="x" * 12)
address = chain.assign_deposit_address(user).address
regtest_node.fund(address, 30)
regtest_node.mine(5)
for _ in range(80):
deposits.scan_deposits(network)
if balance_of(user).spendable_sats:
break
time.sleep(0.25)
assert balance_of(user).spendable_sats == 30 * PLM
return user, address
def open_round():
round_ = Round.objects.create(opened_at=timezone.now() - timedelta(seconds=30), bet_amount_sats=BET)
round_.pool_address = chain.derive_pool_address(round_.pk)
round_.save(update_fields=["pool_address"])
return round_
def test_a_real_bet_goes_from_the_web_to_the_node(regtest_node, network, funded_player):
user, address = funded_player
round_ = open_round()
ChainLedger().place_bet(user, round_.pk, request_id=uuid4()) # the web: admits and reserves, signs nothing
tx = ChainTransaction.objects.get()
assert tx.status == "building" and tx.current_txid is None
done = bets.process_bets(network) # the worker: signs, saves, sends
assert (done["signed"], done["accepted"]) == (1, 1)
tx.refresh_from_db()
assert tx.status == "pending"
entry = regtest_node.rpc("getmempoolentry", tx.current_txid) # the node really has it
assert entry["vsize"] > 0
raw = regtest_node.rpc("getrawtransaction", tx.current_txid)
pool_out, change_out = Transaction.parse(bytes.fromhex(raw)).vout
participation = Participation.objects.get()
assert pool_out.value == participation.bet_amount_sats and pool_out.value < BET
script_pubkey = regtest_node.rpc("getrawtransaction", tx.current_txid, True)["vout"][0]["scriptPubKey"]
assert (script_pubkey.get("address") or script_pubkey["addresses"][0]) == round_.pool_address # the node's own reading
assert change_out.value == 20 * PLM
# sending the same transaction again is "already known": still accepted, never a refusal
verdict = asyncio.run(network.broadcast(tx.raw_hex, tx.current_txid))
assert verdict.outcome is Outcome.ACCEPTED
regtest_node.mine(1)
for _ in range(80): # the change comes back to the player's address: spendable money, not a deposit
deposits.scan_deposits(network)
if Utxo.objects.filter(txid=tx.current_txid).exists():
break
time.sleep(0.25)
change = Utxo.objects.get(txid=tx.current_txid)
assert change.amount_sats == 20 * PLM and not Deposit.objects.filter(utxo=change).exists()
assert Movement.objects.filter(kind="deposit").count() == 1 # still the one real deposit
assert balance_of(user).spendable_sats == 20 * PLM
def test_a_transaction_the_chain_cannot_accept_is_refused_with_proof(network):
# one input that does not exist, one output: the node refuses and no server knows the txid
raw = "01000000" + "01" + "11" * 32 + "00000000" + "00" + "ffffffff" + "01" + "00ca9a3b00000000" + "00" + "00000000"
txid = Transaction.parse(bytes.fromhex(raw)).txid().hex()
verdict = asyncio.run(network.broadcast(raw, txid))
assert verdict.outcome is Outcome.REFUSED and verdict.reason