Skip to content

Commit

Permalink
Restore tests reading old global skills
Browse files Browse the repository at this point in the history
  • Loading branch information
area authored and kronosapiens committed Nov 14, 2023
1 parent e200f47 commit cffeba9
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 9 deletions.
11 changes: 11 additions & 0 deletions helpers/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const NoLimitSubdomains = artifacts.require("NoLimitSubdomains");
const Resolver = artifacts.require("Resolver");
const ContractEditing = artifacts.require("ContractEditing");
const ColonyDomains = artifacts.require("ColonyDomains");
const EtherRouter = artifacts.require("EtherRouter");

const { expect } = chai;

Expand Down Expand Up @@ -1065,6 +1066,16 @@ exports.getColonyEditable = async function getColonyEditable(colony, colonyNetwo
return colonyUnderRecovery;
};

exports.getColonyNetworkEditable = async function getColonyNetworkEditable(colonyNetwork) {
const networkAsEtherRouter = await EtherRouter.at(colonyNetwork.address);
const resolverAddress = await networkAsEtherRouter.resolver();
const colonyNetworkResolver = await Resolver.at(resolverAddress);
const contractEditing = await ContractEditing.new();
await colonyNetworkResolver.register("setStorageSlot(uint256,bytes32)", contractEditing.address);
const colonyNetworkEditable = await ContractEditing.at(colonyNetwork.address);
return colonyNetworkEditable;
};

