nomos-specs/cryptarchia/test_common.py
davidrusu 2d3f463bb7
cryptarchia: Update epoch stabilization schedule to 334 (from 433) (#79)
* feat(cryptarchia/epoch-schedule): switch to 334 schedule (from 433)

* factor out common test config building code

* feat(cryptarchia): test_leader uses common test config object

* cryptarchia: update test_ledger_state_is_properly_updated_on_reorg

* cryptarchia: update test_epoch_transition test

* move to .tip() in tests instead of tip_id()

* cryptarchia: wrap long comments

* cryptarchia: move mk_block to test_common

* cryptarchia: move mk_genesis_state to test_common

* cryptarchia: refactor fork test to use mk_chain

* cryptarchia: fork choice rules tests use mk_chain helper

* cryptarchia: rename fork choice test suite to TestForkChoice

* cryptarchia: config.s is always 3k/f or 3*base_period_length

* cryptarchia: hardcode epoch schedule in specification

* un-hard code epoch sched. params + provide a v0.0.1 spec for params
2024-03-09 17:34:08 +04:00

55 lines
1.4 KiB
Python

from .cryptarchia import (
Config,
TimeConfig,
Id,
Slot,
Coin,
BlockHeader,
LedgerState,
MockLeaderProof,
)
def mk_config() -> Config:
return Config.cryptarchia_v0_0_1().replace(
k=1,
active_slot_coeff=1.0,
)
def mk_genesis_state(initial_stake_distribution: list[Coin]) -> LedgerState:
return LedgerState(
block=bytes(32),
nonce=bytes(32),
total_stake=sum(c.value for c in initial_stake_distribution),
commitments_spend={c.commitment() for c in initial_stake_distribution},
commitments_lead={c.commitment() for c in initial_stake_distribution},
nullifiers=set(),
)
def mk_block(
parent: Id, slot: int, coin: Coin, content=bytes(32), orphaned_proofs=[]
) -> BlockHeader:
assert len(parent) == 32
from hashlib import sha256
return BlockHeader(
slot=Slot(slot),
parent=parent,
content_size=len(content),
content_id=sha256(content).digest(),
leader_proof=MockLeaderProof.new(coin, Slot(slot), parent=parent),
orphaned_proofs=orphaned_proofs,
)
def mk_chain(parent, coin: Coin, slots: list[int]) -> tuple[list[BlockHeader], Coin]:
chain = []
for s in slots:
block = mk_block(parent=parent, slot=s, coin=coin)
chain.append(block)
parent = block.id()
coin = coin.evolve()
return chain, coin