-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy path8-nft-bonanza.ts
More file actions
81 lines (61 loc) · 2.68 KB
/
8-nft-bonanza.ts
File metadata and controls
81 lines (61 loc) · 2.68 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
import { expect } from "chai";
import { Contract, Signer, BigNumber } from "ethers";
import { ethers } from "hardhat";
const BN = BigNumber;
let precision = BN.from(10).pow(18);
let accounts: Signer[];
let attacker: Signer;
let o1: Signer;
let o2: Signer;
let admin: Signer; // should not be used
let adminUser: Signer; // should not be used
let bonanzaMarketplace: Contract;
let nftA: Contract;
let nftB: Contract;
let usdc: Contract; // payment token
/// preliminary state
before(async () => {
accounts = await ethers.getSigners();
[attacker, o1, o2, admin, adminUser] = accounts;
// deploying payment token & NFTs for marketplace
let usdcFactory = await ethers.getContractFactory('Token')
usdc = await usdcFactory.connect(admin).deploy('USDC','USDC')
await usdc.connect(admin).mintPerUser([await adminUser.getAddress()],[precision.mul(100)])
let nftFactory = await ethers.getContractFactory('Nft721')
nftA = await nftFactory.connect(admin).deploy("APES","APES")
nftB = await nftFactory.connect(admin).deploy("ApEs","ApEs")
// adminUser minted NFTs from collections A & B
await nftA.connect(admin).mintForUser(await adminUser.getAddress(),1)
await nftB.connect(admin).mintForUser(await adminUser.getAddress(),1)
// deploying the marketplace & setup
let bonanzaMarketplaceFactory = await ethers.getContractFactory('BonanzaMarketplace')
bonanzaMarketplace = await bonanzaMarketplaceFactory.connect(admin).deploy(
50, // 0.5% fee
await admin.getAddress(),
usdc.address
)
bonanzaMarketplace.connect(admin).addToWhitelist(nftA.address)
bonanzaMarketplace.connect(admin).addToWhitelist(nftB.address)
// adminUser lists NFTs on the bonanza marketplace
await nftA.connect(adminUser).setApprovalForAll(bonanzaMarketplace.address,true)
await nftB.connect(adminUser).setApprovalForAll(bonanzaMarketplace.address,true)
await bonanzaMarketplace.connect(adminUser).createListing(
nftA.address,0,1,precision.mul(100),0
)
await bonanzaMarketplace.connect(adminUser).createListing(
nftB.address,0,1,precision.mul(100),0
)
expect(await nftA.balanceOf(await adminUser.getAddress())).to.be.equal(1)
expect(await nftB.balanceOf(await adminUser.getAddress())).to.be.equal(1)
});
it("solves the challenge", async function () {
// implement solution here
});
/// expected final state
after(async () => {
// attacker steals all listed NFTs from bonanza marketplace
expect(await nftA.balanceOf(await adminUser.getAddress())).to.be.equal(0)
expect(await nftB.balanceOf(await adminUser.getAddress())).to.be.equal(0)
expect(await nftA.balanceOf(await attacker.getAddress())).to.be.equal(1)
expect(await nftB.balanceOf(await attacker.getAddress())).to.be.equal(1)
});