Skip to content

Commit

Permalink
Update ape tests to accomodate latest ape version changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
derekpierre committed Feb 2, 2024
1 parent a9c7356 commit 1ea7fa5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 33 deletions.
32 changes: 16 additions & 16 deletions tests/test_beta_program_initiator.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ def test_register(accounts, beta_program_initiator, token, coordinator):
events = beta_program_initiator.RequestRegistered.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["sender"] == initiator_1
assert event["requestIndex"] == 0
assert event["providers"] == tuple(n.address.lower() for n in nodes)
assert event["authority"] == authority
assert event["duration"] == duration
assert event["accessController"] == access_controller
assert event["payment"] == ritual_cost
assert event.sender == initiator_1
assert event.requestIndex == 0
assert event.providers == list(n.address for n in nodes)
assert event.authority == authority
assert event.duration == duration
assert event.accessController == access_controller
assert event.payment == ritual_cost

# Register another request
nodes = [node_1]
Expand All @@ -140,13 +140,13 @@ def test_register(accounts, beta_program_initiator, token, coordinator):
events = beta_program_initiator.RequestRegistered.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["sender"] == initiator_2
assert event["requestIndex"] == 1
assert event["providers"] == tuple(n.address.lower() for n in nodes)
assert event["authority"] == authority
assert event["duration"] == duration
assert event["accessController"] == access_controller
assert event["payment"] == ritual_cost_2
assert event.sender == initiator_2
assert event.requestIndex == 1
assert event.providers == list(n.address for n in nodes)
assert event.authority == authority
assert event.duration == duration
assert event.accessController == access_controller
assert event.payment == ritual_cost_2


def test_cancel(accounts, beta_program_initiator, token, coordinator, executor):
Expand Down Expand Up @@ -435,13 +435,13 @@ def test_refund(accounts, beta_program_initiator, token, coordinator, executor):

coordinator.processPendingFee(request_1_ritual_id, sender=initiator_1)
assert coordinator.pendingFees(request_1_ritual_id) == 0

fee_deduction_2 = coordinator.feeDeduction(pending_fees_2_before, duration_2)
refund_2 = ritual_cost_2 - fee_deduction_2
assert token.balanceOf(beta_program_initiator.address) == refund_2

tx = beta_program_initiator.refundFailedRequest(1, sender=initiator_2)

assert token.balanceOf(beta_program_initiator.address) == 0
initiator_2_balance_after = token.balanceOf(initiator_2)
assert initiator_2_balance_after - initiator_2_balance_before == refund_2
Expand Down
38 changes: 22 additions & 16 deletions tests/test_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ def test_initiate_ritual(
events = coordinator.StartRitual.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["ritualId"] == ritualID
assert event["authority"] == authority
assert event["participants"] == tuple(n.address.lower() for n in nodes)
assert event.ritualId == ritualID
assert event.authority == authority
assert event.participants == list(n.address for n in nodes)

assert coordinator.getRitualState(0) == RitualState.DKG_AWAITING_TRANSCRIPTS

Expand Down Expand Up @@ -234,8 +234,9 @@ def test_provider_public_key(coordinator, nodes):
events = coordinator.ParticipantPublicKeySet.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["participant"] == selected_provider
assert event["publicKey"] == public_key
assert event.ritualId == ritual_id
assert event.participant == selected_provider
assert tuple(event.publicKey) == public_key
assert coordinator.getProviderPublicKey(selected_provider, ritual_id) == public_key


Expand Down Expand Up @@ -330,7 +331,7 @@ def test_get_participants(coordinator, nodes, initiator, erc20, global_allow_lis
transcript = os.urandom(transcript_size(len(nodes), len(nodes)))

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

# get all participants
participants = coordinator.getParticipants(0, 0, len(nodes), False)
Expand All @@ -341,7 +342,7 @@ def test_get_participants(coordinator, nodes, initiator, erc20, global_allow_lis
assert not participant.transcript

# max is higher than available
participants = coordinator.getParticipants(0, 0, len(nodes)*2, False)
participants = coordinator.getParticipants(0, 0, len(nodes) * 2, False)
assert len(participants) == len(nodes)
for index, participant in enumerate(participants):
assert participant.provider == nodes[index].address
Expand All @@ -368,7 +369,7 @@ def test_get_participants(coordinator, nodes, initiator, erc20, global_allow_lis
participants_n_at_a_time = coordinator.getParticipants(0, index, n_at_a_time, True)
assert len(participants_n_at_a_time) <= n_at_a_time
for i, participant in enumerate(participants_n_at_a_time):
assert participant.provider == nodes[index+i].address
assert participant.provider == nodes[index + i].address
assert participant.aggregated is False
assert participant.transcript == transcript

Expand All @@ -388,7 +389,7 @@ def test_get_participant(nodes, coordinator, initiator, erc20, global_allow_list
transcript = os.urandom(transcript_size(len(nodes), len(nodes)))

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

# find actual participants
for i, node in enumerate(nodes):
Expand Down Expand Up @@ -593,19 +594,23 @@ def test_authorize_using_global_allow_list(
assert global_allow_list.isAuthorized(0, bytes(signature), bytes(data))
assert coordinator.isEncryptionAuthorized(0, bytes(signature), bytes(data))
events = global_allow_list.AddressAuthorizationSet.from_receipt(tx)
assert events == [global_allow_list.AddressAuthorizationSet(
ritualId=0, _address=deployer.address, isAuthorized=True
)]
assert events == [
global_allow_list.AddressAuthorizationSet(
ritualId=0, _address=deployer.address, isAuthorized=True
)
]

# Deauthorize
tx = global_allow_list.deauthorize(0, [deployer.address], sender=initiator)

assert not global_allow_list.isAuthorized(0, bytes(signature), bytes(data))
assert not coordinator.isEncryptionAuthorized(0, bytes(signature), bytes(data))
events = global_allow_list.AddressAuthorizationSet.from_receipt(tx)
assert events == [global_allow_list.AddressAuthorizationSet(
ritualId=0, _address=deployer.address, isAuthorized=False
)]
assert events == [
global_allow_list.AddressAuthorizationSet(
ritualId=0, _address=deployer.address, isAuthorized=False
)
]

# Reauthorize in batch
addresses_to_authorize = [deployer.address, initiator.address]
Expand All @@ -623,7 +628,8 @@ def test_authorize_using_global_allow_list(
global_allow_list.AddressAuthorizationSet(
ritualId=0, _address=deployer.address, isAuthorized=True
),
# TODO was this originally supposed to True (not sure why it passed before)
global_allow_list.AddressAuthorizationSet(
ritualId=0, _address=initiator.address, isAuthorized=False
ritualId=0, _address=initiator.address, isAuthorized=True
),
]
2 changes: 1 addition & 1 deletion tests/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def test_selfdestruct(project, accounts):
contract1_lib = creator.deploy(project.Destroyable, 22)
assert 22 == contract1_lib.constructorValue()
contract1_lib.destroy(sender=creator)
with pytest.raises(ape.exceptions.ContractError):
with pytest.raises(ape.exceptions.ContractNotFoundError):
contract1_lib.constructorValue()

# Can't create dispatcher using address without contract
Expand Down

0 comments on commit 1ea7fa5

Please sign in to comment.