forked from OpenZeppelin/ethernaut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MagicNum.test.js
67 lines (56 loc) · 1.77 KB
/
MagicNum.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
const MagicNumFactory = artifacts.require('./levels/MagicNumFactory.sol');
const MagicNum = artifacts.require('./levels/MagicNum.sol');
const MagicNumSolver = artifacts.require('./attacks/MagicNumSolver.sol');
const MagicNumBadSolver = artifacts.require('./attacks/MagicNumBadSolver.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('MagicNum', function (accounts) {
let ethernaut;
let level;
let instance;
let player = accounts[0];
let statproxy;
before(async function () {
ethernaut = await utils.getEthernautWithStatsProxy();
level = await MagicNumFactory.new();
await ethernaut.registerLevel(level.address);
instance = await utils.createLevelInstance(
ethernaut,
level.address,
player,
MagicNum,
{ from: player }
);
});
describe('instance', function () {
it('should not be solvable with a contract created regularly', async function () {
const badSolver = await MagicNumBadSolver.new();
await instance.setSolver(badSolver.address);
const completed = await utils.submitLevelInstance(
ethernaut,
level.address,
instance.address,
player
);
assert.isFalse(completed);
});
it('should be solvable with a manually constructed contract', async function () {
const solver = await MagicNumSolver.new();
await instance.setSolver(solver.address);
const completed = await utils.submitLevelInstance(
ethernaut,
level.address,
instance.address,
player
);
assert.isTrue(completed);
});
});
});