-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
552 additions
and
20 deletions.
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
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
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
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,80 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol"; | ||
import {AccessToken} from "../src/AccessToken.sol"; | ||
import {IProduct} from "../src/interfaces/IProduct.sol"; | ||
import {MockProduct} from "./mocks/MockProduct.sol"; | ||
import "forge-std/src/Test.sol"; | ||
|
||
contract AccessTokenTest is Test { | ||
AccessToken accessToken; | ||
MockProduct product; | ||
|
||
function setUp() public { | ||
MockProduct productImpl = new MockProduct(); | ||
product = MockProduct(Clones.clone(address(productImpl))); | ||
product.initialize("MockProduct", "MP", "https://examples.com"); | ||
|
||
accessToken = new AccessToken( | ||
IProduct(address(product)), | ||
"AccessToken", | ||
"AC" | ||
); | ||
} | ||
|
||
function testMint() public { | ||
vm.prank(address(this)); | ||
uint256 tokenId = product.mint(address(this)); | ||
|
||
address user = makeAddr("user"); | ||
accessToken.mint(user, tokenId); | ||
|
||
assertEq(accessToken.ownerOf(tokenId), user); | ||
} | ||
|
||
function testMint_NotProductOwner() public { | ||
vm.prank(address(this)); | ||
uint256 tokenId = product.mint(address(this)); | ||
|
||
address notProductOwner = makeAddr("notProductOwner"); | ||
vm.expectRevert("not product owner"); | ||
vm.prank(notProductOwner); | ||
accessToken.mint(notProductOwner, tokenId); | ||
} | ||
|
||
function testBurn() public { | ||
vm.prank(address(this)); | ||
uint256 tokenId = product.mint(address(this)); | ||
|
||
accessToken.mint(address(this), tokenId); | ||
accessToken.burn(tokenId); | ||
|
||
vm.expectRevert(); | ||
accessToken.ownerOf(tokenId); | ||
} | ||
|
||
function testBurn_NotProductOwner() public { | ||
vm.prank(address(this)); | ||
uint256 tokenId = product.mint(address(this)); | ||
|
||
accessToken.mint(address(this), tokenId); | ||
|
||
address notProductOwner = makeAddr("notProductOwner"); | ||
vm.prank(notProductOwner); | ||
vm.expectRevert("not product owner"); | ||
accessToken.burn(tokenId); | ||
} | ||
|
||
function testMint_AfterBurned() public { | ||
vm.prank(address(this)); | ||
uint256 tokenId = product.mint(address(this)); | ||
|
||
address user1 = makeAddr("user1"); | ||
address user2 = makeAddr("user2"); | ||
accessToken.mint(user1, tokenId); | ||
accessToken.burn(tokenId); | ||
accessToken.mint(user2, tokenId); | ||
assertEq(accessToken.ownerOf(tokenId), user2); | ||
} | ||
} |
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,44 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol"; | ||
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | ||
import {AccessTokenFactory} from "../src/AccessTokenFactory.sol"; | ||
import {AccessToken} from "../src/AccessToken.sol"; | ||
import {IProduct} from "../src/interfaces/IProduct.sol"; | ||
import {MockProduct} from "./mocks/MockProduct.sol"; | ||
import "forge-std/src/Test.sol"; | ||
|
||
contract AccessTokenFactoryTest is Test { | ||
AccessTokenFactory factory; | ||
MockProduct product; | ||
|
||
function setUp() public { | ||
factory = new AccessTokenFactory(); | ||
MockProduct productImpl = new MockProduct(); | ||
product = MockProduct(Clones.clone(address(productImpl))); | ||
product.initialize("MockProduct", "MP", "https://examples.com"); | ||
} | ||
|
||
function testCreateAccessToken() public { | ||
address productAddress = address(product); | ||
|
||
assertEq(factory.getAccessToken(productAddress), address(0)); | ||
|
||
address accessTokenAddress = factory.createAccessToken(productAddress); | ||
assertTrue(accessTokenAddress != address(0)); | ||
assertEq(factory.getAccessToken(productAddress), accessTokenAddress); | ||
|
||
AccessToken accessToken = AccessToken(accessTokenAddress); | ||
assertEq(accessToken.name(), "MockProduct"); | ||
assertEq(accessToken.symbol(), "AC.MP"); | ||
} | ||
|
||
function testCreateAccessTokenTwice() public { | ||
address productAddress = address(product); | ||
factory.createAccessToken(productAddress); | ||
|
||
vm.expectRevert("existing access token"); | ||
factory.createAccessToken(productAddress); | ||
} | ||
} |
Oops, something went wrong.