Skip to content

Commit

Permalink
fix: test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
capedcrusader21 committed Aug 22, 2024
1 parent aef3433 commit 1c77688
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 53 deletions.
2 changes: 1 addition & 1 deletion packages/marketplace/test/Exchange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
53 changes: 30 additions & 23 deletions packages/marketplace/test/OrderValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('OrderValidator.sol', function () {
ERC20Contract: Contract,
ERC721Contract: Contract,
ERC1271Contract: Contract,
user: Signer,
user1: Signer,
user2: Signer;

Expand All @@ -42,6 +43,7 @@ describe('OrderValidator.sol', function () {
ERC20Contract,
ERC721Contract,
ERC1271Contract,
user,
user1,
user2,
} = await loadFixture(deployFixturesWithoutWhitelist));
Expand Down Expand Up @@ -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`
);
});

Expand Down Expand Up @@ -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`
);
});

Expand All @@ -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`
);
});

Expand Down Expand Up @@ -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`
);
});

Expand Down Expand Up @@ -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`
);
});

Expand Down Expand Up @@ -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`
);
});

Expand Down Expand Up @@ -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`
);
});

Expand Down
9 changes: 6 additions & 3 deletions packages/marketplace/test/common/AccessControl.behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function checkAccessControl(
OrderValidatorAsUser: Contract,
TrustedForwarderAsUser: Contract,
user: Signer,
DEFAULT_ADMIN_ROLE: string,
contractMap: {[key: string]: Contract};

beforeEach(async function () {
Expand All @@ -26,6 +27,7 @@ export function checkAccessControl(
OrderValidatorAsUser,
TrustedForwarder2: TrustedForwarderAsUser,
user,
DEFAULT_ADMIN_ROLE,
} = await loadFixture(deployFixturesWithoutWhitelist));
contractMap = {
ExchangeContractAsAdmin: ExchangeContractAsAdmin,
Expand All @@ -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}`
);
});

Expand Down
39 changes: 20 additions & 19 deletions packages/marketplace/test/exchange/Config.behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
);
});

Expand All @@ -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}`
);
});

Expand All @@ -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}`
);
});

Expand All @@ -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}`
);
});

Expand All @@ -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}`
);
});

Expand Down
12 changes: 5 additions & 7 deletions packages/marketplace/test/exchange/MatchOrders.behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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}`
);
});

Expand Down

1 comment on commit 1c77688

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage for this commit

98.01%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/marketplace/contracts
   Exchange.sol94.52%93.33%94.44%96%126, 194, 72
   ExchangeCore.sol98.85%96.67%100%100%85
   OrderValidator.sol96.83%92.86%100%100%110, 36
   RoyaltiesRegistry.sol96.32%88.89%100%98.78%194, 216–217, 263, 65
   TransferManager.sol94.86%84.85%100%99.23%150, 181, 191, 239, 379, 385, 400, 412–413, 424, 93
   Whitelist.sol75.81%60%85.71%82.14%104, 108–109, 122, 125, 141–142, 54, 66, 66–67, 71, 76
packages/marketplace/contracts/interfaces
   IOrderValidator.sol100%100%100%100%
   IRoyaltiesProvider.sol100%100%100%100%
   ITransferManager.sol100%100%100%100%
   IWhitelist.sol100%100%100%100%
packages/marketplace/contracts/libraries
   LibAsset.sol100%100%100%100%
   LibMath.sol100%100%100%100%
   LibOrder.sol100%100%100%100%

Please sign in to comment.