Skip to content

Commit

Permalink
Active test: invalid committee public key
Browse files Browse the repository at this point in the history
  • Loading branch information
cristovaoth committed Jun 4, 2024
1 parent 868de3d commit 6dba323
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
14 changes: 14 additions & 0 deletions packages/evm/contracts/test/MockCyphernodeRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@ contract MockCyphernodeRegistry is ICyphernodeRegistry {
return abi.encodePacked(keccak256(abi.encode(e3Id)));
}
}

contract MockCyphernodeRegistryEmptyKey is ICyphernodeRegistry {
function selectCommittee(uint256, address pool, uint32[2] calldata) external pure returns (bool success) {
if (pool == address(2)) {
success = false;
} else {
success = true;
}
}

function getCommitteePublicKey(uint256 e3Id) external pure returns (bytes memory) {
return hex"";
}
}
24 changes: 23 additions & 1 deletion packages/evm/test/Enclave.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,29 @@ describe("Enclave", function () {
await expect(enclave.activate(0)).to.not.be.reverted;
await expect(enclave.activate(0)).to.be.revertedWithCustomError(enclave, "E3AlreadyActivated").withArgs(0);
});
it("reverts if cyphernodeRegistry does not return a public key");
it("reverts if cyphernodeRegistry does not return a public key", 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 prevRegistry = await enclave.cyphernodeRegistry();
const nextRegistry = await deployCyphernodeRegistryFixture("MockCyphernodeRegistryEmptyKey");

await enclave.setCyphernodeRegistry(nextRegistry);
await expect(enclave.activate(0)).to.be.revertedWithCustomError(enclave, "CommitteeSelectionFailed");

await enclave.setCyphernodeRegistry(prevRegistry);
await expect(enclave.activate(0)).to.not.be.reverted;
});
it("sets committeePublicKey correctly");
it("returns true if E3 is activated successfully");
it("emits E3Activated event");
Expand Down
6 changes: 3 additions & 3 deletions packages/evm/test/fixtures/MockCyphernodeRegistry.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ethers } from "hardhat";

import { MockCyphernodeRegistry__factory } from "../../types/factories/contracts/test/MockCyphernodeRegistry__factory";
import { MockCyphernodeRegistry__factory } from "../../types";

export async function deployCyphernodeRegistryFixture() {
const deployment = await (await ethers.getContractFactory("MockCyphernodeRegistry")).deploy();
export async function deployCyphernodeRegistryFixture(name?: string) {
const deployment = await (await ethers.getContractFactory(name || "MockCyphernodeRegistry")).deploy();

return MockCyphernodeRegistry__factory.connect(await deployment.getAddress());
}

0 comments on commit 6dba323

Please sign in to comment.