Skip to content

Commit

Permalink
Simplify computationModuleFixture
Browse files Browse the repository at this point in the history
  • Loading branch information
cristovaoth committed Jun 3, 2024
1 parent c4de25a commit 8e16a39
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
40 changes: 21 additions & 19 deletions packages/evm/test/Enclave.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import { expect } from "chai";
import { ethers } from "hardhat";

import { deployEnclaveFixture } from "./fixtures/Enclave.fixture";
import { deployMockComputationModuleFixture } from "./fixtures/MockComputationModule.fixture";
import { deployComputationModuleFixture } from "./fixtures/MockComputationModule.fixture";
import { deployMockCypherNodeRegistryFixture } from "./fixtures/MockCypherNodeRegistry.fixture";
import { deployMockExecutionModuleFixture } from "./fixtures/MockExecutionModule.fixture";
import { deployMockInputValidatorFixture } from "./fixtures/MockInputValidator.fixture";
import { deployMockOutputVerifierFixture } from "./fixtures/MockOutputVerifier.fixture";
import { Signers } from "./types";

const abiCoder = ethers.AbiCoder.defaultAbiCoder();
const AddressTwo = "0x0000000000000000000000000000000000000002";
Expand All @@ -18,11 +17,7 @@ describe("Enclave", function () {
const enclave = await loadFixture(deployEnclaveFixture);
this.enclave = enclave;

const { mockComputationModule, mockComputationModule_address } = await loadFixture(
deployMockComputationModuleFixture,
);
this.mockComputationModule = mockComputationModule;
this.mockComputationModule_address = mockComputationModule_address;
const computationModule = await loadFixture(deployComputationModuleFixture);

const { mockOutputVerifier, mockOutputVerifier_address } = await loadFixture(deployMockOutputVerifierFixture);
this.mockOutputVerifier = mockOutputVerifier;
Expand All @@ -43,14 +38,14 @@ describe("Enclave", function () {
this.mockInputValidator_address = mockInputValidator_address;

await this.enclave.setCypherNodeRegistry(this.mockCypherNodeRegistry_address);
await this.enclave.enableComputationModule(this.mockComputationModule_address);
await this.enclave.enableComputationModule(await computationModule.getAddress());
await this.enclave.enableExecutionModule(this.mockExecutionModule_address);

this.requestParams = {
poolId: 1n,
threshold: [2n, 2n],
duration: time.duration.days(30),
computationModule: this.mockComputationModule_address,
computationModule: await computationModule.getAddress(),
cMParams: abiCoder.encode(["address"], [this.mockInputValidator_address]),
executionModule: this.mockExecutionModule_address,
eMParams: abiCoder.encode(["address"], [this.mockOutputVerifier_address]),
Expand Down Expand Up @@ -175,17 +170,20 @@ describe("Enclave", function () {
describe("enableComputationModule()", function () {
it("reverts if not called by owner", async function () {
const [, , , notTheOwner] = await ethers.getSigners();
await expect(this.enclave.connect(notTheOwner).enableComputationModule(this.mockComputationModule_address))
const { computationModule } = this.requestParams;
await expect(this.enclave.connect(notTheOwner).enableComputationModule(computationModule))
.to.be.revertedWithCustomError(this.enclave, "OwnableUnauthorizedAccount")
.withArgs(notTheOwner);
});
it("reverts if computation module is already enabled", async function () {
await expect(this.enclave.enableComputationModule(this.mockComputationModule_address))
const { computationModule } = this.requestParams;
await expect(this.enclave.enableComputationModule(computationModule))
.to.be.revertedWithCustomError(this.enclave, "ModuleAlreadyEnabled")
.withArgs(this.mockComputationModule_address);
.withArgs(computationModule);
});
it("enables computation module correctly", async function () {
const enabled = await this.enclave.computationModules(this.mockComputationModule_address);
const { computationModule } = this.requestParams;
const enabled = await this.enclave.computationModules(computationModule);
expect(enabled).to.be.true;
});
it("returns true if computation module is enabled successfully", async function () {
Expand All @@ -202,7 +200,8 @@ describe("Enclave", function () {
describe("disableComputationModule()", function () {
it("reverts if not called by owner", async function () {
const [, , , notTheOwner] = await ethers.getSigners();
await expect(this.enclave.connect(notTheOwner).disableComputationModule(this.mockComputationModule_address))
const { computationModule } = this.requestParams;
await expect(this.enclave.connect(notTheOwner).disableComputationModule(computationModule))
.to.be.revertedWithCustomError(this.enclave, "OwnableUnauthorizedAccount")
.withArgs(notTheOwner);
});
Expand All @@ -212,20 +211,23 @@ describe("Enclave", function () {
.withArgs(AddressTwo);
});
it("disables computation module correctly", async function () {
await this.enclave.disableComputationModule(this.mockComputationModule_address);
const { computationModule } = this.requestParams;
await this.enclave.disableComputationModule(computationModule);

const enabled = await this.enclave.computationModules(this.mockComputationModule_address);
const enabled = await this.enclave.computationModules(computationModule);
expect(enabled).to.be.false;
});
it("returns true if computation module is disabled successfully", async function () {
const result = await this.enclave.disableComputationModule.staticCall(this.mockComputationModule_address);
const { computationModule } = this.requestParams;
const result = await this.enclave.disableComputationModule.staticCall(computationModule);

expect(result).to.be.true;
});
it("emits ComputationModuleDisabled event", async function () {
await expect(this.enclave.disableComputationModule(this.mockComputationModule_address))
const { computationModule } = this.requestParams;
await expect(this.enclave.disableComputationModule(computationModule))
.to.emit(this.enclave, "ComputationModuleDisabled")
.withArgs(this.mockComputationModule_address);
.withArgs(computationModule);
});
});

Expand Down
13 changes: 4 additions & 9 deletions packages/evm/test/fixtures/MockComputationModule.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { ethers } from "hardhat";

import type { MockComputationModule } from "../../types/contracts/test/MockComputationModule";
import type { MockComputationModule__factory } from "../../types/factories/contracts/test/MockComputationModule__factory";
import { MockComputationModule__factory } from "../../types/factories/contracts/test/MockComputationModule__factory";

export async function deployMockComputationModuleFixture() {
const MockComputationModule = (await ethers.getContractFactory(
"MockComputationModule",
)) as MockComputationModule__factory;
const mockComputationModule = (await MockComputationModule.deploy()) as MockComputationModule;
const mockComputationModule_address = await mockComputationModule.getAddress();
export async function deployComputationModuleFixture() {
const deployment = await (await ethers.getContractFactory("MockComputationModule")).deploy();

return { mockComputationModule, mockComputationModule_address };
return MockComputationModule__factory.connect(await deployment.getAddress());
}

0 comments on commit 8e16a39

Please sign in to comment.