Skip to content

Commit

Permalink
test: migrated regression tests to their own file
Browse files Browse the repository at this point in the history
  • Loading branch information
jordaniza committed Mar 8, 2024
1 parent b70df43 commit 6589083
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,9 @@ import {
TOKEN_VOTING_INTERFACE_ID,
} from '../../test-utils/token-voting-constants';
import {
TokenVoting_V1_0_0__factory,
TokenVoting_V1_3_0__factory,
TokenVoting__factory,
TokenVoting,
} from '../../test-utils/typechain-versions';
import {
getProtocolVersion,
deployAndUpgradeFromToCheck,
deployAndUpgradeSelfCheck,
} from '../../test-utils/uups-upgradeable';
import {
VoteOption,
VotingMode,
Expand All @@ -52,13 +45,12 @@ import {
getInterfaceId,
pctToRatio,
RATIO_BASE,
PLUGIN_UUPS_UPGRADEABLE_PERMISSIONS,
} from '@aragon/osx-commons-sdk';
import {DAO, DAO__factory} from '@aragon/osx-ethers';
import {time} from '@nomicfoundation/hardhat-network-helpers';
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers';
import {expect} from 'chai';
import {BigNumber, ContractFactory} from 'ethers';
import {BigNumber} from 'ethers';
import {ethers} from 'hardhat';

describe('TokenVoting', function () {
Expand Down Expand Up @@ -195,92 +187,6 @@ describe('TokenVoting', function () {
});
});

describe('Upgrades', () => {
let legacyContractFactory: ContractFactory;
let currentContractFactory: ContractFactory;
let initArgs: any;

before(() => {
currentContractFactory = new TokenVoting__factory(signers[0]);
});

beforeEach(() => {
initArgs = {
dao: dao.address,
votingSettings: votingSettings,
token: governanceErc20Mock.address,
};
});

it('upgrades to a new implementation', async () => {
await deployAndUpgradeSelfCheck(
signers[0],
signers[1],
initArgs,
'initialize',
currentContractFactory,
PLUGIN_UUPS_UPGRADEABLE_PERMISSIONS.UPGRADE_PLUGIN_PERMISSION_ID,
dao
);
});

it('upgrades from v1.0.0', async () => {
legacyContractFactory = new TokenVoting_V1_0_0__factory(signers[0]);

const {fromImplementation, toImplementation} =
await deployAndUpgradeFromToCheck(
signers[0],
signers[1],
initArgs,
'initialize',
legacyContractFactory,
currentContractFactory,
PLUGIN_UUPS_UPGRADEABLE_PERMISSIONS.UPGRADE_PLUGIN_PERMISSION_ID,
dao
);

expect(toImplementation).to.not.equal(fromImplementation); // The build did change

const fromProtocolVersion = await getProtocolVersion(
legacyContractFactory.attach(fromImplementation)
);
const toProtocolVersion = await getProtocolVersion(
currentContractFactory.attach(toImplementation)
);
expect(fromProtocolVersion).to.not.deep.equal(toProtocolVersion);
expect(fromProtocolVersion).to.deep.equal([1, 0, 0]);
expect(toProtocolVersion).to.deep.equal([1, 4, 0]);
});

it('from v1.3.0', async () => {
legacyContractFactory = new TokenVoting_V1_3_0__factory(signers[0]);

const {fromImplementation, toImplementation} =
await deployAndUpgradeFromToCheck(
signers[0],
signers[1],

initArgs,
'initialize',
legacyContractFactory,
currentContractFactory,
PLUGIN_UUPS_UPGRADEABLE_PERMISSIONS.UPGRADE_PLUGIN_PERMISSION_ID,
dao
);
expect(toImplementation).to.not.equal(fromImplementation);

const fromProtocolVersion = await getProtocolVersion(
legacyContractFactory.attach(fromImplementation)
);
const toProtocolVersion = await getProtocolVersion(
currentContractFactory.attach(toImplementation)
);
expect(fromProtocolVersion).to.not.deep.equal(toProtocolVersion);
expect(fromProtocolVersion).to.deep.equal([1, 0, 0]);
expect(toProtocolVersion).to.deep.equal([1, 4, 0]);
});
});

describe('ERC-165', async () => {
it('does not support the empty interface', async () => {
expect(await voting.supportsInterface('0xffffffff')).to.be.false;
Expand Down
154 changes: 154 additions & 0 deletions packages/contracts/test/30_regression-testing/31_upgradeability.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import {createDaoProxy} from '../test-utils/dao';
import {
TokenVoting_V1_0_0__factory,
TokenVoting_V1_3_0__factory,
TokenVoting__factory,
} from '../test-utils/typechain-versions';
import {
deployAndUpgradeFromToCheck,
deployAndUpgradeSelfCheck,
getProtocolVersion,
} from '../test-utils/uups-upgradeable';
import {VotingMode, VotingSettings} from '../test-utils/voting-helpers';
import {
PLUGIN_UUPS_UPGRADEABLE_PERMISSIONS,
TIME,
pctToRatio,
} from '@aragon/osx-commons-sdk';
import {DAO, TestGovernanceERC20__factory} from '@aragon/osx-ethers';
import {loadFixture} from '@nomicfoundation/hardhat-network-helpers';
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers';
import {expect} from 'chai';
import {ethers} from 'hardhat';
import {Address} from 'hardhat-deploy/types';

describe('Upgrades', () => {
it('upgrades to a new implementation', async () => {
const {deployer, alice, dao, defaultInitData} = await loadFixture(fixture);
const currentContractFactory = new TokenVoting__factory(deployer);

await deployAndUpgradeSelfCheck(
deployer,
alice,
defaultInitData,
'initialize',
currentContractFactory,
PLUGIN_UUPS_UPGRADEABLE_PERMISSIONS.UPGRADE_PLUGIN_PERMISSION_ID,
dao
);
});

it('upgrades from v1.0.0', async () => {
const {deployer, alice, dao, defaultInitData} = await loadFixture(fixture);
const currentContractFactory = new TokenVoting__factory(deployer);
const legacyContractFactory = new TokenVoting_V1_0_0__factory(deployer);

const {fromImplementation, toImplementation} =
await deployAndUpgradeFromToCheck(
deployer,
alice,
defaultInitData,
'initialize',
legacyContractFactory,
currentContractFactory,
PLUGIN_UUPS_UPGRADEABLE_PERMISSIONS.UPGRADE_PLUGIN_PERMISSION_ID,
dao
);

expect(toImplementation).to.not.equal(fromImplementation); // The build did change

const fromProtocolVersion = await getProtocolVersion(
legacyContractFactory.attach(fromImplementation)
);
const toProtocolVersion = await getProtocolVersion(
currentContractFactory.attach(toImplementation)
);

expect(fromProtocolVersion).to.not.deep.equal(toProtocolVersion);
expect(fromProtocolVersion).to.deep.equal([1, 0, 0]);
expect(toProtocolVersion).to.deep.equal([1, 4, 0]); // TODO Check this automatically
});

it('from v1.3.0', async () => {
const {deployer, alice, dao, defaultInitData} = await loadFixture(fixture);
const currentContractFactory = new TokenVoting__factory(deployer);
const legacyContractFactory = new TokenVoting_V1_3_0__factory(deployer);

const {fromImplementation, toImplementation} =
await deployAndUpgradeFromToCheck(
deployer,
alice,
defaultInitData,
'initialize',
legacyContractFactory,
currentContractFactory,
PLUGIN_UUPS_UPGRADEABLE_PERMISSIONS.UPGRADE_PLUGIN_PERMISSION_ID,
dao
);

expect(toImplementation).to.not.equal(fromImplementation);

const fromProtocolVersion = await getProtocolVersion(
legacyContractFactory.attach(fromImplementation)
);
const toProtocolVersion = await getProtocolVersion(
currentContractFactory.attach(toImplementation)
);

expect(fromProtocolVersion).to.not.deep.equal(toProtocolVersion);
expect(fromProtocolVersion).to.deep.equal([1, 0, 0]);
expect(toProtocolVersion).to.deep.equal([1, 4, 0]); // TODO Check this automatically
});
});

type InitDataTokenVoting = [Address, VotingSettings, Address];
type FixtureResult = {
deployer: SignerWithAddress;
alice: SignerWithAddress;
bob: SignerWithAddress;
carol: SignerWithAddress;
defaultInitData: InitDataTokenVoting;
dao: DAO;
};

async function fixture(): Promise<FixtureResult> {
const [deployer, alice, bob, carol] = await ethers.getSigners();

const dummyMetadata = ethers.utils.hexlify(
ethers.utils.toUtf8Bytes('0x123456789')
);

const dao = await createDaoProxy(deployer, dummyMetadata);
const TestGovernanceERC20 = new TestGovernanceERC20__factory(deployer);
const governanceErc20Mock = await TestGovernanceERC20.deploy(
dao.address,
'GOV',
'GOV',
{
receivers: [],
amounts: [],
}
);

// Create an initialized plugin clone
const defaultInitData = [
dao.address,
{
votingMode: VotingMode.EarlyExecution,
supportThreshold: pctToRatio(50),
minParticipation: pctToRatio(20),
minDuration: TIME.HOUR,
minProposerVotingPower: 0,
},
governanceErc20Mock.address,
] as InitDataTokenVoting;

return {
deployer,
alice,
bob,
carol,
dao,
defaultInitData,
};
}

0 comments on commit 6589083

Please sign in to comment.