Skip to content

Commit

Permalink
publishInput tests: checks for correctness and for expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
cristovaoth committed Jun 6, 2024
1 parent 59d11ec commit 79efe76
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
9 changes: 7 additions & 2 deletions packages/evm/contracts/test/MockInputValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ contract MockInputValidator is IInputValidator {
address,
bytes memory params
) external pure returns (bytes memory input, bool success) {
(input) = abi.decode(params, (bytes));
success = true;
input = abi.decode(params, (bytes));

if (input.length == 3) {
success = false;
} else {
success = true;
}
}
}
54 changes: 51 additions & 3 deletions packages/evm/test/Enclave.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { loadFixture, time } from "@nomicfoundation/hardhat-network-helpers";
import { loadFixture, mine, time } from "@nomicfoundation/hardhat-network-helpers";
import { expect } from "chai";
import { ZeroHash } from "ethers";
import { ethers } from "hardhat";
Expand Down Expand Up @@ -720,8 +720,56 @@ describe("Enclave", function () {

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("reverts if input is not valid", 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(["bytes"], ["0xaabbcc"]);

await enclave.activate(0);
await expect(enclave.publishInput(0, inputData)).to.be.revertedWithCustomError(
enclave,
"InvalidInput",
);
});

it("reverts if outside of input window", 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 enclave.activate(0);
await expect(enclave.publishInput(0, inputData)).to.not.be.reverted;

await mine(2, { interval: request.duration });

await expect(enclave.publishInput(0, inputData)).to.be.revertedWithCustomError(
enclave,
"InputDeadlinePassed",
);
});
it("sets ciphertextInput correctly");
it("returns true if input is published successfully");
it("emits InputPublished event");
Expand Down

0 comments on commit 79efe76

Please sign in to comment.