From 68d9c4d0222ab926789595e5061b527db9f7dfb3 Mon Sep 17 00:00:00 2001 From: Yash Date: Fri, 23 Feb 2024 23:30:41 +0530 Subject: [PATCH] test pack --- src/test/pack/Pack.t.sol | 54 +++++++++------------ src/test/pack/PackVRFDirect.t.sol | 20 ++++---- src/test/sdk/base/ERC721DelayedReveal.t.sol | 4 +- 3 files changed, 36 insertions(+), 42 deletions(-) diff --git a/src/test/pack/Pack.t.sol b/src/test/pack/Pack.t.sol index 94d5a8060..37fdae635 100644 --- a/src/test/pack/Pack.t.sol +++ b/src/test/pack/Pack.t.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.0; import { Pack, IERC2981Upgradeable, IERC721Receiver, IERC1155Upgradeable } from "contracts/prebuilts/pack/Pack.sol"; import { IPack } from "contracts/prebuilts/interface/IPack.sol"; import { ITokenBundle } from "contracts/extension/interface/ITokenBundle.sol"; +import { CurrencyTransferLib } from "contracts/lib/CurrencyTransferLib.sol"; // Test imports import { MockERC20 } from "../mocks/MockERC20.sol"; @@ -201,8 +202,8 @@ contract PackTest is BaseTest { } function test_checkForwarders() public { - assertTrue(pack.isTrustedForwarder(eoaForwarder)); - assertTrue(pack.isTrustedForwarder(forwarder)); + assertFalse(pack.isTrustedForwarder(eoaForwarder)); + assertFalse(pack.isTrustedForwarder(forwarder)); } /*/////////////////////////////////////////////////////////////// @@ -393,17 +394,14 @@ contract PackTest is BaseTest { address recipient = address(0x123); - string memory errorMsg = string( - abi.encodePacked( - "Permissions: account ", - Strings.toHexString(uint160(packContents[0].assetContract), 20), - " is missing role ", - Strings.toHexString(uint256(keccak256("ASSET_ROLE")), 32) + vm.prank(address(tokenOwner)); + vm.expectRevert( + abi.encodeWithSelector( + Permissions.PermissionsUnauthorizedAccount.selector, + address(erc721), + keccak256("ASSET_ROLE") ) ); - - vm.prank(address(tokenOwner)); - vm.expectRevert(bytes(errorMsg)); pack.createPack(packContents, numOfRewardUnits, packUri, 0, 1, recipient); } @@ -416,17 +414,14 @@ contract PackTest is BaseTest { address recipient = address(0x123); - string memory errorMsg = string( - abi.encodePacked( - "Permissions: account ", - Strings.toHexString(uint160(address(tokenOwner)), 20), - " is missing role ", - Strings.toHexString(uint256(keccak256("MINTER_ROLE")), 32) + vm.prank(address(tokenOwner)); + vm.expectRevert( + abi.encodeWithSelector( + Permissions.PermissionsUnauthorizedAccount.selector, + address(tokenOwner), + keccak256("MINTER_ROLE") ) ); - - vm.prank(address(tokenOwner)); - vm.expectRevert(bytes(errorMsg)); pack.createPack(packContents, numOfRewardUnits, packUri, 0, 1, recipient); } @@ -449,7 +444,9 @@ contract PackTest is BaseTest { numOfRewardUnits.push(1); vm.prank(address(tokenOwner)); - vm.expectRevert("msg.value != amount"); + vm.expectRevert( + abi.encodeWithSelector(CurrencyTransferLib.CurrencyTransferLibMismatchedValue.selector, 0, 20 ether) + ); pack.createPack(packContents, numOfRewardUnits, packUri, 0, 1, recipient); } @@ -712,17 +709,14 @@ contract PackTest is BaseTest { address randomAccount = address(0x123); - string memory errorMsg = string( - abi.encodePacked( - "Permissions: account ", - Strings.toHexString(uint160(address(randomAccount)), 20), - " is missing role ", - Strings.toHexString(uint256(keccak256("MINTER_ROLE")), 32) + vm.prank(randomAccount); + vm.expectRevert( + abi.encodeWithSelector( + Permissions.PermissionsUnauthorizedAccount.selector, + randomAccount, + keccak256("MINTER_ROLE") ) ); - - vm.prank(randomAccount); - vm.expectRevert(bytes(errorMsg)); pack.addPackContents(packId, additionalContents, additionalContentsRewardUnits, recipient); } diff --git a/src/test/pack/PackVRFDirect.t.sol b/src/test/pack/PackVRFDirect.t.sol index 305378252..55a620e19 100644 --- a/src/test/pack/PackVRFDirect.t.sol +++ b/src/test/pack/PackVRFDirect.t.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.0; import { PackVRFDirect, IERC2981Upgradeable, IERC721Receiver, IERC1155Upgradeable } from "contracts/prebuilts/pack/PackVRFDirect.sol"; import { IPack } from "contracts/prebuilts/interface/IPack.sol"; import { ITokenBundle } from "contracts/extension/interface/ITokenBundle.sol"; +import { CurrencyTransferLib } from "contracts/lib/CurrencyTransferLib.sol"; // Test imports import { MockERC20 } from "../mocks/MockERC20.sol"; @@ -332,17 +333,14 @@ contract PackVRFDirectTest is BaseTest { address recipient = address(0x123); - string memory errorMsg = string( - abi.encodePacked( - "Permissions: account ", - Strings.toHexString(uint160(address(tokenOwner)), 20), - " is missing role ", - Strings.toHexString(uint256(keccak256("MINTER_ROLE")), 32) + vm.prank(address(tokenOwner)); + vm.expectRevert( + abi.encodeWithSelector( + Permissions.PermissionsUnauthorizedAccount.selector, + address(tokenOwner), + keccak256("MINTER_ROLE") ) ); - - vm.prank(address(tokenOwner)); - vm.expectRevert(bytes(errorMsg)); pack.createPack(packContents, numOfRewardUnits, packUri, 0, 1, recipient); } @@ -365,7 +363,9 @@ contract PackVRFDirectTest is BaseTest { numOfRewardUnits.push(1); vm.prank(address(tokenOwner)); - vm.expectRevert("msg.value != amount"); + vm.expectRevert( + abi.encodeWithSelector(CurrencyTransferLib.CurrencyTransferLibMismatchedValue.selector, 0, 20 ether) + ); pack.createPack(packContents, numOfRewardUnits, packUri, 0, 1, recipient); } diff --git a/src/test/sdk/base/ERC721DelayedReveal.t.sol b/src/test/sdk/base/ERC721DelayedReveal.t.sol index 89a901357..dce4da3c2 100644 --- a/src/test/sdk/base/ERC721DelayedReveal.t.sol +++ b/src/test/sdk/base/ERC721DelayedReveal.t.sol @@ -5,7 +5,7 @@ import "@std/Test.sol"; import "@ds-test/test.sol"; import "./BaseUtilTest.sol"; -import { ERC721DelayedReveal } from "contracts/base/ERC721DelayedReveal.sol"; +import { ERC721DelayedReveal, BatchMintMetadata } from "contracts/base/ERC721DelayedReveal.sol"; contract BaseERC721DelayedRevealTest is BaseUtilTest { ERC721DelayedReveal internal base; @@ -77,7 +77,7 @@ contract BaseERC721DelayedRevealTest is BaseUtilTest { vm.startPrank(deployer); base.lazyMint(_amount, _baseURIForTokens, abi.encode(_encryptedBaseURI, provenanceHash)); - vm.expectRevert("Invalid tokenId"); + vm.expectRevert(abi.encodeWithSelector(BatchMintMetadata.BatchMintInvalidTokenId.selector, 100)); base.tokenURI(100); vm.stopPrank();