From e176e3969a346efe7b0ad42115be5b46c642aabd Mon Sep 17 00:00:00 2001 From: Piotr Roslaniec Date: Mon, 3 Jul 2023 13:33:52 +0200 Subject: [PATCH] apply pr suggestions --- ape-config.yaml | 2 +- tests/test_coordinator.py | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/ape-config.yaml b/ape-config.yaml index fba35b39..5dd4d21c 100644 --- a/ape-config.yaml +++ b/ape-config.yaml @@ -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 diff --git a/tests/test_coordinator.py b/tests/test_coordinator.py index 1a6afd35..d2bb54b7 100644 --- a/tests/test_coordinator.py +++ b/tests/test_coordinator.py @@ -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 @@ -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()) @@ -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)) @@ -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( @@ -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( @@ -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):