-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBase.t.sol
More file actions
108 lines (89 loc) · 3.69 KB
/
Base.t.sol
File metadata and controls
108 lines (89 loc) · 3.69 KB
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
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
import "forge-std/Test.sol";
import {MockERC20} from "../mocks/mockERC20.sol";
import {MockERC721} from "../mocks/mockERC721.sol";
import {CollectionBet} from "../src/CollectionBet.sol";
import {ERC721TokenReceiver} from "solmate/src/tokens/ERC721.sol";
import {WETH} from "solmate/src/tokens/WETH.sol";
abstract contract Base is Test, ERC721TokenReceiver {
CollectionBet internal collectionBet;
WETH internal weth;
MockERC20 internal USDC;
MockERC721 internal mockNFT;
uint internal buyerPrivateKey;
address internal buyer;
uint internal sellerPrivateKey;
address internal seller;
address internal admin;
// 20 represets 2% in decimals we divide it by 100
uint16 internal fee = 20;
constructor() {
uint adminPrivateKey = uint(0x5555);
admin = vm.addr(adminPrivateKey);
vm.label(admin, "Admin");
vm.startPrank(admin);
USDC = new MockERC20("USDC token", "USDC", 6);
mockNFT = new MockERC721("mockNFT collection", "MNC");
weth = new WETH();
vm.label(address(weth), "WETH Contract");
vm.label(address(USDC), "USDC Contract");
collectionBet = new CollectionBet(fee, address(weth));
vm.stopPrank();
buyerPrivateKey = uint(0x12345);
buyer = vm.addr(buyerPrivateKey);
vm.label(buyer, "Buyer");
sellerPrivateKey = uint(0x6789);
seller = vm.addr(sellerPrivateKey);
vm.label(seller, "Seller");
}
// @dev "r" and "s" big numbers represented by byte32 and they are the output of the cryptographic algorithm when signing a message.
// @dev "v" known as a recovery id. helps indentify the correct signer's public key.
function signOrder(
uint privateKey,
CollectionBet.Order memory order
) internal returns (bytes memory) {
bytes32 orderHash = collectionBet.hashOrder(order);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, orderHash);
return abi.encodePacked(r, s, v);
}
// @dev "r" and "s" big numbers represented by byte32 and they are the output of the cryptographic algorithm when signing a message.
// @dev "v" known as a recovery id. helps indentify the correct signer's public key.
function signSellOrder(
uint privateKey,
CollectionBet.SellOrder memory sellOrder
) internal returns (bytes memory) {
bytes32 hashedSellOrder = collectionBet.hashSellOrder(sellOrder);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, hashedSellOrder);
return abi.encodePacked(r, s, v);
}
function signOrderHash(
uint privateKey,
bytes32 orderHash
) internal returns (bytes memory) {
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, orderHash);
return abi.encodePacked(r, s, v);
}
function signHash(
uint privateKey,
bytes32 _hash
) internal returns (bytes memory) {
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, _hash);
return abi.encodePacked(r, s, v);
}
function defaultOrder() internal view returns (CollectionBet.Order memory) {
return
CollectionBet.Order({
sellerDeposit: 100 ether,
buyerCollateral: 50 ether,
validity: block.timestamp + 1 hours,
expiry: block.timestamp + 3 days,
nonce: 10,
fee: fee,
maker: buyer,
paymentAsset: address(weth),
collection: address(mockNFT),
isBull: true
});
}
}