diff --git a/packages/contracts/deploy/helpers.ts b/packages/contracts/deploy/helpers.ts index 26688af68..f371f5950 100644 --- a/packages/contracts/deploy/helpers.ts +++ b/packages/contracts/deploy/helpers.ts @@ -1,17 +1,21 @@ import {promises as fs} from 'fs'; import {ethers} from 'hardhat'; import {Contract} from 'ethers'; +import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers'; import {HardhatRuntimeEnvironment} from 'hardhat/types'; import IPFS from 'ipfs-http-client'; -import {findEvent} from '../utils/event'; -import {getMergedABI} from '../utils/abi'; +import {findEvent, findEventTopicLog} from '../utils/event'; import {Operation} from '../utils/types'; import {VersionTag} from '../test/test-utils/psp/types'; -import {ENSRegistry__factory, PluginRepo__factory} from '../typechain'; +import { + ENSRegistry__factory, + PluginRepoFactory__factory, + PluginRepoRegistry__factory, + PluginRepo__factory, +} from '../typechain'; import {VersionCreatedEvent} from '../typechain/PluginRepo'; import {PluginRepoRegisteredEvent} from '../typechain/PluginRepoRegistry'; -import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers'; // TODO: Add support for L2 such as Arbitrum. (https://discuss.ens.domains/t/register-using-layer-2/688) // Make sure you own the ENS set in the {{NETWORK}}_ENS_DOMAIN variable in .env @@ -204,15 +208,7 @@ export async function createPluginRepo( hre ); - const {abi, bytecode} = await getMergedABI(hre, 'PluginRepoFactory', [ - 'PluginRepoRegistry', - ]); - - const pluginRepoFactoryFactory = new ethers.ContractFactory( - abi, - bytecode, - signers[0] - ); + const pluginRepoFactoryFactory = new PluginRepoFactory__factory(signers[0]); const pluginRepoFactoryContract = pluginRepoFactoryFactory.attach( pluginRepoFactoryAddress ); @@ -228,8 +224,9 @@ export async function createPluginRepo( ); await tx.wait(); - const event = await findEvent( + const event = await findEventTopicLog( tx, + PluginRepoRegistry__factory.createInterface(), 'PluginRepoRegistered' ); const repoAddress = event.args.pluginRepo; diff --git a/packages/contracts/deploy/new/40_finalize-managing-dao/30_install-multisig-on-managing-dao.ts b/packages/contracts/deploy/new/40_finalize-managing-dao/30_install-multisig-on-managing-dao.ts index 05140492b..a54a7e4cb 100644 --- a/packages/contracts/deploy/new/40_finalize-managing-dao/30_install-multisig-on-managing-dao.ts +++ b/packages/contracts/deploy/new/40_finalize-managing-dao/30_install-multisig-on-managing-dao.ts @@ -108,17 +108,14 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { address: installationPreparedEvent.plugin, args: [ await multisigSetup.implementation(), - await Multisig__factory.createInterface().encodeFunctionData( - 'initialize', - [ - managingDAOAddress, - approvers, - { - onlyListed: listedOnly, - minApprovals: minApprovals, - }, - ] - ), + Multisig__factory.createInterface().encodeFunctionData('initialize', [ + managingDAOAddress, + approvers, + { + onlyListed: listedOnly, + minApprovals: minApprovals, + }, + ]), ], }); diff --git a/packages/contracts/test/framework/dao/dao-factory.ts b/packages/contracts/test/framework/dao/dao-factory.ts index a0663e0e9..cb5a9cef0 100644 --- a/packages/contracts/test/framework/dao/dao-factory.ts +++ b/packages/contracts/test/framework/dao/dao-factory.ts @@ -26,7 +26,11 @@ import { PluginRepo__factory, IProtocolVersion__factory, IERC165__factory, + PluginRepoRegistry__factory, } from '../../../typechain'; +import {DAORegisteredEvent} from '../../../typechain/DAORegistry'; +import {InstallationPreparedEvent} from '../../../typechain/PluginSetupProcessor'; +import {PluginRepoRegisteredEvent} from '../../../typechain/PluginRepoRegistry'; import {deployENSSubdomainRegistrar} from '../../test-utils/ens'; import {deployPluginSetupProcessor} from '../../test-utils/plugin-setup-processor'; @@ -36,8 +40,7 @@ import { } from '../../test-utils/repo'; import adminMetadata from '../../../src/plugins/governance/admin/build-metadata.json'; -import {findEvent} from '../../../utils/event'; -import {getMergedABI} from '../../../utils/abi'; +import {findEventTopicLog} from '../../../utils/event'; import {daoExampleURI, deployNewDAO} from '../../test-utils/dao'; import {deployWithProxy} from '../../test-utils/proxy'; import {getAppliedSetupId} from '../../test-utils/psp/hash-helpers'; @@ -53,8 +56,6 @@ import { prepareUninstallation, prepareUpdate, } from '../../test-utils/psp/wrappers'; -import {PluginRepoRegisteredEvent} from '../../../typechain/PluginRepoRegistry'; -import {InstallationPreparedEvent} from '../../../typechain/PluginSetupProcessor'; import {getInterfaceID} from '../../test-utils/interfaces'; import {CURRENT_PROTOCOL_VERSION} from '../../test-utils/protocol-version'; @@ -112,26 +113,26 @@ async function extractInfoFromCreateDaoTx(tx: any): Promise<{ helpers: any; permissions: any; }> { - const data = await tx.wait(); - const {events} = data; - const {dao, creator, subdomain} = events.find( - ({event}: {event: any}) => event === EVENTS.DAORegistered - ).args; - - const { - plugin, - preparedSetupData: {permissions, helpers}, - } = events.find( - ({event}: {event: any}) => event === EVENTS.InstallationPrepared - ).args; + const daoRegisteredEvent = await findEventTopicLog( + tx, + DAORegistry__factory.createInterface(), + EVENTS.DAORegistered + ); + + const installationPreparedEvent = + await findEventTopicLog( + tx, + PluginSetupProcessor__factory.createInterface(), + EVENTS.InstallationPrepared + ); return { - dao: dao, - creator: creator, - subdomain: subdomain, - plugin: plugin, - helpers: helpers, - permissions: permissions, + dao: daoRegisteredEvent.args.dao, + creator: daoRegisteredEvent.args.creator, + subdomain: daoRegisteredEvent.args.subdomain, + plugin: installationPreparedEvent.args.plugin, + helpers: installationPreparedEvent.args.preparedSetupData.helpers, + permissions: installationPreparedEvent.args.preparedSetupData.permissions, }; } @@ -163,22 +164,9 @@ describe('DAOFactory: ', function () { let signers: SignerWithAddress[]; let ownerAddress: string; - let mergedABI: any; - let daoFactoryBytecode: any; - before(async () => { signers = await ethers.getSigners(); ownerAddress = await signers[0].getAddress(); - - const {abi, bytecode} = await getMergedABI( - // @ts-ignore - hre, - 'DAOFactory', - ['DAORegistry', 'PluginSetupProcessor', 'src/core/dao/DAO.sol:DAO'] - ); - - mergedABI = abi; - daoFactoryBytecode = bytecode; }); beforeEach(async function () { @@ -217,11 +205,7 @@ describe('DAOFactory: ', function () { ); // Deploy DAO Factory - const DAOFactory = new ethers.ContractFactory( - mergedABI, - daoFactoryBytecode, - signers[0] - ) as DAOFactory__factory; + const DAOFactory = new DAOFactory__factory(signers[0]); daoFactory = await DAOFactory.deploy(daoRegistry.address, psp.address); // Grant the `REGISTER_DAO_PERMISSION` permission to the `daoFactory` @@ -265,8 +249,9 @@ describe('DAOFactory: ', function () { '0x00', '0x00' ); - const event = await findEvent( + const event = await findEventTopicLog( tx, + PluginRepoRegistry__factory.createInterface(), EVENTS.PluginRepoRegistered ); pluginSetupMockRepoAddress = event.args.pluginRepo; @@ -551,16 +536,19 @@ describe('DAOFactory: ', function () { const plugins = [plugin1, plugin2]; const tx = await daoFactory.createDao(daoSettings, plugins); - const {events} = await tx.wait(); - let installEventCount = 0; + // Count how often the event was emitted by inspecting the logs + const receipt = await tx.wait(); + const topic = PluginSetupProcessor__factory.createInterface().getEventTopic( + EVENTS.InstallationApplied + ); - // @ts-ignore - events.forEach(event => { - if (event.event == EVENTS.InstallationApplied) installEventCount++; + let installationAppliedEventCount = 0; + receipt.logs.forEach(log => { + if (log.topics[0] === topic) installationAppliedEventCount++; }); - expect(installEventCount).to.equal(2); + expect(installationAppliedEventCount).to.equal(2); }); describe('E2E: Install,Update,Uninstall Plugin through Admin Plugin', async () => { @@ -596,11 +584,13 @@ describe('DAOFactory: ', function () { '0x11', '0x11' ); - let event = await findEvent( - tx, - EVENTS.PluginRepoRegistered - ); - adminPluginRepoAddress = event.args.pluginRepo; + const pluginRepoRegisteredEvent = + await findEventTopicLog( + tx, + PluginRepoRegistry__factory.createInterface(), + EVENTS.PluginRepoRegistered + ); + adminPluginRepoAddress = pluginRepoRegisteredEvent.args.pluginRepo; // create dao with admin plugin. const adminPluginRepoPointer: PluginRepoPointer = [ @@ -622,15 +612,20 @@ describe('DAOFactory: ', function () { ); tx = await daoFactory.createDao(daoSettings, [adminPluginInstallation]); { - const event = await findEvent( - tx, - EVENTS.InstallationPrepared - ); + const installationPreparedEvent = + await findEventTopicLog( + tx, + PluginSetupProcessor__factory.createInterface(), + EVENTS.InstallationPrepared + ); + const adminFactory = new Admin__factory(signers[0]); - adminPlugin = adminFactory.attach(event.args.plugin); + adminPlugin = adminFactory.attach( + installationPreparedEvent.args.plugin + ); const daoFactory = new DAO__factory(signers[0]); - dao = daoFactory.attach(event.args.dao); + dao = daoFactory.attach(installationPreparedEvent.args.dao); } }); @@ -646,15 +641,15 @@ describe('DAOFactory: ', function () { EMPTY_DATA ); - let DAO_INTERFACE = DAO__factory.createInterface(); - let PSP_INTERFACE = PluginSetupProcessor__factory.createInterface(); + const daoInterface = DAO__factory.createInterface(); + const pspInterface = PluginSetupProcessor__factory.createInterface(); // Prepare actions for apply Installation. let applyInstallationActions = [ { to: dao.address, value: 0, - data: DAO_INTERFACE.encodeFunctionData('grant', [ + data: daoInterface.encodeFunctionData('grant', [ dao.address, psp.address, ethers.utils.id('ROOT_PERMISSION'), @@ -663,7 +658,7 @@ describe('DAOFactory: ', function () { { to: psp.address, value: 0, - data: PSP_INTERFACE.encodeFunctionData('applyInstallation', [ + data: pspInterface.encodeFunctionData('applyInstallation', [ dao.address, createApplyInstallationParams( plugin, @@ -702,7 +697,7 @@ describe('DAOFactory: ', function () { { to: dao.address, value: 0, - data: DAO_INTERFACE.encodeFunctionData('grant', [ + data: daoInterface.encodeFunctionData('grant', [ plugin, psp.address, ethers.utils.id('UPGRADE_PLUGIN_PERMISSION'), @@ -711,7 +706,7 @@ describe('DAOFactory: ', function () { { to: psp.address, value: 0, - data: PSP_INTERFACE.encodeFunctionData('applyUpdate', [ + data: pspInterface.encodeFunctionData('applyUpdate', [ dao.address, createApplyUpdateParams( plugin, @@ -743,7 +738,7 @@ describe('DAOFactory: ', function () { { to: psp.address, value: 0, - data: PSP_INTERFACE.encodeFunctionData('applyUninstallation', [ + data: pspInterface.encodeFunctionData('applyUninstallation', [ dao.address, createApplyUninstallationParams( plugin, diff --git a/packages/contracts/test/framework/plugin/plugin-repo-factory.ts b/packages/contracts/test/framework/plugin/plugin-repo-factory.ts index 7ee96d196..27afbaefa 100644 --- a/packages/contracts/test/framework/plugin/plugin-repo-factory.ts +++ b/packages/contracts/test/framework/plugin/plugin-repo-factory.ts @@ -18,7 +18,6 @@ import { IProtocolVersion__factory, IERC165__factory, } from '../../../typechain'; -import {getMergedABI} from '../../../utils/abi'; import {getInterfaceID} from '../../test-utils/interfaces'; import {CURRENT_PROTOCOL_VERSION} from '../../test-utils/protocol-version'; @@ -53,22 +52,9 @@ describe('PluginRepoFactory: ', function () { let managingDao: DAO; let pluginRepoFactory: PluginRepoFactory; - let mergedABI: any; - let pluginRepoFactoryBytecode: any; - before(async () => { signers = await ethers.getSigners(); ownerAddress = await signers[0].getAddress(); - - const {abi, bytecode} = await getMergedABI( - // @ts-ignore - hre, - 'PluginRepoFactory', - ['PluginRepoRegistry'] - ); - - mergedABI = abi; - pluginRepoFactoryBytecode = bytecode; }); beforeEach(async function () { @@ -90,9 +76,7 @@ describe('PluginRepoFactory: ', function () { ); // deploy PluginRepoFactory - const PluginRepoFactory = new ethers.ContractFactory( - mergedABI, - pluginRepoFactoryBytecode, + const PluginRepoFactory = new PluginRepoFactory__factory( signers[0] ) as PluginRepoFactory__factory; diff --git a/packages/contracts/test/framework/plugin/plugin-setup-processor.ts b/packages/contracts/test/framework/plugin/plugin-setup-processor.ts index d4441929c..b7af6c512 100644 --- a/packages/contracts/test/framework/plugin/plugin-setup-processor.ts +++ b/packages/contracts/test/framework/plugin/plugin-setup-processor.ts @@ -5,9 +5,6 @@ import {anyValue} from '@nomicfoundation/hardhat-chai-matchers/withArgs'; import { PluginSetupProcessor, - PluginUUPSUpgradeableV1Mock__factory, - PluginUUPSUpgradeableV2Mock__factory, - PluginUUPSUpgradeableV3Mock__factory, PluginUUPSUpgradeableSetupV1Mock, PluginUUPSUpgradeableSetupV1MockBad, PluginUUPSUpgradeableSetupV2Mock, @@ -20,21 +17,26 @@ import { PluginRepoRegistry, PluginRepo, DAO, - PluginUUPSUpgradeableSetupV2Mock__factory, + PluginRepo__factory, + PluginRepoRegistry__factory, + PluginUUPSUpgradeable__factory, + PluginUUPSUpgradeableV1Mock__factory, + PluginUUPSUpgradeableV2Mock__factory, + PluginUUPSUpgradeableV3Mock__factory, + PluginUUPSUpgradeableSetupV1Mock__factory, PluginUUPSUpgradeableSetupV1MockBad__factory, + PluginUUPSUpgradeableSetupV2Mock__factory, PluginUUPSUpgradeableSetupV4Mock__factory, + PluginCloneableSetupV1Mock__factory, PluginCloneableSetupV2Mock__factory, PluginCloneableSetupV1MockBad__factory, - PluginUUPSUpgradeableSetupV1Mock__factory, - PluginCloneableSetupV1Mock__factory, - PluginRepo__factory, - PluginUUPSUpgradeable__factory, } from '../../../typechain'; +import {PluginRepoRegisteredEvent} from '../../../typechain/PluginRepoRegistry'; import {deployENSSubdomainRegistrar} from '../../test-utils/ens'; import {deployNewDAO, ZERO_BYTES32} from '../../test-utils/dao'; import {deployPluginSetupProcessor} from '../../test-utils/plugin-setup-processor'; -import {findEvent} from '../../../utils/event'; +import {findEventTopicLog} from '../../../utils/event'; import {Operation} from '../../../utils/types'; import { @@ -82,7 +84,6 @@ import { uninstallPlugin, } from '../../test-utils/psp/atomic-helpers'; import {UPGRADE_PERMISSIONS} from '../../test-utils/permissions'; -import {PluginRepoRegisteredEvent} from '../../../typechain/PluginRepoRegistry'; const EVENTS = { InstallationPrepared: 'InstallationPrepared', @@ -245,12 +246,14 @@ describe('Plugin Setup Processor', function () { buildMetadata ); - let event = await findEvent( - tx, - EVENTS.PluginRepoRegistered - ); + const PluginRepoRegisteredEvent1 = + await findEventTopicLog( + tx, + PluginRepoRegistry__factory.createInterface(), + EVENTS.PluginRepoRegistered + ); const PluginRepo = new PluginRepo__factory(signers[0]); - repoU = PluginRepo.attach(event.args.pluginRepo); + repoU = PluginRepo.attach(PluginRepoRegisteredEvent1.args.pluginRepo); // Add setups await repoU.createVersion(1, setupUV2.address, EMPTY_DATA, EMPTY_DATA); // build 2 @@ -267,11 +270,13 @@ describe('Plugin Setup Processor', function () { buildMetadata ); - event = await findEvent( - tx, - EVENTS.PluginRepoRegistered - ); - repoC = PluginRepo.attach(event.args.pluginRepo); + const PluginRepoRegisteredEvent2 = + await findEventTopicLog( + tx, + PluginRepoRegistry__factory.createInterface(), + EVENTS.PluginRepoRegistered + ); + repoC = PluginRepo.attach(PluginRepoRegisteredEvent2.args.pluginRepo); await repoC.createVersion(1, setupCV1Bad.address, EMPTY_DATA, EMPTY_DATA); await repoC.createVersion(1, setupCV2.address, EMPTY_DATA, EMPTY_DATA); }); diff --git a/packages/contracts/test/plugins/governance/admin/admin.ts b/packages/contracts/test/plugins/governance/admin/admin.ts index 411b1d872..3ffc1a526 100644 --- a/packages/contracts/test/plugins/governance/admin/admin.ts +++ b/packages/contracts/test/plugins/governance/admin/admin.ts @@ -2,12 +2,12 @@ import {expect} from 'chai'; import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers'; import {ethers} from 'hardhat'; -import {getMergedABI} from '../../../../utils/abi'; import { findEvent, DAO_EVENTS, PROPOSAL_EVENTS, MEMBERSHIP_EVENTS, + findEventTopicLog, } from '../../../../utils/event'; import {deployNewDAO} from '../../../test-utils/dao'; import {getInterfaceID} from '../../../test-utils/interfaces'; @@ -16,13 +16,15 @@ import {toBytes32} from '../../../test-utils/voting'; import { AdminCloneFactory, AdminCloneFactory__factory, + Admin__factory, IERC165Upgradeable__factory, IMembership__factory, IPlugin__factory, IProposal__factory, + DAO__factory, } from '../../../../typechain'; import {ProposalCreatedEvent} from '../../../../typechain/Admin'; -import {ExecutedEvent} from '../../../../typechain/DAO'; +import {ExecutedEvent} from '../../../../typechain/IDAO'; // Permissions const EXECUTE_PROPOSAL_PERMISSION_ID = ethers.utils.id( @@ -44,20 +46,10 @@ describe('Admin', function () { let dummyActions: any; let dummyMetadata: string; - let mergedAbi: any; - let adminFactoryBytecode: any; - before(async () => { signers = await ethers.getSigners(); ownerAddress = await signers[0].getAddress(); - ({abi: mergedAbi, bytecode: adminFactoryBytecode} = await getMergedABI( - // @ts-ignore - hre, - 'Admin', - ['src/core/dao/DAO.sol:DAO'] - )); - dummyActions = [ { to: ownerAddress, @@ -76,11 +68,7 @@ describe('Admin', function () { }); beforeEach(async () => { - const AdminFactory = new ethers.ContractFactory( - mergedAbi, - adminFactoryBytecode, - signers[0] - ); + const AdminFactory = new Admin__factory(signers[0]); const nonce = await ethers.provider.getTransactionCount( adminCloneFactory.address @@ -250,7 +238,12 @@ describe('Admin', function () { dummyActions, allowFailureMap ); - const event = await findEvent(tx, DAO_EVENTS.EXECUTED); + + const event = await findEventTopicLog( + tx, + DAO__factory.createInterface(), + DAO_EVENTS.EXECUTED + ); expect(event.args.actor).to.equal(plugin.address); expect(event.args.callId).to.equal(toBytes32(proposalId)); @@ -266,8 +259,12 @@ describe('Admin', function () { const proposalId = 1; const tx = await plugin.executeProposal(dummyMetadata, dummyActions, 0); - const event = await findEvent(tx, DAO_EVENTS.EXECUTED); + const event = await findEventTopicLog( + tx, + DAO__factory.createInterface(), + DAO_EVENTS.EXECUTED + ); expect(event.args.callId).to.equal(toBytes32(proposalId)); } }); diff --git a/packages/contracts/test/plugins/governance/majority-voting/addresslist/addresslist-voting.ts b/packages/contracts/test/plugins/governance/majority-voting/addresslist/addresslist-voting.ts index 01442f4d9..a5aacc786 100644 --- a/packages/contracts/test/plugins/governance/majority-voting/addresslist/addresslist-voting.ts +++ b/packages/contracts/test/plugins/governance/majority-voting/addresslist/addresslist-voting.ts @@ -4,8 +4,10 @@ import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers'; import { AddresslistVoting, + AddresslistVoting__factory, Addresslist__factory, DAO, + DAO__factory, IERC165Upgradeable__factory, IMajorityVoting__factory, IMembership__factory, @@ -14,12 +16,12 @@ import { } from '../../../../../typechain'; import { findEvent, + findEventTopicLog, DAO_EVENTS, VOTING_EVENTS, PROPOSAL_EVENTS, MEMBERSHIP_EVENTS, } from '../../../../../utils/event'; -import {getMergedABI} from '../../../../../utils/abi'; import { VoteOption, pctToRatio, @@ -40,11 +42,11 @@ import {UPGRADE_PERMISSIONS} from '../../../../test-utils/permissions'; import {deployWithProxy} from '../../../../test-utils/proxy'; import {getInterfaceID} from '../../../../test-utils/interfaces'; import {majorityVotingBaseInterface} from '../majority-voting'; -import {ExecutedEvent} from '../../../../../typechain/DAO'; import { ProposalCreatedEvent, ProposalExecutedEvent, } from '../../../../../typechain/AddresslistVoting'; +import {ExecutedEvent} from '../../../../../typechain/IDAO'; export const addresslistVotingInterface = new ethers.utils.Interface([ 'function initialize(address,tuple(uint8,uint32,uint32,uint64,uint256),address[])', @@ -65,20 +67,9 @@ describe('AddresslistVoting', function () { const startOffset = 10; const id = 0; - let mergedAbi: any; - let addresslistVotingFactoryBytecode: any; - before(async () => { signers = await ethers.getSigners(); - ({abi: mergedAbi, bytecode: addresslistVotingFactoryBytecode} = - await getMergedABI( - // @ts-ignore - hre, - 'AddresslistVoting', - ['src/core/dao/DAO.sol:DAO'] - )); - dummyActions = [ { to: signers[0].address, @@ -102,11 +93,7 @@ describe('AddresslistVoting', function () { minProposerVotingPower: 0, }; - const AddresslistVotingFactory = new ethers.ContractFactory( - mergedAbi, - addresslistVotingFactoryBytecode, - signers[0] - ); + const AddresslistVotingFactory = new AddresslistVoting__factory(signers[0]); voting = await deployWithProxy(AddresslistVotingFactory); @@ -1040,7 +1027,11 @@ describe('AddresslistVoting', function () { .connect(signers[6]) .vote(id, VoteOption.Abstain, true); { - const event = await findEvent(tx, DAO_EVENTS.EXECUTED); + const event = await findEventTopicLog( + tx, + DAO__factory.createInterface(), + DAO_EVENTS.EXECUTED + ); expect(event.args.actor).to.equal(voting.address); expect(event.args.callId).to.equal(toBytes32(id)); diff --git a/packages/contracts/test/plugins/governance/majority-voting/token/token-voting.ts b/packages/contracts/test/plugins/governance/majority-voting/token/token-voting.ts index 0031887e4..125ff7e44 100644 --- a/packages/contracts/test/plugins/governance/majority-voting/token/token-voting.ts +++ b/packages/contracts/test/plugins/governance/majority-voting/token/token-voting.ts @@ -5,6 +5,7 @@ import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers'; import { DAO, + DAO__factory, GovernanceERC20Mock, GovernanceERC20Mock__factory, IERC165Upgradeable__factory, @@ -13,15 +14,16 @@ import { IPlugin__factory, IProposal__factory, TokenVoting, + TokenVoting__factory, } from '../../../../../typechain'; import { findEvent, + findEventTopicLog, DAO_EVENTS, VOTING_EVENTS, PROPOSAL_EVENTS, MEMBERSHIP_EVENTS, } from '../../../../../utils/event'; -import {getMergedABI} from '../../../../../utils/abi'; import { VoteOption, pctToRatio, @@ -47,7 +49,7 @@ import { ProposalCreatedEvent, ProposalExecutedEvent, } from '../../../../../typechain/TokenVoting'; -import {ExecutedEvent} from '../../../../../typechain/DAO'; +import {ExecutedEvent} from '../../../../../typechain/IDAO'; export const tokenVotingInterface = new ethers.utils.Interface([ 'function initialize(address,tuple(uint8,uint32,uint32,uint64,uint256),address)', @@ -69,20 +71,9 @@ describe('TokenVoting', function () { const startOffset = 20; const id = 0; - let mergedAbi: any; - let tokenVotingFactoryBytecode: any; - before(async () => { signers = await ethers.getSigners(); - ({abi: mergedAbi, bytecode: tokenVotingFactoryBytecode} = - await getMergedABI( - // @ts-ignore - hre, - 'TokenVoting', - ['src/core/dao/DAO.sol:DAO'] - )); - dummyActions = [ { to: signers[0].address, @@ -118,11 +109,7 @@ describe('TokenVoting', function () { } ); - const TokenVotingFactory = new ethers.ContractFactory( - mergedAbi, - tokenVotingFactoryBytecode, - signers[0] - ); + const TokenVotingFactory = new TokenVoting__factory(signers[0]); voting = await deployWithProxy(TokenVotingFactory); @@ -1396,7 +1383,11 @@ describe('TokenVoting', function () { .connect(signers[6]) .vote(id, VoteOption.Yes, true); { - const event = await findEvent(tx, DAO_EVENTS.EXECUTED); + const event = await findEventTopicLog( + tx, + DAO__factory.createInterface(), + DAO_EVENTS.EXECUTED + ); expect(event.args.actor).to.equal(voting.address); expect(event.args.callId).to.equal(toBytes32(id)); diff --git a/packages/contracts/test/plugins/governance/multisig/multisig.ts b/packages/contracts/test/plugins/governance/multisig/multisig.ts index ff4ab8d7a..c07036794 100644 --- a/packages/contracts/test/plugins/governance/multisig/multisig.ts +++ b/packages/contracts/test/plugins/governance/multisig/multisig.ts @@ -6,21 +6,23 @@ import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers'; import { Addresslist__factory, DAO, + DAO__factory, IERC165Upgradeable__factory, IMembership__factory, IMultisig__factory, IPlugin__factory, IProposal__factory, Multisig, + Multisig__factory, } from '../../../../typechain'; import { findEvent, + findEventTopicLog, DAO_EVENTS, PROPOSAL_EVENTS, MULTISIG_EVENTS, MEMBERSHIP_EVENTS, } from '../../../../utils/event'; -import {getMergedABI} from '../../../../utils/abi'; import {deployNewDAO} from '../../../test-utils/dao'; import {OZ_ERRORS} from '../../../test-utils/error'; import { @@ -76,19 +78,8 @@ describe('Multisig', function () { const id = 0; - let mergedAbi: any; - let multisigFactoryBytecode: any; - before(async () => { signers = await ethers.getSigners(); - - ({abi: mergedAbi, bytecode: multisigFactoryBytecode} = await getMergedABI( - // @ts-ignore - hre, - 'Multisig', - ['src/core/dao/DAO.sol:DAO'] - )); - dummyActions = [ { to: signers[0].address, @@ -109,11 +100,7 @@ describe('Multisig', function () { onlyListed: true, }; - const MultisigFactory = new ethers.ContractFactory( - mergedAbi, - multisigFactoryBytecode, - signers[0] - ); + const MultisigFactory = new Multisig__factory(signers[0]); multisig = await deployWithProxy(MultisigFactory); dao.grant( @@ -1183,21 +1170,33 @@ describe('Multisig', function () { // `tryExecution` is turned on but the vote is not decided yet let tx = await multisig.connect(signers[1]).approve(id, true); await expect( - findEvent(tx, DAO_EVENTS.EXECUTED) - ).to.rejectedWith('Event Executed not found in TX.'); + findEventTopicLog( + tx, + DAO__factory.createInterface(), + DAO_EVENTS.EXECUTED + ) + ).to.rejectedWith('No logs found for the topic of event "Executed".'); expect(await multisig.canExecute(id)).to.equal(false); // `tryExecution` is turned off and the vote is decided tx = await multisig.connect(signers[2]).approve(id, false); await expect( - findEvent(tx, DAO_EVENTS.EXECUTED) - ).to.rejectedWith('Event Executed not found in TX.'); + findEventTopicLog( + tx, + DAO__factory.createInterface(), + DAO_EVENTS.EXECUTED + ) + ).to.rejectedWith('No logs found for the topic of event "Executed".'); // `tryEarlyExecution` is turned on and the vote is decided tx = await multisig.connect(signers[3]).approve(id, true); { - const event = await findEvent(tx, DAO_EVENTS.EXECUTED); + const event = await findEventTopicLog( + tx, + DAO__factory.createInterface(), + DAO_EVENTS.EXECUTED + ); expect(event.args.actor).to.equal(multisig.address); expect(event.args.callId).to.equal(toBytes32(id)); diff --git a/packages/contracts/test/test-utils/plugin-setup-processor.ts b/packages/contracts/test/test-utils/plugin-setup-processor.ts index d9c49f4e4..bf139ac17 100644 --- a/packages/contracts/test/test-utils/plugin-setup-processor.ts +++ b/packages/contracts/test/test-utils/plugin-setup-processor.ts @@ -1,30 +1,21 @@ import {ethers} from 'hardhat'; -import {PluginRepoRegistry, PluginSetupProcessor} from '../../typechain'; - -import {getMergedABI} from '../../utils/abi'; +import { + PluginSetupProcessor__factory, + PluginRepoRegistry, + PluginSetupProcessor, +} from '../../typechain'; export async function deployPluginSetupProcessor( pluginRepoRegistry: PluginRepoRegistry ): Promise { let psp: PluginSetupProcessor; - const {abi, bytecode} = await getMergedABI( - // @ts-ignore - hre, - 'PluginSetupProcessor', - ['ERC1967Upgrade'] - ); - - const PluginSetupProcessor = new ethers.ContractFactory( - abi, - bytecode, + const PluginSetupProcessor = new PluginSetupProcessor__factory( (await ethers.getSigners())[0] ); - psp = (await PluginSetupProcessor.deploy( - pluginRepoRegistry.address - )) as PluginSetupProcessor; + psp = await PluginSetupProcessor.deploy(pluginRepoRegistry.address); return psp; } diff --git a/packages/contracts/test/test-utils/repo.ts b/packages/contracts/test/test-utils/repo.ts index 17eff06bc..e024e2872 100644 --- a/packages/contracts/test/test-utils/repo.ts +++ b/packages/contracts/test/test-utils/repo.ts @@ -8,9 +8,9 @@ import { PluginRepo__factory, PluginUUPSUpgradeableSetupV1Mock__factory, PluginRepoRegistry__factory, + PluginRepoFactory__factory, } from '../../typechain'; import {deployWithProxy} from './proxy'; -import {getMergedABI} from '../../utils/abi'; import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers'; export async function deployMockPluginSetup( @@ -36,23 +36,12 @@ export async function deployPluginRepoFactory( signers: any, pluginRepoRegistry: PluginRepoRegistry ): Promise { - const {abi, bytecode} = await getMergedABI( - // @ts-ignore - hre, - 'PluginRepoFactory', - ['PluginRepoRegistry'] - ); - // PluginRepoFactory - const PluginRepoFactory = new ethers.ContractFactory( - abi, - bytecode, - signers[0] - ); + const PluginRepoFactory = new PluginRepoFactory__factory(signers[0]); - const pluginRepoFactory = (await PluginRepoFactory.deploy( + const pluginRepoFactory = await PluginRepoFactory.deploy( pluginRepoRegistry.address - )) as PluginRepoFactory; + ); return pluginRepoFactory; } diff --git a/packages/contracts/test/upgrade/dao.ts b/packages/contracts/test/upgrade/dao.ts index ec3ba4ec7..5a8ef942d 100644 --- a/packages/contracts/test/upgrade/dao.ts +++ b/packages/contracts/test/upgrade/dao.ts @@ -15,6 +15,7 @@ import {UPGRADE_PERMISSIONS} from '../test-utils/permissions'; import {findEventTopicLog} from '../../utils/event'; import {readImplementationValueFromSlot} from '../../utils/storage'; import {getInterfaceID} from '../test-utils/interfaces'; +import {UpgradedEvent} from '../../typechain/DAO'; let signers: SignerWithAddress[]; let DAO_old: DAO_V1_0_0__factory; @@ -89,7 +90,11 @@ describe('DAO Upgrade', function () { // Check the emitted implementation. const emittedImplementation = ( - await findEventTopicLog(upgradeTx, DAO_old.interface, 'Upgraded') + await findEventTopicLog( + upgradeTx, + DAO_old.interface, + 'Upgraded' + ) ).args.implementation; expect(emittedImplementation).to.equal(daoCurrentImplementaion.address); diff --git a/packages/contracts/utils/abi.ts b/packages/contracts/utils/abi.ts deleted file mode 100644 index c5486f32f..000000000 --- a/packages/contracts/utils/abi.ts +++ /dev/null @@ -1,31 +0,0 @@ -import {HardhatRuntimeEnvironment} from 'hardhat/types'; - -export async function getMergedABI( - hre: HardhatRuntimeEnvironment, - primaryABI: string, - secondaryABIs: string[] -): Promise<{abi: any; bytecode: any}> { - const primaryArtifact = await hre.artifacts.readArtifact(primaryABI); - - const secondariesArtifacts = secondaryABIs.map( - async name => await hre.artifacts.readArtifact(name) - ); - - const _merged = [...primaryArtifact.abi]; - - for (let i = 0; i < secondariesArtifacts.length; i++) { - const artifact = await secondariesArtifacts[i]; - _merged.push(...artifact.abi.filter((f: any) => f.type === 'event')); - } - - // remove duplicated events - const merged = _merged.filter( - (value, index, self) => - index === self.findIndex(event => event.name === value.name) - ); - - return { - abi: merged, - bytecode: primaryArtifact.bytecode, - }; -} diff --git a/packages/contracts/utils/event.ts b/packages/contracts/utils/event.ts index b6d54f743..bf6dcdd8b 100644 --- a/packages/contracts/utils/event.ts +++ b/packages/contracts/utils/event.ts @@ -1,7 +1,10 @@ import {ContractTransaction} from 'ethers'; import {Interface, LogDescription} from 'ethers/lib/utils'; -export async function findEvent(tx: ContractTransaction, eventName: string) { +export async function findEvent( + tx: ContractTransaction, + eventName: string +): Promise { const receipt = await tx.wait(); const event = (receipt.events || []).find(event => event.event === eventName); @@ -12,18 +15,18 @@ export async function findEvent(tx: ContractTransaction, eventName: string) { return event as unknown as T; } -export async function findEventTopicLog( +export async function findEventTopicLog( tx: ContractTransaction, iface: Interface, eventName: string -): Promise { +): Promise { const receipt = await tx.wait(); const topic = iface.getEventTopic(eventName); const log = receipt.logs.find(x => x.topics[0] === topic); if (!log) { - throw new Error(`No logs found for this event ${eventName} topic.`); + throw new Error(`No logs found for the topic of event "${eventName}".`); } - return iface.parseLog(log); + return iface.parseLog(log) as LogDescription & (T | LogDescription); } export async function filterEvents(tx: any, eventName: string) {