-
Notifications
You must be signed in to change notification settings - Fork 1
/
RenftMarket.t.sol
111 lines (104 loc) · 3.4 KB
/
RenftMarket.t.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {Test, console} from "forge-std/Test.sol";
import {Counter} from "../src/Counter.sol";
import {SigUtils} from "./utils/SigUtils.sol";
import {RenftMarket} from "../src/RenftMarket.sol";
import {IRenftMarket} from "../src/interface/IRenftMarket.sol";
import {NFTFactory, S2NFT} from "../src/NFTFactory.sol";
import {Signature} from "../src/utils/Signature.sol";
contract RenftMarketTest is Test {
struct RentoutOrder {
address maker; // 出租方地址
address nft_ca; // NFT合约地址
uint256 token_id; // NFT tokenId
uint256 daily_rent; // 每日租金
uint256 max_rental_duration; // 最大租赁时长
uint256 min_collateral; // 最小抵押
uint256 list_endtime; // 挂单结束时间
}
SigUtils internal sigUtils = new SigUtils();
uint256 ownerPrivateKey = 0xA11CE;
address alice = vm.addr(ownerPrivateKey);
uint256 buyerPrivateKey = 0xB22DC;
address tom = vm.addr(buyerPrivateKey);
address owner = makeAddr("owner");
RenftMarket renft;
NFTFactory factory;
address nft;
S2NFT s2;
function setUp() public {
vm.startPrank(alice);
renft = new RenftMarket();
factory = new NFTFactory();
nft = factory.deployNFT("aa", "aa", "aa", 100);
s2 = S2NFT(nft);
s2.freeMint(2);
s2.approve(address(renft), 1);
vm.stopPrank();
}
function test_cancel() public {
//取消后在进行购买
uint256 tokenId = 1;
vm.deal(tom, 10 ether);
vm.startPrank(alice);
SigUtils.RentoutOrder memory _rentout = SigUtils.RentoutOrder(
address(alice),
nft,
tokenId,
1 ether,
10 days,
5 ether,
block.timestamp + 5 days
);
bytes32 digest = sigUtils.getTypedDataHash(_rentout);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(ownerPrivateKey, digest);
bytes memory _sign = Signature.fromVRS(v, r, s);
renft.cancelOrder(
IRenftMarket.RentoutOrder(
address(alice),
nft,
tokenId,
1 ether,
10 days,
5 ether,
block.timestamp + 5 days
),
_sign
);
test_borrow();
}
function test_borrow() public {
uint256 tokenId = 1;
vm.deal(tom, 10 ether);
vm.startPrank(tom);
SigUtils.RentoutOrder memory _rentout = SigUtils.RentoutOrder(
address(alice),
nft,
tokenId,
1 ether,
10 days,
5 ether,
block.timestamp + 5 days
);
bytes32 digest = sigUtils.getTypedDataHash(_rentout);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(ownerPrivateKey, digest);
bytes memory _sign = Signature.fromVRS(v, r, s);
renft.borrow{value: 10 ether}(
IRenftMarket.RentoutOrder(
address(alice),
nft,
tokenId,
1 ether,
10 days,
5 ether,
block.timestamp + 5 days
),
_sign
);
// SigUtils.Permit memory permit = SigUtils.Permit(_rentout);
// renft.borrow(_rentout);
vm.stopPrank();
}
function testFuzz_SetNumber(uint256 x) public {}
}