Skip to content

Commit

Permalink
apply pr suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Jul 3, 2023
1 parent ee616ac commit e176e39
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ape-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ deployments:

test:
mnemonic: test test test test test test test test test test test junk
number_of_accounts: 67
number_of_accounts: 10
28 changes: 18 additions & 10 deletions tests/test_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import pytest
from web3 import Web3

TRANSCRIPT_SIZE = 500
TIMEOUT = 1000
MAX_DKG_SIZE = 64
MAX_DKG_SIZE = 4
FEE_RATE = 42
ERC20_SUPPLY = 10**24
DURATION = 1234
Expand All @@ -26,6 +25,12 @@
)


# This formula returns an approximated size
# To have a representative size, create transcripts with `nucypher-core`
def transcript_size(shares, threshold):
return int(424 + 240 * (shares / 2) + 50 * (threshold))


@pytest.fixture(scope="module")
def nodes(accounts):
return sorted(accounts[:MAX_DKG_SIZE], key=lambda x: x.address.lower())
Expand Down Expand Up @@ -128,11 +133,11 @@ def test_post_transcript(coordinator, nodes, initiator, erc20, flat_rate_fee_mod
cost = flat_rate_fee_model.getRitualInitiationCost(nodes, DURATION)
erc20.approve(coordinator.address, cost, sender=initiator)
coordinator.initiateRitual(nodes, initiator, DURATION, sender=initiator)
transcript = os.urandom(transcript_size(len(nodes), len(nodes)))

for node in nodes:
assert coordinator.getRitualState(0) == RitualState.AWAITING_TRANSCRIPTS

transcript = os.urandom(TRANSCRIPT_SIZE)
tx = coordinator.postTranscript(0, transcript, sender=node)

events = list(coordinator.TranscriptPosted.from_receipt(tx))
Expand All @@ -156,8 +161,9 @@ def test_post_transcript_but_not_part_of_ritual(
cost = flat_rate_fee_model.getRitualInitiationCost(nodes, DURATION)
erc20.approve(coordinator.address, cost, sender=initiator)
coordinator.initiateRitual(nodes, initiator, DURATION, sender=initiator)
transcript = os.urandom(transcript_size(len(nodes), len(nodes)))
with ape.reverts("Participant not part of ritual"):
coordinator.postTranscript(0, os.urandom(TRANSCRIPT_SIZE), sender=initiator)
coordinator.postTranscript(0, transcript, sender=initiator)


def test_post_transcript_but_already_posted_transcript(
Expand All @@ -166,9 +172,10 @@ def test_post_transcript_but_already_posted_transcript(
cost = flat_rate_fee_model.getRitualInitiationCost(nodes, DURATION)
erc20.approve(coordinator.address, cost, sender=initiator)
coordinator.initiateRitual(nodes, initiator, DURATION, sender=initiator)
coordinator.postTranscript(0, os.urandom(TRANSCRIPT_SIZE), sender=nodes[0])
transcript = os.urandom(transcript_size(len(nodes), len(nodes)))
coordinator.postTranscript(0, transcript, sender=nodes[0])
with ape.reverts("Node already posted transcript"):
coordinator.postTranscript(0, os.urandom(TRANSCRIPT_SIZE), sender=nodes[0])
coordinator.postTranscript(0, transcript, sender=nodes[0])


def test_post_transcript_but_not_waiting_for_transcripts(
Expand All @@ -177,23 +184,24 @@ def test_post_transcript_but_not_waiting_for_transcripts(
cost = flat_rate_fee_model.getRitualInitiationCost(nodes, DURATION)
erc20.approve(coordinator.address, cost, sender=initiator)
coordinator.initiateRitual(nodes, initiator, DURATION, sender=initiator)
transcript = os.urandom(transcript_size(len(nodes), len(nodes)))
for node in nodes:
transcript = os.urandom(TRANSCRIPT_SIZE)
coordinator.postTranscript(0, transcript, sender=node)

with ape.reverts("Not waiting for transcripts"):
coordinator.postTranscript(0, os.urandom(TRANSCRIPT_SIZE), sender=nodes[1])
coordinator.postTranscript(0, transcript, sender=nodes[1])


def test_post_aggregation(coordinator, nodes, initiator, erc20, flat_rate_fee_model):
cost = flat_rate_fee_model.getRitualInitiationCost(nodes, DURATION)
erc20.approve(coordinator.address, cost, sender=initiator)
coordinator.initiateRitual(nodes, initiator, DURATION, sender=initiator)
transcript = os.urandom(TRANSCRIPT_SIZE)
transcript = os.urandom(transcript_size(len(nodes), len(nodes)))

for node in nodes:
coordinator.postTranscript(0, transcript, sender=node)

aggregated = os.urandom(TRANSCRIPT_SIZE)
aggregated = transcript # has the same size as transcript
decryptionRequestStaticKeys = [os.urandom(42) for node in nodes]
publicKey = (os.urandom(32), os.urandom(16))
for i, node in enumerate(nodes):
Expand Down

0 comments on commit e176e39

Please sign in to comment.