Skip to content

Commit

Permalink
generic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zajck committed Jun 12, 2023
1 parent 3967780 commit 0185e67
Show file tree
Hide file tree
Showing 5 changed files with 417 additions and 1 deletion.
12 changes: 12 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ module.exports = {
},
solidity: {
compilers: [
{
version: "0.8.9",
settings: {
optimizer: {
enabled: true,
runs: 200,
details: {
yul: true,
},
},
},
},
{
version: "0.8.18",
settings: {
Expand Down
107 changes: 107 additions & 0 deletions scripts/migrations/migrate_2.3.0.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
const shell = require("shelljs");
const { readContracts } = require("../util/utils.js");
const hre = require("hardhat");
const ethers = hre.ethers;
const network = hre.network.name;
// const { getStateModifyingFunctionsHashes } = require("../../scripts/util/diamond-utils.js");
const tag = "HEAD";
const version = "2.3.0";

const config = {
// status at 451dc3d. ToDo: update this to the latest commit
addOrUpgrade: [
"DisputeResolverHandlerFacet",
"FundsHandlerFacet",
"MetaTransactionsHandlerFacet",
"OfferHandlerFacet",
"OrchestrationHandlerFacet1",
"ProtocolInitializationHandlerFacet",
"SellerHandlerFacet",
"TwinHandlerFacet",
],
remove: [],
skipSelectors: {},
facetsToInit: {},
initializationData: "0x",
};

async function migrate(env) {
console.log(`Migration ${tag} started`);
try {
console.log("Removing any local changes before upgrading");
shell.exec(`git reset @{u}`);
const statusOutput = shell.exec("git status -s -uno scripts");

if (statusOutput.stdout) {
throw new Error("Local changes found. Please stash them before upgrading");
}

if (env != "upgrade-test") {
console.log("Installing dependencies");
shell.exec(`npm install`);
}

const { chainId } = await ethers.provider.getNetwork();
const contractsFile = readContracts(chainId, network, env);

if (contractsFile?.protocolVersion != "2.2.1") {
throw new Error("Current contract version must be 2.2.1");
}

// let contracts = contractsFile?.contracts;

// Get addresses of currently deployed contracts
// const protocolAddress = contracts.find((c) => c.name === "ProtocolDiamond")?.address;

// Checking old version contracts to get selectors to remove
// ToDo: at 451dc3d, no selectors to remove. Comment out this section. It will be needed when other changes are merged into main
// console.log("Checking out contracts on version 2.2.1");
// shell.exec(`rm -rf contracts/*`);
// shell.exec(`git checkout v2.2.1 contracts`);

// console.log("Compiling old contracts");
// await hre.run("clean");
// await hre.run("compile");

// const getFunctionHashesClosure = getStateModifyingFunctionsHashes(
// ["SellerHandlerFacet", "OrchestrationHandlerFacet1"],
// undefined,
// ["createSeller", "updateSeller"]
// );

// const selectorsToRemove = await getFunctionHashesClosure();

console.log(`Checking out contracts on version ${tag}`);
shell.exec(`rm -rf contracts/*`);
shell.exec(`git checkout ${tag} contracts`);

console.log("Compiling contracts");
await hre.run("clean");
await hre.run("compile");

console.log("Executing upgrade facets script");
await hre.run("upgrade-facets", {
env,
facetConfig: JSON.stringify(config),
newVersion: version,
});

// const selectorsToAdd = await getFunctionHashesClosure();

// const metaTransactionHandlerFacet = await ethers.getContractAt("MetaTransactionsHandlerFacet", protocolAddress);

// console.log("Removing selectors", selectorsToRemove.join(","));
// await metaTransactionHandlerFacet.setAllowlistedFunctions(selectorsToRemove, false);
// console.log("Adding selectors", selectorsToAdd.join(","));
// await metaTransactionHandlerFacet.setAllowlistedFunctions(selectorsToAdd, true);

shell.exec(`git checkout HEAD`);
console.log(`Migration ${tag} completed`);
} catch (e) {
console.error(e);
shell.exec(`git checkout HEAD`);
throw `Migration failed with: ${e}`;
}
}

exports.migrate = migrate;
8 changes: 7 additions & 1 deletion test/upgrade/00_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ async function getFacets() {
"v2.0.0": v2_0_0,
"v2.1.0": v2_0_0, // same as v2.0.0
"v2.2.0": v2_2_0,
"v2.2.1": v2_2_0, // same as v2.2.0
},
upgrade: {
"v2.1.0": {
Expand Down Expand Up @@ -190,6 +191,7 @@ async function getFacets() {
},
initializationData: "0x0000000000000000000000000000000000000000000000000000000000002710", // input for initV2_2_0, representing maxPremintedVoucher (0x2710=10000)
},
// POST 2.2.0 upgrade configs are part of respective migration script
},
};

Expand All @@ -210,7 +212,11 @@ const tagsByVersion = {
},
"2.2.1": {
oldVersion: "v2.2.0",
newVersion: "v2.2.1-rc.1",
newVersion: "v2.2.1",
},
"2.3.0": {
oldVersion: "v2.2.1",
newVersion: "v2.3.0",
},
};

Expand Down
Loading

0 comments on commit 0185e67

Please sign in to comment.