Skip to content

Commit

Permalink
publishInput tests. Include a validation in the contract that was mis…
Browse files Browse the repository at this point in the history
…sing
  • Loading branch information
cristovaoth committed Jun 6, 2024
1 parent c7bde67 commit 59d11ec
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/evm/contracts/Enclave.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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

This comment has been minimized.

Copy link
@auryn-macmillan

auryn-macmillan Jun 6, 2024

Member

Perhaps we use type(uint256).max as the magic value for no expiration? Or just don't even worry about it since that would be practically forever anyway.

This comment has been minimized.

Copy link
@cristovaoth

cristovaoth Jun 6, 2024

Author Contributor

Right, makes sense

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;
Expand Down
35 changes: 33 additions & 2 deletions packages/evm/test/Enclave.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 59d11ec

Please sign in to comment.