From 1c77688fea4a75f9a7b490234d527c45e1a56ca9 Mon Sep 17 00:00:00 2001 From: Ayush Tiwari Date: Thu, 22 Aug 2024 14:48:17 +0530 Subject: [PATCH] fix: test cases --- packages/marketplace/test/Exchange.test.ts | 2 +- .../marketplace/test/OrderValidator.test.ts | 53 +++++++++++-------- .../test/common/AccessControl.behavior.ts | 9 ++-- .../test/exchange/Config.behavior.ts | 39 +++++++------- .../test/exchange/MatchOrders.behavior.ts | 12 ++--- 5 files changed, 62 insertions(+), 53 deletions(-) diff --git a/packages/marketplace/test/Exchange.test.ts b/packages/marketplace/test/Exchange.test.ts index 2955f9b20a..fa043bb1c0 100644 --- a/packages/marketplace/test/Exchange.test.ts +++ b/packages/marketplace/test/Exchange.test.ts @@ -311,7 +311,7 @@ describe('Exchange.sol', function () { signatureRight: takerSig, }, ]) - ).to.be.revertedWithCustomError(ExchangeContractAsUser, 'EnforcedPause'); + ).to.be.revertedWith('Pausable: paused'); }); it('should not execute match order with an empty order array', async function () { diff --git a/packages/marketplace/test/OrderValidator.test.ts b/packages/marketplace/test/OrderValidator.test.ts index 3657c89516..c986be01a9 100644 --- a/packages/marketplace/test/OrderValidator.test.ts +++ b/packages/marketplace/test/OrderValidator.test.ts @@ -30,6 +30,7 @@ describe('OrderValidator.sol', function () { ERC20Contract: Contract, ERC721Contract: Contract, ERC1271Contract: Contract, + user: Signer, user1: Signer, user2: Signer; @@ -42,6 +43,7 @@ describe('OrderValidator.sol', function () { ERC20Contract, ERC721Contract, ERC1271Contract, + user, user1, user2, } = await loadFixture(deployFixturesWithoutWhitelist)); @@ -376,11 +378,10 @@ describe('OrderValidator.sol', function () { }); it('should not set permission for token if caller is not owner', async function () { - await expect( - OrderValidatorAsUser.enableRole(TSBRole) - ).to.be.revertedWithCustomError( - OrderValidatorAsUser, - 'AccessControlUnauthorizedAccount' + await expect(OrderValidatorAsUser.enableRole(TSBRole)).to.revertedWith( + `AccessControl: account ${( + await user.getAddress() + ).toLowerCase()} is missing role 0x0000000000000000000000000000000000000000000000000000000000000000` ); }); @@ -413,9 +414,10 @@ describe('OrderValidator.sol', function () { it('should not be able to add token to tsb list if caller is not owner', async function () { await expect( OrderValidatorAsUser.grantRole(TSBRole, await ERC20Contract.getAddress()) - ).to.be.revertedWithCustomError( - OrderValidatorAsUser, - 'AccessControlUnauthorizedAccount' + ).to.be.revertedWith( + `AccessControl: account ${( + await user.getAddress() + ).toLowerCase()} is missing role 0x0000000000000000000000000000000000000000000000000000000000000000` ); }); @@ -441,9 +443,10 @@ describe('OrderValidator.sol', function () { it('should not be able to remove token from tsb list if caller is not owner', async function () { await expect( OrderValidatorAsUser.revokeRole(TSBRole, await ERC20Contract.getAddress()) - ).to.be.revertedWithCustomError( - OrderValidatorAsUser, - 'AccessControlUnauthorizedAccount' + ).to.be.revertedWith( + `AccessControl: account ${( + await user.getAddress() + ).toLowerCase()} is missing role 0x0000000000000000000000000000000000000000000000000000000000000000` ); }); @@ -483,9 +486,10 @@ describe('OrderValidator.sol', function () { PartnerRole, await ERC20Contract.getAddress() ) - ).to.be.revertedWithCustomError( - OrderValidatorAsUser, - 'AccessControlUnauthorizedAccount' + ).to.be.revertedWith( + `AccessControl: account ${( + await user.getAddress() + ).toLowerCase()} is missing role 0x0000000000000000000000000000000000000000000000000000000000000000` ); }); @@ -514,9 +518,10 @@ describe('OrderValidator.sol', function () { PartnerRole, await ERC20Contract.getAddress() ) - ).to.be.revertedWithCustomError( - OrderValidatorAsUser, - 'AccessControlUnauthorizedAccount' + ).to.be.revertedWith( + `AccessControl: account ${( + await user.getAddress() + ).toLowerCase()} is missing role 0x0000000000000000000000000000000000000000000000000000000000000000` ); }); @@ -556,9 +561,10 @@ describe('OrderValidator.sol', function () { ERC20Role, await ERC20Contract.getAddress() ) - ).to.be.revertedWithCustomError( - OrderValidatorAsUser, - 'AccessControlUnauthorizedAccount' + ).to.be.revertedWith( + `AccessControl: account ${( + await user.getAddress() + ).toLowerCase()} is missing role 0x0000000000000000000000000000000000000000000000000000000000000000` ); }); @@ -587,9 +593,10 @@ describe('OrderValidator.sol', function () { ERC20Role, await ERC20Contract.getAddress() ) - ).to.be.revertedWithCustomError( - OrderValidatorAsUser, - 'AccessControlUnauthorizedAccount' + ).to.be.revertedWith( + `AccessControl: account ${( + await user.getAddress() + ).toLowerCase()} is missing role 0x0000000000000000000000000000000000000000000000000000000000000000` ); }); diff --git a/packages/marketplace/test/common/AccessControl.behavior.ts b/packages/marketplace/test/common/AccessControl.behavior.ts index 2280083307..a35ca842e5 100644 --- a/packages/marketplace/test/common/AccessControl.behavior.ts +++ b/packages/marketplace/test/common/AccessControl.behavior.ts @@ -16,6 +16,7 @@ export function checkAccessControl( OrderValidatorAsUser: Contract, TrustedForwarderAsUser: Contract, user: Signer, + DEFAULT_ADMIN_ROLE: string, contractMap: {[key: string]: Contract}; beforeEach(async function () { @@ -26,6 +27,7 @@ export function checkAccessControl( OrderValidatorAsUser, TrustedForwarder2: TrustedForwarderAsUser, user, + DEFAULT_ADMIN_ROLE, } = await loadFixture(deployFixturesWithoutWhitelist)); contractMap = { ExchangeContractAsAdmin: ExchangeContractAsAdmin, @@ -40,9 +42,10 @@ export function checkAccessControl( it(`should not set ${functionName[i]} if caller is not in the role`, async function () { await expect( ExchangeContractAsUser[functionName[i]](user.getAddress()) - ).to.be.revertedWithCustomError( - ExchangeContractAsUser, - 'AccessControlUnauthorizedAccount' + ).to.be.revertedWith( + `AccessControl: account ${( + await user.getAddress() + ).toLowerCase()} is missing role ${DEFAULT_ADMIN_ROLE}` ); }); diff --git a/packages/marketplace/test/exchange/Config.behavior.ts b/packages/marketplace/test/exchange/Config.behavior.ts index 28f19ed469..1841d2df36 100644 --- a/packages/marketplace/test/exchange/Config.behavior.ts +++ b/packages/marketplace/test/exchange/Config.behavior.ts @@ -57,11 +57,10 @@ export function exchangeConfig() { describe('pauser role', function () { it('should not pause if caller is not in the role', async function () { - await expect( - ExchangeContractAsUser.pause() - ).to.be.revertedWithCustomError( - ExchangeContractAsUser, - 'AccessControlUnauthorizedAccount' + await expect(ExchangeContractAsUser.pause()).to.be.revertedWith( + `AccessControl: account ${( + await user.getAddress() + ).toLowerCase()} is missing role ${PAUSER_ROLE}` ); }); @@ -82,9 +81,10 @@ export function exchangeConfig() { newProtocolFeePrimary, newProtocolFeeSecondary ) - ).to.be.revertedWithCustomError( - ExchangeContractAsUser, - 'AccessControlUnauthorizedAccount' + ).to.be.revertedWith( + `AccessControl: account ${( + await user.getAddress() + ).toLowerCase()} is missing role ${EXCHANGE_ADMIN_ROLE}` ); }); @@ -106,11 +106,10 @@ export function exchangeConfig() { const {ExchangeContractAsUser} = await loadFixture( deployFixturesWithoutWhitelist ); - await expect( - ExchangeContractAsUser.unpause() - ).to.be.revertedWithCustomError( - ExchangeContractAsUser, - 'AccessControlUnauthorizedAccount' + await expect(ExchangeContractAsUser.unpause()).to.be.revertedWith( + `AccessControl: account ${( + await user.getAddress() + ).toLowerCase()} is missing role ${EXCHANGE_ADMIN_ROLE}` ); }); @@ -128,9 +127,10 @@ export function exchangeConfig() { it('should not set setDefaultFeeReceiver if caller is not in the role', async function () { await expect( ExchangeContractAsUser.setDefaultFeeReceiver(user.getAddress()) - ).to.be.revertedWithCustomError( - ExchangeContractAsUser, - 'AccessControlUnauthorizedAccount' + ).to.be.revertedWith( + `AccessControl: account ${( + await user.getAddress() + ).toLowerCase()} is missing role ${EXCHANGE_ADMIN_ROLE}` ); }); @@ -155,9 +155,10 @@ export function exchangeConfig() { const newMatchOrdersLimit = 200; await expect( ExchangeContractAsUser.setMatchOrdersLimit(newMatchOrdersLimit) - ).to.be.revertedWithCustomError( - ExchangeContractAsUser, - 'AccessControlUnauthorizedAccount' + ).to.be.revertedWith( + `AccessControl: account ${( + await user.getAddress() + ).toLowerCase()} is missing role ${EXCHANGE_ADMIN_ROLE}` ); }); diff --git a/packages/marketplace/test/exchange/MatchOrders.behavior.ts b/packages/marketplace/test/exchange/MatchOrders.behavior.ts index 01ce2ea1bc..8af023a857 100644 --- a/packages/marketplace/test/exchange/MatchOrders.behavior.ts +++ b/packages/marketplace/test/exchange/MatchOrders.behavior.ts @@ -881,10 +881,7 @@ export function shouldMatchOrders() { }, ] ) - ).to.be.revertedWithCustomError( - ExchangeContractAsUser, - 'EnforcedPause' - ); + ).to.be.revertedWith('Pausable: paused'); }); it('should not execute matchOrdersFrom if caller do not have ERC1776 operator role', async function () { @@ -897,9 +894,10 @@ export function shouldMatchOrders() { signatureRight: takerSig, }, ]) - ).to.be.revertedWithCustomError( - ExchangeContractAsUser, - 'AccessControlUnauthorizedAccount' + ).to.be.revertedWith( + `AccessControl: account ${( + await user.getAddress() + ).toLowerCase()} is missing role ${ERC1776_OPERATOR_ROLE}` ); });