Skip to content

Commit

Permalink
Merge pull request #94 from gnosisguild/mock-deploy
Browse files Browse the repository at this point in the history
Deploy mocks, working committee requesting
  • Loading branch information
samepant authored Sep 17, 2024
2 parents 60cc057 + 5aaadcb commit 9e149e1
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 39 deletions.
1 change: 1 addition & 0 deletions packages/evm/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ coverage
dist
node_modules
types
deployments/localhost

# files
*.env
Expand Down
5 changes: 2 additions & 3 deletions packages/evm/contracts/registry/NaiveRegistryFilter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ contract NaiveRegistryFilter is IRegistryFilter, OwnableUpgradeable {
uint256 e3Id,
uint32[2] calldata threshold
) external onlyRegistry returns (bool success) {
Committee storage committee = committees[e3Id];
require(committee.threshold.length == 0, CommitteeAlreadyExists());
committee.threshold = threshold;
require(committees[e3Id].threshold[1] == 0, CommitteeAlreadyExists());
committees[e3Id].threshold = threshold;
success = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,4 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log(`Enclave contract updated with registry`);
};
export default func;
func.id = "deploy_enclave"; // id required to prevent reexecution
func.tags = ["Enclave"];
func.tags = ["enclave"];
33 changes: 33 additions & 0 deletions packages/evm/deploy/mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await hre.getNamedAccounts();
const { deploy } = hre.deployments;

await deploy("MockE3Program", {
from: deployer,
args: [],
log: true,
});

await deploy("MockComputeProvider", {
from: deployer,
args: [],
log: true,
});

await deploy("MockDecryptionVerifier", {
from: deployer,
args: [],
log: true,
});

await deploy("MockInputValidator", {
from: deployer,
args: [],
log: true,
});
};
export default func;
func.tags = ["mocks"];
3 changes: 2 additions & 1 deletion packages/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"clean": "rimraf ./artifacts ./cache ./coverage ./types ./coverage.json && yarn typechain",
"compile": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat compile",
"coverage": "hardhat coverage --solcoverjs ./.solcover.js --temp artifacts --testfiles \"test/**/*.ts\" && yarn typechain",
"deploy": "hardhat deploy",
"deploy": "hardhat deploy --tags enclave",
"deploy:mocks": "hardhat deploy --tags enclave,mocks",
"ciphernode:add": "hardhat ciphernode:add",
"ciphernode:remove": "hardhat ciphernode:remove",
"lint": "yarn lint:sol && yarn lint:ts && yarn prettier:check",
Expand Down
18 changes: 0 additions & 18 deletions packages/evm/tasks/ciphernode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,3 @@ task("ciphernode:add", "Register a ciphernode to the registry")

console.log(`Ciphernode ${taskArguments.ciphernodeAddress} registered`);
});

task("ciphernode:remove", "Remove a ciphernode from the registry")
.addParam("ciphernodeAddress", "address of ciphernode to remove")
.setAction(async function (taskArguments: TaskArguments, hre) {
const registry = await hre.deployments.get("CiphernodeRegistryOwnable");

const registryContract = await hre.ethers.getContractAt(
"CiphernodeRegistryOwnable",
registry.address,
);

const tx = await registryContract.removeCiphernode(
taskArguments.ciphernodeAddress,
);
await tx.wait();

console.log(`Ciphernode ${taskArguments.ciphernodeAddress} removed`);
});
48 changes: 33 additions & 15 deletions packages/evm/tasks/committee.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { task, types } from "hardhat/config";
import type { TaskArguments } from "hardhat/types";

task("committee:new", "Request a new ciphernode committee")
task(
"committee:new",
"Request a new ciphernode committee, will use E3 mock contracts by default",
)
.addOptionalParam(
"filter",
"address of filter contract to use",
"0x0000000000000000000000000000000000000006",
undefined,
types.string,
)
.addOptionalParam(
Expand Down Expand Up @@ -41,7 +44,7 @@ task("committee:new", "Request a new ciphernode committee")
.addOptionalParam(
"e3Address",
"address of the E3 program",
"0x95E366f13c16976A26339aBe7992a1AB523388f5",
undefined,
types.string,
)
.addOptionalParam(
Expand All @@ -64,34 +67,49 @@ task("committee:new", "Request a new ciphernode committee")
enclave.address,
);

try {
const enableE3Tx = await enclaveContract.enableE3Program(
taskArguments.e3Address,
let e3Address = taskArguments.e3Address;
if (!e3Address) {
const mockE3Program = await hre.deployments.get("MockE3Program");
if (!mockE3Program) {
throw new Error("MockE3Program not deployed");
}
e3Address = mockE3Program.address;
}

let filterAddress = taskArguments.filter;
if (!filterAddress) {
const naiveRegistryFilter = await hre.deployments.get(
"NaiveRegistryFilter",
);
if (!naiveRegistryFilter) {
throw new Error("NaiveRegistryFilter not deployed");
}
filterAddress = naiveRegistryFilter.address;
}

try {
const enableE3Tx = await enclaveContract.enableE3Program(e3Address);
await enableE3Tx.wait();
} catch (e: unknown) {
console.log(
"E3 program enabling failed, probably already enabled: ",
e.message,
);
} catch (e) {
console.log("E3 program enabling failed, probably already enabled: ", e);
}

console.log(
"requesting committee...",
taskArguments.filter,
filterAddress,
[taskArguments.thresholdQuorum, taskArguments.thresholdTotal],
[taskArguments.windowStart, taskArguments.windowEnd],
taskArguments.duration,
taskArguments.e3Address,
e3Address,
taskArguments.e3Params,
taskArguments.computeParams,
);
const tx = await enclaveContract.request(
taskArguments.filter,
filterAddress,
[taskArguments.thresholdQuorum, taskArguments.thresholdTotal],
[taskArguments.windowStart, taskArguments.windowEnd],
taskArguments.duration,
taskArguments.e3Address,
e3Address,
taskArguments.e3Params,
taskArguments.computeParams,
// 1 ETH
Expand Down

0 comments on commit 9e149e1

Please sign in to comment.