-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for ERC1155 Discount Validator (#40)
* Init * Add unit tests for ERC1155 Discount Validator
- Loading branch information
1 parent
8d204e0
commit c02661e
Showing
4 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
test/discounts/ERC1155DiscountValidator/ERC1155DiscountValidatorBase.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
test/discounts/ERC1155DiscountValidator/IsValidDiscountRegistration.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, "")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, ""); | ||
} | ||
} |