diff --git a/packages/land/test/common/Config.behavior.ts b/packages/land/test/common/Config.behavior.ts index b5960421fb..e809d9ef90 100644 --- a/packages/land/test/common/Config.behavior.ts +++ b/packages/land/test/common/Config.behavior.ts @@ -7,9 +7,9 @@ export function landConfig(setupLand, Contract: string) { describe('roles', function () { it('Only admin can set landMinter', async function () { const {LandContract, deployer} = await loadFixture(setupLand); - await expect(LandContract.setMinter(deployer, true)).to.be.revertedWith( - 'only admin allowed', - ); + await expect( + LandContract.setMinter(deployer, true), + ).to.be.revertedWithCustomError(LandContract, 'OnlyAdmin'); }); it('should enable a landMinter', async function () { @@ -27,9 +27,9 @@ export function landConfig(setupLand, Contract: string) { it('should not set royaltyManager if caller is not admin', async function () { const {LandAsOther, other} = await loadFixture(setupLand); - await expect(LandAsOther.setRoyaltyManager(other)).to.be.revertedWith( - 'only admin allowed', - ); + await expect( + LandAsOther.setRoyaltyManager(other), + ).to.be.revertedWithCustomError(LandAsOther, 'OnlyAdmin'); }); it('should set royaltyManager', async function () { @@ -44,9 +44,9 @@ export function landConfig(setupLand, Contract: string) { it('should not set owner if caller is not admin', async function () { const {LandAsOther, other} = await loadFixture(setupLand); - await expect(LandAsOther.transferOwnership(other)).to.be.revertedWith( - 'only admin allowed', - ); + await expect( + LandAsOther.transferOwnership(other), + ).to.be.revertedWithCustomError(LandAsOther, 'OnlyAdmin'); }); it('should set owner', async function () { diff --git a/packages/land/test/common/ERC721.behavior.ts b/packages/land/test/common/ERC721.behavior.ts index c78398a585..d84e708e61 100644 --- a/packages/land/test/common/ERC721.behavior.ts +++ b/packages/land/test/common/ERC721.behavior.ts @@ -153,13 +153,16 @@ export function shouldCheckForERC721(setupLand, Contract: string) { }); it('should revert burning tokens by unauthorized operator', async function () { - const {LandAsMinter, other, LandAsOther1} = + const {LandAsMinter, other, other1, LandAsOther1} = await loadFixture(setupLand); await LandAsMinter.mintQuad(other, 1, 0, 0, '0x'); - await expect(LandAsOther1.burnFrom(other, 0)).to.be.revertedWith( - 'UNAUTHORIZED_BURN', - ); + await expect(LandAsOther1.burnFrom(other, 0)) + .to.be.revertedWithCustomError( + LandAsOther1, + 'ERC721InsufficientApproval', + ) + .withArgs(other1, 0); }); }); @@ -168,14 +171,14 @@ export function shouldCheckForERC721(setupLand, Contract: string) { const {LandAsOwner, other, tokenIds} = await loadFixture(setupLand); await expect( LandAsOwner.batchTransferFrom(ZeroAddress, other, tokenIds, '0x'), - ).to.be.revertedWith('NOT_FROM_ZEROADDRESS'); + ).to.be.revertedWithCustomError(LandAsOwner, 'InvalidAddress'); }); it('should revert batchTransfer to zero address', async function () { const {LandAsOwner, landOwner, tokenIds} = await loadFixture(setupLand); await expect( LandAsOwner.batchTransferFrom(landOwner, ZeroAddress, tokenIds, '0x'), - ).to.be.revertedWith('NOT_TO_ZEROADDRESS'); + ).to.be.revertedWithCustomError(LandAsOwner, 'InvalidAddress'); }); it('should revert batchTransfer from unauthorized sender', async function () { @@ -183,7 +186,12 @@ export function shouldCheckForERC721(setupLand, Contract: string) { await loadFixture(setupLand); await expect( LandAsOther.batchTransferFrom(landOwner, other, tokenIds, '0x'), - ).to.be.revertedWith('NOT_AUTHORIZED'); + ) + .to.be.revertedWithCustomError( + LandAsOther, + 'ERC721InsufficientApproval', + ) + .withArgs(other, tokenIds[0]); }); it('should batch transfer tokens from authorized sender', async function () { @@ -241,7 +249,9 @@ export function shouldCheckForERC721(setupLand, Contract: string) { [tokenIds[1], tokenIds[1], tokenIds[0]], '0x', ), - ).to.be.revertedWith('BATCHTRANSFERFROM_NOT_OWNER'); + ) + .to.be.revertedWithCustomError(LandAsOwner, 'ERC721InvalidOwner') + .withArgs(landOwner); }); it('batch transfer works', async function () { @@ -279,7 +289,10 @@ export function shouldCheckForERC721(setupLand, Contract: string) { [tokenIds[0]], '0x', ), - ).to.be.revertedWith('Batch Receive not allowed'); + ).to.be.revertedWithCustomError( + TestERC721TokenReceiver, + 'BatchReceiveNotAllowed', + ); }); it('batch transferring to a contract that do not accept erc721 token should fail', async function () { @@ -293,7 +306,10 @@ export function shouldCheckForERC721(setupLand, Contract: string) { [tokenIds[0]], '0x', ), - ).to.be.revertedWith('Batch Receive not allowed'); + ).to.be.revertedWithCustomError( + TestERC721TokenReceiver, + 'BatchReceiveNotAllowed', + ); }); it('batch transferring to a contract that do not return the correct onERC721Received bytes should fail', async function () { @@ -307,7 +323,12 @@ export function shouldCheckForERC721(setupLand, Contract: string) { [tokenIds[0]], '0x', ), - ).to.be.revertedWith('ERC721_BATCH_RECEIVED_REJECTED'); + ) + .to.be.revertedWithCustomError( + LandAsOwner, + 'ERC721InvalidBatchReceiver', + ) + .withArgs(TestERC721TokenReceiver); }); it('batch transferring to a contract that do not implemented mandatory receiver should not fail', async function () { @@ -359,7 +380,10 @@ export function shouldCheckForERC721(setupLand, Contract: string) { TestERC721TokenReceiver, tokenIds[0], ), - ).to.be.revertedWith('Receive not allowed'); + ).to.be.revertedWithCustomError( + TestERC721TokenReceiver, + 'ReceiveNotAllowed', + ); }); it('transferring to a contract that do not return the correct onERC721Received bytes should fail', async function () { @@ -372,7 +396,9 @@ export function shouldCheckForERC721(setupLand, Contract: string) { TestERC721TokenReceiver, tokenIds[0], ), - ).to.be.revertedWith('ERC721_TRANSFER_REJECTED'); + ) + .to.be.revertedWithCustomError(LandAsOwner, 'ERC721InvalidReceiver') + .withArgs(TestERC721TokenReceiver); }); it('transferring to a contract that do not implemented mandatory receiver should not fail', async function () { @@ -410,7 +436,9 @@ export function shouldCheckForERC721(setupLand, Contract: string) { [tokenIds[0], tokenIds[1], tokenIds[0]], '0x', ), - ).to.be.revertedWith('BATCHTRANSFERFROM_NOT_OWNER'); + ) + .to.be.revertedWithCustomError(LandAsOwner, 'ERC721InvalidOwner') + .withArgs(landOwner); }); it('safe batch transfer works', async function () { @@ -491,16 +519,19 @@ export function shouldCheckForERC721(setupLand, Contract: string) { it('transferring from without approval should fails', async function () { const {LandAsOther, landOwner, other, tokenIds} = await loadFixture(setupLand); - await expect( - LandAsOther.transferFrom(landOwner, other, tokenIds[0]), - ).to.be.revertedWith('UNAUTHORIZED_TRANSFER'); + await expect(LandAsOther.transferFrom(landOwner, other, tokenIds[0])) + .to.be.revertedWithCustomError( + LandAsOther, + 'ERC721InsufficientApproval', + ) + .withArgs(other, tokenIds[0]); }); it('transferring to zero address should fails', async function () { const {LandAsOwner, landOwner, tokenIds} = await loadFixture(setupLand); await expect( LandAsOwner.transferFrom(landOwner, ZeroAddress, tokenIds[0]), - ).to.be.revertedWith('NOT_TO_ZEROADDRESS'); + ).to.be.revertedWithCustomError(LandAsOwner, 'InvalidAddress'); }); it('transferring to a contract that accepts erc721 token should not fail', async function () { @@ -563,12 +594,12 @@ export function shouldCheckForERC721(setupLand, Contract: string) { }); it('should revert approveFor from unauthorized sender', async function () { - const {LandContract, LandAsMinter, other1, other} = + const {LandContract, LandAsMinter, other1, other, deployer} = await loadFixture(setupLand); await LandAsMinter.mintQuad(other, 1, 0, 0, '0x'); - await expect( - LandContract.approveFor(other, other1, 0), - ).to.be.revertedWith('UNAUTHORIZED_APPROVAL'); + await expect(LandContract.approveFor(other, other1, 0)) + .to.be.revertedWithCustomError(LandContract, 'ERC721InvalidApprover') + .withArgs(deployer); }); it('should approveFor when sender is superOperator', async function () { @@ -612,10 +643,11 @@ export function shouldCheckForERC721(setupLand, Contract: string) { }); it('should revert setApprovalForAllFor from unauthorized sender', async function () { - const {LandAsOther, other1, deployer} = await loadFixture(setupLand); - await expect( - LandAsOther.setApprovalForAllFor(deployer, other1, true), - ).to.be.revertedWith('UNAUTHORIZED_APPROVE_FOR_ALL'); + const {LandAsOther, other, other1, deployer} = + await loadFixture(setupLand); + await expect(LandAsOther.setApprovalForAllFor(deployer, other1, true)) + .to.be.revertedWithCustomError(LandAsOther, 'ERC721InvalidApprover') + .withArgs(other); }); it('should setApprovalForAllFor from authorized sender', async function () { @@ -635,9 +667,9 @@ export function shouldCheckForERC721(setupLand, Contract: string) { const {LandAsOther1, LandAsAdmin, other, other1} = await loadFixture(setupLand); await LandAsAdmin.setSuperOperator(other1, true); - await expect( - LandAsOther1.setApprovalForAllFor(other, other1, true), - ).to.be.revertedWith('INVALID_APPROVAL_CHANGE'); + await expect(LandAsOther1.setApprovalForAllFor(other, other1, true)) + .to.be.revertedWithCustomError(LandAsAdmin, 'ERC721InvalidOperator') + .withArgs(other1); }); }); @@ -683,7 +715,7 @@ export function shouldCheckForERC721(setupLand, Contract: string) { await loadFixture(setupLand); await expect( safeTransferFrom(LandAsOwner, landOwner, ZeroAddress, tokenIds[0]), - ).to.be.revertedWith('NOT_TO_ZEROADDRESS'); + ).to.be.revertedWithCustomError(LandAsOwner, 'InvalidAddress'); }, ); @@ -704,7 +736,12 @@ export function shouldCheckForERC721(setupLand, Contract: string) { await loadFixture(setupLand); await expect( safeTransferFrom(LandAsOther, landOwner, other, tokenIds[0]), - ).to.be.revertedWith('UNAUTHORIZED_TRANSFER'); + ) + .to.be.revertedWithCustomError( + LandAsOther, + 'ERC721InsufficientApproval', + ) + .withArgs(other, tokenIds[0]); }, ); @@ -722,7 +759,10 @@ export function shouldCheckForERC721(setupLand, Contract: string) { TestERC721TokenReceiver, tokenIds[0], ), - ).to.be.revertedWith('Receive not allowed'); + ).to.be.revertedWithCustomError( + TestERC721TokenReceiver, + 'ReceiveNotAllowed', + ); }, ); @@ -740,7 +780,9 @@ export function shouldCheckForERC721(setupLand, Contract: string) { TestERC721TokenReceiver, tokenIds[0], ), - ).to.be.revertedWith('ERC721_TRANSFER_REJECTED'); + ) + .to.be.revertedWithCustomError(LandAsOwner, 'ERC721InvalidReceiver') + .withArgs(TestERC721TokenReceiver); }, ); @@ -889,9 +931,12 @@ export function shouldCheckForERC721(setupLand, Contract: string) { await loadFixture(setupLand); await LandAsOwner.approve(other1, tokenIds[0]); await LandAsOther1.transferFrom(landOwner, other, tokenIds[0]); - await expect( - LandAsOther1.transferFrom(other, landOwner, tokenIds[0]), - ).to.be.revertedWith('UNAUTHORIZED_TRANSFER'); + await expect(LandAsOther1.transferFrom(other, landOwner, tokenIds[0])) + .to.be.revertedWithCustomError( + LandAsOther1, + 'ERC721InsufficientApproval', + ) + .withArgs(other1, tokenIds[0]); }); it('approval by operator works', async function () { @@ -964,9 +1009,12 @@ export function shouldCheckForERC721(setupLand, Contract: string) { await loadFixture(setupLand); await LandAsOwner.setApprovalForAll(other1, true); await LandAsOwner.transferFrom(landOwner, other, tokenIds[0]); - await expect( - LandAsOther1.transferFrom(other, other1, tokenIds[0]), - ).to.be.revertedWith('UNAUTHORIZED_TRANSFER'); + await expect(LandAsOther1.transferFrom(other, other1, tokenIds[0])) + .to.be.revertedWithCustomError( + LandAsOwner, + 'ERC721InsufficientApproval', + ) + .withArgs(other1, tokenIds[0]); }); it('approval for all set before will work on a transfered NFT', async function () { diff --git a/packages/land/test/common/LandGetter.behavior.ts b/packages/land/test/common/LandGetter.behavior.ts index 1b7101db1e..1943524605 100644 --- a/packages/land/test/common/LandGetter.behavior.ts +++ b/packages/land/test/common/LandGetter.behavior.ts @@ -55,33 +55,33 @@ export function shouldCheckLandGetter(setupLand, Contract: string) { it('should revert when fetching owner of given quad id with wrong size', async function () { const {LandContract} = await loadFixture(setupLand); const id = getId(9, 0, 0); - await expect(LandContract.ownerOf(id)).to.be.revertedWith( - 'Invalid token id', - ); + await expect(LandContract.ownerOf(id)) + .to.be.revertedWithCustomError(LandContract, 'ERC721NonexistentToken') + .withArgs(id); }); it('should revert when fetching owner of given quad id with invalid token', async function () { const {LandContract} = await loadFixture(setupLand); const id = getId(3, 2, 2); - await expect(LandContract.ownerOf(id)).to.be.revertedWith( - 'Invalid token id', - ); + await expect(LandContract.ownerOf(id)) + .to.be.revertedWithCustomError(LandContract, 'ERC721NonexistentToken') + .withArgs(id); }); it('should revert when fetching owner of given quad id with invalid token by(x)', async function () { const {LandContract} = await loadFixture(setupLand); const id = getId(3, 2, 0); - await expect(LandContract.ownerOf(id)).to.be.revertedWith( - 'Invalid token id', - ); + await expect(LandContract.ownerOf(id)) + .to.be.revertedWithCustomError(LandContract, 'ERC721NonexistentToken') + .withArgs(id); }); it('should revert when fetching owner of given quad id with invalid token(y)', async function () { const {LandAsMinter} = await loadFixture(setupLand); const id = getId(3, 0, 2); - await expect(LandAsMinter.ownerOf(id)).to.be.revertedWith( - 'Invalid token id', - ); + await expect(LandAsMinter.ownerOf(id)) + .to.be.revertedWithCustomError(LandAsMinter, 'ERC721NonexistentToken') + .withArgs(id); }); it('should return owner of given quad id', async function () { @@ -152,9 +152,9 @@ export function shouldCheckLandGetter(setupLand, Contract: string) { const {LandContract} = await loadFixture(setupLand); const tokenId = 2 + 2 * GRID_SIZE; - await expect(LandContract.tokenURI(tokenId)).to.be.revertedWith( - 'Id does not exist', - ); + await expect(LandContract.tokenURI(tokenId)) + .to.be.revertedWithCustomError(LandContract, 'ERC721NonexistentToken') + .withArgs(tokenId); }); }); } diff --git a/packages/land/test/common/MintQuad.behavior.ts b/packages/land/test/common/MintQuad.behavior.ts index 12b831de17..e25e587b6c 100644 --- a/packages/land/test/common/MintQuad.behavior.ts +++ b/packages/land/test/common/MintQuad.behavior.ts @@ -12,37 +12,37 @@ export function shouldCheckMintQuad(setupLand, Contract: string) { it('should revert if signer is not landMinter', async function () { const {LandContract, deployer} = await loadFixture(setupLand); - await expect( - LandContract.mintQuad(deployer, 3, 0, 0, '0x'), - ).to.be.revertedWith('!AUTHORIZED'); + await expect(LandContract.mintQuad(deployer, 3, 0, 0, '0x')) + .to.be.revertedWithCustomError(LandContract, 'ERC721InvalidOwner') + .withArgs(deployer); }); it('should revert when to x coordinates are wrong', async function () { const {LandAsMinter, deployer} = await loadFixture(setupLand); - await expect( - LandAsMinter.mintQuad(deployer, 3, 5, 5, '0x'), - ).to.be.revertedWith('Invalid x coordinate'); + await expect(LandAsMinter.mintQuad(deployer, 3, 5, 5, '0x')) + .to.be.revertedWithCustomError(LandAsMinter, 'InvalidCoordinates') + .withArgs(3, 5, 5); }); it('should revert when to y coordinates are wrong', async function () { const {LandAsMinter, deployer} = await loadFixture(setupLand); - await expect( - LandAsMinter.mintQuad(deployer, 3, 0, 5, '0x'), - ).to.be.revertedWith('Invalid y coordinate'); + await expect(LandAsMinter.mintQuad(deployer, 3, 0, 5, '0x')) + .to.be.revertedWithCustomError(LandAsMinter, 'InvalidCoordinates') + .withArgs(3, 0, 5); }); it('should revert when x quad is out of bounds', async function () { const {LandAsMinter, deployer} = await loadFixture(setupLand); - await expect( - LandAsMinter.mintQuad(deployer, 3, 441, 0, '0x'), - ).to.be.revertedWith('x out of bounds'); + await expect(LandAsMinter.mintQuad(deployer, 3, 441, 0, '0x')) + .to.be.revertedWithCustomError(LandAsMinter, 'InvalidCoordinates') + .withArgs(3, 441, 0); }); it('should revert when y quad is out of bounds)', async function () { const {LandAsMinter, deployer} = await loadFixture(setupLand); - await expect( - LandAsMinter.mintQuad(deployer, 3, 0, 441, '0x'), - ).to.be.revertedWith('y out of bounds'); + await expect(LandAsMinter.mintQuad(deployer, 3, 0, 441, '0x')) + .to.be.revertedWithCustomError(LandAsMinter, 'InvalidCoordinates') + .withArgs(3, 0, 441); }); it('should revert if to address is zero', async function () { @@ -52,15 +52,15 @@ export function shouldCheckMintQuad(setupLand, Contract: string) { await expect( LandAsMinter.mintQuad(ZeroAddress, 3, 3, 3, bytes), - ).to.be.revertedWith('to is zero address'); + ).to.be.revertedWithCustomError(LandAsMinter, 'InvalidAddress'); }); it('should revert for wrong size', async function () { const {LandAsMinter, deployer} = await loadFixture(setupLand); - await expect( - LandAsMinter.mintQuad(deployer, 9, 0, 0, '0x'), - ).to.be.revertedWith('Invalid size'); + await expect(LandAsMinter.mintQuad(deployer, 9, 0, 0, '0x')) + .to.be.revertedWithCustomError(LandAsMinter, 'InvalidCoordinates') + .withArgs(9, 0, 0); }); describe(`should return true for quad minted inside another quad`, function () { @@ -99,7 +99,7 @@ export function shouldCheckMintQuad(setupLand, Contract: string) { await expect( LandAsMinter.mintQuad(deployer, size1, 0, 0, bytes), - ).to.be.revertedWith('Already minted'); + ).to.be.revertedWithCustomError(LandAsMinter, 'AlreadyMinted'); }); }); }); @@ -116,7 +116,7 @@ export function shouldCheckMintQuad(setupLand, Contract: string) { await expect( LandAsMinter.mintQuad(deployer, size1, 0, 0, bytes), - ).to.be.revertedWith('Already minted'); + ).to.be.revertedWithCustomError(LandAsMinter, 'AlreadyMinted'); }); }); }); @@ -163,7 +163,7 @@ export function shouldCheckMintQuad(setupLand, Contract: string) { await LandContract.burn(tokenId); await expect( LandAsMinter.mintQuad(deployer, 1, x, y, '0x'), - ).to.be.revertedWith('Already minted'); + ).to.be.revertedWithCustomError(LandAsMinter, 'AlreadyMinted'); }); }); diff --git a/packages/land/test/common/OperatorFilter.behavior.ts b/packages/land/test/common/OperatorFilter.behavior.ts index 8d5f80cf62..3a910e22a1 100644 --- a/packages/land/test/common/OperatorFilter.behavior.ts +++ b/packages/land/test/common/OperatorFilter.behavior.ts @@ -11,14 +11,14 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { await loadFixture(setupLand); await expect( LandAsOther.register(operatorFilterSubscription, true), - ).to.be.revertedWith('only admin allowed'); + ).to.be.revertedWithCustomError(LandAsOther, 'OnlyAdmin'); }); it('should not set registry if subscription is zero address', async function () { const {LandAsAdmin} = await loadFixture(setupLand); - await expect(LandAsAdmin.register(ZeroAddress, true)).to.be.revertedWith( - "subscription can't be zero", - ); + await expect( + LandAsAdmin.register(ZeroAddress, true), + ).to.be.revertedWithCustomError(LandAsAdmin, 'InvalidAddress'); }); it('should not set operatorRegistry if caller is not admin', async function () { @@ -26,7 +26,7 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { await loadFixture(setupLand); await expect( LandAsOther.setOperatorRegistry(OperatorFilterRegistry), - ).to.be.revertedWith('only admin allowed'); + ).to.be.revertedWithCustomError(LandAsOther, 'OnlyAdmin'); }); it('should be registered', async function () { @@ -213,9 +213,9 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { it('should revert for minted invalid size', async function () { const {LandAsMinter, other} = await loadFixture(setupLand); - await expect( - LandAsMinter.mintQuad(other, 25, 0, 0, '0x'), - ).to.be.revertedWith('Invalid size'); + await expect(LandAsMinter.mintQuad(other, 25, 0, 0, '0x')) + .to.be.revertedWithCustomError(LandAsMinter, 'InvalidCoordinates') + .withArgs(25, 0, 0); }); it('should be able to safe transfer land if from is the owner of token', async function () { @@ -445,7 +445,10 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { await expect( LandAsOther.approve(MockMarketPlace3, id2), - ).to.be.revertedWith('Address is filtered'); + ).to.be.revertedWithCustomError( + OperatorFilterRegistry, + 'AddressIsFiltered', + ); }); it('it should not be able to approveFor non blacklisted market places after they are blacklisted', async function () { @@ -474,7 +477,10 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { await expect( LandAsOther.approveFor(other, MockMarketPlace3, id2), - ).to.be.revertedWith('Address is filtered'); + ).to.be.revertedWithCustomError( + OperatorFilterRegistry, + 'AddressIsFiltered', + ); }); it('it should not be able to setApprovalForAll non blacklisted market places after they are blacklisted', async function () { @@ -500,7 +506,10 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { await expect( LandAsOther1.setApprovalForAll(MockMarketPlace3, true), - ).to.be.revertedWith('Address is filtered'); + ).to.be.revertedWithCustomError( + OperatorFilterRegistry, + 'AddressIsFiltered', + ); }); it('it should not be able to setApprovalForAllFor non blacklisted market places after they are blacklisted', async function () { @@ -527,7 +536,10 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { await expect( LandAsOther1.setApprovalForAllFor(other1, MockMarketPlace3, true), - ).to.be.revertedWith('Address is filtered'); + ).to.be.revertedWithCustomError( + OperatorFilterRegistry, + 'AddressIsFiltered', + ); }); it('it should not be able to approve non blacklisted market places after there codeHashes are blacklisted', async function () { @@ -560,7 +572,10 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { await expect( LandAsOther.approve(MockMarketPlace3, id2), - ).to.be.revertedWith('Codehash is filtered'); + ).to.be.revertedWithCustomError( + OperatorFilterRegistry, + 'CodehashIsFiltered', + ); }); it('it should not be able to approveFor non blacklisted market places after there codeHashes are blacklisted', async function () { @@ -593,7 +608,10 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { await expect( LandAsOther.approveFor(other, MockMarketPlace3, id2), - ).to.be.revertedWith('Codehash is filtered'); + ).to.be.revertedWithCustomError( + OperatorFilterRegistry, + 'CodehashIsFiltered', + ); }); it('it should not be able to setApprovalForAll non blacklisted market places after there codeHashes are blacklisted', async function () { @@ -623,7 +641,10 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { await expect( LandAsOther1.setApprovalForAll(MockMarketPlace3, true), - ).to.be.revertedWith('Codehash is filtered'); + ).to.be.revertedWithCustomError( + OperatorFilterRegistry, + 'CodehashIsFiltered', + ); }); it('it should not be able to setApprovalForAllFor non blacklisted market places after there codeHashes are blacklisted', async function () { @@ -654,7 +675,10 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { await expect( LandAsOther1.setApprovalForAllFor(other1, MockMarketPlace3, true), - ).to.be.revertedWith('Codehash is filtered'); + ).to.be.revertedWithCustomError( + OperatorFilterRegistry, + 'CodehashIsFiltered', + ); }); it('it should be able to approve blacklisted market places after they are removed from the blacklist', async function () { @@ -675,7 +699,10 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { await expect( LandAsOther.approve(MockMarketPlace1, id), - ).to.be.revertedWith('Address is filtered'); + ).to.be.revertedWithCustomError( + OperatorFilterRegistry, + 'AddressIsFiltered', + ); await OperatorFilterRegistry.updateCodeHash( operatorFilterSubscription, @@ -712,7 +739,10 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { await expect( LandAsOther.approveFor(other, MockMarketPlace1, id), - ).to.be.revertedWith('Address is filtered'); + ).to.be.revertedWithCustomError( + OperatorFilterRegistry, + 'AddressIsFiltered', + ); await OperatorFilterRegistry.updateCodeHash( operatorFilterSubscription, @@ -745,7 +775,10 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { await expect( LandAsOther.setApprovalForAll(MockMarketPlace1, true), - ).to.be.revertedWith('Address is filtered'); + ).to.be.revertedWithCustomError( + OperatorFilterRegistry, + 'AddressIsFiltered', + ); await OperatorFilterRegistry.updateCodeHash( operatorFilterSubscription, @@ -779,7 +812,10 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { await expect( LandAsOther.setApprovalForAllFor(other, MockMarketPlace1, true), - ).to.be.revertedWith('Address is filtered'); + ).to.be.revertedWithCustomError( + OperatorFilterRegistry, + 'AddressIsFiltered', + ); await OperatorFilterRegistry.updateCodeHash( operatorFilterSubscription, @@ -801,8 +837,14 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { }); it('it should not be able to transfer through blacklisted market places', async function () { - const {MockMarketPlace1, LandAsMinter, LandAsOther, other, other1} = - await loadFixture(setupLand); + const { + MockMarketPlace1, + LandAsMinter, + LandAsOther, + OperatorFilterRegistry, + other, + other1, + } = await loadFixture(setupLand); await LandAsMinter.mintQuad(other, 1, 0, 0, '0x'); const id = getId(1, 0, 0); @@ -815,7 +857,10 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { id, '0x', ), - ).to.be.revertedWith('Address is filtered'); + ).to.be.revertedWithCustomError( + OperatorFilterRegistry, + 'AddressIsFiltered', + ); }); it('it should not be able to transfer through market places after they are blacklisted', async function () { @@ -856,7 +901,10 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { id2, '0x', ), - ).to.be.revertedWith('Address is filtered'); + ).to.be.revertedWithCustomError( + OperatorFilterRegistry, + 'AddressIsFiltered', + ); }); it('it should be able to transfer through non blacklisted market places', async function () { @@ -911,7 +959,10 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { id2, '0x', ), - ).to.be.revertedWith('Codehash is filtered'); + ).to.be.revertedWithCustomError( + OperatorFilterRegistry, + 'CodehashIsFiltered', + ); }); it('it should be able to transfer through blacklisted market places after they are removed from blacklist', async function () { @@ -939,7 +990,10 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { id, '0x', ), - ).to.be.revertedWith('Address is filtered'); + ).to.be.revertedWithCustomError( + OperatorFilterRegistry, + 'AddressIsFiltered', + ); await OperatorFilterRegistry.updateCodeHash( operatorFilterSubscription, @@ -965,6 +1019,7 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { LandAsMinter, LandAsOther, LandAsOther1, + OperatorFilterRegistry, other, other1, } = await loadFixture(setupLand); @@ -979,7 +1034,10 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { other1, id, ), - ).to.be.revertedWith('Address is filtered'); + ).to.be.revertedWithCustomError( + OperatorFilterRegistry, + 'AddressIsFiltered', + ); }); it('it should be able to transfer(without data) through non blacklisted market places', async function () { @@ -1040,7 +1098,10 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { other, id, ), - ).to.be.revertedWith('Address is filtered'); + ).to.be.revertedWithCustomError( + OperatorFilterRegistry, + 'AddressIsFiltered', + ); }); it('it should be not be able to transfer(without data) through market places after their codeHash is blackListed', async function () { @@ -1086,7 +1147,10 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { other, id, ), - ).to.be.revertedWith('Codehash is filtered'); + ).to.be.revertedWithCustomError( + OperatorFilterRegistry, + 'CodehashIsFiltered', + ); }); it('it should be able to transfer(without data) through blacklisted market places after they are removed from blacklist', async function () { @@ -1112,7 +1176,10 @@ export function shouldCheckForOperatorFilter(setupLand, Contract: string) { other1, id, ), - ).to.be.revertedWith('Address is filtered'); + ).to.be.revertedWithCustomError( + OperatorFilterRegistry, + 'AddressIsFiltered', + ); await OperatorFilterRegistry.updateCodeHash( operatorFilterSubscription, diff --git a/packages/land/test/common/TransferQuad.behavior.ts b/packages/land/test/common/TransferQuad.behavior.ts index 9a20b1c9e7..5cecbd811a 100644 --- a/packages/land/test/common/TransferQuad.behavior.ts +++ b/packages/land/test/common/TransferQuad.behavior.ts @@ -15,7 +15,9 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await LandAsMinter.mintQuad(deployer, 6, 0, 0, '0x'); await expect( LandContract.transferQuad(deployer, landAdmin, 6, 1, 1, '0x'), - ).to.be.revertedWith('Invalid x coordinate'); + ) + .to.be.revertedWithCustomError(LandContract, 'InvalidCoordinates') + .withArgs(6, 1, 1); }); it('should revert if y co-ordinate of Quad is invalid', async function () { @@ -24,7 +26,9 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await LandAsMinter.mintQuad(deployer, 6, 0, 0, '0x'); await expect( LandContract.transferQuad(deployer, landAdmin, 6, 0, 5, '0x'), - ).to.be.revertedWith('Invalid y coordinate'); + ) + .to.be.revertedWithCustomError(LandContract, 'InvalidCoordinates') + .withArgs(6, 0, 5); }); it('should revert when x coordinate is out of bounds', async function () { @@ -33,7 +37,9 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await LandAsMinter.mintQuad(deployer, 6, 0, 0, '0x'); await expect( LandContract.transferQuad(deployer, landAdmin, 3, 441, 0, '0x'), - ).to.be.revertedWith('x out of bounds'); + ) + .to.be.revertedWithCustomError(LandAsMinter, 'InvalidCoordinates') + .withArgs(3, 441, 0); }); it('should revert when y coordinate is out of bounds', async function () { @@ -42,7 +48,9 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await LandAsMinter.mintQuad(deployer, 6, 0, 0, '0x'); await expect( LandContract.transferQuad(deployer, landAdmin, 3, 0, 441, '0x'), - ).to.be.revertedWith('y out of bounds'); + ) + .to.be.revertedWithCustomError(LandAsMinter, 'InvalidCoordinates') + .withArgs(3, 0, 441); }); it('should revert for invalid size', async function () { @@ -51,7 +59,9 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await LandAsMinter.mintQuad(deployer, 6, 0, 0, '0x'); await expect( LandContract.transferQuad(deployer, landAdmin, 9, 0, 0, '0x'), - ).to.be.revertedWith('Invalid size'); + ) + .to.be.revertedWithCustomError(LandContract, 'InvalidCoordinates') + .withArgs(9, 0, 0); }); it('should revert when to is ZeroAddress', async function () { @@ -60,7 +70,7 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await LandAsMinter.mintQuad(landAdmin, 3, 0, 0, '0x'); await expect( LandAsAdmin.transferQuad(landAdmin, ZeroAddress, 3, 0, 0, '0x'), - ).to.be.revertedWith("can't send to zero address"); + ).to.be.revertedWithCustomError(LandAsAdmin, 'InvalidAddress'); }); it('should revert when from is ZeroAddress', async function () { @@ -69,7 +79,7 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await LandAsMinter.mintQuad(landAdmin, 3, 0, 0, '0x'); await expect( LandAsAdmin.transferQuad(ZeroAddress, landAdmin, 3, 0, 0, '0x'), - ).to.be.revertedWith('from is zero address'); + ).to.be.revertedWithCustomError(LandAsAdmin, 'InvalidAddress'); }); it('should revert when operator is not approved', async function () { @@ -78,30 +88,32 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await LandAsMinter.mintQuad(landAdmin, 3, 0, 0, '0x'); await expect( LandContract.transferQuad(landAdmin, deployer, 3, 0, 0, '0x'), - ).to.be.revertedWith('not authorized to transferQuad'); + ) + .to.be.revertedWithCustomError(LandContract, 'ERC721InvalidOwner') + .withArgs(deployer); }); it('should revert when token does not exist', async function () { const {LandAsAdmin, deployer, landAdmin} = await loadFixture(setupLand); - await expect( - LandAsAdmin.transferQuad(landAdmin, deployer, 1, 0, 0, '0x'), - ).to.be.revertedWith('token does not exist'); + await expect(LandAsAdmin.transferQuad(landAdmin, deployer, 1, 0, 0, '0x')) + .to.be.revertedWithCustomError(LandAsAdmin, 'InvalidCoordinates') + .withArgs(1, 0, 0); }); it('should revert for transfer Quad of zero size', async function () { const {LandAsAdmin, deployer, landAdmin} = await loadFixture(setupLand); - await expect( - LandAsAdmin.transferQuad(landAdmin, deployer, 0, 0, 0, '0x'), - ).to.be.revertedWith('Invalid size'); + await expect(LandAsAdmin.transferQuad(landAdmin, deployer, 0, 0, 0, '0x')) + .to.be.revertedWithCustomError(LandAsAdmin, 'InvalidCoordinates') + .withArgs(0, 0, 0); }); it('should revert when sender is not owner of Quad', async function () { const {LandAsAdmin, deployer, landAdmin, LandAsMinter} = await loadFixture(setupLand); await LandAsMinter.mintQuad(deployer, 3, 0, 0, '0x'); - await expect( - LandAsAdmin.transferQuad(landAdmin, deployer, 6, 0, 0, '0x'), - ).to.be.revertedWith('not owner of child Quad'); + await expect(LandAsAdmin.transferQuad(landAdmin, deployer, 6, 0, 0, '0x')) + .to.be.revertedWithCustomError(LandAsAdmin, 'NotOwner') + .withArgs(0, 0); }); it('should revert if some sub-quads are not owned by the sender', async function () { @@ -110,9 +122,9 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await LandAsMinter.mintQuad(other, 6, 0, 0, '0x'); await LandAsOther.transferQuad(other, other2, 1, 0, 0, '0x'); - await expect( - LandAsOther.transferQuad(other, other1, 6, 0, 0, '0x'), - ).to.be.revertedWith('not owner'); + await expect(LandAsOther.transferQuad(other, other1, 6, 0, 0, '0x')) + .to.be.revertedWithCustomError(LandAsOther, 'ERC721InvalidOwner') + .withArgs(other); }); it('should not revert when from is owner of all subQuads of Quad', async function () { @@ -154,7 +166,12 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await LandAsMinter.mintQuad(other, 6, 0, 0, '0x'); await expect( LandAsOther.transferQuad(other, TestERC721TokenReceiver, 6, 0, 0, '0x'), - ).to.be.revertedWith('erc721 batchTransfer rejected'); + ) + .to.be.revertedWithCustomError( + LandAsOther, + 'ERC721InvalidBatchReceiver', + ) + .withArgs(TestERC721TokenReceiver); }); it('should transfer quads to a contract supporting ERC721 mandatory receiver', async function () { @@ -209,7 +226,9 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { } await expect( LandContract.transferQuad(deployer, other, size1, 0, 0, '0x'), - ).to.be.revertedWith('not owner'); + ) + .to.be.revertedWithCustomError(LandContract, 'NotOwner') + .withArgs(0, 0); } } }); @@ -233,9 +252,9 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await LandContract.burn(0); // should not be able to transfer a 3x3 quad that has a burnt 1x1 - await expect( - LandContract.transferQuad(deployer, other, 3, 0, 0, '0x'), - ).to.be.revertedWith('not owner'); + await expect(LandContract.transferQuad(deployer, other, 3, 0, 0, '0x')) + .to.be.revertedWithCustomError(LandContract, 'NotOwner') + .withArgs(0, 0); }); it('transfers of quads of all sizes from self', async function () { @@ -275,7 +294,7 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { 0, bytes, ), - ).to.be.revertedWith('from is zero address'); + ).to.be.revertedWithCustomError(LandContract, 'InvalidAddress'); }); it('should revert transfer quad to zero address', async function () { @@ -292,7 +311,7 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { 0, bytes, ), - ).to.be.revertedWith("can't send to zero address"); + ).to.be.revertedWithCustomError(LandContract, 'InvalidAddress'); }); describe('With approval', function () { @@ -313,7 +332,9 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await expect( LandContract.transferQuad(other, deployer, 1, 0, 0, bytes), - ).to.be.revertedWith('token does not exist'); + ) + .to.be.revertedWithCustomError(LandAsOther, 'InvalidCoordinates') + .withArgs(1, 0, 0); }); it('should not transfer burned quads', async function () { @@ -340,7 +361,9 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await expect( LandContract.transferQuad(other, deployer, size, 0, 0, bytes), - ).to.be.revertedWith('not owner'); + ) + .to.be.revertedWithCustomError(LandAsOther, 'NotOwner') + .withArgs(0, 0); } }); }); @@ -361,7 +384,9 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await expect( LandContract.transferQuad(deployer, other, 1, 0, 0, bytes), - ).to.be.revertedWith('token does not exist'); + ) + .to.be.revertedWithCustomError(LandContract, 'InvalidCoordinates') + .withArgs(1, 0, 0); }); it('should not transfer burned quads', async function () { @@ -388,7 +413,9 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await expect( LandAsOther.transferQuad(other, deployer, size, 0, 0, bytes), - ).to.be.revertedWith('not owner'); + ) + .to.be.revertedWithCustomError(LandAsOther, 'NotOwner') + .withArgs(0, 0); } }); }); @@ -451,7 +478,9 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await expect( LandContract.transferQuad(other, deployer, size, 0, 0, bytes), - ).to.be.revertedWith('not authorized to transferQuad'); + ) + .to.be.revertedWithCustomError(LandContract, 'ERC721InvalidOwner') + .withArgs(deployer); } }); }); @@ -483,7 +512,9 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { 0, '0x', ), - ).to.be.revertedWith('not owner'); + ) + .to.be.revertedWithCustomError(LandContract, 'ERC721InvalidOwner') + .withArgs(deployer); }); }); }); @@ -604,7 +635,7 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await expect( LandAsMinter.mintQuad(deployer, 3, 3, 3, bytes), - ).to.be.revertedWith('Already minted'); + ).to.be.revertedWithCustomError(LandAsOther, 'AlreadyMinted'); }); it('transferring all 1X1 quad from a 6x6', async function () { @@ -639,7 +670,7 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await expect( LandAsMinter.mintQuad(deployer, 6, 6, 6, bytes), - ).to.be.revertedWith('Already minted'); + ).to.be.revertedWithCustomError(LandAsOther, 'AlreadyMinted'); }); it('transferring all 1X1 quad from a 12x12', async function () { @@ -673,7 +704,7 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await expect( LandAsMinter.mintQuad(deployer, 12, 12, 12, bytes), - ).to.be.revertedWith('Already minted'); + ).to.be.revertedWithCustomError(LandAsOther, 'AlreadyMinted'); }); }); }); @@ -696,7 +727,7 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { 0, '0x', ), - ).to.be.revertedWith('Already minted'); + ).to.be.revertedWithCustomError(LandAsMinter, 'AlreadyMinted'); }); }); }); @@ -708,7 +739,7 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { sizes.forEach((innerSize) => { if (innerSize <= outerSize) return; it(`inner ${innerSize}x${innerSize} quad, outer ${outerSize}x${outerSize} quad`, async function () { - const {LandAsMinter, deployer, landAdmin} = + const {LandAsMinter, deployer, landAdmin, landMinter} = await loadFixture(setupLand); await LandAsMinter.mintQuad(deployer, innerSize, 0, 0, '0x'); await expect( @@ -719,7 +750,9 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { 0, '0x', ), - ).to.be.revertedWith('not owner'); + ) + .to.be.revertedWithCustomError(LandAsMinter, 'ERC721InvalidOwner') + .withArgs(landMinter); }); }); }); @@ -728,9 +761,9 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { it('should revert if signer is not landMinter', async function () { const {LandAsOther, other} = await loadFixture(setupLand); - await expect( - LandAsOther.mintAndTransferQuad(other, 3, 0, 0, '0x'), - ).to.be.revertedWith('!AUTHORIZED'); + await expect(LandAsOther.mintAndTransferQuad(other, 3, 0, 0, '0x')) + .to.be.revertedWithCustomError(LandAsOther, 'ERC721InvalidOwner') + .withArgs(other); }); it('should revert if to zero address', async function () { @@ -739,21 +772,21 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await LandAsAdmin.setMinter(deployer, true); await expect( LandContract.mintAndTransferQuad(ZeroAddress, 3, 3, 3, '0x'), - ).to.be.revertedWith('to is zero address'); + ).to.be.revertedWithCustomError(LandContract, 'InvalidAddress'); }); it('should revert when y is out of bound', async function () { const {LandAsMinter, landAdmin} = await loadFixture(setupLand); - await expect( - LandAsMinter.mintAndTransferQuad(landAdmin, 3, 0, 441, '0x'), - ).to.be.revertedWith('y out of bounds'); + await expect(LandAsMinter.mintAndTransferQuad(landAdmin, 3, 0, 441, '0x')) + .to.be.revertedWithCustomError(LandAsMinter, 'InvalidCoordinates') + .withArgs(3, 0, 441); }); it('should revert when x is out of bound', async function () { const {LandAsMinter, landAdmin} = await loadFixture(setupLand); - await expect( - LandAsMinter.mintAndTransferQuad(landAdmin, 3, 441, 0, '0x'), - ).to.be.revertedWith('x out of bounds'); + await expect(LandAsMinter.mintAndTransferQuad(landAdmin, 3, 441, 0, '0x')) + .to.be.revertedWithCustomError(LandAsMinter, 'InvalidCoordinates') + .withArgs(3, 441, 0); }); it('should revert when size is invalid', async function () { @@ -769,7 +802,9 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { 0, '0x', ), - ).to.be.revertedWith('Invalid size'); + ) + .to.be.revertedWithCustomError(LandAsMinter, 'InvalidCoordinates') + .withArgs(9, 0, 0); }); it('should revert when to is non ERC721 receiving contract', async function () { @@ -785,7 +820,12 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { 0, '0x', ), - ).to.be.revertedWith('erc721 batchTransfer rejected'); + ) + .to.be.revertedWithCustomError( + LandAsMinter, + 'ERC721InvalidBatchReceiver', + ) + .withArgs(TestERC721TokenReceiver); }); it('should not revert when to is ERC721 receiving contract', async function () { @@ -830,9 +870,9 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { it('should revert when coordinates are wrong', async function () { const {LandAsMinter, deployer} = await loadFixture(setupLand); - await expect( - LandAsMinter.mintAndTransferQuad(deployer, 3, 5, 5, '0x'), - ).to.be.revertedWith('Invalid x coordinate'); + await expect(LandAsMinter.mintAndTransferQuad(deployer, 3, 5, 5, '0x')) + .to.be.revertedWithCustomError(LandAsMinter, 'InvalidCoordinates') + .withArgs(3, 5, 5); }); it('should mint and transfer quad when a part of quad is already minted', async function () { @@ -873,7 +913,7 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { [0], '0x', ), - ).to.be.revertedWith('invalid from'); + ).to.be.revertedWithCustomError(LandContract, 'InvalidAddress'); }); it('should revert when sizes, x, y are not of same length', async function () { @@ -889,7 +929,7 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { [0, 6], '0x', ), - ).to.be.revertedWith("sizes's and x's are different"); + ).to.be.revertedWithCustomError(LandContract, 'InvalidLength'); }); it('should revert when x, y are not of same length', async function () { @@ -905,7 +945,7 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { [6], '0x', ), - ).to.be.revertedWith("x's and y's are different"); + ).to.be.revertedWithCustomError(LandContract, 'InvalidLength'); }); it('should revert when size, x are not of same length', async function () { @@ -921,7 +961,7 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { [0, 6], '0x', ), - ).to.be.revertedWith("sizes's and x's are different"); + ).to.be.revertedWithCustomError(LandContract, 'InvalidLength'); }); it('should revert when to is a contract and not a ERC721 receiver', async function () { @@ -938,7 +978,12 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { [0], '0x', ), - ).to.be.revertedWith('erc721 batchTransfer rejected'); + ) + .to.be.revertedWithCustomError( + LandContract, + 'ERC721InvalidBatchReceiver', + ) + .withArgs(TestERC721TokenReceiver); }); it('should transfer quads to a contract supporting ERC721 receiver', async function () { @@ -983,7 +1028,7 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { [0], '0x', ), - ).to.be.revertedWith("can't send to zero address"); + ).to.be.revertedWithCustomError(LandContract, 'InvalidAddress'); }); it('should revert when size array and coordinates array are of different length', async function () { @@ -999,7 +1044,7 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { [0], '0x', ), - ).to.be.revertedWith("can't send to zero address"); + ).to.be.revertedWithCustomError(LandContract, 'InvalidAddress'); }); it('should revert when signer is not approved', async function () { @@ -1008,7 +1053,9 @@ export function shouldCheckTransferQuad(setupLand, Contract: string) { await LandAsMinter.mintQuad(deployer, 6, 0, 0, '0x'); await expect( LandAsAdmin.batchTransferQuad(deployer, landAdmin, [6], [0], [0], '0x'), - ).to.be.revertedWith('not authorized'); + ) + .to.be.revertedWithCustomError(LandAsAdmin, 'ERC721InvalidOwner') + .withArgs(landAdmin); }); it('transfers batch of quads of different sizes', async function () { diff --git a/packages/land/test/common/WithAdmin.behavior.ts b/packages/land/test/common/WithAdmin.behavior.ts index 542de7b1fa..8f374d321d 100644 --- a/packages/land/test/common/WithAdmin.behavior.ts +++ b/packages/land/test/common/WithAdmin.behavior.ts @@ -12,16 +12,16 @@ export function shouldCheckForAdmin(setupLand, Contract: string) { it('Only admin can change admin', async function () { const {LandContract, deployer} = await loadFixture(setupLand); - await expect(LandContract.changeAdmin(deployer)).to.be.revertedWith( - 'only admin allowed', - ); + await expect( + LandContract.changeAdmin(deployer), + ).to.be.revertedWithCustomError(LandContract, 'OnlyAdmin'); }); it('should not accept zero address as new admin', async function () { const {LandAsAdmin} = await loadFixture(setupLand); - await expect(LandAsAdmin.changeAdmin(ZeroAddress)).to.be.revertedWith( - 'invalid admin', - ); + await expect( + LandAsAdmin.changeAdmin(ZeroAddress), + ).to.be.revertedWithCustomError(LandAsAdmin, 'InvalidAddress'); }); it('should change the admin to a new address', async function () { @@ -32,9 +32,9 @@ export function shouldCheckForAdmin(setupLand, Contract: string) { it('should only be changed to a new admin', async function () { const {LandAsAdmin, landAdmin} = await loadFixture(setupLand); - await expect(LandAsAdmin.changeAdmin(landAdmin)).to.be.revertedWith( - 'only new admin', - ); + await expect( + LandAsAdmin.changeAdmin(landAdmin), + ).to.be.revertedWithCustomError(LandAsAdmin, 'InvalidArgument'); }); }); } diff --git a/packages/land/test/common/WithMetadataRegistry.behavior.ts b/packages/land/test/common/WithMetadataRegistry.behavior.ts index b55d4d95b6..9f92f30e8d 100644 --- a/packages/land/test/common/WithMetadataRegistry.behavior.ts +++ b/packages/land/test/common/WithMetadataRegistry.behavior.ts @@ -10,7 +10,7 @@ export function shouldCheckForMetadataRegistry(setupLand, Contract: string) { await loadFixture(setupLand); await expect( LandAsOther.setMetadataRegistry(MetadataRegistryContract2), - ).to.be.revertedWith('only admin allowed'); + ).to.be.revertedWithCustomError(LandAsOther, 'OnlyAdmin'); }); it('should not accept zero address as metadataRegistry', async function () { @@ -18,7 +18,7 @@ export function shouldCheckForMetadataRegistry(setupLand, Contract: string) { await expect( LandAsAdmin.setMetadataRegistry(ZeroAddress), - ).to.be.revertedWith('invalid registry address'); + ).to.be.revertedWithCustomError(LandAsAdmin, 'InvalidAddress'); }); it('should set metadataRegistry', async function () { diff --git a/packages/land/test/common/WithSuperOperators.behavior.ts b/packages/land/test/common/WithSuperOperators.behavior.ts index 1e2e7c468f..215598fde1 100644 --- a/packages/land/test/common/WithSuperOperators.behavior.ts +++ b/packages/land/test/common/WithSuperOperators.behavior.ts @@ -14,7 +14,7 @@ export function shouldCheckForSuperOperators(setupLand, Contract: string) { const {LandContract, deployer} = await loadFixture(setupLand); await expect( LandContract.setSuperOperator(deployer, true), - ).to.be.revertedWith('only admin allowed'); + ).to.be.revertedWithCustomError(LandContract, 'OnlyAdmin'); expect(await LandContract.isSuperOperator(deployer)).to.be.false; }); @@ -38,10 +38,10 @@ export function shouldCheckForSuperOperators(setupLand, Contract: string) { const {LandAsAdmin} = await loadFixture(setupLand); await expect( LandAsAdmin.setSuperOperator(ZeroAddress, false), - ).to.be.revertedWith('address 0 is not allowed'); + ).to.be.revertedWithCustomError(LandAsAdmin, 'InvalidAddress'); await expect( LandAsAdmin.setSuperOperator(ZeroAddress, true), - ).to.be.revertedWith('address 0 is not allowed'); + ).to.be.revertedWithCustomError(LandAsAdmin, 'InvalidAddress'); expect(await LandAsAdmin.isSuperOperator(ZeroAddress)).to.be.false; }); @@ -52,7 +52,7 @@ export function shouldCheckForSuperOperators(setupLand, Contract: string) { expect(await LandAsAdmin.isSuperOperator(landAdmin.address)).to.be.true; await expect( LandAsAdmin.setSuperOperator(landAdmin.address, true), - ).to.be.revertedWith('invalid status'); + ).to.be.revertedWithCustomError(LandAsAdmin, 'InvalidArgument'); await expect(LandAsAdmin.setSuperOperator(landAdmin.address, false)).not .to.be.reverted; }); @@ -62,7 +62,7 @@ export function shouldCheckForSuperOperators(setupLand, Contract: string) { expect(await LandAsAdmin.isSuperOperator(landAdmin.address)).to.be.false; await expect( LandAsAdmin.setSuperOperator(landAdmin.address, false), - ).to.be.revertedWith('invalid status'); + ).to.be.revertedWithCustomError(LandAsAdmin, 'InvalidArgument'); await expect(LandAsAdmin.setSuperOperator(landAdmin.address, true)).not.to .be.reverted; }); diff --git a/packages/land/test/mainnet/land.test.ts b/packages/land/test/mainnet/land.test.ts index 6637bbecf4..1d75ffc8d4 100644 --- a/packages/land/test/mainnet/land.test.ts +++ b/packages/land/test/mainnet/land.test.ts @@ -59,9 +59,9 @@ describe('Land.sol', function () { it(`should revert for invalid size`, async function () { const {LandContract} = await loadFixture(setupLand); - await expect(LandContract.exists(5, 5, 5)).to.be.revertedWith( - 'Invalid size', - ); + await expect(LandContract.exists(5, 5, 5)) + .to.be.revertedWithCustomError(LandContract, 'InvalidCoordinates') + .withArgs(5, 5, 5); }); it('should not be a landMinter by default', async function () { @@ -71,12 +71,12 @@ describe('Land.sol', function () { it('should not accept zero address as landMinter', async function () { const {LandAsAdmin} = await setupLand(); - await expect(LandAsAdmin.setMinter(ZeroAddress, false)).to.be.revertedWith( - 'address 0 is not allowed', - ); - await expect(LandAsAdmin.setMinter(ZeroAddress, true)).to.be.revertedWith( - 'address 0 is not allowed', - ); + await expect( + LandAsAdmin.setMinter(ZeroAddress, false), + ).to.be.revertedWithCustomError(LandAsAdmin, 'InvalidAddress'); + await expect( + LandAsAdmin.setMinter(ZeroAddress, true), + ).to.be.revertedWithCustomError(LandAsAdmin, 'InvalidAddress'); expect(await LandAsAdmin.isMinter(ZeroAddress)).to.be.false; }); @@ -84,18 +84,18 @@ describe('Land.sol', function () { const {LandAsAdmin, deployer} = await setupLand(); await expect(LandAsAdmin.setMinter(deployer, true)).not.to.be.reverted; expect(await LandAsAdmin.isMinter(deployer)).to.be.true; - await expect(LandAsAdmin.setMinter(deployer, true)).to.be.revertedWith( - 'the status should be different', - ); + await expect( + LandAsAdmin.setMinter(deployer, true), + ).to.be.revertedWithCustomError(LandAsAdmin, 'InvalidArgument'); await expect(LandAsAdmin.setMinter(deployer, false)).not.to.be.reverted; }); it('should only be able to enable a disabled landMinter', async function () { const {LandAsAdmin, deployer} = await setupLand(); expect(await LandAsAdmin.isMinter(deployer)).to.be.false; - await expect(LandAsAdmin.setMinter(deployer, false)).to.be.revertedWith( - 'the status should be different', - ); + await expect( + LandAsAdmin.setMinter(deployer, false), + ).to.be.revertedWithCustomError(LandAsAdmin, 'InvalidArgument'); await expect(LandAsAdmin.setMinter(deployer, true)).not.to.be.reverted; }); diff --git a/packages/land/test/polygon/PolygonLand.test.ts b/packages/land/test/polygon/PolygonLand.test.ts index 8a5ad84df8..aa49542e20 100644 --- a/packages/land/test/polygon/PolygonLand.test.ts +++ b/packages/land/test/polygon/PolygonLand.test.ts @@ -66,7 +66,7 @@ describe('PolygonLand.sol', function () { await loadFixture(setupPolygonLand); await expect( LandAsOther.setTrustedForwarder(TrustedForwarderContract), - ).to.be.revertedWith('only admin allowed'); + ).to.be.revertedWithCustomError(LandAsOther, 'OnlyAdmin'); }); it('should return the trusted forwarder', async function () { @@ -91,7 +91,7 @@ describe('PolygonLand.sol', function () { await expect( LandAsAdmin.setMinter('0x0000000000000000000000000000000000000000', true), - ).to.be.revertedWith('address 0 is not allowed'); + ).to.be.revertedWithCustomError(LandAsAdmin, 'InvalidAddress'); }); it('changes the admin to a new address via meta transaction', async function () { @@ -165,9 +165,9 @@ describe('PolygonLand.sol', function () { 'transferQuad(address,address,uint256,uint256,uint256,bytes)' ].populateTransaction(landHolder, landReceiver, size, x, y, bytes); - await expect(sendMetaTx(landReceiver, to, data)).to.revertedWith( - 'not authorized to transferQuad', - ); + await expect(sendMetaTx(landReceiver, to, data)) + .to.revertedWithCustomError(LandAsMinter, 'ERC721InvalidOwner') + .withArgs(landReceiver); expect(await LandAsMinter.balanceOf(landReceiver)).to.be.equal(0); expect(await LandAsMinter.balanceOf(landHolder)).to.be.equal( plotCount, @@ -251,7 +251,12 @@ describe('PolygonLand.sol', function () { y, bytes, ), - ).to.be.revertedWith(/not owner/); + ) + .to.be.revertedWithCustomError( + LandAsOther, + 'ERC721InvalidOwner', + ) + .withArgs(other); } } } @@ -311,7 +316,9 @@ describe('PolygonLand.sol', function () { await expect( LandAsOther.transferQuad(landHolder, landReceiver, size, x, y, bytes), - ).to.be.revertedWith('token does not exist'); + ) + .to.be.revertedWithCustomError(LandAsOther, 'InvalidCoordinates') + .withArgs(size, x, y); }); it('should revert transfer of quad if a sub quad is burned', async function () { @@ -365,7 +372,9 @@ describe('PolygonLand.sol', function () { y, bytes, ), - ).to.be.revertedWith('not owner'); + ) + .to.be.revertedWithCustomError(LandAsOther, 'NotOwner') + .withArgs(x, y); //check override await expect(LandAsOther.ownerOf(0)) @@ -410,7 +419,9 @@ describe('PolygonLand.sol', function () { y, bytes, ), - ).to.be.revertedWith('not owner'); + ) + .to.be.revertedWithCustomError(LandAsOther, 'NotOwner') + .withArgs(x, y); } }); }); diff --git a/packages/land/test/registry/registry.test.ts b/packages/land/test/registry/registry.test.ts index 224c490469..68bf2f2b7c 100644 --- a/packages/land/test/registry/registry.test.ts +++ b/packages/land/test/registry/registry.test.ts @@ -31,17 +31,17 @@ describe('LandMetadataRegistry', function () { const {registryAsOther} = await loadFixture(setupRegistry); await expect( registryAsOther.setMetadata(tokenId, true, neighborhoodId), - ).to.revertedWith('only admin'); + ).to.revertedWithCustomError(registryAsOther, 'OnlyAdmin'); }); it('admin should fail to set metadata if the neighborhood number is invalid', async function () { const {registryAsAdmin} = await loadFixture(setupRegistry); - await expect( - registryAsAdmin.setMetadata(tokenId, true, 0), - ).to.revertedWith('neighborhoodId must be >0'); - await expect( - registryAsAdmin.setMetadata(tokenId, true, 127), - ).to.revertedWith('neighborhoodId must be <127'); + await expect(registryAsAdmin.setMetadata(tokenId, true, 0)) + .to.revertedWithCustomError(registryAsAdmin, 'InvalidNeighborhoodId') + .withArgs(0); + await expect(registryAsAdmin.setMetadata(tokenId, true, 127)) + .to.revertedWithCustomError(registryAsAdmin, 'InvalidNeighborhoodId') + .withArgs(127); }); }); @@ -62,9 +62,9 @@ describe('LandMetadataRegistry', function () { it('other should fail to set premiumness', async function () { const {registryAsOther} = await loadFixture(setupRegistry); - await expect(registryAsOther.setPremium(tokenId, true)).to.revertedWith( - 'only admin', - ); + await expect( + registryAsOther.setPremium(tokenId, true), + ).to.revertedWithCustomError(registryAsOther, 'OnlyAdmin'); }); }); @@ -84,17 +84,17 @@ describe('LandMetadataRegistry', function () { const {registryAsOther} = await loadFixture(setupRegistry); await expect( registryAsOther.setNeighborhoodId(tokenId, neighborhoodId), - ).to.revertedWith('only admin'); + ).to.revertedWithCustomError(registryAsOther, 'OnlyAdmin'); }); it('admin should fail to set neighborhood number if the number is invalid', async function () { const {registryAsAdmin} = await loadFixture(setupRegistry); - await expect( - registryAsAdmin.setNeighborhoodId(tokenId, 0), - ).to.revertedWith('neighborhoodId must be >0'); - await expect( - registryAsAdmin.setNeighborhoodId(tokenId, 127), - ).to.revertedWith('neighborhoodId must be <127'); + await expect(registryAsAdmin.setNeighborhoodId(tokenId, 0)) + .to.revertedWithCustomError(registryAsAdmin, 'InvalidNeighborhoodId') + .withArgs(0); + await expect(registryAsAdmin.setNeighborhoodId(tokenId, 127)) + .to.revertedWithCustomError(registryAsAdmin, 'InvalidNeighborhoodId') + .withArgs(127); }); }); @@ -127,17 +127,17 @@ describe('LandMetadataRegistry', function () { const {registryAsOther} = await loadFixture(setupRegistry); await expect( registryAsOther.setNeighborhoodName(neighborhoodId, neighborhoodName), - ).to.revertedWith('only admin'); + ).to.revertedWithCustomError(registryAsOther, 'OnlyAdmin'); }); it('admin should fail to set neighborhood name if the neighborhood number is invalid', async function () { const {registryAsAdmin} = await loadFixture(setupRegistry); - await expect( - registryAsAdmin.setNeighborhoodName(0, neighborhoodName), - ).to.revertedWith('neighborhoodId must be >0'); - await expect( - registryAsAdmin.setNeighborhoodName(127, neighborhoodName), - ).to.revertedWith('neighborhoodId must be <127'); + await expect(registryAsAdmin.setNeighborhoodName(0, neighborhoodName)) + .to.revertedWithCustomError(registryAsAdmin, 'InvalidNeighborhoodId') + .withArgs(0); + await expect(registryAsAdmin.setNeighborhoodName(127, neighborhoodName)) + .to.revertedWithCustomError(registryAsAdmin, 'InvalidNeighborhoodId') + .withArgs(127); }); }); @@ -189,16 +189,17 @@ describe('LandMetadataRegistry', function () { registryAsOther.batchSetMetadata([ {baseTokenId: tokenId, metadata: neighborhoodId | 0x80n}, ]), - ).to.revertedWith('only admin'); + ).to.revertedWithCustomError(registryAsOther, 'OnlyAdmin'); }); it('admin should fail to batch set metadata if baseTokenId is invalid', async function () { const {registryAsAdmin} = await loadFixture(setupRegistry); + const baseTokenId = 32n * (tokenId / 32n) + 1n; await expect( - registryAsAdmin.batchSetMetadata([ - {baseTokenId: 32n * (tokenId / 32n) + 1n, metadata: 0n}, - ]), - ).to.revertedWith('invalid base tokenId'); + registryAsAdmin.batchSetMetadata([{baseTokenId, metadata: 0n}]), + ) + .to.revertedWithCustomError(registryAsAdmin, 'InvalidBaseTokenId') + .withArgs(baseTokenId); }); }); @@ -219,12 +220,12 @@ describe('LandMetadataRegistry', function () { ]); // known type await registryAsAdmin.setNeighborhoodId(tokenId, neighborhoodId); - await expect(registryAsAdmin.setNeighborhoodId(tokenId, 0)).to.revertedWith( - 'neighborhoodId must be >0', - ); - await expect( - registryAsAdmin.setMetadata(tokenId, false, 0), - ).to.revertedWith('neighborhoodId must be >0'); + await expect(registryAsAdmin.setNeighborhoodId(tokenId, 0)) + .to.revertedWithCustomError(registryAsAdmin, 'InvalidNeighborhoodId') + .withArgs(0); + await expect(registryAsAdmin.setMetadata(tokenId, false, 0)) + .to.revertedWithCustomError(registryAsAdmin, 'InvalidNeighborhoodId') + .withArgs(0); }); describe('coverage', function () {