Skip to content

Commit

Permalink
Stylistic tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kronosapiens committed Nov 7, 2023
1 parent 4f8933c commit 691ccac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 44 deletions.
33 changes: 9 additions & 24 deletions contracts/colony/Colony.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
42 changes: 22 additions & 20 deletions scripts/deployOldUpgradeableVersion.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
// 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);

const metaColonyAddress = await colonyNetwork.getMetaColony();
const metaColony = await artifacts.require("IMetaColony").at(metaColonyAddress);
await metaColony.addExtensionToNetwork(web3.utils.soliditySha3(contractName), extensionResolverAddress);
Expand All @@ -25,6 +28,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,
Expand All @@ -33,12 +37,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);
Expand All @@ -50,13 +54,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}`);
Expand All @@ -66,34 +72,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);
Expand Down

0 comments on commit 691ccac

Please sign in to comment.