From 59d11ec6de99d94b8a2dd07d1a68af3fa2e45f7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crist=C3=B3v=C3=A3o=20Honorato?= Date: Thu, 6 Jun 2024 11:12:18 +0200 Subject: [PATCH] publishInput tests. Include a validation in the contract that was missing --- packages/evm/contracts/Enclave.sol | 4 ++++ packages/evm/test/Enclave.spec.ts | 35 ++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/packages/evm/contracts/Enclave.sol b/packages/evm/contracts/Enclave.sol index d5e7ca6f..13d3eaba 100644 --- a/packages/evm/contracts/Enclave.sol +++ b/packages/evm/contracts/Enclave.sol @@ -45,6 +45,7 @@ contract Enclave is IEnclave, OwnableUpgradeable { error CommitteeSelectionFailed(); error ComputationModuleNotAllowed(IComputationModule computationModule); error E3AlreadyActivated(uint256 e3Id); + error E3NotActivated(uint256 e3Id); error E3DoesNotExist(uint256 e3Id); error ModuleAlreadyEnabled(address module); error ModuleNotEnabled(address module); @@ -172,6 +173,9 @@ contract Enclave is IEnclave, OwnableUpgradeable { function publishInput(uint256 e3Id, bytes memory data) external returns (bool success) { E3 memory e3 = getE3(e3Id); + + // Note: if we make 0 a no expiration, this has to be refactored + require(e3.expiration > 0, E3NotActivated(e3Id)); // TODO: should we have an input window, including both a start and end timestamp? require(e3.expiration > block.timestamp, InputDeadlinePassed(e3Id, e3.expiration)); bytes memory input; diff --git a/packages/evm/test/Enclave.spec.ts b/packages/evm/test/Enclave.spec.ts index d49c7549..b9cff2cf 100644 --- a/packages/evm/test/Enclave.spec.ts +++ b/packages/evm/test/Enclave.spec.ts @@ -687,8 +687,39 @@ describe("Enclave", function () { }); describe("publishInput()", function () { - it("reverts if E3 does not exist"); - it("reverts if E3 has not been activated"); + it("reverts if E3 does not exist", async function () { + const { enclave } = await loadFixture(setup); + + await expect(enclave.publishInput(0, "0x")) + .to.be.revertedWithCustomError(enclave, "E3DoesNotExist") + .withArgs(0); + }); + + it("reverts if E3 has not been activated", 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 inputData = abiCoder.encode(["bytes32"], [ZeroHash]); + + await expect(enclave.getE3(0)).to.not.be.reverted; + await expect(enclave.publishInput(0, inputData)) + .to.be.revertedWithCustomError(enclave, "E3NotActivated") + .withArgs(0); + + await enclave.activate(0); + + await expect(enclave.publishInput(0, inputData)).to.not.be.reverted; + }); it("reverts if outside of input window"); it("reverts if input is not valid"); it("sets ciphertextInput correctly");