Skip to content

Commit

Permalink
finish publish input tests
Browse files Browse the repository at this point in the history
  • Loading branch information
auryn-macmillan committed Jun 22, 2024
1 parent b2e7196 commit 7482c89
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
4 changes: 3 additions & 1 deletion packages/evm/contracts/Enclave.sol
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ contract Enclave is IEnclave, OwnableUpgradeable {
inputValidator: inputValidator,
outputVerifier: outputVerifier,
committeePublicKey: hex"",
inputs: new bytes[](0),
ciphertextOutput: hex"",
plaintextOutput: hex""
});
Expand Down Expand Up @@ -217,7 +218,8 @@ contract Enclave is IEnclave, OwnableUpgradeable {
bytes memory input;
(input, success) = e3.inputValidator.validate(msg.sender, data);
require(success, InvalidInput());
// TODO: do we need to store or accumulate the inputs? Probably yes.
// TODO: probably better to accumulate inputs, rather than just dumping them in storage.
e3s[e3Id].inputs.push(input);
emit InputPublished(e3Id, input);
}

Expand Down
1 change: 1 addition & 0 deletions packages/evm/contracts/interfaces/IE3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct E3 {
IInputValidator inputValidator;
IOutputVerifier outputVerifier;
bytes committeePublicKey;
bytes[] inputs;
bytes ciphertextOutput;
bytes plaintextOutput;
}
2 changes: 1 addition & 1 deletion packages/evm/contracts/test/MockInputValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ contract MockInputValidator is IInputValidator {
address,
bytes memory params
) external pure returns (bytes memory input, bool success) {
input = abi.decode(params, (bytes));
input = params;

if (input.length == 3) {
success = false;
Expand Down
59 changes: 49 additions & 10 deletions packages/evm/test/Enclave.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -782,11 +782,9 @@ describe("Enclave", function () {
{ value: 10 },
);

const inputData = abiCoder.encode(["bytes"], ["0xaabbcc"]);

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

Expand All @@ -804,19 +802,60 @@ describe("Enclave", function () {
{ value: 10 },
);

const inputData = abiCoder.encode(["bytes32"], [ZeroHash]);

await enclave.activate(0);
await expect(enclave.publishInput(0, inputData)).to.not.be.reverted;
await expect(enclave.publishInput(0, ZeroHash)).to.not.be.reverted;

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

await expect(
enclave.publishInput(0, inputData),
enclave.publishInput(0, ZeroHash),
).to.be.revertedWithCustomError(enclave, "InputDeadlinePassed");
});
it("sets ciphertextInput correctly");
it("returns true if input is published successfully");
it("sets ciphertextInput correctly", async function () {
const { enclave, request } = await loadFixture(setup);
const inputData = "0x12345678";

await enclave.request(
request.filter,
request.threshold,
request.duration,
request.computationModule,
request.cMParams,
request.executionModule,
request.eMParams,
{ value: 10 },
);

await enclave.activate(0);

expect(await enclave.publishInput(0, inputData)).to.not.be.reverted;
let e3 = await enclave.getE3(0);
expect(e3.inputs[0]).to.equal(inputData);
expect(await enclave.publishInput(0, inputData)).to.not.be.reverted;
e3 = await enclave.getE3(0);
expect(e3.inputs[1]).to.equal(inputData);
});
it("returns true if input is published successfully", async function () {
const { enclave, request } = await loadFixture(setup);
const inputData = "0x12345678";

await enclave.request(
request.filter,
request.threshold,
request.duration,
request.computationModule,
request.cMParams,
request.executionModule,
request.eMParams,
{ value: 10 },
);

await enclave.activate(0);

expect(await enclave.publishInput.staticCall(0, inputData)).to.equal(
true,
);
});
it("emits InputPublished event", async function () {
const { enclave, request } = await loadFixture(setup);

Expand All @@ -838,7 +877,7 @@ describe("Enclave", function () {

await expect(enclave.publishInput(e3Id, inputData))
.to.emit(enclave, "InputPublished")
.withArgs(e3Id, "0xaabbccddeeff");
.withArgs(e3Id, inputData);
});
});

Expand Down

0 comments on commit 7482c89

Please sign in to comment.