generated from nicobevilacqua/hardhat-solidity-typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 7
/
20-TokenBank.test.ts
47 lines (35 loc) · 1.21 KB
/
20-TokenBank.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
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { expect } from 'chai';
import { Contract } from 'ethers';
import { ethers } from 'hardhat';
const { utils } = ethers;
const TOTAL_TOKENS_SUPPLY = 1000000;
describe('TokenBankChallenge', () => {
let target: Contract;
let token: Contract;
let attacker: SignerWithAddress;
let deployer: SignerWithAddress;
before(async () => {
[attacker, deployer] = await ethers.getSigners();
const [targetFactory, tokenFactory] = await Promise.all([
ethers.getContractFactory('TokenBankChallenge', deployer),
ethers.getContractFactory('SimpleERC223Token', deployer),
]);
target = await targetFactory.deploy(attacker.address);
await target.deployed();
const tokenAddress = await target.token();
token = await tokenFactory.attach(tokenAddress);
await token.deployed();
target = target.connect(attacker);
token = token.connect(attacker);
});
it('exploit', async () => {
/**
* YOUR CODE HERE
* */
expect(await token.balanceOf(target.address)).to.equal(0);
expect(await token.balanceOf(attacker.address)).to.equal(
utils.parseEther(TOTAL_TOKENS_SUPPLY.toString())
);
});
});