From 596d01a063254bf29b5c596f391c8dae7bffdc45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crist=C3=B3v=C3=A3o=20Honorato?= Date: Tue, 11 Jun 2024 14:43:53 +0200 Subject: [PATCH] Adjust tests --- packages/evm/contracts/Enclave.sol | 1 - .../registry/NaiveRegistryFilter.sol | 49 ++++------------- packages/evm/test/Enclave.spec.ts | 54 ++++++++++--------- 3 files changed, 38 insertions(+), 66 deletions(-) diff --git a/packages/evm/contracts/Enclave.sol b/packages/evm/contracts/Enclave.sol index a4f9a475..9fac99d5 100644 --- a/packages/evm/contracts/Enclave.sol +++ b/packages/evm/contracts/Enclave.sol @@ -172,7 +172,6 @@ contract Enclave is IEnclave, OwnableUpgradeable { cyphernodeRegistry.requestCommittee(e3Id, filter, threshold), CommitteeSelectionFailed() ); - // TODO: validate that the selected pool accepts both the computation and execution modules. emit E3Requested( e3Id, diff --git a/packages/evm/contracts/registry/NaiveRegistryFilter.sol b/packages/evm/contracts/registry/NaiveRegistryFilter.sol index bf51509c..d48bba7e 100644 --- a/packages/evm/contracts/registry/NaiveRegistryFilter.sol +++ b/packages/evm/contracts/registry/NaiveRegistryFilter.sol @@ -6,6 +6,14 @@ import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; +interface IRegistry { + function publishCommittee( + uint256 e3Id, + address[] calldata cyphernodes, + bytes calldata publicKey + ) external; +} + contract NaiveRegistryFilter is IRegistryFilter, OwnableUpgradeable { struct Committee { address[] nodes; @@ -13,13 +21,6 @@ contract NaiveRegistryFilter is IRegistryFilter, OwnableUpgradeable { bytes publicKey; } - struct Node { - bool eligible; - // Number of duties the node has not yet completed. - // Incremented each time a duty is added, decremented each time a duty is completed. - uint256 outstandingDuties; - } - //////////////////////////////////////////////////////////// // // // Storage Variables // @@ -85,26 +86,6 @@ contract NaiveRegistryFilter is IRegistryFilter, OwnableUpgradeable { success = true; } - function retrieveCommittee( - uint256 e3Id - ) - external - view - returns ( - uint32[2] memory threshold, - bytes memory publicKey, - address[] memory ciphernodes - ) - { - Committee storage committee = committees[e3Id]; - require(committee.threshold.length > 0, CommitteeDoesNotExist()); - threshold = committee.threshold; - require(committee.publicKey.length > 0, CommitteeNotPublished()); - publicKey = committee.publicKey; - require(committee.nodes.length > 0, CommitteeNotPublished()); - ciphernodes = committee.nodes; - } - function publishCommittee( uint256 e3Id, address[] memory nodes, @@ -117,6 +98,7 @@ contract NaiveRegistryFilter is IRegistryFilter, OwnableUpgradeable { ); committee.nodes = nodes; committee.publicKey = publicKey; + IRegistry(registry).publishCommittee(e3Id, nodes, publicKey); } //////////////////////////////////////////////////////////// @@ -128,17 +110,4 @@ contract NaiveRegistryFilter is IRegistryFilter, OwnableUpgradeable { function setRegistry(address _registry) public onlyOwner { registry = _registry; } - - //////////////////////////////////////////////////////////// - // // - // Get Functions // - // // - //////////////////////////////////////////////////////////// - - function committeePublicKey( - uint256 e3Id - ) external view returns (bytes memory publicKey) { - publicKey = committees[e3Id].publicKey; - require(publicKey.length > 0, CommitteeNotPublished()); - } } diff --git a/packages/evm/test/Enclave.spec.ts b/packages/evm/test/Enclave.spec.ts index a98838c9..d5653999 100644 --- a/packages/evm/test/Enclave.spec.ts +++ b/packages/evm/test/Enclave.spec.ts @@ -16,6 +16,10 @@ import { deployOutputVerifierFixture } from "./fixtures/MockOutputVerifier.fixtu const abiCoder = ethers.AbiCoder.defaultAbiCoder(); const AddressTwo = "0x0000000000000000000000000000000000000002"; +const AddressSix = "0x0000000000000000000000000000000000000006"; + +const FilterFail = AddressTwo; +const FilterOkay = AddressSix; describe("Enclave", function () { async function setup() { @@ -47,7 +51,7 @@ describe("Enclave", function () { registry, }, request: { - pool: [ethers.ZeroAddress], + filter: FilterOkay, threshold: [2, 2] as [number, number], duration: time.duration.days(30), computationModule: await computationModule.getAddress(), @@ -177,7 +181,7 @@ describe("Enclave", function () { it("returns correct E3 details", async function () { const { enclave, request } = await loadFixture(setup); await enclave.request( - request.pool, + request.filter, request.threshold, request.duration, request.computationModule, @@ -399,7 +403,7 @@ describe("Enclave", function () { const { enclave, request } = await loadFixture(setup); await expect( enclave.request( - request.pool, + request.filter, request.threshold, request.duration, request.computationModule, @@ -413,7 +417,7 @@ describe("Enclave", function () { const { enclave, request } = await loadFixture(setup); await expect( enclave.request( - request.pool, + request.filter, [0, 2], request.duration, request.computationModule, @@ -428,7 +432,7 @@ describe("Enclave", function () { const { enclave, request } = await loadFixture(setup); await expect( enclave.request( - request.pool, + request.filter, [3, 2], request.duration, request.computationModule, @@ -443,7 +447,7 @@ describe("Enclave", function () { const { enclave, request } = await loadFixture(setup); await expect( enclave.request( - request.pool, + request.filter, request.threshold, 0, request.computationModule, @@ -458,7 +462,7 @@ describe("Enclave", function () { const { enclave, request } = await loadFixture(setup); await expect( enclave.request( - request.pool, + request.filter, request.threshold, time.duration.days(31), request.computationModule, @@ -473,7 +477,7 @@ describe("Enclave", function () { const { enclave, request } = await loadFixture(setup); await expect( enclave.request( - request.pool, + request.filter, request.threshold, request.duration, ethers.ZeroAddress, @@ -490,7 +494,7 @@ describe("Enclave", function () { const { enclave, request } = await loadFixture(setup); await expect( enclave.request( - request.pool, + request.filter, request.threshold, request.duration, request.computationModule, @@ -508,7 +512,7 @@ describe("Enclave", function () { await expect( enclave.request( - request.pool, + request.filter, request.threshold, request.duration, request.computationModule, @@ -523,7 +527,7 @@ describe("Enclave", function () { const { enclave, request } = await loadFixture(setup); await expect( enclave.request( - request.pool, + request.filter, request.threshold, request.duration, request.computationModule, @@ -538,7 +542,7 @@ describe("Enclave", function () { const { enclave, request } = await loadFixture(setup); await expect( enclave.request( - [AddressTwo], + FilterFail, request.threshold, request.duration, request.computationModule, @@ -552,7 +556,7 @@ describe("Enclave", function () { it("instantiates a new E3", async function () { const { enclave, request } = await loadFixture(setup); await enclave.request( - request.pool, + request.filter, request.threshold, request.duration, request.computationModule, @@ -580,7 +584,7 @@ describe("Enclave", function () { it("emits E3Requested event", async function () { const { enclave, request } = await loadFixture(setup); const tx = await enclave.request( - request.pool, + request.filter, request.threshold, request.duration, request.computationModule, @@ -596,7 +600,7 @@ describe("Enclave", function () { .withArgs( 0, e3, - request.pool, + request.filter, request.computationModule, request.executionModule, ); @@ -615,7 +619,7 @@ describe("Enclave", function () { const { enclave, request } = await loadFixture(setup); await enclave.request( - request.pool, + request.filter, request.threshold, request.duration, request.computationModule, @@ -635,7 +639,7 @@ describe("Enclave", function () { const { enclave, request } = await loadFixture(setup); await enclave.request( - request.pool, + request.filter, request.threshold, request.duration, request.computationModule, @@ -667,7 +671,7 @@ describe("Enclave", function () { } = await loadFixture(setup); await enclave.request( - request.pool, + request.filter, request.threshold, request.duration, request.computationModule, @@ -678,7 +682,7 @@ describe("Enclave", function () { ); const e3Id = 0; - const publicKey = await registry.getCommitteePublicKey(e3Id); + const publicKey = await registry.committeePublicKey(e3Id); let e3 = await enclave.getE3(e3Id); expect(e3.committeePublicKey).to.not.equal(publicKey); @@ -692,7 +696,7 @@ describe("Enclave", function () { const { enclave, request } = await loadFixture(setup); await enclave.request( - request.pool, + request.filter, request.threshold, request.duration, request.computationModule, @@ -710,7 +714,7 @@ describe("Enclave", function () { const { enclave, request } = await loadFixture(setup); await enclave.request( - request.pool, + request.filter, request.threshold, request.duration, request.computationModule, @@ -742,7 +746,7 @@ describe("Enclave", function () { const { enclave, request } = await loadFixture(setup); await enclave.request( - request.pool, + request.filter, request.threshold, request.duration, request.computationModule, @@ -768,7 +772,7 @@ describe("Enclave", function () { const { enclave, request } = await loadFixture(setup); await enclave.request( - request.pool, + request.filter, request.threshold, request.duration, request.computationModule, @@ -790,7 +794,7 @@ describe("Enclave", function () { const { enclave, request } = await loadFixture(setup); await enclave.request( - request.pool, + request.filter, request.threshold, request.duration, request.computationModule, @@ -817,7 +821,7 @@ describe("Enclave", function () { const { enclave, request } = await loadFixture(setup); await enclave.request( - request.pool, + request.filter, request.threshold, request.duration, request.computationModule,