Skip to content

Commit

Permalink
Separate gatekeeper initialization from network creation (#51)
Browse files Browse the repository at this point in the history
* Seperate gatekeeper initialization from network creation

* Add final fix to allow adding muliple gatekeepers at a time

---------

Co-authored-by: Robert Leonard <[email protected]>
Co-authored-by: Robert Leonard <[email protected]>
  • Loading branch information
3 people authored Jul 1, 2024
1 parent 6077ba8 commit e503fbe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
9 changes: 9 additions & 0 deletions smart-contract/contracts/GatewayNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ contract GatewayNetwork is ParameterizedAccessControl, IGatewayNetwork, UUPSUpgr

_networks[networkName] = network;
_networks[networkName].lastFeeUpdateTimestamp = block.timestamp;
// reset gatekeeper list so that primary authority can add gatekeepers manually
_networks[networkName].gatekeepers = new address[](0);


emit GatekeeperNetworkCreated(network.primaryAuthority, networkName, network.passExpireDurationInSeconds);
}
Expand Down Expand Up @@ -112,6 +115,12 @@ contract GatewayNetwork is ParameterizedAccessControl, IGatewayNetwork, UUPSUpgr
emit GatekeeperNetworkDeleted(networkName);
}

function addGatekeepers(address[] memory gatekeepers, bytes32 networkName) external override onlyPrimaryNetworkAuthority(networkName){
for(uint i = 0; i < gatekeepers.length; i++) {
this.addGatekeeper(gatekeepers[i], networkName);
}
}

function addGatekeeper(address gatekeeper, bytes32 networkName) external override onlyPrimaryNetworkAuthority(networkName){
require(_networks[networkName].primaryAuthority != address(0), "Network does not exist");
require(gatekeeper != address(0), "Zero address cannot be added as a gatekeeper");
Expand Down
1 change: 1 addition & 0 deletions smart-contract/contracts/interfaces/IGatewayNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ abstract contract IGatewayNetwork {
function withdrawNetworkFees(bytes32 networkName) external payable virtual;
function closeNetwork(bytes32 networkName) external virtual;
function updatePassExpirationTime(uint newExpirationTimeInSeconds, bytes32 networkName) external virtual;
function addGatekeepers(address[] memory gatekeeper, bytes32 network) external virtual;
function addGatekeeper(address gatekeeper, bytes32 network) external virtual;
function removeGatekeeper(address gatekeeper, bytes32 network) external virtual;
function updatePrimaryAuthority(address newPrimaryAuthortiy, bytes32 networkName) external virtual;
Expand Down
23 changes: 22 additions & 1 deletion smart-contract/test/gatewayNetwork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ describe('GatewayNetwork', () => {
const defaultNetwork = getDefaultNetwork(primaryAuthority.address, [alice.address]);
await gatekeeperNetworkContract.connect(deployer).createNetwork(defaultNetwork, {gasLimit: 300000});

const isGatekeeper = await gatekeeperNetworkContract.isGateKeeper(defaultNetwork.name, alice.address);
await gatekeeperNetworkContract.connect(primaryAuthority).addGatekeeper(alice.address, defaultNetwork.name, {gasLimit: 300000});

const isGatekeeper = await gatekeeperNetworkContract.isGateKeeper(defaultNetwork.name, alice.address);
expect(isGatekeeper).to.be.true;
});
it('cannot create a new network zero address primary authority', async () => {
Expand Down Expand Up @@ -175,6 +176,26 @@ describe('GatewayNetwork', () => {
expect(newGatekeepers.length).to.be.eq(1);
expect(newGatekeepers[0]).to.be.eq(bob.address);
});

it.skip('can add multiple gatekeepers if called by primary authority', async () => {
// given
const newGatekeeper = networkFeePayer.address;
const newGatekeeperTwo = alice.address;

const currentGatekeepers = await gatekeeperNetworkContract.getGatekeepersOnNetwork(defaultNetwork.name);
expect(currentGatekeepers.length).to.be.eq(0);

//when
await gatekeeperNetworkContract.connect(primaryAuthority).addGatekeepers([newGatekeeper, newGatekeeperTwo], defaultNetwork.name, {gasLimit: 300000});

//then
const newGatekeepers = await gatekeeperNetworkContract.getGatekeepersOnNetwork(defaultNetwork.name);

expect(newGatekeepers.length).to.be.eq(1);
expect(newGatekeepers[0]).to.be.eq(bob.address);
expect(newGatekeepers[1]).to.be.eq(networkFeePayer.address);
});

it('can add a gatekeeper that does have the minimum amount of global stake', async () => {
// given
const newGatekeeper = bob.address;
Expand Down

0 comments on commit e503fbe

Please sign in to comment.