HackQuest_搭建测试网
uwupu 啦啦啦啦啦

参考文献:https://www.hackquest.io/

Anvil

(和之前的文章重复了?!)

扩展:

1
anvil --fork-url YOUR_ENDPOINT_URL --fork-block-number 19000000

从指定端点fork数据,然后在本地运行。

代码:

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
pragma solidity 0.8.20;
import {Test, console} from "forge-std/Test.sol";
//创建接口
interface IERC20 {
function balanceOf(address) external view returns (uint256);
function transfer(address, uint256) external returns (bool);
function decimals() external view returns (uint8);
}

//执行操作
contract PEPETransferTest is Test {
IERC20 pepe;
address myAddress = 0xF977814e90dA44bFA03b6295A0616a897441aceC;
address recipient = 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045;
address pepeAddress = 0x6982508145454Ce325dDbE47a25d4ec3d2311933;

function setUp() public {
pepe = IERC20(pepeAddress);
vm.startPrank(myAddress);
}

function testPEPETransfer() public {
uint256 recipientBalanceBefore = pepe.balanceOf(recipient);
console.log(
"PEPE balance of recipient before: ",
recipientBalanceBefore
);
pepe.transfer(recipient, 10000000);

uint256 recipientBalanceAfter = pepe.balanceOf(recipient);
console.log("PEPE balance of recipient after: ", recipientBalanceAfter);
assertEq(
recipientBalanceAfter,
recipientBalanceBefore + 10000000,
"failed"
);
}
}

 评论