Skip to content

Commit

Permalink
tests: moved integration tests and all working except build upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
jordaniza committed Mar 8, 2024
1 parent 6589083 commit bc4dce7
Show file tree
Hide file tree
Showing 8 changed files with 689 additions and 309 deletions.
6 changes: 4 additions & 2 deletions packages/contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function getHardhatNetworkAccountsConfig(
const oneEther = BigNumber.from(10).pow(18);
return {
privateKey,
balance: oneEther.mul(1000).toString(),
balance: oneEther.mul(10000).toString(),
};
}
);
Expand Down Expand Up @@ -168,7 +168,9 @@ const config: HardhatUserConfig = {
tests: './test',
deploy: './deploy',
},

mocha: {
timeout: 60_000,
},
solidity: {
version: '0.8.17',
settings: {
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/plugin-settings.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import buildMetadata from './src/build-metadata.json';
import releaseMetadata from './src/release-metadata.json';
import {GovernanceERC20} from './test/test-utils/typechain-versions';
import {VersionTag} from '@aragon/osx-commons-sdk';
import {ethers} from 'hardhat';
import { GovernanceERC20 } from './test/test-utils/typechain-versions';

export const PLUGIN_CONTRACT_NAME = 'TokenVoting'; // This must match the filename `packages/contracts/src/MyPlugin.sol` and the contract name `MyPlugin` within.
export const PLUGIN_SETUP_CONTRACT_NAME = 'TokenVotingSetup'; // This must match the filename `packages/contracts/src/MyPluginSetup.sol` and the contract name `MyPluginSetup` within.
Expand All @@ -13,7 +13,7 @@ export const GOVERNANCE_WRAPPED_ERC20_CONTRACT_NAME = 'GovernanceWrappedERC20';

export const VERSION: VersionTag = {
release: 1, // Increment this number ONLY if breaking/incompatible changes were made. Updates between releases are NOT possible.
build: 1, // Increment this number if non-breaking/compatible changes were made. Updates to newer builds are possible.
build: 3, // Increment this number if non-breaking/compatible changes were made. Updates to newer builds are possible.
};

/* DO NOT CHANGE UNLESS YOU KNOW WHAT YOU ARE DOING */
Expand Down
255 changes: 132 additions & 123 deletions packages/contracts/test/20_integration-testing/21_deployment.ts
Original file line number Diff line number Diff line change
@@ -1,123 +1,132 @@
// import {METADATA, VERSION} from '../../plugin-settings';
// import {getProductionNetworkName, findPluginRepo} from '../../utils/helpers';
// import {
// getLatestNetworkDeployment,
// getNetworkNameByAlias,
// } from '@aragon/osx-commons-configs';
// import {
// DAO_PERMISSIONS,
// PERMISSION_MANAGER_FLAGS,
// PLUGIN_REPO_PERMISSIONS,
// UnsupportedNetworkError,
// toHex,
// uploadToIPFS,
// } from '@aragon/osx-commons-sdk';
// import {
// PluginRepo,
// PluginRepoRegistry,
// PluginRepoRegistry__factory,
// } from '@aragon/osx-ethers';
// import {loadFixture} from '@nomicfoundation/hardhat-network-helpers';
// import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers';
// import {expect} from 'chai';
// import env, {deployments, ethers} from 'hardhat';

// const productionNetworkName = getProductionNetworkName(env);

// describe(`Deployment on network '${productionNetworkName}'`, function () {
// it('creates the repo', async () => {
// const {pluginRepo, pluginRepoRegistry} = await loadFixture(fixture);

// expect(await pluginRepoRegistry.entries(pluginRepo.address)).to.be.true;
// });

// it('makes the deployer the repo maintainer', async () => {
// const {deployer, pluginRepo} = await loadFixture(fixture);

// expect(
// await pluginRepo.isGranted(
// pluginRepo.address,
// deployer.address,
// DAO_PERMISSIONS.ROOT_PERMISSION_ID,
// PERMISSION_MANAGER_FLAGS.NO_CONDITION
// )
// ).to.be.true;

// expect(
// await pluginRepo.isGranted(
// pluginRepo.address,
// deployer.address,
// PLUGIN_REPO_PERMISSIONS.UPGRADE_REPO_PERMISSION_ID,
// PERMISSION_MANAGER_FLAGS.NO_CONDITION
// )
// ).to.be.true;

// expect(
// await pluginRepo.isGranted(
// pluginRepo.address,
// deployer.address,
// PLUGIN_REPO_PERMISSIONS.MAINTAINER_PERMISSION_ID,
// PERMISSION_MANAGER_FLAGS.NO_CONDITION
// )
// ).to.be.true;
// });

// context('PluginSetup Publication', async () => {
// it('registers the setup', async () => {
// const {pluginRepo} = await loadFixture(fixture);

// await pluginRepo['getVersion((uint8,uint16))']({
// release: VERSION.release,
// build: VERSION.build,
// });

// const results = await pluginRepo['getVersion((uint8,uint16))']({
// release: VERSION.release,
// build: VERSION.build,
// });

// const buildMetadataURI = `ipfs://${await uploadToIPFS(
// JSON.stringify(METADATA.build, null, 2)
// )}`;

// expect(results.buildMetadata).to.equal(toHex(buildMetadataURI));
// });
// });
// });

// type FixtureResult = {
// deployer: SignerWithAddress;
// pluginRepo: PluginRepo;
// pluginRepoRegistry: PluginRepoRegistry;
// };

// async function fixture(): Promise<FixtureResult> {
// // Deploy all
// const tags = ['CreateRepo', 'NewVersion'];
// await deployments.fixture(tags);

// const [deployer] = await ethers.getSigners();

// // Plugin Repo
// const {pluginRepo, ensDomain} = await findPluginRepo(env);
// if (pluginRepo === null) {
// throw `PluginRepo '${ensDomain}' does not exist yet.`;
// }

// const network = getNetworkNameByAlias(productionNetworkName);
// if (network === null) {
// throw new UnsupportedNetworkError(productionNetworkName);
// }
// const networkDeployments = getLatestNetworkDeployment(network);
// if (networkDeployments === null) {
// throw `Deployments are not available on network ${network}.`;
// }

// // Plugin repo registry
// const pluginRepoRegistry = PluginRepoRegistry__factory.connect(
// networkDeployments.PluginRepoRegistryProxy.address,
// deployer
// );

// return {deployer, pluginRepo, pluginRepoRegistry};
// }
import {METADATA, VERSION} from '../../plugin-settings';
import {getProductionNetworkName, findPluginRepo} from '../../utils/helpers';
import {
getLatestNetworkDeployment,
getNetworkNameByAlias,
} from '@aragon/osx-commons-configs';
import {
DAO_PERMISSIONS,
PERMISSION_MANAGER_FLAGS,
PLUGIN_REPO_PERMISSIONS,
UnsupportedNetworkError,
toHex,
uploadToIPFS,
} from '@aragon/osx-commons-sdk';
import {
DAO,
DAO__factory,
PluginRepo,
PluginRepoRegistry,
PluginRepoRegistry__factory,
} from '@aragon/osx-ethers';
import {loadFixture} from '@nomicfoundation/hardhat-network-helpers';
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers';
import {expect} from 'chai';
import env, {deployments, ethers} from 'hardhat';

const productionNetworkName = getProductionNetworkName(env);

describe(`Deployment on network '${productionNetworkName}'`, function () {
it('creates the repo', async () => {
const {pluginRepo, pluginRepoRegistry} = await loadFixture(fixture);

expect(await pluginRepoRegistry.entries(pluginRepo.address)).to.be.true;
});

it('gives the management DAO permissions over the repo', async () => {
const {pluginRepo, managementDaoProxy} = await loadFixture(fixture);

expect(
await pluginRepo.isGranted(
pluginRepo.address,
managementDaoProxy.address,
DAO_PERMISSIONS.ROOT_PERMISSION_ID,
PERMISSION_MANAGER_FLAGS.NO_CONDITION
)
).to.be.true;

expect(
await pluginRepo.isGranted(
pluginRepo.address,
managementDaoProxy.address,
PLUGIN_REPO_PERMISSIONS.UPGRADE_REPO_PERMISSION_ID,
PERMISSION_MANAGER_FLAGS.NO_CONDITION
)
).to.be.true;

expect(
await pluginRepo.isGranted(
pluginRepo.address,
managementDaoProxy.address,
PLUGIN_REPO_PERMISSIONS.MAINTAINER_PERMISSION_ID,
PERMISSION_MANAGER_FLAGS.NO_CONDITION
)
).to.be.true;
});

context('PluginSetup Publication', async () => {
it('registers the setup', async () => {
const {pluginRepo} = await loadFixture(fixture);

await pluginRepo['getVersion((uint8,uint16))']({
release: VERSION.release,
build: VERSION.build,
});

const results = await pluginRepo['getVersion((uint8,uint16))']({
release: VERSION.release,
build: VERSION.build,
});

const buildMetadataURI = `ipfs://${await uploadToIPFS(
JSON.stringify(METADATA.build, null, 2)
)}`;

expect(results.buildMetadata).to.equal(toHex(buildMetadataURI));
});
});
});

type FixtureResult = {
deployer: SignerWithAddress;
pluginRepo: PluginRepo;
pluginRepoRegistry: PluginRepoRegistry;
managementDaoProxy: DAO;
};

async function fixture(): Promise<FixtureResult> {
// Deploy all
const tags = ['CreateRepo', 'NewVersion', 'TransferOwnershipToManagmentDao'];

await deployments.fixture(tags);
const [deployer] = await ethers.getSigners();

// Plugin repo
const {pluginRepo, ensDomain} = await findPluginRepo(env);
if (pluginRepo === null) {
throw `PluginRepo '${ensDomain}' does not exist yet.`;
}

const network = getNetworkNameByAlias(productionNetworkName);
if (network === null) {
throw new UnsupportedNetworkError(productionNetworkName);
}
const networkDeployments = getLatestNetworkDeployment(network);
if (networkDeployments === null) {
throw `Deployments are not available on network ${network}.`;
}

// Plugin repo registry
const pluginRepoRegistry = PluginRepoRegistry__factory.connect(
networkDeployments.PluginRepoRegistryProxy.address,
deployer
);

// Management DAO proxy
const managementDaoProxy = DAO__factory.connect(
networkDeployments.ManagementDAOProxy.address,
deployer
);

return {deployer, pluginRepo, pluginRepoRegistry, managementDaoProxy};
}
Loading

0 comments on commit bc4dce7

Please sign in to comment.