Skip to content

Commit

Permalink
Deployment test: support of custom errors with test through Hardhat
Browse files Browse the repository at this point in the history
  • Loading branch information
rya-sge committed Aug 21, 2023
1 parent c678ee0 commit a5af55d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
7 changes: 2 additions & 5 deletions contracts/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ library Errors {
error CMTAT_SnapshotModule_SnapshotNeverScheduled();

// Generic
error AddressZeroNotAllowed();
error DirectCallToImplementation();

// ERC20BaseModule
Expand All @@ -45,9 +44,7 @@ library Errors {
// ValidationModule
error CMTAT_ValidationModule_SameValue();

/*// EnforcementModule
error CMTAT_EnforcementModule_TransferRejectedAddressFromIsFrozen();
error CMTAT_EnforcementModule_TransferRejectedAddressToIsFrozen();
*/
// AuthorizationModule
error CMTAT_AuthorizationModule_AddressZeroNotAllowed();
}

4 changes: 3 additions & 1 deletion contracts/modules/security/AuthorizationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ abstract contract AuthorizationModule is AccessControlUpgradeable {
function __AuthorizationModule_init_unchained(
address admin
) internal onlyInitializing {
if(admin == address(0)) revert Errors.AddressZeroNotAllowed();
if(admin == address(0)){
revert Errors.CMTAT_AuthorizationModule_AddressZeroNotAllowed();
}
_grantRole(DEFAULT_ADMIN_ROLE, admin);
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"test:hardhat:authorization": "npx hardhat test test/standard/modules/AuthorizationModule/AuthorizationModule.test.js test/proxy/modules/AuthorizationModule/AuthorizationModule.test.js",
"test:hardhat:snapshot": "npx hardhat test test/standard/modules/SnapshotModule.test.js test/proxy/modules/SnapshotModule.test.js",
"test:hardhat:enforcement": "npx hardhat test test/standard/modules/EnforcementModule.test.js test/proxy/modules/EnforcementModule.test.js",
"test:hardhat:proxy": "npx hardhat test test/proxy/general/KillImplementation.test.js test/proxy/general/Proxy.test.js test/proxy/general/UpgradeProxy.test.js"
"test:hardhat:proxy": "npx hardhat test test/proxy/general/KillImplementation.test.js test/proxy/general/Proxy.test.js test/proxy/general/UpgradeProxy.test.js",
"test:hardhat:deployment": "npx hardhat test test/deployment/deployment.test.js"
},
"repository": {
"type": "git",
Expand Down
17 changes: 12 additions & 5 deletions test/deployment/deployment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,31 @@ const { expectRevert } = require('@openzeppelin/test-helpers')
const CMTAT_STANDALONE = artifacts.require('CMTAT_STANDALONE')
const CMTAT_PROXY = artifacts.require('CMTAT_PROXY')
const { deployProxy } = require('@openzeppelin/truffle-upgrades')
const { expectRevertCustomError } = require('../../openzeppelin-contracts-upgradeable/test/helpers/customError.js');
const { ZERO_ADDRESS } = require('../utils')
const { deployCMTATProxyWithParameter, deployCMTATStandaloneWithParameter } = require('../deploymentUtils')
contract(
'CMTAT - Deployment',
function ([_], admin) {
it('testCannotDeployProxyWithAdminSetToAddressZero', async function () {
this.flag = 5
const DECIMAL = 0
// Act + Assert
await expectRevert.unspecified(deployProxy(CMTAT_PROXY, [ZERO_ADDRESS, 'CMTA Token', 'CMTAT', DECIMAL, 'CMTAT_ISIN', 'https://cmta.ch', ZERO_ADDRESS, 'CMTAT_info', this.flag], {
initializer: 'initialize',
constructorArgs: [_]
}))
await expectRevertCustomError(
deployCMTATProxyWithParameter(admin, _, ZERO_ADDRESS, 'CMTA Token', 'CMTAT', DECIMAL, 'CMTAT_ISIN', 'https://cmta.ch', ZERO_ADDRESS, 'CMTAT_info', this.flag),
'CMTAT_AuthorizationModule_AddressZeroNotAllowed',
[]
)
})
it('testCannotDeployStandaloneWithAdminSetToAddressZero', async function () {
this.flag = 5
const DECIMAL = 0
// Act + Assert
await expectRevert.unspecified(CMTAT_STANDALONE.new(_, ZERO_ADDRESS, 'CMTA Token', 'CMTAT', DECIMAL, 'CMTAT_ISIN', 'https://cmta.ch', ZERO_ADDRESS, 'CMTAT_info', this.flag, { from: admin }))
await expectRevertCustomError(
deployCMTATStandaloneWithParameter(admin, _, ZERO_ADDRESS, 'CMTA Token', 'CMTAT', DECIMAL, 'CMTAT_ISIN', 'https://cmta.ch', ZERO_ADDRESS, 'CMTAT_info', this.flag),
'CMTAT_AuthorizationModule_AddressZeroNotAllowed',
[]
)
})
}
)

0 comments on commit a5af55d

Please sign in to comment.