exports.getWaitForNSubmissionsPromise = async function getWaitForNSubmissionsPromise(repCycleEthers, rootHash, nLeaves, jrh, n) {
return new Promise(function (resolve, reject) {
repCycleEthers.on("ReputationRootHashSubmitted", async (_miner, _hash, _nLeaves, _jrh, _entryIndex, event) => {
Expand Down
107 changes: 98 additions & 9 deletions scripts/deployOldUpgradeableVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,30 @@ const path = require("path");
const Promise = require("bluebird");
const exec = Promise.promisify(require("child_process").exec);
const contract = require("@truffle/contract");
const { getColonyEditable, getColonyNetworkEditable } = require("../helpers/test-helper");
const { ROOT_ROLE } = require("../helpers/constants");

const colonyDeployed = {};
const colonyNetworkDeployed = {};
const deployedResolverAddresses = {};

module.exports.deployOldExtensionVersion = async (contractName, interfaceName, implementationNames, versionTag, colonyNetwork) => {
if (versionTag.indexOf(" ") !== -1) {
throw new Error("Version tag cannot contain spaces");
}
if (deployedResolverAddresses[interfaceName] && deployedResolverAddresses[interfaceName][versionTag]) {
// Already deployed
return;
}

try {
// eslint-disable-next-line prettier/prettier
const extensionResolverAddress = await deployOldUpgradeableVersion(
const extensionResolverAddress = await module.exports.deployOldUpgradeableVersion(
contractName,
interfaceName,
implementationNames,
versionTag,
colonyNetwork
colonyNetwork,
);

const metaColonyAddress = await colonyNetwork.getMetaColony();
Expand All @@ -36,9 +46,16 @@ module.exports.deployOldColonyVersion = async (contractName, interfaceName, impl
if (versionTag.indexOf(" ") !== -1) {
throw new Error("Version tag cannot contain spaces");
}
if (!colonyDeployed[interfaceName]) {
colonyDeployed[interfaceName] = {};
}
if (colonyDeployed[interfaceName][versionTag]) {
// Already deployed
return colonyDeployed[interfaceName][versionTag];
}

try {
const colonyVersionResolverAddress = await deployOldUpgradeableVersion(
const colonyVersionResolverAddress = await module.exports.deployOldUpgradeableVersion(
contractName,
interfaceName,
implementationNames,
Expand All @@ -48,7 +65,7 @@ module.exports.deployOldColonyVersion = async (contractName, interfaceName, impl

const colonyVersionResolver = await artifacts.require("Resolver").at(colonyVersionResolverAddress);
const versionImplementationAddress = await colonyVersionResolver.lookup(web3.utils.soliditySha3("version()").slice(0, 10));
const versionImplementation = await artifacts.require("IColony").at(versionImplementationAddress);
const versionImplementation = await artifacts.require("IMetaColony").at(versionImplementationAddress);
const version = await versionImplementation.version();

const metaColonyAddress = await colonyNetwork.getMetaColony();
Expand All @@ -59,14 +76,85 @@ module.exports.deployOldColonyVersion = async (contractName, interfaceName, impl
const OldInterface = contract(JSON.parse(interfaceArtifact));
OldInterface.setProvider(web3.currentProvider);

return OldInterface;
const oldAuthorityArtifact = fs.readFileSync(`./colonyNetwork-${versionTag}/build/contracts/ColonyAuthority.json`);
const OldAuthority = contract(JSON.parse(oldAuthorityArtifact));
OldAuthority.setProvider(web3.currentProvider);

colonyDeployed[interfaceName] = colonyDeployed[interfaceName] || {};
colonyDeployed[interfaceName][versionTag] = { OldInterface, OldAuthority, resolverAddress: colonyVersionResolverAddress };

return colonyDeployed[interfaceName][versionTag];
} catch (e) {
console.log(e);
return process.exit(1);
}
};

async function deployOldUpgradeableVersion(contractName, interfaceName, implementationNames, versionTag) {
module.exports.downgradeColony = async (colonyNetwork, colony, version) => {
if (!colonyDeployed.IMetaColony[version]) {
throw new Error("Version not deployed");
}
const accounts = await web3.eth.getAccounts();
const editableColony = await getColonyEditable(colony, colonyNetwork);

const oldAuthority = await colonyDeployed.IMetaColony[version].OldAuthority.new(colony.address, { from: accounts[0] });
const owner = await oldAuthority.owner();
await oldAuthority.setUserRole(accounts[0], ROOT_ROLE, true, { from: owner });
await oldAuthority.setOwner(colony.address, { from: accounts[0] });
await editableColony.setStorageSlot(0, `0x${"0".repeat(24)}${oldAuthority.address.slice(2)}`);
const oldVersionResolver = colonyDeployed.IMetaColony[version].resolverAddress;
await editableColony.setStorageSlot(2, `0x${"0".repeat(24)}${oldVersionResolver.slice(2)}`);
};

module.exports.downgradeColonyNetwork = async (colonyNetwork, version) => {
if (!colonyNetworkDeployed[version]) {
throw new Error("Version not deployed");
}

const editableNetwork = await getColonyNetworkEditable(colonyNetwork);
const accounts = await web3.eth.getAccounts();
const oldAuthority = await colonyNetworkDeployed[version].OldAuthority.new(colonyNetwork.address, { from: accounts[0] });
await editableNetwork.setStorageSlot(0, `0x${"0".repeat(24)}${oldAuthority.address.slice(2)}`);
const oldVersionResolver = colonyNetworkDeployed[version].resolverAddress;
await editableNetwork.setStorageSlot(2, `0x${"0".repeat(24)}${oldVersionResolver.slice(2)}`);
};

module.exports.deployOldColonyNetworkVersion = async (contractName, interfaceName, implementationNames, versionTag, colonyNetwork) => {
if (versionTag.indexOf(" ") !== -1) {
throw new Error("Version tag cannot contain spaces");
}
if (colonyNetworkDeployed[versionTag]) {
return colonyNetworkDeployed[versionTag];
}
colonyNetworkDeployed[versionTag] = {};

try {
const colonyNetworkResolverAddress = await module.exports.deployOldUpgradeableVersion(
contractName,
interfaceName,
implementationNames,
versionTag,
colonyNetwork,
);

const interfaceArtifact = fs.readFileSync(`./colonyNetwork-${versionTag}/build/contracts/IColonyNetwork.json`);
const OldInterface = contract(JSON.parse(interfaceArtifact));
OldInterface.setProvider(web3.currentProvider);

const oldAuthorityArtifact = fs.readFileSync(`./colonyNetwork-${versionTag}/build/contracts/ColonyNetworkAuthority.json`);
const OldAuthority = contract(JSON.parse(oldAuthorityArtifact));
OldAuthority.setProvider(web3.currentProvider);

colonyNetworkDeployed[versionTag] = { resolverAddress: colonyNetworkResolverAddress, OldInterface, OldAuthority };

return colonyNetworkDeployed[versionTag];
} catch (e) {
console.log(e);
return process.exit(1);
}
};

module.exports.deployOldUpgradeableVersion = async (contractName, interfaceName, implementationNames, versionTag) => {
// Check out old version of repo in to a new directory
// If directory exists, assume we've already done this and skip
let exists;
Expand Down Expand Up @@ -111,12 +199,13 @@ async function deployOldUpgradeableVersion(contractName, interfaceName, implemen
"&& npx truffle exec ./scripts/deployOldUpgradeableVersionTruffle.js " +
`--network ${network} --interfaceName ${interfaceName} --implementationNames ${implementationNames.join(",")}`,
);

console.log("res", res);
} catch (err) {
console.log("err", err);
}

const resolverAddress = res.split("\n").slice(-2)[0].trim();
deployedResolverAddresses[interfaceName] = deployedResolverAddresses[interfaceName] || {};
deployedResolverAddresses[interfaceName][versionTag] = resolverAddress;

return resolverAddress;
}
};
61 changes: 61 additions & 0 deletions test/contracts-network/meta-colony.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ const { soliditySha3 } = require("web3-utils");
const { UINT256_MAX, WAD, ADDRESS_ZERO, HASHZERO } = require("../../helpers/constants");
const { checkErrorRevert, removeSubdomainLimit, restoreSubdomainLimit } = require("../../helpers/test-helper");
const { setupColonyNetwork, setupMetaColonyWithLockedCLNYToken, setupRandomColony } = require("../../helpers/test-data-generator");
const {
deployOldColonyVersion,
downgradeColony,
deployOldColonyNetworkVersion,
downgradeColonyNetwork,
} = require("../../scripts/deployOldUpgradeableVersion");

const IMetaColony = artifacts.require("IMetaColony");
const EtherRouter = artifacts.require("EtherRouter");

const { expect } = chai;
chai.use(bnChai(web3.utils.BN));
Expand Down Expand Up @@ -410,6 +417,60 @@ contract("Meta Colony", (accounts) => {
});
});

describe("when managing global skills", () => {
let globalSkillId;
beforeEach(async () => {
const { OldInterface } = await deployOldColonyVersion(
"Colony",
"IMetaColony",
[
// eslint-disable-next-line max-len
"Colony,ColonyDomains,ColonyExpenditure,ColonyFunding,ColonyPayment,ColonyRewards,ColonyRoles,ColonyTask,ContractRecovery,ColonyArbitraryTransaction",
],
"glwss4",
colonyNetwork,
);

await downgradeColony(colonyNetwork, metaColony, "glwss4");

// Make the colonyNetwork the old version
await deployOldColonyNetworkVersion(
"",
"IColonyNetwork",
["ColonyNetwork,ColonyNetworkAuction,ColonyNetworkDeployer,ColonyNetworkENS,ColonyNetworkExtensions,ColonyNetworkMining,ContractRecovery"],
"glwss4",
);

const colonyNetworkAsEtherRouter = await EtherRouter.at(colonyNetwork.address);
const latestResolver = await colonyNetworkAsEtherRouter.resolver();

await downgradeColonyNetwork(colonyNetwork, "glwss4");

// Add global skill
const oldMetaColony = await OldInterface.at(metaColony.address);
await oldMetaColony.addGlobalSkill({ from: accounts[0] });
globalSkillId = await colonyNetwork.getSkillCount();

// Upgrade to current version
await colonyNetworkAsEtherRouter.setResolver(latestResolver);
await metaColony.upgrade(14, { from: accounts[0] });
});

describe("when getting a skill", () => {
it("should return a true flag if the skill is global", async () => {
const globalSkill = await colonyNetwork.getSkill(globalSkillId);

expect(globalSkill.DEPRECATED_globalSkill).to.be.true;
});

it("should return a false flag if the skill is a domain or local skill", async () => {
const domainSkill = await colonyNetwork.getSkill(3);

expect(domainSkill.DEPRECATED_globalSkill).to.be.false;
});
});
});

describe("when managing the payout whitelist", () => {
it("should allow a meta colony root user to update the whitelist", async () => {
let status = await colonyNetwork.getPayoutWhitelist(clnyToken.address);
Expand Down

0 comments on commit cffeba9

Please sign in to comment.