Skip to content

Commit

Permalink
Adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cristovaoth committed Jun 11, 2024
1 parent c6b5ac3 commit 596d01a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 66 deletions.
1 change: 0 additions & 1 deletion packages/evm/contracts/Enclave.sol
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ contract Enclave is IEnclave, OwnableUpgradeable {
cyphernodeRegistry.requestCommittee(e3Id, filter, threshold),
CommitteeSelectionFailed()
);
// TODO: validate that the selected pool accepts both the computation and execution modules.

emit E3Requested(
e3Id,
Expand Down
49 changes: 9 additions & 40 deletions packages/evm/contracts/registry/NaiveRegistryFilter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ import {
OwnableUpgradeable
} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

interface IRegistry {
function publishCommittee(
uint256 e3Id,
address[] calldata cyphernodes,
bytes calldata publicKey
) external;
}

contract NaiveRegistryFilter is IRegistryFilter, OwnableUpgradeable {
struct Committee {
address[] nodes;
uint32[2] threshold;
bytes publicKey;
}

struct Node {
bool eligible;
// Number of duties the node has not yet completed.
// Incremented each time a duty is added, decremented each time a duty is completed.
uint256 outstandingDuties;
}

////////////////////////////////////////////////////////////
// //
// Storage Variables //
Expand Down Expand Up @@ -85,26 +86,6 @@ contract NaiveRegistryFilter is IRegistryFilter, OwnableUpgradeable {
success = true;
}

function retrieveCommittee(
uint256 e3Id
)
external
view
returns (
uint32[2] memory threshold,
bytes memory publicKey,
address[] memory ciphernodes
)
{
Committee storage committee = committees[e3Id];
require(committee.threshold.length > 0, CommitteeDoesNotExist());
threshold = committee.threshold;
require(committee.publicKey.length > 0, CommitteeNotPublished());
publicKey = committee.publicKey;
require(committee.nodes.length > 0, CommitteeNotPublished());
ciphernodes = committee.nodes;
}

function publishCommittee(
uint256 e3Id,
address[] memory nodes,
Expand All @@ -117,6 +98,7 @@ contract NaiveRegistryFilter is IRegistryFilter, OwnableUpgradeable {
);
committee.nodes = nodes;
committee.publicKey = publicKey;
IRegistry(registry).publishCommittee(e3Id, nodes, publicKey);
}

////////////////////////////////////////////////////////////
Expand All @@ -128,17 +110,4 @@ contract NaiveRegistryFilter is IRegistryFilter, OwnableUpgradeable {
function setRegistry(address _registry) public onlyOwner {
registry = _registry;
}

////////////////////////////////////////////////////////////
// //
// Get Functions //
// //
////////////////////////////////////////////////////////////

function committeePublicKey(
uint256 e3Id
) external view returns (bytes memory publicKey) {
publicKey = committees[e3Id].publicKey;
require(publicKey.length > 0, CommitteeNotPublished());
}
}
54 changes: 29 additions & 25 deletions packages/evm/test/Enclave.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import { deployOutputVerifierFixture } from "./fixtures/MockOutputVerifier.fixtu

const abiCoder = ethers.AbiCoder.defaultAbiCoder();
const AddressTwo = "0x0000000000000000000000000000000000000002";
const AddressSix = "0x0000000000000000000000000000000000000006";

const FilterFail = AddressTwo;
const FilterOkay = AddressSix;

describe("Enclave", function () {
async function setup() {
Expand Down Expand Up @@ -47,7 +51,7 @@ describe("Enclave", function () {
registry,
},
request: {
pool: [ethers.ZeroAddress],
filter: FilterOkay,
threshold: [2, 2] as [number, number],
duration: time.duration.days(30),
computationModule: await computationModule.getAddress(),
Expand Down Expand Up @@ -177,7 +181,7 @@ describe("Enclave", function () {
it("returns correct E3 details", async function () {
const { enclave, request } = await loadFixture(setup);
await enclave.request(
request.pool,
request.filter,
request.threshold,
request.duration,
request.computationModule,
Expand Down Expand Up @@ -399,7 +403,7 @@ describe("Enclave", function () {
const { enclave, request } = await loadFixture(setup);
await expect(
enclave.request(
request.pool,
request.filter,
request.threshold,
request.duration,
request.computationModule,
Expand All @@ -413,7 +417,7 @@ describe("Enclave", function () {
const { enclave, request } = await loadFixture(setup);
await expect(
enclave.request(
request.pool,
request.filter,
[0, 2],
request.duration,
request.computationModule,
Expand All @@ -428,7 +432,7 @@ describe("Enclave", function () {
const { enclave, request } = await loadFixture(setup);
await expect(
enclave.request(
request.pool,
request.filter,
[3, 2],
request.duration,
request.computationModule,
Expand All @@ -443,7 +447,7 @@ describe("Enclave", function () {
const { enclave, request } = await loadFixture(setup);
await expect(
enclave.request(
request.pool,
request.filter,
request.threshold,
0,
request.computationModule,
Expand All @@ -458,7 +462,7 @@ describe("Enclave", function () {
const { enclave, request } = await loadFixture(setup);
await expect(
enclave.request(
request.pool,
request.filter,
request.threshold,
time.duration.days(31),
request.computationModule,
Expand All @@ -473,7 +477,7 @@ describe("Enclave", function () {
const { enclave, request } = await loadFixture(setup);
await expect(
enclave.request(
request.pool,
request.filter,
request.threshold,
request.duration,
ethers.ZeroAddress,
Expand All @@ -490,7 +494,7 @@ describe("Enclave", function () {
const { enclave, request } = await loadFixture(setup);
await expect(
enclave.request(
request.pool,
request.filter,
request.threshold,
request.duration,
request.computationModule,
Expand All @@ -508,7 +512,7 @@ describe("Enclave", function () {

await expect(
enclave.request(
request.pool,
request.filter,
request.threshold,
request.duration,
request.computationModule,
Expand All @@ -523,7 +527,7 @@ describe("Enclave", function () {
const { enclave, request } = await loadFixture(setup);
await expect(
enclave.request(
request.pool,
request.filter,
request.threshold,
request.duration,
request.computationModule,
Expand All @@ -538,7 +542,7 @@ describe("Enclave", function () {
const { enclave, request } = await loadFixture(setup);
await expect(
enclave.request(
[AddressTwo],
FilterFail,
request.threshold,
request.duration,
request.computationModule,
Expand All @@ -552,7 +556,7 @@ describe("Enclave", function () {
it("instantiates a new E3", async function () {
const { enclave, request } = await loadFixture(setup);
await enclave.request(
request.pool,
request.filter,
request.threshold,
request.duration,
request.computationModule,
Expand Down Expand Up @@ -580,7 +584,7 @@ describe("Enclave", function () {
it("emits E3Requested event", async function () {
const { enclave, request } = await loadFixture(setup);
const tx = await enclave.request(
request.pool,
request.filter,
request.threshold,
request.duration,
request.computationModule,
Expand All @@ -596,7 +600,7 @@ describe("Enclave", function () {
.withArgs(
0,
e3,
request.pool,
request.filter,
request.computationModule,
request.executionModule,
);
Expand All @@ -615,7 +619,7 @@ describe("Enclave", function () {
const { enclave, request } = await loadFixture(setup);

await enclave.request(
request.pool,
request.filter,
request.threshold,
request.duration,
request.computationModule,
Expand All @@ -635,7 +639,7 @@ describe("Enclave", function () {
const { enclave, request } = await loadFixture(setup);

await enclave.request(
request.pool,
request.filter,
request.threshold,
request.duration,
request.computationModule,
Expand Down Expand Up @@ -667,7 +671,7 @@ describe("Enclave", function () {
} = await loadFixture(setup);

await enclave.request(
request.pool,
request.filter,
request.threshold,
request.duration,
request.computationModule,
Expand All @@ -678,7 +682,7 @@ describe("Enclave", function () {
);

const e3Id = 0;
const publicKey = await registry.getCommitteePublicKey(e3Id);
const publicKey = await registry.committeePublicKey(e3Id);

let e3 = await enclave.getE3(e3Id);
expect(e3.committeePublicKey).to.not.equal(publicKey);
Expand All @@ -692,7 +696,7 @@ describe("Enclave", function () {
const { enclave, request } = await loadFixture(setup);

await enclave.request(
request.pool,
request.filter,
request.threshold,
request.duration,
request.computationModule,
Expand All @@ -710,7 +714,7 @@ describe("Enclave", function () {
const { enclave, request } = await loadFixture(setup);

await enclave.request(
request.pool,
request.filter,
request.threshold,
request.duration,
request.computationModule,
Expand Down Expand Up @@ -742,7 +746,7 @@ describe("Enclave", function () {
const { enclave, request } = await loadFixture(setup);

await enclave.request(
request.pool,
request.filter,
request.threshold,
request.duration,
request.computationModule,
Expand All @@ -768,7 +772,7 @@ describe("Enclave", function () {
const { enclave, request } = await loadFixture(setup);

await enclave.request(
request.pool,
request.filter,
request.threshold,
request.duration,
request.computationModule,
Expand All @@ -790,7 +794,7 @@ describe("Enclave", function () {
const { enclave, request } = await loadFixture(setup);

await enclave.request(
request.pool,
request.filter,
request.threshold,
request.duration,
request.computationModule,
Expand All @@ -817,7 +821,7 @@ describe("Enclave", function () {
const { enclave, request } = await loadFixture(setup);

await enclave.request(
request.pool,
request.filter,
request.threshold,
request.duration,
request.computationModule,
Expand Down

0 comments on commit 596d01a

Please sign in to comment.