-
Notifications
You must be signed in to change notification settings - Fork 1
/
WalletMining.js
106 lines (85 loc) · 4.16 KB
/
WalletMining.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
// NOTE: Saved here for reference to try and build the Foundry version later.
// NOTE: Saved here for reference to try and build the Foundry version later.
// NOTE: Saved here for reference to try and build the Foundry version later.
const { ethers, upgrades } = require('hardhat');
const { expect } = require('chai');
describe('[Challenge] Wallet mining', function () {
let deployer, player;
let token, authorizer, walletDeployer;
let initialWalletDeployerTokenBalance;
const DEPOSIT_ADDRESS = '0x9b6fb606a9f5789444c17768c6dfcf2f83563801';
const DEPOSIT_TOKEN_AMOUNT = 20000000n * 10n ** 18n;
before(async function () {
/** SETUP SCENARIO - NO NEED TO CHANGE ANYTHING HERE */
[ deployer, ward, player ] = await ethers.getSigners();
// Deploy Damn Valuable Token contract
token = await (await ethers.getContractFactory('DamnValuableToken', deployer)).deploy();
// Deploy authorizer with the corresponding proxy
authorizer = await upgrades.deployProxy(
await ethers.getContractFactory('AuthorizerUpgradeable', deployer),
[ [ ward.address ], [ DEPOSIT_ADDRESS ] ], // initialization data
{ kind: 'uups', initializer: 'init' }
);
expect(await authorizer.owner()).to.eq(deployer.address);
expect(await authorizer.can(ward.address, DEPOSIT_ADDRESS)).to.be.true;
expect(await authorizer.can(player.address, DEPOSIT_ADDRESS)).to.be.false;
// Deploy Safe Deployer contract
walletDeployer = await (await ethers.getContractFactory('WalletDeployer', deployer)).deploy(
token.address
);
expect(await walletDeployer.chief()).to.eq(deployer.address);
expect(await walletDeployer.gem()).to.eq(token.address);
// Set Authorizer in Safe Deployer
await walletDeployer.rule(authorizer.address);
expect(await walletDeployer.mom()).to.eq(authorizer.address);
await expect(walletDeployer.can(ward.address, DEPOSIT_ADDRESS)).not.to.be.reverted;
await expect(walletDeployer.can(player.address, DEPOSIT_ADDRESS)).to.be.reverted;
// Fund Safe Deployer with tokens
initialWalletDeployerTokenBalance = (await walletDeployer.pay()).mul(43);
await token.transfer(
walletDeployer.address,
initialWalletDeployerTokenBalance
);
// Ensure these accounts start empty
expect(await ethers.provider.getCode(DEPOSIT_ADDRESS)).to.eq('0x');
expect(await ethers.provider.getCode(await walletDeployer.fact())).to.eq('0x');
expect(await ethers.provider.getCode(await walletDeployer.copy())).to.eq('0x');
// Deposit large amount of DVT tokens to the deposit address
await token.transfer(DEPOSIT_ADDRESS, DEPOSIT_TOKEN_AMOUNT);
// Ensure initial balances are set correctly
expect(await token.balanceOf(DEPOSIT_ADDRESS)).eq(DEPOSIT_TOKEN_AMOUNT);
expect(await token.balanceOf(walletDeployer.address)).eq(
initialWalletDeployerTokenBalance
);
expect(await token.balanceOf(player.address)).eq(0);
});
it('Execution', async function () {
/** CODE YOUR SOLUTION HERE */
});
after(async function () {
/** SUCCESS CONDITIONS */
// Factory account must have code
expect(
await ethers.provider.getCode(await walletDeployer.fact())
).to.not.eq('0x');
// Master copy account must have code
expect(
await ethers.provider.getCode(await walletDeployer.copy())
).to.not.eq('0x');
// Deposit account must have code
expect(
await ethers.provider.getCode(DEPOSIT_ADDRESS)
).to.not.eq('0x');
// The deposit address and the Safe Deployer contract must not hold tokens
expect(
await token.balanceOf(DEPOSIT_ADDRESS)
).to.eq(0);
expect(
await token.balanceOf(walletDeployer.address)
).to.eq(0);
// Player must own all tokens
expect(
await token.balanceOf(player.address)
).to.eq(initialWalletDeployerTokenBalance.add(DEPOSIT_TOKEN_AMOUNT));
});
});