Skip to content

Commit

Permalink
cryptarchia: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrusu committed Nov 1, 2024
1 parent 987060d commit 9eabadd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
18 changes: 9 additions & 9 deletions cryptarchia/cryptarchia.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ def nullifier(self) -> Id:

@dataclass
class MockLeaderProof:
commitment: Id = bytes(32)
nullifier: Id = bytes(32)
evolved_commitment: Id = bytes(32)
slot: Slot = field(default_factory=lambda: Slot(0))
parent: Id = bytes(32)
commitment: Id
nullifier: Id
evolved_commitment: Id
slot: Slot
parent: Id

@staticmethod
def new(coin: Coin, slot: Slot, parent: Id):
Expand Down Expand Up @@ -207,10 +207,10 @@ def verify(self, slot: Slot, parent: Id):
@dataclass
class BlockHeader:
slot: Slot
parent: Id = bytes(32)
content_size: int = 0
content_id: Id = bytes(32)
leader_proof: MockLeaderProof = field(default_factory=MockLeaderProof)
parent: Id
content_size: int
content_id: Id
leader_proof: MockLeaderProof

orphaned_proofs: List["BlockHeader"] = field(default_factory=list)

Expand Down
10 changes: 9 additions & 1 deletion cryptarchia/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ def mk_config(initial_stake_distribution: list[Coin]) -> Config:

def mk_genesis_state(initial_stake_distribution: list[Coin]) -> LedgerState:
return LedgerState(
block=BlockHeader(slot=Slot(0), parent=bytes(32)),
block=BlockHeader(
slot=Slot(0),
parent=bytes(32),
content_size=0,
content_id=bytes(32),
leader_proof=MockLeaderProof.new(
Coin(sk=0, value=0), Slot(0), parent=bytes(32)
),
),
nonce=bytes(32),
commitments_spend={c.commitment() for c in initial_stake_distribution},
commitments_lead={c.commitment() for c in initial_stake_distribution},
Expand Down
14 changes: 7 additions & 7 deletions cryptarchia/test_fork_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from cryptarchia.cryptarchia import (
block_weight,
ghost_maxvalid_bg,
BlockHeader,
Slot,
Coin,
Follower,
Expand Down Expand Up @@ -33,7 +32,7 @@ def test_ghost_fork_choice(self):

coin = Coin(sk=1, value=100)

b0 = BlockHeader(slot=Slot(0), parent=bytes(32))
b0 = mk_genesis_state([]).block

b1A = mk_block(b0, 1, coin, content=b"b1A")
b2A = mk_block(b1A, 2, coin, content=b"b2A")
Expand Down Expand Up @@ -105,7 +104,7 @@ def test_block_weight_paper(self):

coin = Coin(sk=1, value=100)

b0 = BlockHeader(slot=Slot(0), parent=bytes(32))
b0 = mk_genesis_state([]).block

b1A = mk_block(b0, 1, coin, content=b"b1A")
b2A = mk_block(b1A, 2, coin, content=b"b2A")
Expand Down Expand Up @@ -186,7 +185,7 @@ def test_block_weight(self):

coin = Coin(sk=1, value=100)

b0 = BlockHeader(slot=Slot(0), parent=bytes(32))
b0 = mk_genesis_state([]).block
b1 = mk_block(b0, 1, coin)
b2 = mk_block(b1, 2, coin)
b3 = mk_block(b2, 3, coin)
Expand Down Expand Up @@ -223,7 +222,7 @@ def test_common_prefix_depth(self):

coin = Coin(sk=1, value=100)

b0 = BlockHeader(slot=Slot(0), parent=bytes(32))
b0 = mk_genesis_state([]).block
b1 = mk_block(b0, 1, coin)
b2 = mk_block(b1, 2, coin)
b3 = mk_block(b2, 3, coin)
Expand Down Expand Up @@ -261,7 +260,8 @@ def test_common_prefix_depth(self):

def test_fork_choice_long_sparse_chain(self):
# The longest chain is not dense after the fork
genesis = BlockHeader(slot=Slot(0), parent=bytes(32))
genesis = mk_genesis_state([]).block

short_coin, long_coin = Coin(sk=0, value=100), Coin(sk=1, value=100)
common, long_coin = mk_chain(parent=genesis, coin=long_coin, slots=range(50))

Expand Down Expand Up @@ -304,7 +304,7 @@ def test_fork_choice_long_dense_chain(self):
# The longest chain is also the densest after the fork
short_coin, long_coin = Coin(sk=0, value=100), Coin(sk=1, value=100)
common, long_coin = mk_chain(
parent=BlockHeader(slot=Slot(0), parent=bytes(32)),
parent=mk_genesis_state([]).block,
coin=long_coin,
slots=range(1, 50),
)
Expand Down

0 comments on commit 9eabadd

Please sign in to comment.