From 0b68faae67285b6922c9177de66c5ad83af907d2 Mon Sep 17 00:00:00 2001 From: Robert Leonard Date: Tue, 28 May 2024 10:13:03 -0400 Subject: [PATCH] Seperate gatekeeper initialization from network creation --- smart-contract/contracts/GatewayNetwork.sol | 10 ++++++++++ .../contracts/interfaces/IGatewayNetwork.sol | 1 + smart-contract/test/gatewayNetwork.test.ts | 3 ++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/smart-contract/contracts/GatewayNetwork.sol b/smart-contract/contracts/GatewayNetwork.sol index f1cf90ef..12d46e38 100644 --- a/smart-contract/contracts/GatewayNetwork.sol +++ b/smart-contract/contracts/GatewayNetwork.sol @@ -53,6 +53,10 @@ contract GatewayNetwork is ParameterizedAccessControl, IGatewayNetwork { _networks[networkName] = network; _networks[networkName].lastFeeUpdateTimestamp = block.timestamp; + // reset gatekeeper list so that primary authority can add gatekeepers manually + // The creator os the network probably won't be the primary authority of the network so they can't initialize gatekeepers + _networks[networkName].gatekeepers = new address[](20); + emit GatekeeperNetworkCreated(network.primaryAuthority, networkName, network.passExpireDurationInSeconds); } @@ -113,6 +117,12 @@ contract GatewayNetwork is ParameterizedAccessControl, IGatewayNetwork { emit GatekeeperNetworkDeleted(networkName); } + function addGatekeepers(address[] memory gatekeepers, bytes32 networkName) external override { + 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"); diff --git a/smart-contract/contracts/interfaces/IGatewayNetwork.sol b/smart-contract/contracts/interfaces/IGatewayNetwork.sol index 86ce914b..c269ecb9 100644 --- a/smart-contract/contracts/interfaces/IGatewayNetwork.sol +++ b/smart-contract/contracts/interfaces/IGatewayNetwork.sol @@ -71,6 +71,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; diff --git a/smart-contract/test/gatewayNetwork.test.ts b/smart-contract/test/gatewayNetwork.test.ts index 249cd803..3a6b4637 100644 --- a/smart-contract/test/gatewayNetwork.test.ts +++ b/smart-contract/test/gatewayNetwork.test.ts @@ -95,8 +95,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 () => {