Skip to content

Commit

Permalink
Adapt tests to new FeeModel situation
Browse files Browse the repository at this point in the history
  • Loading branch information
cygnusv committed Aug 11, 2023
1 parent 3ac5ed9 commit e0350a8
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions tests/test_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,15 @@ def erc20(project, initiator):


@pytest.fixture()
def flat_rate_fee_model(project, deployer, stake_info, erc20):
contract = project.FlatRateFeeModel.deploy(
erc20.address, FEE_RATE, stake_info.address, sender=deployer
)
return contract


@pytest.fixture()
def coordinator(project, deployer, stake_info, flat_rate_fee_model, initiator):
def coordinator(project, deployer, stake_info, erc20, initiator):
admin = deployer
contract = project.Coordinator.deploy(
stake_info.address,
TIMEOUT,
MAX_DKG_SIZE,
admin,
flat_rate_fee_model.address,
erc20.address,
FEE_RATE,
sender=deployer,
)
contract.grantRole(contract.INITIATOR_ROLE(), initiator, sender=admin)
Expand Down Expand Up @@ -124,18 +117,18 @@ def test_invalid_initiate_ritual(coordinator, nodes, accounts, initiator):
coordinator.initiateRitual(nodes, initiator, DURATION, sender=initiator)


def initiate_ritual(coordinator, erc20, flat_rate_fee_model, initiator, nodes):
def initiate_ritual(coordinator, erc20, initiator, nodes):
for node in nodes:
public_key = gen_public_key()
coordinator.setProviderPublicKey(public_key, sender=node)
cost = flat_rate_fee_model.getRitualInitiationCost(nodes, DURATION)
cost = coordinator.getRitualInitiationCost(nodes, DURATION)
erc20.approve(coordinator.address, cost, sender=initiator)
tx = coordinator.initiateRitual(nodes, initiator, DURATION, sender=initiator)
return initiator, tx


def test_initiate_ritual(coordinator, nodes, initiator, erc20, flat_rate_fee_model):
authority, tx = initiate_ritual(coordinator, erc20, flat_rate_fee_model, initiator, nodes)
def test_initiate_ritual(coordinator, nodes, initiator, erc20):
authority, tx = initiate_ritual(coordinator, erc20, initiator, nodes)

ritualID = 0

Expand Down Expand Up @@ -176,8 +169,8 @@ def test_provider_public_key(coordinator, nodes):
assert coordinator.getProviderPublicKey(selected_provider, ritual_id) == public_key


def test_post_transcript(coordinator, nodes, initiator, erc20, flat_rate_fee_model):
initiate_ritual(coordinator, erc20, flat_rate_fee_model, initiator, nodes)
def test_post_transcript(coordinator, nodes, initiator, erc20):
initiate_ritual(coordinator, erc20, initiator, nodes)
transcript = os.urandom(transcript_size(len(nodes), len(nodes)))

for node in nodes:
Expand All @@ -201,28 +194,28 @@ def test_post_transcript(coordinator, nodes, initiator, erc20, flat_rate_fee_mod


def test_post_transcript_but_not_part_of_ritual(
coordinator, nodes, initiator, erc20, flat_rate_fee_model
coordinator, nodes, initiator, erc20
):
initiate_ritual(coordinator, erc20, flat_rate_fee_model, initiator, nodes)
initiate_ritual(coordinator, erc20, initiator, nodes)
transcript = os.urandom(transcript_size(len(nodes), len(nodes)))
with ape.reverts("Participant not part of ritual"):
coordinator.postTranscript(0, transcript, sender=initiator)


def test_post_transcript_but_already_posted_transcript(
coordinator, nodes, initiator, erc20, flat_rate_fee_model
coordinator, nodes, initiator, erc20
):
initiate_ritual(coordinator, erc20, flat_rate_fee_model, initiator, nodes)
initiate_ritual(coordinator, erc20, initiator, nodes)
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, transcript, sender=nodes[0])


def test_post_transcript_but_not_waiting_for_transcripts(
coordinator, nodes, initiator, erc20, flat_rate_fee_model
coordinator, nodes, initiator, erc20
):
initiate_ritual(coordinator, erc20, flat_rate_fee_model, initiator, nodes)
initiate_ritual(coordinator, erc20, initiator, nodes)
transcript = os.urandom(transcript_size(len(nodes), len(nodes)))
for node in nodes:
coordinator.postTranscript(0, transcript, sender=node)
Expand All @@ -231,8 +224,8 @@ def test_post_transcript_but_not_waiting_for_transcripts(
coordinator.postTranscript(0, transcript, sender=nodes[1])


def test_post_aggregation(coordinator, nodes, initiator, erc20, flat_rate_fee_model):
initiate_ritual(coordinator, erc20, flat_rate_fee_model, initiator, nodes)
def test_post_aggregation(coordinator, nodes, initiator, erc20):
initiate_ritual(coordinator, erc20, initiator, nodes)
ritualID = 0
transcript = os.urandom(transcript_size(len(nodes), len(nodes)))
for node in nodes:
Expand Down

0 comments on commit e0350a8

Please sign in to comment.