forked from OpenZeppelin/ethernaut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gatekeeper.test.js
128 lines (111 loc) · 3.05 KB
/
Gatekeeper.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const GatekeeperOneFactory = artifacts.require(
'./levels/GatekeeperOneFactory.sol'
);
const GatekeeperTwoFactory = artifacts.require(
'./levels/GatekeeperTwoFactory.sol'
);
const GatekeeperOne = artifacts.require('./levels/GatekeeperOne.sol');
const GatekeeperTwo = artifacts.require('./levels/GatekeeperTwo.sol');
const GatekeeperOneAttack = artifacts.require(
'./attacks/GatekeeperOneAttack.sol'
);
const GatekeeperTwoAttack = artifacts.require(
'./attacks/GatekeeperTwoAttack.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('GatekeeperOne', function (accounts) {
let ethernaut;
let level;
let owner = accounts[1];
let player = accounts[0];
let statproxy;
before(async function () {
ethernaut = await utils.getEthernautWithStatsProxy();
level = await GatekeeperOneFactory.new();
await ethernaut.registerLevel(level.address);
});
it('should fail if the player didnt solve the level', async function () {
const instance = await utils.createLevelInstance(
ethernaut,
level.address,
player,
GatekeeperOne
);
const completed = await utils.submitLevelInstance(
ethernaut,
level.address,
instance.address,
player
);
assert.isFalse(completed);
});
it('should allow the player to solve the level', async function () {
const instance = await utils.createLevelInstance(
ethernaut,
level.address,
player,
GatekeeperOne
);
const attacker = await GatekeeperOneAttack.new(instance.address, {
from: player,
});
const completed = await utils.submitLevelInstance(
ethernaut,
level.address,
instance.address,
player
);
assert.isTrue(completed);
});
});
contract('GatekeeperTwo', function (accounts) {
let ethernaut;
let level;
let player = accounts[0];
before(async function () {
ethernaut = await utils.getEthernautWithStatsProxy();
level = await GatekeeperTwoFactory.new();
await ethernaut.registerLevel(level.address);
});
it('should fail if the player didnt solve the level', async function () {
const instance = await utils.createLevelInstance(
ethernaut,
level.address,
player,
GatekeeperTwo
);
const completed = await utils.submitLevelInstance(
ethernaut,
level.address,
instance.address,
player
);
assert.isFalse(completed);
});
it('should allow the player to solve the level', async function () {
const instance = await utils.createLevelInstance(
ethernaut,
level.address,
player,
GatekeeperTwo
);
const attacker = await GatekeeperTwoAttack.new(instance.address, {
from: player,
});
const completed = await utils.submitLevelInstance(
ethernaut,
level.address,
instance.address,
player
);
assert.isTrue(completed);
});
});