Skip to content

Commit

Permalink
test: update scripts rework
Browse files Browse the repository at this point in the history
  • Loading branch information
heueristik committed Sep 20, 2023
1 parent b89cb57 commit 86b8c95
Show file tree
Hide file tree
Showing 11 changed files with 281 additions and 48 deletions.
68 changes: 68 additions & 0 deletions packages/contracts/deploy/update/to_v1.4.0/10_DAOFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import {Operation} from '../../../utils/types';
import {getActiveContractAddress} from '../../helpers';
import {DAO__factory} from '../../../typechain';

import daoFactoryArtifact from '../../../artifacts/src/framework/dao/DAOFactory.sol/DAOFactory.json';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log('\nUpdating DAOFactory');
const {deployments, ethers} = hre;
const {deploy} = deployments;
const [deployer] = await ethers.getSigners();

const managingDAOAddress = await getActiveContractAddress('managingDAO', hre);
const pluginSetupProcessorAddress = await getActiveContractAddress(
'PluginSetupProcessor',
hre
);
const daoRegistryAddress = await getActiveContractAddress('DAORegistry', hre);
const previousDAOFactoryAddress = await getActiveContractAddress(
'DAOFactory',
hre
);
console.log(`Using managingDAO ${managingDAOAddress}`);
console.log(`Using PluginSetupProcessor ${pluginSetupProcessorAddress}`);
console.log(`Using DAORegistry ${daoRegistryAddress}`);
console.log(`Using PreviousDAOFactory ${previousDAOFactoryAddress}`);

const deployResult = await deploy('DAOFactory', {
contract: daoFactoryArtifact,
from: deployer.address,
args: [daoRegistryAddress, pluginSetupProcessorAddress],
log: true,
});

const daoInterface = DAO__factory.createInterface();
const calldata = daoInterface.encodeFunctionData(
'applyMultiTargetPermissions',
[
[
{
who: previousDAOFactoryAddress,
where: daoRegistryAddress,
operation: Operation.Revoke,
permissionId: ethers.utils.id('REGISTER_DAO_PERMISSION'),
condition: ethers.constants.AddressZero,
},
{
who: deployResult.address,
where: daoRegistryAddress,
operation: Operation.Grant,
permissionId: ethers.utils.id('REGISTER_DAO_PERMISSION'),
condition: ethers.constants.AddressZero,
},
],
]
);
// update permissions actions
hre.managingDAOActions.push({
to: managingDAOAddress,
value: 0,
data: calldata,
description: `Moves the REGISTER_DAO_PERMISSION_ID permission on the DAORegistry (${daoRegistryAddress}) from the old to the new DAOFactory (${previousDAOFactoryAddress} -> ${deployResult.address}).`,
});
};
export default func;
func.tags = ['DAOFactory', 'v1.4.0'];
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import {DAOFactory__factory} from '../../../typechain';
import {getContractAddress} from '../../helpers';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log('\nConcluding DAOFactory update');
const {deployments, ethers} = hre;
const [deployer] = await ethers.getSigners();

const daoFactoryAddress = await getContractAddress('DAOFactory', hre);
const daoFactory = DAOFactory__factory.connect(daoFactoryAddress, deployer);
const daoBase = await daoFactory.callStatic.daoBase();

hre.aragonToVerifyContracts.push(await deployments.get('DAOFactory'));
hre.aragonToVerifyContracts.push({
address: daoBase,
args: [],
});
};
export default func;
func.tags = ['DAOFactory', 'Verify', 'v1.4.0'];
40 changes: 40 additions & 0 deletions packages/contracts/deploy/update/to_v1.4.0/90_ManagingDAO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import {DAOFactory__factory, DAO__factory} from '../../../typechain';
import {getContractAddress} from '../../helpers';
import {IMPLICIT_INITIAL_PROTOCOL_VERSION} from '../../../test/test-utils/protocol-version';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log('\nUpgrade the managing DAO to new implemenation');

const daoFactoryAddress = await getContractAddress('DAOFactory', hre);
const newDaoImplementation = await DAOFactory__factory.connect(
daoFactoryAddress,
hre.ethers.provider
).daoBase();

const managingDAOAddress = await getContractAddress('managingDAO', hre);
const managingDAO = DAO__factory.connect(
managingDAOAddress,
hre.ethers.provider
);
const upgradeTX = await managingDAO.populateTransaction.upgradeToAndCall(
newDaoImplementation,
managingDAO.interface.encodeFunctionData('initializeFrom', [
IMPLICIT_INITIAL_PROTOCOL_VERSION,
[],
])
);

if (!upgradeTX.to || !upgradeTX.data) {
throw new Error(`Failed to populate upgradeToAndCall transaction`);
}
hre.managingDAOActions.push({
to: upgradeTX.to,
data: upgradeTX.data,
value: 0,
description: `Upgrade the managing DAO to the new implementation (${newDaoImplementation})`,
});
};
export default func;
func.tags = ['ManagingDAO', 'v1.4.0'];
3 changes: 2 additions & 1 deletion packages/contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'solidity-coverage';
import 'solidity-docgen';

