-
-
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
195 additions
and
64 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
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,65 @@ | ||
// SPDX-License-Identifier: SEE LICENSE IN LICENSE | ||
pragma solidity ^0.8.25; | ||
|
||
import { Test, console2 } from "forge-std/src/Test.sol"; | ||
import { NFTMarket, BaseERC20 } from "../src/Week2/NFTMarket.sol"; | ||
import { MyERC721 } from "../src/Week2/MyERC721.sol"; | ||
|
||
contract NFTMarketTest is Test { | ||
NFTMarket nftMarket; | ||
address alice = makeAddr("alice"); | ||
BaseERC20 private my20; | ||
|
||
address bob = makeAddr("bob"); | ||
address tom = makeAddr("tom"); | ||
MyERC721 internal my721; | ||
|
||
function setUp() public { | ||
my20 = new BaseERC20(alice); | ||
my721 = new MyERC721(); | ||
|
||
nftMarket = new NFTMarket(address(my721), address(my20)); | ||
|
||
my721.mint(bob, "https://ipfs.io/ipfs/QmY5WwRyZm7P6cT9y4uNcHr5eVJvXsQkLX9VZgVn5h7uZ"); | ||
my721.mint(tom, "https://ipfs.io/ipfs/QmY5WwRyZm7P6cT9y4uNcHr5eVJvXsQkLX9VZgVn5h7uZ"); | ||
} | ||
|
||
function test_list() public { | ||
list(bob, 0, 100); | ||
} | ||
|
||
function test_buyNFT() public { | ||
list(bob, 0, 100); | ||
vm.prank(bob); | ||
my721.approve(address(nftMarket), 0); | ||
vm.startPrank(alice); | ||
my20.approve(address(nftMarket), 100); | ||
assertEq(my20.balanceOf(bob), 0); | ||
// | ||
nftMarket.buyNFT(0); | ||
assertEq(my20.balanceOf(bob), 100); | ||
assertEq(my721.ownerOf(0), alice); | ||
assertEq(nftMarket.checkList(0).ownerAddress, alice); | ||
vm.stopPrank(); | ||
} | ||
|
||
function test_tokenReceive() public { | ||
list(bob, 0, 100); | ||
vm.startPrank(alice); | ||
uint256 i = 0; | ||
my20.transferWithFallback(address(nftMarket), 100, abi.encodePacked(i)); | ||
|
||
assertEq(my20.balanceOf(bob), 100); | ||
assertEq(nftMarket.checkList(0).ownerAddress, alice); | ||
vm.stopPrank(); | ||
} | ||
|
||
function list(address who, uint256 _tokenId, uint256 price) public { | ||
vm.startPrank(who); | ||
assertEq(my721.ownerOf(_tokenId), who); | ||
nftMarket.list(_tokenId, price); | ||
assertEq(nftMarket.checkList(_tokenId).price, price); | ||
assertEq(nftMarket.checkList(_tokenId).ownerAddress, who); | ||
vm.stopPrank(); | ||
} | ||
} |
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,63 @@ | ||
// SPDX-License-Identifier: SEE LICENSE IN LICENSE | ||
pragma solidity ^0.8.25; | ||
|
||
import { Test, console2 } from "forge-std/src/Test.sol"; | ||
import { TokenBank, BaseERC20 } from "../src/Week2/BaseERC20.sol"; | ||
|
||
contract TokenBankTest is Test { | ||
TokenBank tokenBank; | ||
// address myErc20; | ||
address alice; | ||
BaseERC20 private my20; | ||
|
||
function setUp() public virtual { | ||
alice = makeAddr("alice"); | ||
// myErc20 = makeAddr("myErc20"); | ||
my20 = new BaseERC20(alice); | ||
tokenBank = new TokenBank(address(my20)); | ||
} | ||
|
||
function testFailDeposit() public { | ||
vm.startPrank(alice); | ||
|
||
// my20.approve(address(tokenBank), 10_000); | ||
|
||
tokenBank.deposit(10_000); | ||
|
||
assertEq(tokenBank.getAccounts(), 10_000); | ||
|
||
vm.stopPrank(); | ||
} | ||
|
||
function test_deposit() public { | ||
deposit(alice, 10_000); | ||
} | ||
|
||
function test_withdraw() public { | ||
deposit(alice, 10_000); | ||
vm.startPrank(alice); | ||
|
||
tokenBank.withdraw(10_000); | ||
assertEq(tokenBank.getAccounts(), 0); | ||
} | ||
|
||
function test_tokenReceive() public { | ||
vm.startPrank(alice); | ||
my20.transferWithFallback(address(tokenBank), 10_000, "test"); | ||
|
||
assertEq(tokenBank.getAccounts(), 10_000); | ||
vm.stopPrank(); | ||
} | ||
|
||
function deposit(address who, uint256 value) private { | ||
vm.startPrank(who); | ||
|
||
my20.approve(address(tokenBank), value); | ||
|
||
tokenBank.deposit(value); | ||
|
||
assertEq(tokenBank.getAccounts(), value); | ||
|
||
vm.stopPrank(); | ||
} | ||
} |