From 6dba3234a4eb1d6703753f0f87769aaf511deb2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crist=C3=B3v=C3=A3o=20Honorato?= Date: Tue, 4 Jun 2024 12:26:29 +0200 Subject: [PATCH] Active test: invalid committee public key --- .../contracts/test/MockCyphernodeRegistry.sol | 14 +++++++++++ packages/evm/test/Enclave.spec.ts | 24 ++++++++++++++++++- .../MockCyphernodeRegistry.fixture.ts | 6 ++--- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/packages/evm/contracts/test/MockCyphernodeRegistry.sol b/packages/evm/contracts/test/MockCyphernodeRegistry.sol index 44151eac..d9380963 100644 --- a/packages/evm/contracts/test/MockCyphernodeRegistry.sol +++ b/packages/evm/contracts/test/MockCyphernodeRegistry.sol @@ -16,3 +16,17 @@ contract MockCyphernodeRegistry is ICyphernodeRegistry { return abi.encodePacked(keccak256(abi.encode(e3Id))); } } + +contract MockCyphernodeRegistryEmptyKey is ICyphernodeRegistry { + function selectCommittee(uint256, address pool, uint32[2] calldata) external pure returns (bool success) { + if (pool == address(2)) { + success = false; + } else { + success = true; + } + } + + function getCommitteePublicKey(uint256 e3Id) external pure returns (bytes memory) { + return hex""; + } +} diff --git a/packages/evm/test/Enclave.spec.ts b/packages/evm/test/Enclave.spec.ts index f4323ed9..07d46851 100644 --- a/packages/evm/test/Enclave.spec.ts +++ b/packages/evm/test/Enclave.spec.ts @@ -565,7 +565,29 @@ describe("Enclave", function () { await expect(enclave.activate(0)).to.not.be.reverted; await expect(enclave.activate(0)).to.be.revertedWithCustomError(enclave, "E3AlreadyActivated").withArgs(0); }); - it("reverts if cyphernodeRegistry does not return a public key"); + it("reverts if cyphernodeRegistry does not return a public key", async function () { + const { enclave, request } = await loadFixture(setup); + + await enclave.request( + request.pool, + request.threshold, + request.duration, + request.computationModule, + request.cMParams, + request.executionModule, + request.eMParams, + { value: 10 }, + ); + + const prevRegistry = await enclave.cyphernodeRegistry(); + const nextRegistry = await deployCyphernodeRegistryFixture("MockCyphernodeRegistryEmptyKey"); + + await enclave.setCyphernodeRegistry(nextRegistry); + await expect(enclave.activate(0)).to.be.revertedWithCustomError(enclave, "CommitteeSelectionFailed"); + + await enclave.setCyphernodeRegistry(prevRegistry); + await expect(enclave.activate(0)).to.not.be.reverted; + }); it("sets committeePublicKey correctly"); it("returns true if E3 is activated successfully"); it("emits E3Activated event"); diff --git a/packages/evm/test/fixtures/MockCyphernodeRegistry.fixture.ts b/packages/evm/test/fixtures/MockCyphernodeRegistry.fixture.ts index cd1a588b..73d87fbe 100644 --- a/packages/evm/test/fixtures/MockCyphernodeRegistry.fixture.ts +++ b/packages/evm/test/fixtures/MockCyphernodeRegistry.fixture.ts @@ -1,9 +1,9 @@ import { ethers } from "hardhat"; -import { MockCyphernodeRegistry__factory } from "../../types/factories/contracts/test/MockCyphernodeRegistry__factory"; +import { MockCyphernodeRegistry__factory } from "../../types"; -export async function deployCyphernodeRegistryFixture() { - const deployment = await (await ethers.getContractFactory("MockCyphernodeRegistry")).deploy(); +export async function deployCyphernodeRegistryFixture(name?: string) { + const deployment = await (await ethers.getContractFactory(name || "MockCyphernodeRegistry")).deploy(); return MockCyphernodeRegistry__factory.connect(await deployment.getAddress()); }