generated from PaulRBerg/hardhat-template
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtruster.challenge.ts
39 lines (28 loc) · 1.41 KB
/
truster.challenge.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
const { ethers } = require("hardhat");
const { expect } = require("chai");
describe("[Challenge] Truster", function () {
let deployer, attacker;
const TOKENS_IN_POOL = ethers.utils.parseEther("1000000");
before(async function () {
/** SETUP SCENARIO - NO NEED TO CHANGE ANYTHING HERE */
[deployer, attacker] = await ethers.getSigners();
const DamnValuableToken = await ethers.getContractFactory("DamnValuableToken", deployer);
const TrusterLenderPool = await ethers.getContractFactory("TrusterLenderPool", deployer);
this.token = await DamnValuableToken.deploy();
this.pool = await TrusterLenderPool.deploy(this.token.address);
await this.token.transfer(this.pool.address, TOKENS_IN_POOL);
expect(await this.token.balanceOf(this.pool.address)).to.equal(TOKENS_IN_POOL);
expect(await this.token.balanceOf(attacker.address)).to.equal("0");
});
it("Exploit", async function () {
/** CODE YOUR EXPLOIT HERE */
const TrusterAttackerFactory = await ethers.getContractFactory("TrusterAttacker", attacker);
await TrusterAttackerFactory.deploy(TOKENS_IN_POOL, this.pool.address, this.token.address);
});
after(async function () {
/** SUCCESS CONDITIONS */
// Attacker has taken all tokens from the pool
expect(await this.token.balanceOf(attacker.address)).to.equal(TOKENS_IN_POOL);
expect(await this.token.balanceOf(this.pool.address)).to.equal("0");
});
});