From f4f7e11c6d6bdd816c77d112c226f597987d5f2f Mon Sep 17 00:00:00 2001 From: Daniel Kronovet Date: Tue, 7 Nov 2023 11:23:26 -0500 Subject: [PATCH] Stylistic tweaks --- contracts/colony/Colony.sol | 33 +++++------------ scripts/deployOldUpgradeableVersion.js | 51 +++++++++++++++----------- 2 files changed, 39 insertions(+), 45 deletions(-) diff --git a/contracts/colony/Colony.sol b/contracts/colony/Colony.sol index 0b31748859..c4262f76a4 100755 --- a/contracts/colony/Colony.sol +++ b/contracts/colony/Colony.sol @@ -339,36 +339,21 @@ contract Colony is BasicMetaTransaction, Multicall, ColonyStorage, PatriciaTreeP colonyAuthority.setRoleCapability(uint8(ColonyRole.Administration), address(this), sig, false); sig = bytes4(keccak256("finalizePayment(uint256,uint256,uint256)")); - // If OneTxPayment extension is installed, if it has permissions in root, add the new role - // and upgrade it + // If OneTxPayment extension is installed, add the new role and upgrade it bytes32 ONE_TX_PAYMENT = keccak256("OneTxPayment"); - address oneTxPaymentAddress = IColonyNetwork(colonyNetworkAddress).getExtensionInstallation( - ONE_TX_PAYMENT, - address(this) - ); - if (oneTxPaymentAddress != address(0x00)) { - // Then it's installed. Is it version 5? + IColonyNetwork network = IColonyNetwork(colonyNetworkAddress); + address oneTxPaymentAddress = network.getExtensionInstallation(ONE_TX_PAYMENT, address(this)); + + if (oneTxPaymentAddress != address(0x0)) { uint256 installedVersion = ColonyExtension(oneTxPaymentAddress).version(); require(installedVersion >= 5, "colony-upgrade-one-tx-payment-to-6"); if (installedVersion == 5) { - // Does it have administration permission in root? - if ( - ColonyAuthority(address(authority)).hasUserRole( - oneTxPaymentAddress, - 1, - uint8(ColonyRole.Administration) - ) - ) { - // Add arbitration permission in root - ColonyAuthority(address(authority)).setUserRole( - oneTxPaymentAddress, - 1, - uint8(ColonyRole.Arbitration), - true - ); + // If installed in root, add arbitration permission + if (colonyAuthority.hasUserRole(oneTxPaymentAddress, 1, uint8(ColonyRole.Administration))) { + colonyAuthority.setUserRole(oneTxPaymentAddress, 1, uint8(ColonyRole.Arbitration), true); } // Upgrade extension - IColonyNetwork(colonyNetworkAddress).upgradeExtension(ONE_TX_PAYMENT, 6); + network.upgradeExtension(ONE_TX_PAYMENT, 6); } } } diff --git a/scripts/deployOldUpgradeableVersion.js b/scripts/deployOldUpgradeableVersion.js index bebeaf7f28..efd67d1693 100644 --- a/scripts/deployOldUpgradeableVersion.js +++ b/scripts/deployOldUpgradeableVersion.js @@ -1,17 +1,27 @@ // Input: /* globals artifacts */ -const Promise = require("bluebird"); +const fs = require("fs"); const path = require("path"); + +const Promise = require("bluebird"); const exec = Promise.promisify(require("child_process").exec); -const fs = require("fs"); module.exports.deployOldExtensionVersion = async (contractName, interfaceName, implementationNames, versionTag, colonyNetwork) => { if (versionTag.indexOf(" ") !== -1) { throw new Error("Version tag cannot contain spaces"); } + try { - const extensionResolverAddress = await deployOldUpgradeableVersion(contractName, interfaceName, implementationNames, versionTag, colonyNetwork); + // eslint-disable-next-line prettier/prettier + const extensionResolverAddress = await deployOldUpgradeableVersion( + contractName, + interfaceName, + implementationNames, + versionTag, + colonyNetwork + ); + const metaColonyAddress = await colonyNetwork.getMetaColony(); const metaColony = await artifacts.require("IMetaColony").at(metaColonyAddress); await metaColony.addExtensionToNetwork(web3.utils.soliditySha3(contractName), extensionResolverAddress); @@ -25,6 +35,7 @@ module.exports.deployOldColonyVersion = async (contractName, interfaceName, impl if (versionTag.indexOf(" ") !== -1) { throw new Error("Version tag cannot contain spaces"); } + try { const colonyVersionResolverAddress = await deployOldUpgradeableVersion( contractName, @@ -33,12 +44,12 @@ module.exports.deployOldColonyVersion = async (contractName, interfaceName, impl versionTag, colonyNetwork, ); - console.log(colonyVersionResolverAddress); - const colonyVersionResolver = await artifacts.require("Resolver").at(colonyVersionResolverAddress); + 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 version = await versionImplementation.version(); + const metaColonyAddress = await colonyNetwork.getMetaColony(); const metaColony = await artifacts.require("IMetaColony").at(metaColonyAddress); await metaColony.addNetworkColonyVersion(version, colonyVersionResolverAddress); @@ -50,13 +61,15 @@ module.exports.deployOldColonyVersion = async (contractName, interfaceName, impl async function deployOldUpgradeableVersion(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 + // If directory exists, assume we've already done this and skip let exists; + try { exists = fs.existsSync(`./colonyNetwork-${versionTag}/build/contracts/`); } catch (err) { exists = false; } + if (!exists) { console.log("doesnt exist"); await exec(`rm -rf colonyNetwork-${versionTag}`); @@ -66,34 +79,30 @@ async function deployOldUpgradeableVersion(contractName, interfaceName, implemen await exec(`cd colonyNetwork-${versionTag} && npm install`); await exec(`cd colonyNetwork-${versionTag} && npm run provision:token:contracts`); } - // This is how we could do it without an extra script, but pricing ourselves in to 'truffle deploy' every time, which - // takes about an extra minute. - // await exec(`cd colonyNetwork-${versionTag} && npx truffle deploy`); + // This is how we could do it without an extra script, but pricing ourselves in to 'truffle deploy' every time, + // which takes about an extra minute. + + // await exec(`cd colonyNetwork-${versionTag} && npx truffle deploy`); // const etherRouterJSONContents = fs.readFileSync(`./colonyNetwork-${versionTag}/etherrouter-address.json`); // const otherColonyNetworkAddress = JSON.parse(etherRouterJSONContents).etherRouterAddress; // const otherColonyNetwork = await artifacts.require("IColonyNetwork").at(otherColonyNetworkAddress); // const events = await otherColonyNetwork.getPastEvents("ExtensionAddedToNetwork", { fromBlock: 0, toBlock: "latest" }); - - // const relevantEvents = events.filter((event) => { - // return event.returnValues.extensionId === web3.utils.soliditySha3(contractName); - // }); + // const relevantEvents = events.filter((event) => event.returnValues.extensionId === web3.utils.soliditySha3(contractName)); // const extensionVersion = await relevantEvents[0].returnValues.version; - // const extensionResolverAddress = await otherColonyNetwork.getExtensionResolver(web3.utils.soliditySha3(contractName), extensionVersion); - const network = process.env.SOLIDITY_COVERAGE ? "coverage" : "development"; - await exec(`cp ./scripts/deployOldUpgradeableVersionTruffle.js ./colonyNetwork-${versionTag}/scripts/deployOldUpgradeableVersionTruffle.js`); + + const network = process.env.SOLIDITY_COVERAGE ? "coverage" : "development"; let res; + try { res = await exec( - `cd ${path.resolve( - __dirname, - `../colonyNetwork-${versionTag}`, - )} && npx truffle exec --network ${network} ./scripts/deployOldUpgradeableVersionTruffle.js --interfaceName ${interfaceName}` + - ` --implementationNames ${implementationNames.join(",")}`, + `cd ${path.resolve(__dirname, `../colonyNetwork-${versionTag}`)} ` + + "&& npx truffle exec ./scripts/deployOldUpgradeableVersionTruffle.js " + + `--network ${network} --interfaceName ${interfaceName} --implementationNames ${implementationNames.join(",")}`, ); console.log("res", res);