forked from aragon/osx-plugin-template-hardhat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: removed majority voting base tests and fixed 165 tests
- Loading branch information
Showing
7 changed files
with
253 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,10 @@ import {IDAO} from "@aragon/osx-commons-contracts/src/dao/IDAO.sol"; | |
import {IVotesUpgradeable} from "@openzeppelin/contracts-upgradeable/governance/utils/IVotesUpgradeable.sol"; | ||
import {IMembership} from "@aragon/osx-commons-contracts/src/plugin/extensions/membership/IMembership.sol"; | ||
|
||
/// @title ITokenVoting | ||
/// @author Aragon X - 2024 | ||
/// @notice Interface for Aragon IVotes-based voting and proposal plugin "TokenVoting". | ||
/// @custom:security-contact [email protected] | ||
interface ITokenVoting { | ||
/// @notice Vote options that a voter can chose from. | ||
/// @param None The default option state of a voter indicating the absence from the vote. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
packages/contracts/test/10_unit-testing/13_Interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import {createDaoProxy} from '../20_integration-testing/test-helpers'; | ||
import { | ||
IERC165Upgradeable__factory, | ||
IPlugin__factory, | ||
IProposal__factory, | ||
IProtocolVersion__factory, | ||
ProxyFactory__factory, | ||
ITokenVoting__factory, | ||
ITokenVoting, | ||
} from '../../typechain'; | ||
import {ProxyCreatedEvent} from '../../typechain/@aragon/osx-commons-contracts/src/utils/deployment/ProxyFactory'; | ||
import {IMembership__factory} from '../../typechain/factories/@aragon/osx-v1.0.0/core/plugin/membership'; | ||
import {TOKEN_VOTING_INTERFACE} from '../test-utils/token-voting-constants'; | ||
import { | ||
TokenVoting, | ||
TokenVoting__factory, | ||
} from '../test-utils/typechain-versions'; | ||
import {VotingMode} from '../test-utils/voting-helpers'; | ||
import {TIME, findEvent} from '@aragon/osx-commons-sdk'; | ||
import {getInterfaceId} from '@aragon/osx-commons-sdk'; | ||
import {pctToRatio} from '@aragon/osx-commons-sdk'; | ||
import {DAO} from '@aragon/osx-ethers'; | ||
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers'; | ||
import {expect} from 'chai'; | ||
import {ethers} from 'hardhat'; | ||
|
||
describe('ERC-165', async () => { | ||
let signers: SignerWithAddress[]; | ||
let deployer: SignerWithAddress; | ||
let plugin: TokenVoting; | ||
let dao: DAO; | ||
let votingSettings: ITokenVoting.VotingSettingsStruct; | ||
|
||
before(async () => { | ||
signers = await ethers.getSigners(); | ||
deployer = signers[0]; | ||
|
||
dao = await createDaoProxy(signers[0], '0x00'); | ||
}); | ||
|
||
beforeEach(async () => { | ||
votingSettings = { | ||
votingMode: VotingMode.EarlyExecution, | ||
supportThreshold: pctToRatio(50), | ||
minParticipation: pctToRatio(20), | ||
minDuration: TIME.HOUR, | ||
minProposerVotingPower: 0, | ||
}; | ||
|
||
const pluginImplementation = await new TokenVoting__factory( | ||
signers[0] | ||
).deploy(); | ||
const proxyFactory = await new ProxyFactory__factory(deployer).deploy( | ||
pluginImplementation.address | ||
); | ||
const deploymentTx1 = await proxyFactory.deployUUPSProxy([]); | ||
const proxyCreatedEvent1 = findEvent<ProxyCreatedEvent>( | ||
await deploymentTx1.wait(), | ||
proxyFactory.interface.getEvent('ProxyCreated').name | ||
); | ||
plugin = TokenVoting__factory.connect( | ||
proxyCreatedEvent1.args.proxy, | ||
deployer | ||
); | ||
}); | ||
|
||
it('does not support the empty interface', async () => { | ||
expect(await plugin.supportsInterface('0xffffffff')).to.be.false; | ||
}); | ||
|
||
it('supports the `IERC165Upgradeable` interface', async () => { | ||
const iface = IERC165Upgradeable__factory.createInterface(); | ||
expect(await plugin.supportsInterface(getInterfaceId(iface))).to.be.true; | ||
}); | ||
|
||
it('supports the `IPlugin` interface', async () => { | ||
const iface = IPlugin__factory.createInterface(); | ||
expect(await plugin.supportsInterface(getInterfaceId(iface))).to.be.true; | ||
}); | ||
|
||
it('supports the `IProtocolVersion` interface', async () => { | ||
const iface = IProtocolVersion__factory.createInterface(); | ||
expect(await plugin.supportsInterface(getInterfaceId(iface))).to.be.true; | ||
}); | ||
|
||
it('supports the `IProposal` interface', async () => { | ||
const iface = IProposal__factory.createInterface(); | ||
expect(await plugin.supportsInterface(getInterfaceId(iface))).to.be.true; | ||
}); | ||
|
||
it('supports the `ITokenVoting` interface', async () => { | ||
const iface = ITokenVoting__factory.createInterface(); | ||
expect(await plugin.supportsInterface(getInterfaceId(iface))).to.be.true; | ||
}); | ||
|
||
it('supports the `IMembership` interface', async () => { | ||
const iface = IMembership__factory.createInterface(); | ||
expect(await plugin.supportsInterface(getInterfaceId(iface))).to.be.true; | ||
}); | ||
|
||
it('supports the `TokenVoting` interface', async () => { | ||
const interfaceId = getInterfaceId(TOKEN_VOTING_INTERFACE); | ||
expect(await plugin.supportsInterface(interfaceId)).to.be.true; | ||
}); | ||
}); |
128 changes: 128 additions & 0 deletions
128
packages/contracts/test/10_unit-testing/14_update-settings.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import {createDaoProxy} from '../20_integration-testing/test-helpers'; | ||
import { | ||
IERC165Upgradeable__factory, | ||
IPlugin__factory, | ||
IProposal__factory, | ||
IProtocolVersion__factory, | ||
ProxyFactory__factory, | ||
ITokenVoting__factory, | ||
ITokenVoting, | ||
} from '../../typechain'; | ||
import {ProxyCreatedEvent} from '../../typechain/@aragon/osx-commons-contracts/src/utils/deployment/ProxyFactory'; | ||
import { | ||
TokenVoting, | ||
TokenVoting__factory, | ||
} from '../test-utils/typechain-versions'; | ||
import {VotingMode} from '../test-utils/voting-helpers'; | ||
import {TIME, findEvent} from '@aragon/osx-commons-sdk'; | ||
import {pctToRatio} from '@aragon/osx-commons-sdk'; | ||
import {DAO} from '@aragon/osx-ethers'; | ||
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers'; | ||
import {expect} from 'chai'; | ||
import {ethers} from 'hardhat'; | ||
|
||
describe('updateVotingSettings', async () => { | ||
let signers: SignerWithAddress[]; | ||
let deployer: SignerWithAddress; | ||
let votingBase: TokenVoting; | ||
let dao: DAO; | ||
const mockTokenAddress = ethers.constants.AddressZero; | ||
let votingSettings: ITokenVoting.VotingSettingsStruct; | ||
|
||
before(async () => { | ||
signers = await ethers.getSigners(); | ||
deployer = signers[0]; | ||
dao = await createDaoProxy(signers[0], '0x00'); | ||
}); | ||
|
||
beforeEach(async () => { | ||
votingSettings = { | ||
votingMode: VotingMode.EarlyExecution, | ||
supportThreshold: pctToRatio(50), | ||
minParticipation: pctToRatio(20), | ||
minDuration: TIME.HOUR, | ||
minProposerVotingPower: 0, | ||
}; | ||
|
||
const pluginImplementation = await new TokenVoting__factory( | ||
signers[0] | ||
).deploy(); | ||
const proxyFactory = await new ProxyFactory__factory(deployer).deploy( | ||
pluginImplementation.address | ||
); | ||
const deploymentTx1 = await proxyFactory.deployUUPSProxy([]); | ||
const proxyCreatedEvent1 = findEvent<ProxyCreatedEvent>( | ||
await deploymentTx1.wait(), | ||
proxyFactory.interface.getEvent('ProxyCreated').name | ||
); | ||
votingBase = TokenVoting__factory.connect( | ||
proxyCreatedEvent1.args.proxy, | ||
deployer | ||
); | ||
|
||
await dao.grant( | ||
votingBase.address, | ||
deployer.address, | ||
ethers.utils.id('UPDATE_VOTING_SETTINGS_PERMISSION') | ||
); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await votingBase.initialize(dao.address, votingSettings, mockTokenAddress); | ||
}); | ||
|
||
it('reverts if the support threshold specified equals 100%', async () => { | ||
votingSettings.supportThreshold = pctToRatio(100); | ||
await expect(votingBase.updateVotingSettings(votingSettings)) | ||
.to.be.revertedWithCustomError(votingBase, 'RatioOutOfBounds') | ||
.withArgs(pctToRatio(100).sub(1), votingSettings.supportThreshold); | ||
}); | ||
|
||
it('reverts if the support threshold specified exceeds 100%', async () => { | ||
votingSettings.supportThreshold = pctToRatio(1000); | ||
await expect(votingBase.updateVotingSettings(votingSettings)) | ||
.to.be.revertedWithCustomError(votingBase, 'RatioOutOfBounds') | ||
.withArgs(pctToRatio(100).sub(1), votingSettings.supportThreshold); | ||
}); | ||
|
||
it('reverts if the support threshold specified equals 100%', async () => { | ||
votingSettings.supportThreshold = pctToRatio(1000); | ||
await expect(votingBase.updateVotingSettings(votingSettings)) | ||
.to.be.revertedWithCustomError(votingBase, 'RatioOutOfBounds') | ||
.withArgs(pctToRatio(100).sub(1), votingSettings.supportThreshold); | ||
}); | ||
|
||
it('reverts if the minimum participation specified exceeds 100%', async () => { | ||
votingSettings.minParticipation = pctToRatio(1000); | ||
|
||
await expect(votingBase.updateVotingSettings(votingSettings)) | ||
.to.be.revertedWithCustomError(votingBase, 'RatioOutOfBounds') | ||
.withArgs(pctToRatio(100), votingSettings.minParticipation); | ||
}); | ||
|
||
it('reverts if the minimal duration is shorter than one hour', async () => { | ||
votingSettings.minDuration = TIME.HOUR - 1; | ||
await expect(votingBase.updateVotingSettings(votingSettings)) | ||
.to.be.revertedWithCustomError(votingBase, 'MinDurationOutOfBounds') | ||
.withArgs(TIME.HOUR, votingSettings.minDuration); | ||
}); | ||
|
||
it('reverts if the minimal duration is longer than one year', async () => { | ||
votingSettings.minDuration = TIME.YEAR + 1; | ||
await expect(votingBase.updateVotingSettings(votingSettings)) | ||
.to.be.revertedWithCustomError(votingBase, 'MinDurationOutOfBounds') | ||
.withArgs(TIME.YEAR, votingSettings.minDuration); | ||
}); | ||
|
||
it('should change the voting settings successfully', async () => { | ||
await expect(votingBase.updateVotingSettings(votingSettings)) | ||
.to.emit(votingBase, 'VotingSettingsUpdated') | ||
.withArgs( | ||
votingSettings.votingMode, | ||
votingSettings.supportThreshold, | ||
votingSettings.minParticipation, | ||
votingSettings.minDuration, | ||
votingSettings.minProposerVotingPower | ||
); | ||
}); | ||
}); |
Oops, something went wrong.