Skip to content

Commit

Permalink
Add unit tests for ERC1155 Discount Validator (#40)
Browse files Browse the repository at this point in the history
* Init

* Add unit tests for ERC1155 Discount Validator
  • Loading branch information
stevieraykatz authored Jun 25, 2024
1 parent 8d204e0 commit c02661e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/L1Resolver/L1ResolverBase.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
pragma solidity ^0.8.23;

import {Test, console} from "forge-std/Test.sol";
import {L1Resolver} from "src/L1/L1Resolver.sol";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import {Test} from "forge-std/Test.sol";
import {ERC1155DiscountValidator} from "src/L2/discounts/ERC1155DiscountValidator.sol";
import {MockERC1155} from "test/mocks/MockERC1155.sol";

contract ERC1155DiscountValidatorBase is Test {
ERC1155DiscountValidator validator;
MockERC1155 token;
uint256 tokenId = 1;
address userA = makeAddr("userA");
address userB = makeAddr("userB");

function setUp() public {
token = new MockERC1155();
validator = new ERC1155DiscountValidator(address(token), tokenId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import {ERC1155DiscountValidatorBase} from "./ERC1155DiscountValidatorBase.t.sol";

contract IsValidDiscountRegistration is ERC1155DiscountValidatorBase {
function test_returnsFalse_whenTheClaimerDoesNotHaveTheToken() public view {
assertFalse(validator.isValidDiscountRegistration(userA, ""));
}

function test_returnsFalse_whenAnotherUserHasTheToken() public {
token.mint(userA, tokenId, 1);
assertFalse(validator.isValidDiscountRegistration(userB, ""));
}

function test_returnsTrue_whenTheUserHasTheToken() public {
token.mint(userA, tokenId, 1);
assertTrue(validator.isValidDiscountRegistration(userA, ""));
}
}
12 changes: 12 additions & 0 deletions test/mocks/MockERC1155.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";

contract MockERC1155 is ERC1155 {
constructor() ERC1155("") {}

function mint(address to, uint256 id, uint256 value) public {
_mint(to, id, value, "");
}
}

0 comments on commit c02661e

Please sign in to comment.