forked from OpenZeppelin/ethernaut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Privacy.test.js
68 lines (59 loc) · 1.88 KB
/
Privacy.test.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const PrivacyFactory = artifacts.require('./levels/PrivacyFactory.sol');
const Privacy = artifacts.require('./attacks/Privacy.sol');
const Ethernaut = artifacts.require('./Ethernaut.sol');
const {
BN,
constants,
expectEvent,
expectRevert,
} = require('openzeppelin-test-helpers');
const utils = require('../utils/TestUtils');
const { ethers, upgrades } = require('hardhat');
contract('Privacy', function (accounts) {
let ethernaut;
let level;
let instance;
let player = accounts[0];
let statproxy;
before(async function () {
ethernaut = await utils.getEthernautWithStatsProxy();
level = await PrivacyFactory.new();
await ethernaut.registerLevel(level.address);
instance = await utils.createLevelInstance(
ethernaut,
level.address,
player,
Privacy,
{ from: player, value: web3.utils.toWei('1', 'ether') }
);
});
describe('instance', function () {
it('should start locked', async function () {
assert.equal(await instance.locked(), true);
});
it('should not unlock with any key', async function () {
await expectRevert.unspecified(instance.unlock('0x123'));
});
it('should unlock with the proper key', async function () {
// Read storage.
for (let i = 0; i < 6; i++) {
//console.log(await web3.eth.getStorageAt(instance.address, i));
}
// Read contract storage.
const dataEntry = await web3.eth.getStorageAt(instance.address, 5);
//console.log("data entry " + dataEntry)
const key = '0x' + dataEntry.substring(2, 34);
// Unlock.
await instance.unlock(key);
assert.equal(await instance.locked(), false);
// Factory check (should pass)
const completed = await utils.submitLevelInstance(
ethernaut,
level.address,
instance.address,
player
);
assert.equal(completed, true);
});
});
});