Skip to content

Commit

Permalink
use hardhat ^v2.22.3 to fix Invalid Chai property: revertedWith
Browse files Browse the repository at this point in the history
  • Loading branch information
yuetloo committed May 16, 2024
1 parent d8cd50c commit bb48206
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 367 deletions.
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@types/mocha": "^10.0.6",
"chai": "4",
"ethers": "^6.12.1",
"hardhat": "^2.19.4",
"hardhat": "^2.22.3",
"hardhat-contract-sizer": "^2.10.0",
"hardhat-gas-reporter": "^1.0.8",
"ipfs-only-hash": "^2.0.1",
Expand Down
5 changes: 4 additions & 1 deletion contracts/tests/maciFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ describe('MACI factory', () => {
coordinatorMaciFactory.setMaciParameters(
...maciParameters.asContractParam()
)
).to.be.revertedWith('Ownable: caller is not the owner')
).to.be.revertedWithCustomError(
coordinatorMaciFactory,
'OwnableUnauthorizedAccount'
)
})

it('deploys MACI', async () => {
Expand Down
12 changes: 9 additions & 3 deletions contracts/tests/recipientRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ describe('Simple Recipient Registry', async () => {
const registryAsRecipient = registry.connect(recipient) as Contract
await expect(
registryAsRecipient.addRecipient(recipientAddress, metadata)
).to.be.revertedWith('Ownable: caller is not the owner')
).to.be.revertedWithCustomError(
registryAsRecipient,
'OwnableUnauthorizedAccount'
)
})

it('should not accept zero-address as recipient address', async () => {
Expand Down Expand Up @@ -218,7 +221,10 @@ describe('Simple Recipient Registry', async () => {
const registryAsRecipient = registry.connect(recipient) as Contract
await expect(
registryAsRecipient.removeRecipient(recipientId)
).to.be.revertedWith('Ownable: caller is not the owner')
).to.be.revertedWithCustomError(
registryAsRecipient,
'OwnableUnauthorizedAccount'
)
})

it('reverts if recipient is not in registry', async () => {
Expand Down Expand Up @@ -762,7 +768,7 @@ describe('Optimistic recipient registry', () => {
recipientId,
requester.address
)
).to.be.revertedWith('Ownable: caller is not the owner')
).to.be.revertedWithCustomError(registry, 'OwnableUnauthorizedAccount')
})

it('should not allow to challenge resolved request', async () => {
Expand Down
14 changes: 10 additions & 4 deletions contracts/tests/round.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ describe('Funding Round', () => {
it('requires approval', async () => {
await expect(
fundingRoundAsContributor.contribute(userPubKey, contributionAmount)
).to.be.revertedWith('ERC20: insufficient allowance')
).to.be.revertedWithCustomError(token, 'ERC20InsufficientAllowance')
})

it('rejects contributions from unverified users', async () => {
Expand Down Expand Up @@ -750,7 +750,10 @@ describe('Funding Round', () => {
newResultCommitment,
perVOSpentVoiceCreditsHash
)
).to.be.revertedWith('Ownable: caller is not the owner')
).to.be.revertedWithCustomError(
fundingRoundAsCoordinator,
'OwnableUnauthorizedAccount'
)
})
})

Expand Down Expand Up @@ -811,8 +814,11 @@ describe('Funding Round', () => {
const fundingRoundAsCoordinator = fundingRound.connect(
coordinator
) as Contract
await expect(fundingRoundAsCoordinator.cancel()).to.be.revertedWith(
'Ownable: caller is not the owner'
await expect(
fundingRoundAsCoordinator.cancel()
).to.be.revertedWithCustomError(
fundingRoundAsCoordinator,
'OwnableUnauthorizedAccount'
)
})
})
Expand Down
14 changes: 10 additions & 4 deletions contracts/tests/userRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ describe('Simple User Registry', () => {

it('allows only owner to add users', async () => {
const registryAsUser = registry.connect(user) as Contract
await expect(registryAsUser.addUser(user.address)).to.be.revertedWith(
'Ownable: caller is not the owner'
await expect(
registryAsUser.addUser(user.address)
).to.be.revertedWithCustomError(
registryAsUser,
'OwnableUnauthorizedAccount'
)
})

Expand All @@ -66,8 +69,11 @@ describe('Simple User Registry', () => {
it('allows only owner to remove users', async () => {
await registry.addUser(user.address)
const registryAsUser = registry.connect(user) as Contract
await expect(registryAsUser.removeUser(user.address)).to.be.revertedWith(
'Ownable: caller is not the owner'
await expect(
registryAsUser.removeUser(user.address)
).to.be.revertedWithCustomError(
registryAsUser,
'OwnableUnauthorizedAccount'
)
})
})
Expand Down
5 changes: 4 additions & 1 deletion contracts/tests/userRegistryMerkle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ describe('Merkle User Registry', () => {
const registryAsUser = registry.connect(signers[user1.address]) as Contract
await expect(
registryAsUser.setMerkleRoot(randomBytes(32), 'non owner')
).to.be.revertedWith('Ownable: caller is not the owner')
).to.be.revertedWithCustomError(
registryAsUser,
'OwnableUnauthorizedAccount'
)
})

describe('registration', () => {
Expand Down
12 changes: 9 additions & 3 deletions contracts/tests/userRegistrySemaphore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ describe('Semaphore User Registry', () => {
const registryAsUser = registry.connect(user) as Contract
await expect(
registryAsUser.addUser(user.address, semaphoreId)
).to.be.revertedWith('Ownable: caller is not the owner')
).to.be.revertedWithCustomError(
registryAsUser,
'OwnableUnauthorizedAccount'
)
})

it('allows owner to remove user', async () => {
Expand All @@ -88,8 +91,11 @@ describe('Semaphore User Registry', () => {
const semaphoreId = 1
await registry.addUser(user.address, semaphoreId)
const registryAsUser = registry.connect(user) as Contract
await expect(registryAsUser.removeUser(user.address)).to.be.revertedWith(
'Ownable: caller is not the owner'
await expect(
registryAsUser.removeUser(user.address)
).to.be.revertedWithCustomError(
registryAsUser,
'OwnableUnauthorizedAccount'
)
})

Expand Down
5 changes: 2 additions & 3 deletions contracts/utils/testutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { EContracts } from './types'
import { Libraries } from 'hardhat/types'
import { MACIFactory, VkRegistry } from '../typechain-types'
import { ZERO_ADDRESS } from './constants'
import { EMode } from 'maci-contracts'

/**
* Deploy a mock contract with the given contract name
Expand Down Expand Up @@ -236,7 +237,6 @@ export async function deployTestFundingRound(
factories.pollFactory,
factories.messageProcessorFactory,
factories.tallyFactory,
factories.subsidyFactory,
fundingRound.target,
fundingRound.target,
topupToken.target,
Expand All @@ -254,8 +254,7 @@ export async function deployTestFundingRound(
coordinatorPubKey.asContractParam(),
mockVerifier.target,
vkRegistry.target,
// pass false to not deploy the subsidy contract
false
EMode.QV
)
const pollAddr = await getEventArg(
deployPollTx,
Expand Down
Loading

0 comments on commit bb48206

Please sign in to comment.