Skip to content

Commit

Permalink
chore: refactor helpers (#57)
Browse files Browse the repository at this point in the history
* refactor: delete hashHelpers

* style: fix linter

* fix: import

* build: bump OZ dependency

* chore: bump osx-commons-sdk dependency

* chore: bumped commons-contracts
  • Loading branch information
heueristik authored Apr 18, 2024
1 parent 5b1aada commit a779deb
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 287 deletions.
4 changes: 2 additions & 2 deletions packages/contracts/deploy/10_create_repo/11_create_repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

// Get the PluginRepo address and deployment block number from the txn and event therein
const eventLog =
await findEventTopicLog<PluginRepoRegistryEvents.PluginRepoRegisteredEvent>(
tx,
findEventTopicLog<PluginRepoRegistryEvents.PluginRepoRegisteredEvent>(
await tx.wait(),
PluginRepoRegistry__factory.createInterface(),
'PluginRepoRegistered'
);
Expand Down
11 changes: 4 additions & 7 deletions packages/contracts/deploy/20_new_version/23_publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ import {
getPastVersionCreatedEvents,
pluginEnsDomain,
} from '../../utils/helpers';
import {
PLUGIN_REPO_PERMISSIONS,
toHex,
uploadToIPFS,
} from '@aragon/osx-commons-sdk';
import {PLUGIN_REPO_PERMISSIONS, uploadToIPFS} from '@aragon/osx-commons-sdk';
import {ethers} from 'hardhat';
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import path from 'path';
Expand Down Expand Up @@ -89,8 +86,8 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const tx = await pluginRepo.createVersion(
VERSION.release,
setup.address,
toHex(buildMetadataURI),
toHex(releaseMetadataURI)
ethers.utils.hexlify(ethers.utils.toUtf8Bytes(buildMetadataURI)),
ethers.utils.hexlify(ethers.utils.toUtf8Bytes(releaseMetadataURI))
);

if (setup == undefined || setup?.receipt == undefined) {
Expand Down
8 changes: 4 additions & 4 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
"clean": "rimraf ./artifacts ./cache ./coverage ./typechain ./types ./coverage.json && yarn typechain"
},
"dependencies": {
"@aragon/osx-commons-contracts": "1.4.0-alpha.3",
"@openzeppelin/contracts": "^4.9.5",
"@openzeppelin/contracts-upgradeable": "^4.9.5"
"@aragon/osx-commons-contracts": "1.4.0-alpha.4",
"@openzeppelin/contracts": "^4.9.6",
"@openzeppelin/contracts-upgradeable": "^4.9.6"
},
"devDependencies": {
"@aragon/osx-commons-configs": "0.4.0",
"@aragon/osx-ethers": "1.4.0-alpha.0",
"@aragon/osx-commons-sdk": "0.0.1-alpha.5",
"@aragon/osx-commons-sdk": "0.0.1-alpha.8",
"@ethersproject/abi": "^5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/bignumber": "^5.7.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/contracts/test/10_unit-testing/12_plugin-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from '../../typechain';
import {STORE_PERMISSION_ID, defaultInitData} from './11_plugin';
import {
ADDRESS,
Operation,
PERMISSION_MANAGER_FLAGS,
getNamedTypesFromMetadata,
Expand Down Expand Up @@ -111,7 +110,7 @@ describe(PLUGIN_SETUP_CONTRACT_NAME, function () {
const {pluginSetup, daoMock, prepareUninstallationInputs} =
await loadFixture(fixture);

const dummyAddr = ADDRESS.ZERO;
const dummyAddr = ethers.constants.AddressZero;

const permissions = await pluginSetup.callStatic.prepareUninstallation(
daoMock.address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
PERMISSION_MANAGER_FLAGS,
PLUGIN_REPO_PERMISSIONS,
UnsupportedNetworkError,
toHex,
uploadToIPFS,
} from '@aragon/osx-commons-sdk';
import {
Expand Down Expand Up @@ -80,7 +79,9 @@ describe(`Deployment on network '${productionNetworkName}'`, function () {
JSON.stringify(METADATA.build, null, 2)
)}`;

expect(results.buildMetadata).to.equal(toHex(buildMetadataURI));
expect(results.buildMetadata).to.equal(
ethers.utils.hexlify(ethers.utils.toUtf8Bytes(buildMetadataURI))
);
});
});
});
Expand Down
43 changes: 26 additions & 17 deletions packages/contracts/test/20_integration-testing/test-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {DAOMock, IPlugin} from '../../typechain';
import {hashHelpers} from '../../utils/helpers';
import {
DAO_PERMISSIONS,
PLUGIN_SETUP_PROCESSOR_PERMISSIONS,
Expand All @@ -14,6 +13,7 @@ import {
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers';
import {expect} from 'chai';
import {ContractTransaction} from 'ethers';
import {ethers} from 'hardhat';

export async function installPLugin(
signer: SignerWithAddress,
Expand All @@ -33,8 +33,8 @@ export async function installPLugin(
});

const preparedEvent =
await findEvent<PluginSetupProcessorEvents.InstallationPreparedEvent>(
prepareTx,
findEvent<PluginSetupProcessorEvents.InstallationPreparedEvent>(
await prepareTx.wait(),
psp.interface.getEvent('InstallationPrepared').name
);

Expand All @@ -53,12 +53,17 @@ export async function installPLugin(
pluginSetupRef: pluginSetupRef,
plugin: plugin,
permissions: preparedPermissions,
helpersHash: hashHelpers(preparedEvent.args.preparedSetupData.helpers),
helpersHash: ethers.utils.keccak256(
ethers.utils.defaultAbiCoder.encode(
['address[]'],
[preparedEvent.args.preparedSetupData.helpers]
)
),
});

const appliedEvent =
await findEvent<PluginSetupProcessorEvents.InstallationAppliedEvent>(
applyTx,
findEvent<PluginSetupProcessorEvents.InstallationAppliedEvent>(
await applyTx.wait(),
psp.interface.getEvent('InstallationApplied').name
);

Expand Down Expand Up @@ -92,7 +97,7 @@ export async function uninstallPLugin(

const preparedEvent =
await findEvent<PluginSetupProcessorEvents.UninstallationPreparedEvent>(
prepareTx,
await prepareTx.wait(),
psp.interface.getEvent('UninstallationPrepared').name
);

Expand All @@ -113,8 +118,8 @@ export async function uninstallPLugin(
});

const appliedEvent =
await findEvent<PluginSetupProcessorEvents.UninstallationAppliedEvent>(
applyTx,
findEvent<PluginSetupProcessorEvents.UninstallationAppliedEvent>(
await applyTx.wait(),
psp.interface.getEvent('UninstallationApplied').name
);

Expand Down Expand Up @@ -150,8 +155,8 @@ export async function updatePlugin(
},
});
const preparedEvent =
await findEvent<PluginSetupProcessorEvents.UpdatePreparedEvent>(
prepareTx,
findEvent<PluginSetupProcessorEvents.UpdatePreparedEvent>(
await prepareTx.wait(),
psp.interface.getEvent('UpdatePrepared').name
);

Expand All @@ -170,13 +175,17 @@ export async function updatePlugin(
pluginSetupRef: pluginSetupRefUpdate,
initData: preparedEvent.args.initData,
permissions: preparedPermissions,
helpersHash: hashHelpers(preparedEvent.args.preparedSetupData.helpers),
helpersHash: ethers.utils.keccak256(
ethers.utils.defaultAbiCoder.encode(
['address[]'],
[preparedEvent.args.preparedSetupData.helpers]
)
),
});
const appliedEvent =
await findEvent<PluginSetupProcessorEvents.UpdateAppliedEvent>(
applyTx,
psp.interface.getEvent('UpdateApplied').name
);
const appliedEvent = findEvent<PluginSetupProcessorEvents.UpdateAppliedEvent>(
await applyTx.wait(),
psp.interface.getEvent('UpdateApplied').name
);

return {prepareTx, applyTx, preparedEvent, appliedEvent};
}
Expand Down
28 changes: 9 additions & 19 deletions packages/contracts/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import {
getLatestNetworkDeployment,
getNetworkNameByAlias,
} from '@aragon/osx-commons-configs';
import {
UnsupportedNetworkError,
VersionTag,
findEvent,
} from '@aragon/osx-commons-sdk';
import {UnsupportedNetworkError, findEvent} from '@aragon/osx-commons-sdk';
import {
ENSSubdomainRegistrar__factory,
ENS__factory,
Expand All @@ -17,8 +13,7 @@ import {
PluginRepoEvents,
PluginRepo__factory,
} from '@aragon/osx-ethers';
import {ContractTransaction} from 'ethers';
import {LogDescription, defaultAbiCoder, keccak256} from 'ethers/lib/utils';
import {ContractTransaction, utils} from 'ethers';
import {ethers} from 'hardhat';
import {HardhatRuntimeEnvironment} from 'hardhat/types';

Expand Down Expand Up @@ -108,7 +103,7 @@ export async function findPluginRepo(
}

export type EventWithBlockNumber = {
event: LogDescription;
event: utils.LogDescription;
blockNumber: number;
};

Expand All @@ -132,12 +127,8 @@ export async function getPastVersionCreatedEvents(
});
}

export function hashHelpers(helpers: string[]) {
return keccak256(defaultAbiCoder.encode(['address[]'], [helpers]));
}

export type LatestVersion = {
versionTag: VersionTag;
versionTag: PluginRepo.VersionStruct;
pluginSetupContract: string;
releaseMetadata: string;
buildMetadata: string;
Expand Down Expand Up @@ -166,12 +157,11 @@ export async function createVersion(

await tx.wait();

const versionCreatedEvent =
await findEvent<PluginRepoEvents.VersionCreatedEvent>(
tx,
pluginRepo.interface.events['VersionCreated(uint8,uint16,address,bytes)']
.name
);
const versionCreatedEvent = findEvent<PluginRepoEvents.VersionCreatedEvent>(
await tx.wait(),
pluginRepo.interface.events['VersionCreated(uint8,uint16,address,bytes)']
.name
);

// Check if versionCreatedEvent is not undefined
if (versionCreatedEvent) {
Expand Down
Loading

0 comments on commit a779deb

Please sign in to comment.