generated from nicobevilacqua/hardhat-solidity-typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGuessTheNewNumberChallenge.test.ts
34 lines (29 loc) · 1.01 KB
/
GuessTheNewNumberChallenge.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
import { expect } from 'chai';
import { Contract } from 'ethers';
import { ethers, network } from 'hardhat';
const { utils, provider } = ethers;
describe('GuessTheNewNumberChallenge', () => {
let target: Contract;
before(async () => {
const targetFactory = await ethers.getContractFactory('GuessTheNewNumberChallenge');
target = await targetFactory.deploy({
value: utils.parseEther('1'),
});
await target.deployed();
console.log('Target deployed to:', target.address);
});
it('Exploit', async () => {
const attackerFactory = await ethers.getContractFactory('GuessTheNewNumberChallengeAttacker');
const attacker = await attackerFactory.deploy(target.address);
await attacker.deployed();
console.log('attacker deployed on', attacker.address);
console.log('Attacking');
const tx = await attacker.attack({
value: utils.parseEther('1'),
});
await tx.wait();
});
after(async () => {
expect(await provider.getBalance(target.address)).to.equal(0);
});
});