Skip to content

Commit

Permalink
Add convenience method for checking whether provider public key has a…
Browse files Browse the repository at this point in the history
…lready been set.
  • Loading branch information
derekpierre committed Sep 13, 2023
1 parent 3b70a7c commit afce141
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions contracts/contracts/coordination/Coordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ contract Coordinator is AccessControlDefaultAdminRules, FlatRateFeeModel {
revert("No keys found prior to the provided ritual");
}

function isProviderPublicKeySet(address _provider) external view returns (bool) {
ParticipantKey[] storage participantHistory = participantKeysHistory[_provider];
return participantHistory.length > 0;
}

function setTimeout(uint32 newTimeout) external onlyRole(DEFAULT_ADMIN_ROLE) {
emit TimeoutChanged(timeout, newTimeout);
timeout = newTimeout;
Expand Down
7 changes: 7 additions & 0 deletions tests/test_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ def test_invalid_initiate_ritual(coordinator, nodes, accounts, initiator, global
def initiate_ritual(coordinator, erc20, allow_logic, authority, nodes):
for node in nodes:
public_key = gen_public_key()
assert not coordinator.isProviderPublicKeySet(node)
coordinator.setProviderPublicKey(public_key, sender=node)
assert coordinator.isProviderPublicKeySet(node)

cost = coordinator.getRitualInitiationCost(nodes, DURATION)
erc20.approve(coordinator.address, cost, sender=authority)
tx = coordinator.initiateRitual(
Expand Down Expand Up @@ -212,7 +215,11 @@ def test_initiate_ritual(
def test_provider_public_key(coordinator, nodes):
selected_provider = nodes[0]
public_key = gen_public_key()

assert not coordinator.isProviderPublicKeySet(selected_provider)
tx = coordinator.setProviderPublicKey(public_key, sender=selected_provider)
assert coordinator.isProviderPublicKeySet(selected_provider)

ritual_id = coordinator.numberOfRituals()

events = coordinator.ParticipantPublicKeySet.from_receipt(tx)
Expand Down

0 comments on commit afce141

Please sign in to comment.