Skip to content

Commit

Permalink
test: add interface tests and subgraph renaming (#474)
Browse files Browse the repository at this point in the history
* test: add interface tests and subgraph renaming

* fix: wrong imports
  • Loading branch information
heueristik authored Oct 5, 2023
1 parent e35f6f8 commit aab6b9b
Show file tree
Hide file tree
Showing 18 changed files with 369 additions and 109 deletions.
6 changes: 6 additions & 0 deletions packages/contracts/src/test/Migration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ import {MerkleMinter as MerkleMinter_v1_3_0} from "@aragon/osx-v1.3.0-rc0.2/plug

import {MerkleDistributor as MerkleDistributor_v1_0_0} from "@aragon/osx-v1.0.1/plugins/token/MerkleDistributor.sol";
import {MerkleDistributor as MerkleDistributor_v1_3_0} from "@aragon/osx-v1.3.0-rc0.2/plugins/token/MerkleDistributor.sol";

import {GovernanceERC20 as GovernanceERC20_v1_0_0} from "@aragon/osx-v1.0.1/token/ERC20/governance/GovernanceERC20.sol";
import {GovernanceERC20 as GovernanceERC20_v1_3_0} from "@aragon/osx-v1.3.0-rc0.2/token/ERC20/governance/GovernanceERC20.sol";

import {GovernanceWrappedERC20 as GovernanceWrappedERC20_v1_0_0} from "@aragon/osx-v1.0.1/token/ERC20/governance/GovernanceWrappedERC20.sol";
import {GovernanceWrappedERC20 as GovernanceWrappedERC20_v1_3_0} from "@aragon/osx-v1.3.0-rc0.2/token/ERC20/governance/GovernanceWrappedERC20.sol";
4 changes: 0 additions & 4 deletions packages/contracts/test/core/dao/dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,6 @@ describe('DAO', function () {
]);
});

it('does not support the empty interface', async () => {
expect(await dao.supportsInterface('0xffffffff')).to.be.false;
});

