Skip to content

Commit

Permalink
test pack
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaryash90 committed Feb 23, 2024
1 parent fe3b2a6 commit 68d9c4d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 42 deletions.
54 changes: 24 additions & 30 deletions src/test/pack/Pack.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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));
}

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

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

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

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

Expand Down
20 changes: 10 additions & 10 deletions src/test/pack/PackVRFDirect.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}

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

Expand Down
4 changes: 2 additions & 2 deletions src/test/sdk/base/ERC721DelayedReveal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 68d9c4d

Please sign in to comment.