Skip to content

Commit

Permalink
Merge remote-tracking branch 'template/develop' into feature/refactor…
Browse files Browse the repository at this point in the history
…-helpers
  • Loading branch information
heueristik committed Apr 18, 2024
2 parents 9ae31a3 + a779deb commit 4310e9d
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 318 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
19 changes: 10 additions & 9 deletions packages/contracts/deploy/20_new_version/23_publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ import {
isLocal,
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 {writeFile} from 'fs/promises';
import {ethers} from 'hardhat';
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import path from 'path';
Expand Down Expand Up @@ -114,8 +111,8 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
.createVersion(
VERSION.release,
setup.address,
toHex(buildMetadataURI),
toHex(releaseMetadataURI)
ethers.utils.hexlify(ethers.utils.toUtf8Bytes(buildMetadataURI)),
ethers.utils.hexlify(ethers.utils.toUtf8Bytes(releaseMetadataURI))
);

await tx.wait();
Expand Down Expand Up @@ -145,8 +142,12 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
createVersion: {
_release: VERSION.release,
_pluginSetup: setup.address,
_buildMetadata: toHex(buildMetadataURI),
_releaseMetadata: toHex(releaseMetadataURI),
_buildMetadata: ethers.utils.hexlify(
ethers.utils.toUtf8Bytes(buildMetadataURI)
),
_releaseMetadata: ethers.utils.hexlify(
ethers.utils.toUtf8Bytes(releaseMetadataURI)
),
},
},
],
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
16 changes: 8 additions & 8 deletions packages/contracts/test/10_unit-testing/11_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ describe(PLUGIN_CONTRACT_NAME, function () {

const eventName = plugin.interface.getEvent('ProposalCreated').name;
await expect(tx).to.emit(plugin, eventName);
const event = await findEvent<ProposalCreatedEvent>(tx, eventName);
const event = findEvent<ProposalCreatedEvent>(await tx.wait(), eventName);
expect(event.args.proposalId).to.equal(currentExpectedProposalId);
expect(event.args.creator).to.equal(alice.address);
expect(event.args.metadata).to.equal(dummyMetadata);
Expand Down Expand Up @@ -293,7 +293,7 @@ describe(PLUGIN_CONTRACT_NAME, function () {
const eventName = plugin.interface.getEvent('ProposalCreated').name;
await expect(tx).to.emit(plugin, eventName);

const event = await findEvent<ProposalCreatedEvent>(tx, eventName);
const event = findEvent<ProposalCreatedEvent>(await tx.wait(), eventName);
expect(event.args.proposalId).to.equal(nextExpectedProposalId);
});

Expand Down Expand Up @@ -328,8 +328,8 @@ describe(PLUGIN_CONTRACT_NAME, function () {
.connect(alice)
.executeProposal(dummyMetadata, dummyActions, allowFailureMap);

const event = await findEventTopicLog<DAOEvents.ExecutedEvent>(
tx,
const event = findEventTopicLog<DAOEvents.ExecutedEvent>(
await tx.wait(),
dao.interface,
dao.interface.getEvent('Executed').name
);
Expand All @@ -351,8 +351,8 @@ describe(PLUGIN_CONTRACT_NAME, function () {
.connect(alice)
.executeProposal(dummyMetadata, dummyActions, 0);

const event = await findEventTopicLog<DAOEvents.ExecutedEvent>(
tx,
const event = findEventTopicLog<DAOEvents.ExecutedEvent>(
await tx.wait(),
dao.interface,
dao.interface.getEvent('Executed').name
);
Expand Down Expand Up @@ -392,7 +392,7 @@ async function fixture(): Promise<FixtureResult> {
adminPluginInitdata
);
const proxyCreatedEvent1 = await findEvent<ProxyCreatedEvent>(
deploymentTx1,
await deploymentTx1.wait(),
adminProxyFactory.interface.getEvent('ProxyCreated').name
);
const initializedPlugin = Admin__factory.connect(
Expand All @@ -402,7 +402,7 @@ async function fixture(): Promise<FixtureResult> {

const deploymentTx2 = await adminProxyFactory.deployMinimalProxy([]);
const proxyCreatedEvent2 = await findEvent<ProxyCreatedEvent>(
deploymentTx2,
await deploymentTx2.wait(),
adminProxyFactory.interface.getEvent('ProxyCreated').name
);
const uninitializedPlugin = Admin__factory.connect(
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 @@ -82,7 +81,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
46 changes: 27 additions & 19 deletions packages/contracts/test/20_integration-testing/test-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {IPlugin, ProxyFactory__factory} from '../../typechain';
import {ProxyCreatedEvent} from '../../typechain/@aragon/osx-commons-contracts/src/utils/deployment/ProxyFactory';
import {hashHelpers} from '../../utils/helpers';
import {
DAO_PERMISSIONS,
PLUGIN_SETUP_PROCESSOR_PERMISSIONS,
Expand Down Expand Up @@ -37,8 +36,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 @@ -57,12 +56,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 @@ -96,7 +100,7 @@ export async function uninstallPLugin(

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

Expand All @@ -117,8 +121,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 @@ -154,8 +158,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 @@ -174,13 +178,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 Expand Up @@ -237,8 +245,8 @@ export async function createDaoProxy(
]
);
const tx = await daoProxyFactory.deployUUPSProxy(daoInitData);
const event = await findEvent<ProxyCreatedEvent>(
tx,
const event = findEvent<ProxyCreatedEvent>(
await tx.wait(),
daoProxyFactory.interface.getEvent('ProxyCreated').name
);
const dao = DAO__factory.connect(event.args.proxy, deployer);
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 {
DAO,
DAO__factory,
Expand All @@ -21,8 +17,7 @@ import {
} from '@aragon/osx-ethers';
import {setBalance} from '@nomicfoundation/hardhat-network-helpers';
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers';
import {BigNumber, ContractTransaction} from 'ethers';
import {LogDescription, defaultAbiCoder, keccak256} from 'ethers/lib/utils';
import {BigNumber, ContractTransaction, utils} from 'ethers';
import {ethers} from 'hardhat';
import {HardhatRuntimeEnvironment} from 'hardhat/types';

Expand Down Expand Up @@ -168,7 +163,7 @@ export async function impersonatedManagementDaoSigner(
}

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

Expand All @@ -192,12 +187,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 @@ -226,12 +217,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 4310e9d

Please sign in to comment.