describe('initialize', async () => {
it('reverts if trying to re-initialize', async () => {
await expect(
Expand Down
216 changes: 216 additions & 0 deletions packages/contracts/test/interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
import {expect} from 'chai';

import {getInterfaceID} from './test-utils/interfaces';

import {
// core
IDAO__factory,
IEIP4824__factory,
IPermissionCondition__factory,
IPlugin__factory,
IMembership__factory,
IProposal__factory,
// framework
IPluginRepo__factory,
IPluginSetup__factory,
// plugins
IMajorityVoting__factory,
IMultisig__factory,
IMerkleMinter__factory,
IMerkleDistributor__factory,
// token
IERC20MintableUpgradeable__factory,
IGovernanceWrappedERC20__factory,
// utils
IProtocolVersion__factory,
} from '../typechain';

import {IDAO__factory as IDAO_V1_0_0__factory} from '../typechain/@aragon/osx-v1.0.1/core/dao/IDAO.sol';
import {IEIP4824__factory as IEIP4824_V1_0_0__factory} from '../typechain/@aragon/osx-v1.0.1/core/dao/IEIP4824.sol';
import {IPermissionCondition__factory as IPermissionCondition_V1_0_0__factory} from '../typechain/@aragon/osx-v1.0.1/core/permission/IPermissionCondition.sol';
import {IPlugin__factory as IPlugin_V1_0_0__factory} from '../typechain/@aragon/osx-v1.0.1/core/plugin/IPlugin.sol';
import {IMembership__factory as IMembership_V1_0_0__factory} from '../typechain/@aragon/osx-v1.0.1/core/plugin/membership/IMembership.sol';
import {IProposal__factory as IProposal_V1_0_0__factory} from '../typechain/@aragon/osx-v1.0.1/core/plugin/proposal/IProposal.sol';

import {IPluginRepo__factory as IPluginRepo_V1_0_0__factory} from '../typechain/@aragon/osx-v1.0.1/framework/plugin/repo/IPluginRepo.sol';
import {IPluginSetup__factory as IPluginSetup_V1_0_0__factory} from '../typechain/@aragon/osx-v1.0.1/framework/plugin/setup/IPluginSetup.sol';

import {IMajorityVoting__factory as IMajorityVoting_V1_0_0__factory} from '../typechain/@aragon/osx-v1.0.1/plugins/governance/majority-voting/IMajorityVoting.sol';
import {IMultisig__factory as IMultisig_V1_0_0__factory} from '../typechain/@aragon/osx-v1.0.1/plugins/governance/multisig/IMultisig.sol';
import {IMerkleMinter__factory as IMerkleMinter_V1_0_0__factory} from '../typechain/@aragon/osx-v1.0.1/plugins/token/IMerkleMinter.sol';
import {IMerkleDistributor__factory as IMerkleDistributor_V1_0_0__factory} from '../typechain/@aragon/osx-v1.0.1/plugins/token/IMerkleDistributor.sol';

import {IERC20MintableUpgradeable__factory as IERC20MintableUpgradeable_V1_0_0__factory} from '../typechain/@aragon/osx-v1.0.1/token/ERC20/IERC20MintableUpgradeable.sol';
import {IGovernanceWrappedERC20__factory as IGovernanceWrappedERC20_V1_0_0__factory} from '../typechain/@aragon/osx-v1.0.1/token/ERC20/governance/IGovernanceWrappedERC20.sol'; // TODO: For some reason this file is missing.

import {IProtocolVersion__factory as IProtocolVersion_V1_3_0__factory} from '../typechain/@aragon/osx-v1.3.0-rc0.2/utils/protocol/IProtocolVersion.sol';

describe('Interfaces', function () {
context('introduced in v1.0.0', function () {
describe('IDAO', function () {
it('has still the same interface ID', async () => {
const current = getInterfaceID(IDAO__factory.createInterface());
const initial = getInterfaceID(IDAO_V1_0_0__factory.createInterface());
expect(current).to.equal(initial);
});
});

describe('IEIP4824', function () {
it('has still the same interface ID', async () => {
const current = getInterfaceID(IEIP4824__factory.createInterface());
const initial = getInterfaceID(
IEIP4824_V1_0_0__factory.createInterface()
);
expect(current).to.equal(initial);
});
});

describe('IPermissionCondition', function () {
it('has still the same interface ID', async () => {
const current = getInterfaceID(
IPermissionCondition__factory.createInterface()
);
const initial = getInterfaceID(
IPermissionCondition_V1_0_0__factory.createInterface()
);
expect(current).to.equal(initial);
});
});
describe('IPlugin', function () {
it('has still the same interface ID', async () => {
const current = getInterfaceID(IPlugin__factory.createInterface());
const initial = getInterfaceID(
IPlugin_V1_0_0__factory.createInterface()
);
expect(current).to.equal(initial);
});
});

describe('IMembership', function () {
it('has still the same interface ID', async () => {
const current = getInterfaceID(IMembership__factory.createInterface());
const initial = getInterfaceID(
IMembership_V1_0_0__factory.createInterface()
);
expect(current).to.equal(initial);
});
});

describe('IProposal', function () {
it('has still the same interface ID', async () => {
const current = getInterfaceID(IProposal__factory.createInterface());
const initial = getInterfaceID(
IProposal_V1_0_0__factory.createInterface()
);
expect(current).to.equal(initial);
});
});

describe('IPluginRepo', function () {
it('has still the same interface ID', async () => {
const current = getInterfaceID(IPluginRepo__factory.createInterface());
const initial = getInterfaceID(
IPluginRepo_V1_0_0__factory.createInterface()
);
expect(current).to.equal(initial);
});
});

describe('IPluginSetup', function () {
it('has still the same interface ID', async () => {
const current = getInterfaceID(IPluginSetup__factory.createInterface());
const initial = getInterfaceID(
IPluginSetup_V1_0_0__factory.createInterface()
);
expect(current).to.equal(initial);
});
});

// plugins
describe('IMajorityVoting', function () {
it('has still the same interface ID', async () => {
const current = getInterfaceID(
IMajorityVoting__factory.createInterface()
);
const initial = getInterfaceID(
IMajorityVoting_V1_0_0__factory.createInterface()
);
expect(current).to.equal(initial);
});
});

describe('IMultisig', function () {
it('has still the same interface ID', async () => {
const current = getInterfaceID(IMultisig__factory.createInterface());
const initial = getInterfaceID(
IMultisig_V1_0_0__factory.createInterface()
);
expect(current).to.equal(initial);
});
});

describe('IMerkleMinter', function () {
it('has still the same interface ID', async () => {
const current = getInterfaceID(
IMerkleMinter__factory.createInterface()
);
const initial = getInterfaceID(
IMerkleMinter_V1_0_0__factory.createInterface()
);
expect(current).to.equal(initial);
});
});

describe('IMerkleDistributor', function () {
it('has still the same interface ID', async () => {
const current = getInterfaceID(
IMerkleDistributor__factory.createInterface()
);
const initial = getInterfaceID(
IMerkleDistributor_V1_0_0__factory.createInterface()
);
expect(current).to.equal(initial);
});
});

// tokens
describe('IERC20MintableUpgradeable', function () {
it('has still the same interface ID', async () => {
const current = getInterfaceID(
IERC20MintableUpgradeable__factory.createInterface()
);
const initial = getInterfaceID(
IERC20MintableUpgradeable_V1_0_0__factory.createInterface()
);
expect(current).to.equal(initial);
});
});

describe('IGovernanceWrappedERC20', function () {
it('has still the same interface ID', async () => {
const current = getInterfaceID(
IGovernanceWrappedERC20__factory.createInterface()
);
const initial = getInterfaceID(
IGovernanceWrappedERC20_V1_0_0__factory.createInterface()
);
expect(current).to.equal(initial);
});
});
});

// utils
context('introduced in v1.3.0', function () {
describe('IProtocolVersion', function () {
it('has still the same interface ID', async () => {
const current = getInterfaceID(
IProtocolVersion__factory.createInterface()
);
const initial = getInterfaceID(
IProtocolVersion_V1_3_0__factory.createInterface()
);
expect(current).to.equal(initial);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import {
Admin__factory,
} from '../../../../typechain';
import {deployNewDAO} from '../../../test-utils/dao';
import {getInterfaceID} from '../../../test-utils/interfaces';
import {ADMIN_INTERFACE, getInterfaceID} from '../../../test-utils/interfaces';
import metadata from '../../../../src/plugins/governance/admin/build-metadata.json';
import {adminInterface} from './admin';
import {getNamedTypesFromMetadata} from '../../../../utils/metadata';

const abiCoder = ethers.utils.defaultAbiCoder;
Expand Down Expand Up @@ -59,7 +58,7 @@ describe('AdminSetup', function () {

expect(
await adminAddressContract.supportsInterface(
getInterfaceID(adminInterface)
getInterfaceID(ADMIN_INTERFACE)
)
).to.be.eq(true);
});
Expand Down
14 changes: 6 additions & 8 deletions packages/contracts/test/plugins/governance/admin/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
findEventTopicLog,
} from '../../../../utils/event';
import {deployNewDAO} from '../../../test-utils/dao';
import {getInterfaceID} from '../../../test-utils/interfaces';
import {ADMIN_INTERFACE, getInterfaceID} from '../../../test-utils/interfaces';
import {ADMIN_INTERFACE_ID} from '../../../../../subgraph/src/utils/constants';

import {OZ_ERRORS} from '../../../test-utils/error';
import {toBytes32} from '../../../test-utils/voting';
import {
Expand All @@ -33,11 +35,6 @@ const EXECUTE_PROPOSAL_PERMISSION_ID = ethers.utils.id(
);
const EXECUTE_PERMISSION_ID = ethers.utils.id('EXECUTE_PERMISSION');

export const adminInterface = new ethers.utils.Interface([
'function initialize(address)',
'function executeProposal(bytes,tuple(address,uint256,bytes)[],uint256)',
]);

describe('Admin', function () {
let signers: SignerWithAddress[];
let plugin: any;
Expand Down Expand Up @@ -144,8 +141,9 @@ describe('Admin', function () {
});

it('supports the `Admin` interface', async () => {
expect(await plugin.supportsInterface(getInterfaceID(adminInterface))).to
.be.true;
const iface = getInterfaceID(ADMIN_INTERFACE);
expect(iface).to.equal(ADMIN_INTERFACE_ID); // checks that it didn't change
expect(await plugin.supportsInterface(iface)).to.be.true;
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import {
AddresslistVoting__factory,
} from '../../../../../typechain';
import {deployNewDAO} from '../../../../test-utils/dao';
import {getInterfaceID} from '../../../../test-utils/interfaces';
import {
ADDRESSLIST_VOTING_INTERFACE,
getInterfaceID,
} from '../../../../test-utils/interfaces';
import {Operation} from '../../../../../utils/types';
import {
VotingSettings,
Expand All @@ -17,7 +20,6 @@ import {
ONE_HOUR,
} from '../../../../test-utils/voting';
import metadata from '../../../../../src/plugins/governance/majority-voting/addresslist/build-metadata.json';
import {addresslistVotingInterface} from './addresslist-voting';
import {getNamedTypesFromMetadata} from '../../../../../utils/metadata';

let defaultData: any;
Expand Down Expand Up @@ -83,7 +85,7 @@ describe('AddresslistVotingSetup', function () {

expect(
await addresslistVotingContract.supportsInterface(
getInterfaceID(addresslistVotingInterface)
getInterfaceID(ADDRESSLIST_VOTING_INTERFACE)
)
).to.be.eq(true);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ import {deployNewDAO} from '../../../../test-utils/dao';
import {OZ_ERRORS} from '../../../../test-utils/error';
import {UPGRADE_PERMISSIONS} from '../../../../test-utils/permissions';
import {deployWithProxy} from '../../../../test-utils/proxy';
import {getInterfaceID} from '../../../../test-utils/interfaces';
import {
ADDRESSLIST_VOTING_INTERFACE,
getInterfaceID,
} from '../../../../test-utils/interfaces';
import {ADDRESSLIST_VOTING_INTERFACE_ID} from '../../../../../../subgraph/src/utils/constants';

import {
getProtocolVersion,
Expand All @@ -63,12 +67,6 @@ import {
} from '../../../../test-utils/protocol-version';
import {ExecutedEvent} from '../../../../../typechain/DAO';

export const addresslistVotingInterface = new ethers.utils.Interface([
'function initialize(address,tuple(uint8,uint32,uint32,uint64,uint256),address[])',
'function addAddresses(address[])',
'function removeAddresses(address[])',
]);

describe('AddresslistVoting', function () {
let signers: SignerWithAddress[];
let voting: AddresslistVoting;
Expand Down Expand Up @@ -276,11 +274,9 @@ describe('AddresslistVoting', function () {
});

it('supports the `AddresslistVoting` interface', async () => {
expect(
await voting.supportsInterface(
getInterfaceID(addresslistVotingInterface)
)
).to.be.true;
const iface = getInterfaceID(ADDRESSLIST_VOTING_INTERFACE);
expect(iface).to.equal(ADDRESSLIST_VOTING_INTERFACE_ID); // checks that it didn't change
expect(await voting.supportsInterface(iface)).to.be.true;
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
TokenVoting__factory,
} from '../../../../../typechain';
import {deployNewDAO} from '../../../../test-utils/dao';
import {getInterfaceID} from '../../../../test-utils/interfaces';
import {
TOKEN_VOTING_INTERFACE,
getInterfaceID,
} from '../../../../test-utils/interfaces';
import {Operation} from '../../../../../utils/types';
import metadata from '../../../../../src/plugins/governance/majority-voting/token/build-metadata.json';

Expand All @@ -24,7 +27,6 @@ import {
pctToRatio,
ONE_HOUR,
} from '../../../../test-utils/voting';
import {tokenVotingInterface} from './token-voting';
import {getNamedTypesFromMetadata} from '../../../../../utils/metadata';

let defaultData: any;
Expand Down Expand Up @@ -137,7 +139,9 @@ describe('TokenVotingSetup', function () {
const tokenVoting = factory.attach(implementationAddress);

expect(
await tokenVoting.supportsInterface(getInterfaceID(tokenVotingInterface))
await tokenVoting.supportsInterface(
getInterfaceID(TOKEN_VOTING_INTERFACE)
)
).to.be.eq(true);
});

Expand Down
Loading

0 comments on commit aab6b9b

Please sign in to comment.