Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arr00 committed Dec 5, 2023
1 parent 09c798c commit e3cc70b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/gatekeepers/TokenGateKeeper.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Test } from "../../lib/forge-std/src/Test.sol";
import { console } from "../../lib/forge-std/src/console.sol";
import { DummyERC20 } from "../DummyERC20.sol";
import { DummyERC721 } from "../DummyERC721.sol";
import { DummyERC1155 } from "../DummyERC1155.sol";
import { TestUtils } from "../TestUtils.sol";
import { TokenGateKeeper } from "../../contracts/gatekeepers/TokenGateKeeper.sol";
import "../../contracts/utils/LibERC20Compat.sol";
Expand All @@ -13,8 +14,10 @@ contract TokenGateKeeperTest is Test, TestUtils {
TokenGateKeeper gk;
uint256 constant MIN_ERC20_BALANCE = 10e18;
uint256 constant MIN_ERC721_BALANCE = 1;
uint256 constant MIN_ERC1155_BALANCE = 1;
DummyERC20 dummyERC20 = new DummyERC20();
DummyERC721 dummyERC721 = new DummyERC721();
DummyERC1155 dummyERC1155 = new DummyERC1155();

function setUp() public {
gk = new TokenGateKeeper(address(0));
Expand Down Expand Up @@ -67,4 +70,25 @@ contract TokenGateKeeperTest is Test, TestUtils {
assertFalse(gk.isAllowed(user1, ERC721gateId, ""));
assertFalse(gk.isAllowed(user2, ERC20gateId, ""));
}

function test1155Gate() public {
bytes12 ERC1155gateId = gk.createGate(address(dummyERC1155), 1, MIN_ERC1155_BALANCE);
address user = _randomAddress();
dummyERC1155.deal(user, 1, 1);
assertTrue(gk.isAllowed(user, ERC1155gateId, ""));
}

function test1155Gate_wrongId() public {
bytes12 ERC1155gateId = gk.createGate(address(dummyERC1155), 1, MIN_ERC1155_BALANCE);
address user = _randomAddress();
dummyERC1155.deal(user, 2, 1);
assertFalse(gk.isAllowed(user, ERC1155gateId, ""));
}

function test1155Gate_notEnough() public {
bytes12 ERC1155gateId = gk.createGate(address(dummyERC1155), 1, 3);
address user = _randomAddress();
dummyERC1155.deal(user, 1, 2);
assertFalse(gk.isAllowed(user, ERC1155gateId, ""));
}
}

0 comments on commit e3cc70b

Please sign in to comment.