Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improvements surfaced from the admin plugin #36

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/contracts-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ jobs:
- name: 'Test the contracts and generate the coverage report'
run: 'yarn coverage'
env:
NETWORK_NAME: ${{ vars.NETWORK_NAME }}
INFURA_API_KEY: ${{ secrets.INFURA_API_KEY }}
6 changes: 5 additions & 1 deletion packages/contracts/deploy/00_info/01_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
isLocal,
} from '../../utils/helpers';
import {getNetworkByNameOrAlias} from '@aragon/osx-commons-configs';
import {UnsupportedNetworkError} from '@aragon/osx-commons-sdk';
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import path from 'path';
Expand All @@ -26,7 +27,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
);

// Fork the network provided in the `.env` file
const networkConfig = getNetworkByNameOrAlias(productionNetworkName)!;
const networkConfig = getNetworkByNameOrAlias(productionNetworkName);
if (networkConfig === null) {
throw new UnsupportedNetworkError(productionNetworkName);
}
await hre.network.provider.request({
method: 'hardhat_reset',
params: [
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/deploy/10_create_repo/11_create_repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
);

console.log(
`'${pluginEnsDomain(hre)}' PluginRepo deployed at: ${pluginRepo.address}.`
`PluginRepo '${pluginEnsDomain(hre)}' deployed at '${pluginRepo.address}'.`
);

hre.aragonToVerifyContracts.push({
Expand Down
6 changes: 5 additions & 1 deletion packages/contracts/deploy/20_new_version/21_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const {deploy} = deployments;
const {deployer} = await getNamedAccounts();

await deploy(PLUGIN_SETUP_CONTRACT_NAME, {
const res = await deploy(PLUGIN_SETUP_CONTRACT_NAME, {
from: deployer,
args: [],
log: true,
});

console.log(
`Deployed '${PLUGIN_SETUP_CONTRACT_NAME}' contract at '${res.address}'`
);
};

export default func;
Expand Down
31 changes: 24 additions & 7 deletions packages/contracts/deploy/30_upgrade_repo/31_upgrade_repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import {
getLatestNetworkDeployment,
getNetworkNameByAlias,
} from '@aragon/osx-commons-configs';
import {PLUGIN_REPO_PERMISSIONS} from '@aragon/osx-commons-sdk';
import {
PLUGIN_REPO_PERMISSIONS,
UnsupportedNetworkError,
} from '@aragon/osx-commons-sdk';
import {PluginRepo__factory} from '@aragon/osx-ethers';
import {BytesLike} from 'ethers';
import {DeployFunction} from 'hardhat-deploy/types';
Expand All @@ -15,6 +18,14 @@ type SemVer = [number, number, number];
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const [deployer] = await hre.ethers.getSigners();
const productionNetworkName: string = getProductionNetworkName(hre);
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}.`;
}

// Get PluginRepo
const {pluginRepo, ensDomain} = await findPluginRepo(hre);
Expand All @@ -28,8 +39,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

// Get the latest `PluginRepo` implementation as the upgrade target
const latestPluginRepoImplementation = PluginRepo__factory.connect(
getLatestNetworkDeployment(getNetworkNameByAlias(productionNetworkName)!)!
.PluginRepoBase.address,
networkDeployments.PluginRepoBase.address,
deployer
);

Expand All @@ -53,11 +63,11 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// Re-initialization will happen through a call to `function initializeFrom(uint8[3] calldata _previousProtocolVersion, bytes calldata _initData)`
// that Aragon might add to the `PluginRepo` contract once it's required.
/*
// Define the `initData` arguments that
// Define the `_initData` arguments
const initData: BytesLike[] = [];
// Encode the call to `function initializeFrom(uint8[3] calldata _previousProtocolVersion, bytes calldata _initData)` with `initData`
const initializeFromCalldata =
newPluginRepoImplementation.interface.encodeFunctionData('initializeFrom', [
latestPluginRepoImplementation.interface.encodeFunctionData('initializeFrom', [
current,
initData,
]);
Expand Down Expand Up @@ -102,11 +112,18 @@ func.skip = async (hre: HardhatRuntimeEnvironment) => {

const [deployer] = await hre.ethers.getSigners();
const productionNetworkName: string = getProductionNetworkName(hre);
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}.`;
}

// Get the latest `PluginRepo` implementation as the upgrade target
const latestPluginRepoImplementation = PluginRepo__factory.connect(
getLatestNetworkDeployment(getNetworkNameByAlias(productionNetworkName)!)!
.PluginRepoBase.address,
networkDeployments.PluginRepoBase.address,
deployer
);

Expand Down
53 changes: 35 additions & 18 deletions packages/contracts/test/10_unit-testing/12_plugin-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type FixtureResult = {
alice: SignerWithAddress;
bob: SignerWithAddress;
pluginSetup: MyPluginSetup;
prepareInstallationInputs: string;
prepareUninstallationInputs: string;
daoMock: DAOMock;
};

Expand All @@ -32,24 +34,36 @@ async function fixture(): Promise<FixtureResult> {
const daoMock = await new DAOMock__factory(deployer).deploy();
const pluginSetup = await new MyPluginSetup__factory(deployer).deploy();

return {deployer, alice, bob, pluginSetup, daoMock};
const prepareInstallationInputs = ethers.utils.defaultAbiCoder.encode(
getNamedTypesFromMetadata(
buildMetadata.pluginSetup.prepareInstallation.inputs
),
[defaultInitData.number]
);

const prepareUninstallationInputs = ethers.utils.defaultAbiCoder.encode(
getNamedTypesFromMetadata(
buildMetadata.pluginSetup.prepareUninstallation.inputs
),
[]
);

return {
deployer,
alice,
bob,
pluginSetup,
prepareInstallationInputs,
prepareUninstallationInputs,
daoMock,
};
}

describe(PLUGIN_SETUP_CONTRACT_NAME, function () {
describe('prepareInstallation', async () => {
let initData: string;

before(async () => {
initData = ethers.utils.defaultAbiCoder.encode(
getNamedTypesFromMetadata(
buildMetadata.pluginSetup.prepareInstallation.inputs
),
[defaultInitData.number]
);
});

it('returns the plugin, helpers, and permissions', async () => {
const {deployer, pluginSetup, daoMock} = await loadFixture(fixture);
const {deployer, pluginSetup, prepareInstallationInputs, daoMock} =
await loadFixture(fixture);

const nonce = await ethers.provider.getTransactionCount(
pluginSetup.address
Expand All @@ -64,7 +78,7 @@ describe(PLUGIN_SETUP_CONTRACT_NAME, function () {
preparedSetupData: {helpers, permissions},
} = await pluginSetup.callStatic.prepareInstallation(
daoMock.address,
initData
prepareInstallationInputs
);

expect(plugin).to.be.equal(anticipatedPluginAddress);
Expand All @@ -80,7 +94,10 @@ describe(PLUGIN_SETUP_CONTRACT_NAME, function () {
],
]);

await pluginSetup.prepareInstallation(daoMock.address, initData);
await pluginSetup.prepareInstallation(
daoMock.address,
prepareInstallationInputs
);
const myPlugin = new MyPlugin__factory(deployer).attach(plugin);

// initialization is correct
Expand All @@ -91,17 +108,17 @@ describe(PLUGIN_SETUP_CONTRACT_NAME, function () {

describe('prepareUninstallation', async () => {
it('returns the permissions', async () => {
const {pluginSetup, daoMock} = await loadFixture(fixture);
const {pluginSetup, daoMock, prepareUninstallationInputs} =
await loadFixture(fixture);

const dummyAddr = ADDRESS.ZERO;
const emptyData = '0x';

const permissions = await pluginSetup.callStatic.prepareUninstallation(
daoMock.address,
{
plugin: dummyAddr,
currentHelpers: [],
data: emptyData,
data: prepareUninstallationInputs,
}
);

Expand Down
34 changes: 22 additions & 12 deletions packages/contracts/test/20_integration-testing/21_deployment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {METADATA} from '../../plugin-settings';
import {METADATA, VERSION} from '../../plugin-settings';
import {getProductionNetworkName, findPluginRepo} from '../../utils/helpers';
import {
getLatestNetworkDeployment,
Expand All @@ -8,6 +8,7 @@ import {
DAO_PERMISSIONS,
PERMISSION_MANAGER_FLAGS,
PLUGIN_REPO_PERMISSIONS,
UnsupportedNetworkError,
toHex,
uploadToIPFS,
} from '@aragon/osx-commons-sdk';
Expand Down Expand Up @@ -66,13 +67,13 @@ describe(`Deployment on network '${productionNetworkName}'`, function () {
const {pluginRepo} = await loadFixture(fixture);

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

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

const buildMetadataURI = `ipfs://${await uploadToIPFS(
Expand All @@ -97,17 +98,26 @@ async function fixture(): Promise<FixtureResult> {

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

// Plugin repo registry
const pluginRepoRegistry = PluginRepoRegistry__factory.connect(
getLatestNetworkDeployment(getNetworkNameByAlias(productionNetworkName)!)!
.PluginRepoRegistryProxy.address,
deployer
);

// 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};
}
Loading
Loading