Skip to content

Commit

Permalink
Make short-circuiting old version deployments more robust to snapshot…
Browse files Browse the repository at this point in the history
…-reverts
  • Loading branch information
area committed Sep 23, 2024
1 parent c940c67 commit 8211ab9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 14 additions & 10 deletions scripts/deployOldUpgradeableVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const contract = require("@truffle/contract");
const { web3GetCode, setStorageSlot } = require("../helpers/test-helper");
const { ROOT_ROLE, RECOVERY_ROLE, ADMINISTRATION_ROLE, ARCHITECTURE_ROLE, ADDRESS_ZERO } = require("../helpers/constants");

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

module.exports.deployOldExtensionVersion = async (contractName, interfaceName, implementationNames, versionTag, colonyNetwork) => {
if (versionTag.indexOf(" ") !== -1) {
Expand Down Expand Up @@ -108,6 +108,12 @@ module.exports.registerOldColonyVersion = async (colonyVersionResolverAddress, c
}
};

module.exports.resetAlreadyDeployedVersionTracking = async () => {
colonyDeployed = {};
colonyNetworkDeployed = {};
deployedResolverAddresses = {};
};

module.exports.deployOldColonyVersion = async (contractName, interfaceName, implementationNames, versionTag, colonyNetwork) => {
if (versionTag.indexOf(" ") !== -1) {
throw new Error("Version tag cannot contain spaces");
Expand All @@ -116,14 +122,12 @@ module.exports.deployOldColonyVersion = async (contractName, interfaceName, impl
colonyDeployed[interfaceName] = {};
}
if (colonyDeployed[interfaceName][versionTag]) {
// Already deployed... if truffle's not snapshotted it away. See if there's any code there.
// Already deployed... note that if a snapshot revert is made without calling `resetAlreadyDeployedVersionTracking`,
// then this will break.
const { resolverAddress } = colonyDeployed[interfaceName][versionTag];
const code = await web3GetCode(resolverAddress);
if (code !== "0x") {
// Must also check it's registered
await module.exports.registerOldColonyVersion(resolverAddress, colonyNetwork);
return colonyDeployed[interfaceName][versionTag];
}
// Must also check it's registered
await module.exports.registerOldColonyVersion(resolverAddress, colonyNetwork);
return colonyDeployed[interfaceName][versionTag];
}

try {
Expand Down
2 changes: 2 additions & 0 deletions test/truffle-fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const ethers = require("ethers");
const { soliditySha3 } = require("web3-utils");
const truffleContract = require("@truffle/contract");
const createXABI = require("../lib/createx/artifacts/src/ICreateX.sol/ICreateX.json");
const { resetAlreadyDeployedVersionTracking } = require("../scripts/deployOldUpgradeableVersion");

let postFixtureSnapshotId;

Expand All @@ -82,6 +83,7 @@ const { getChainId, hardhatRevert, hardhatSnapshot, deployCreateXIfNeeded, isXda
module.exports = async () => {
if (postFixtureSnapshotId) {
await hardhatRevert(hre.network.provider, postFixtureSnapshotId);
await resetAlreadyDeployedVersionTracking();
postFixtureSnapshotId = await hardhatSnapshot(hre.network.provider);
return;
}
Expand Down

0 comments on commit 8211ab9

Please sign in to comment.