-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompromised.challenge.js
More file actions
81 lines (67 loc) · 3.22 KB
/
compromised.challenge.js
File metadata and controls
81 lines (67 loc) · 3.22 KB
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
const { expect } = require('chai');
const { ethers } = require('hardhat');
const { setBalance } = require('@nomicfoundation/hardhat-network-helpers');
describe('Compromised challenge', function () {
let deployer, player;
let oracle, exchange, nftToken;
const sources = [
'0xA73209FB1a42495120166736362A1DfA9F95A105',
'0xe92401A4d3af5E446d93D11EEc806b1462b39D15',
'0x81A5D6E50C214044bE44cA0CB057fe119097850c'
];
const EXCHANGE_INITIAL_ETH_BALANCE = 999n * 10n ** 18n;
const INITIAL_NFT_PRICE = 999n * 10n ** 18n;
const PLAYER_INITIAL_ETH_BALANCE = 1n * 10n ** 17n;
const TRUSTED_SOURCE_INITIAL_ETH_BALANCE = 2n * 10n ** 18n;
before(async function () {
/** SETUP SCENARIO - NO NEED TO CHANGE ANYTHING HERE */
[deployer, player] = await ethers.getSigners();
// Initialize balance of the trusted source addresses
for (let i = 0; i < sources.length; i++) {
setBalance(sources[i], TRUSTED_SOURCE_INITIAL_ETH_BALANCE);
expect(await ethers.provider.getBalance(sources[i])).to.equal(TRUSTED_SOURCE_INITIAL_ETH_BALANCE);
}
// Player starts with limited balance
setBalance(player.address, PLAYER_INITIAL_ETH_BALANCE);
expect(await ethers.provider.getBalance(player.address)).to.equal(PLAYER_INITIAL_ETH_BALANCE);
// Deploy the oracle and setup the trusted sources with initial prices
const TrustfulOracleInitializerFactory = await ethers.getContractFactory('TrustfulOracleInitializer', deployer);
oracle = await (await ethers.getContractFactory('TrustfulOracle', deployer)).attach(
await (await TrustfulOracleInitializerFactory.deploy(
sources,
['DVNFT', 'DVNFT', 'DVNFT'],
[INITIAL_NFT_PRICE, INITIAL_NFT_PRICE, INITIAL_NFT_PRICE]
)).oracle()
);
// Deploy the exchange and get an instance to the associated ERC721 token
exchange = await (await ethers.getContractFactory('Exchange', deployer)).deploy(
oracle.address,
{ value: EXCHANGE_INITIAL_ETH_BALANCE }
);
nftToken = await (await ethers.getContractFactory('DamnValuableNFT', deployer)).attach(await exchange.token());
expect(await nftToken.owner()).to.eq(ethers.constants.AddressZero); // ownership renounced
expect(await nftToken.rolesOf(exchange.address)).to.eq(await nftToken.MINTER_ROLE());
});
it('Execution', async function () {
/** CODE YOUR SOLUTION HERE */
});
after(async function () {
/** SUCCESS CONDITIONS - NO NEED TO CHANGE ANYTHING HERE */
// Exchange must have lost all ETH
expect(
await ethers.provider.getBalance(exchange.address)
).to.be.eq(0);
// Player's ETH balance must have significantly increased
expect(
await ethers.provider.getBalance(player.address)
).to.be.gt(EXCHANGE_INITIAL_ETH_BALANCE);
// Player must not own any NFT
expect(
await nftToken.balanceOf(player.address)
).to.be.eq(0);
// NFT price shouldn't have changed
expect(
await oracle.getMedianPrice('DVNFT')
).to.eq(INITIAL_NFT_PRICE);
});
});