import {AragonPluginRepos, TestingFork} from './utils/types';
import {parseUnits} from 'ethers/lib/utils';

dotenv.config();

Expand Down Expand Up @@ -75,7 +76,7 @@ const config: HardhatUserConfig = {
throwOnTransactionFailures: true,
throwOnCallFailures: true,
blockGasLimit: 3000000000, // really high to test some things that are only possible with a higher block gas limit
gasPrice: 80000000000,
gasPrice: parseUnits('400.0', 'gwei').toNumber(),
deploy: ENABLE_DEPLOY_TEST
? ['./deploy']
: ['./deploy/new', './deploy/verification'],
Expand Down
17 changes: 6 additions & 11 deletions packages/contracts/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,40 @@
"url": "https://goerli.infura.io/v3/481a4cdc7c774286b8627f21c6827f48",
"isTestnet": true,
"chainId": 5,
"deploy": ["./deploy/update/to_v1.3.0", "./deploy/verification"]
"deploy": ["./deploy/update/to_v1.4.0", "./deploy/verification"]
},
"mainnet": {
"url": "https://mainnet.infura.io/v3/481a4cdc7c774286b8627f21c6827f48",
"isTestnet": false,
"chainId": 1,
"deploy": ["./deploy/update/to_v1.3.0", "./deploy/verification"]
},
"arbitrum": {
"url": "https://arbitrum-mainnet.infura.io/v3/481a4cdc7c774286b8627f21c6827f48",
"isTestnet": false,
"chainId": 42161
"deploy": ["./deploy/update/to_v1.4.0", "./deploy/verification"]
},
"polygon": {
"url": "https://polygon-mainnet.infura.io/v3/481a4cdc7c774286b8627f21c6827f48",
"isTestnet": false,
"chainId": 137,
"feesUrl": "https://gasstation-mainnet.matic.network/v2",
"deploy": ["./deploy/update/to_v1.3.0", "./deploy/verification"]
"deploy": ["./deploy/update/to_v1.4.0", "./deploy/verification"]
},
"mumbai": {
"url": "https://polygon-mumbai.infura.io/v3/481a4cdc7c774286b8627f21c6827f48",
"isTestnet": true,
"chainId": 80001,
"feesUrl": "https://gasstation-mumbai.matic.today/v2",
"deploy": ["./deploy/update/to_v1.3.0", "./deploy/verification"]
"deploy": ["./deploy/update/to_v1.4.0", "./deploy/verification"]
},
"baseMainnet": {
"url": "https://developer-access-mainnet.base.org",
"isTestnet": false,
"chainId": 8453,
"deploy": ["./deploy/new", "./deploy/verification"],
"deploy": ["./deploy/update/to_v1.4.0", "./deploy/verification"],
"gasPrice": 1000
},
"baseGoerli": {
"url": "https://goerli.base.org",
"isTestnet": true,
"chainId": 84531,
"deploy": ["./deploy/new", "./deploy/verification"],
"deploy": ["./deploy/update/to_v1.4.0", "./deploy/verification"],
"gasPrice": 1000000
}
}
3 changes: 2 additions & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
},
"homepage": "https://github.com/aragon/osx#readme",
"devDependencies": {
"@aragon/osx-ethers-v1.2.0": "npm:@aragon/[email protected]",
"@aragon/osx-ethers-v1.2.1": "npm:@aragon/[email protected]",
"@aragon/osx-ethers-v1.3.0-rc0.2": "npm:@aragon/[email protected]",
"@aragon/osx-v1.0.1": "npm:@aragon/[email protected]",
"@aragon/osx-v1.3.0-rc0.2": "npm:@aragon/[email protected]",
"@defi-wonderland/smock": "^2.3.4",
Expand Down
15 changes: 15 additions & 0 deletions packages/contracts/test/deploy/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {expect} from 'chai';

import {deployments} from 'hardhat';
import {
ForkOsxVersion,
initForkForOsxVersion,
initializeDeploymentFixture,
} from '../test-utils/fixture';

const enableTest = process.env.TEST_UPDATE_DEPLOY_SCRIPT !== undefined;

export type NetworkForkData = {
networkName: string;
forkBlockNumber: number;
};
78 changes: 48 additions & 30 deletions packages/contracts/test/deploy/updateTo1_3_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,62 @@ import {
initForkForOsxVersion,
initializeDeploymentFixture,
} from '../test-utils/fixture';
import {activeContractsList as v1_2_0_activeContracts} from '@aragon/osx-ethers-v1.2.0';
import {activeContractsList as v1_2_1_activeContracts} from '@aragon/osx-ethers-v1.2.1';

const enableTest = process.env.TEST_UPDATE_DEPLOY_SCRIPT !== undefined;
const network = 'mainnet';

export type NetworkForkData = {
networkName: string;
forkBlockNumber: number;
};

if (enableTest) {
describe('update/to_v1.3.0', function () {
before(async () => {
const previousOsxVersion: ForkOsxVersion = {
version: 'v1.0.1',
activeContracts: v1_2_0_activeContracts,
forkBlockNumber: 16722881,
};

await initForkForOsxVersion(network, previousOsxVersion);

const updateDeployTags = ['v1.3.0'];
await initializeDeploymentFixture(updateDeployTags);
});
[
// TODO: check if those are correct forkBlockNumbers
{networkName: 'mainnet', forkBlockNumber: 16722881},
{networkName: 'goerli', forkBlockNumber: 9225868},
{networkName: 'polygon', forkBlockNumber: 42000000},
{networkName: 'mumbai', forkBlockNumber: 33960187},
].forEach(function (networkData: NetworkForkData) {
describe(`${networkData.networkName} update/to_v1.3.0`, function () {
before(async () => {
const previousOsxVersion: ForkOsxVersion = {
version: 'v1.0.1', // TODO: Write explaining comment why v1.0.1
activeContracts: v1_2_1_activeContracts, // TODO: Write explaining comment why v1.2.1
forkBlockNumber: networkData.forkBlockNumber,
};

await initForkForOsxVersion(
networkData.networkName,
previousOsxVersion
);

const updateDeployTags = ['v1.3.0'];
await initializeDeploymentFixture(updateDeployTags);
});

it('deploys new contracts with new addresses', async function () {
const changedContracts = [
'DAOFactory',
'PluginRepoFactory',
'MultisigSetup',
'TokenVotingSetup',
'AddresslistVotingSetup',
];
it('deploys new contracts with new addresses', async function () {
const changedContracts = [
'DAOFactory',
'PluginRepoFactory',
'MultisigSetup',
'TokenVotingSetup',
'AddresslistVotingSetup',
// TODO: what about `managingDAOImplemenation` (note the typo in "Implemenation" )
];

const allDeployments = await deployments.all();
const allDeployments = await deployments.all();

changedContracts.forEach((contractName: string) => {
const previous = (v1_2_0_activeContracts as any)[network][contractName];
const current = allDeployments[contractName].address;
changedContracts.forEach((contractName: string) => {
const previous = (v1_2_1_activeContracts as any)[
networkData.networkName
][contractName];
const current = allDeployments[contractName].address;

expect(previous).to.not.be.empty;
expect(current).to.not.be.empty;
expect(current).to.not.eq(previous);
expect(previous).to.not.be.empty;
expect(current).to.not.be.empty;
expect(current).to.not.eq(previous);
});
});
});
});
Expand Down
66 changes: 66 additions & 0 deletions packages/contracts/test/deploy/updateTo1_4_0.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {expect} from 'chai';

import {deployments} from 'hardhat';
import {
ForkOsxVersion,
initForkForOsxVersion,
initializeDeploymentFixture,
} from '../test-utils/fixture';
import {activeContractsList as v1_3_0_rc0_2_activeContracts} from '@aragon/osx-ethers-v1.3.0-rc0.2';

const enableTest = process.env.TEST_UPDATE_DEPLOY_SCRIPT !== undefined;

export type NetworkForkData = {
networkName: string;
forkBlockNumber: number;
};

if (enableTest) {
[
// TODO: check if those are correct forkBlockNumbers
{networkName: 'mainnet', forkBlockNumber: 16722881},
{networkName: 'goerli', forkBlockNumber: 9225868},
{networkName: 'polygon', forkBlockNumber: 42000000},
{networkName: 'mumbai', forkBlockNumber: 33960187},
{networkName: 'baseMainnet', forkBlockNumber: 2094661},
{networkName: 'baseGoerli', forkBlockNumber: 7890908},
].forEach(function (networkData: NetworkForkData) {
describe(`${networkData.networkName} update/to_v1.4.0`, function () {
before(async () => {
const previousOsxVersion: ForkOsxVersion = {
version: 'v1.3.0',
activeContracts: v1_3_0_rc0_2_activeContracts,
forkBlockNumber: networkData.forkBlockNumber,
};

await initForkForOsxVersion(
networkData.networkName,
previousOsxVersion
);

const updateDeployTags = ['v1.4.0'];
await initializeDeploymentFixture(updateDeployTags);
});

it('deploys new contracts with new addresses', async function () {
const changedContracts = [
'DAOFactory',
// TODO: what about `managingDAOImplemenation` (note the typo in "Implemenation" )
];

const allDeployments = await deployments.all();

changedContracts.forEach((contractName: string) => {
const previous = (v1_3_0_rc0_2_activeContracts as any)[
networkData.networkName
][contractName];
const current = allDeployments[contractName].address;

expect(previous).to.not.be.empty;
expect(current).to.not.be.empty;
expect(current).to.not.eq(previous);
});
});
});
});
}
2 changes: 1 addition & 1 deletion packages/contracts/test/test-utils/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function initForkForOsxVersion(
// Aggregate necessary information to HardhatEnvironment.
hre.testingFork = {
network: forkNetwork,
osxVersion: osxVersion.version,
osxVersion: osxVersion.version, // TODO: What is the `osxVersion` used for?
activeContracts: osxVersion.activeContracts,
};

Expand Down
Loading

0 comments on commit 86b8c95

Please sign in to comment.