-
Notifications
You must be signed in to change notification settings - Fork 4
/
testv1_1.ts
127 lines (105 loc) · 4.56 KB
/
testv1_1.ts
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { expect } from "chai";
import { ethers, upgrades } from "hardhat";
describe("CreatorDAOCommissionV1_1 test", function () {
it("Should return the new greeting once it's changed", async function () {
const [admin, dao, artist, usr] = await ethers.getSigners();
// const theGmFansStudio = await ethers.getContractFactory("CreatorDAOCommission");
// const beacon = await upgrades.deployBeacon(theGmFansStudio);
// const instance = await upgrades.deployBeaconProxy(beacon, theGmFansStudio, [admin.address, dao.address]);
const gmFans_imp = await ethers.getContractFactory(
"CreatorDAOCommissionV1_1"
);
const gmFans = await upgrades.deployProxy(gmFans_imp, [
admin.address,
admin.address,
]);
await gmFans.deployed();
console.log("CreatorDAOCommission deployed to:", gmFans.address);
let adminBalance = await ethers.provider.getBalance(admin.address);
expect(adminBalance).to.be.gt(ethers.utils.parseEther("1000"));
expect(await gmFans.newShopIndex()).to.be.equal(1);
//add shop
await expect(await gmFans.addShop(1, 50, artist.address))
.to.emit(gmFans, "NewShop")
.withArgs("1", "1", "50", artist.address);
expect(await gmFans.newShopIndex()).to.be.equal(2);
await expect(await gmFans.addShop(10, 100, artist.address))
.to.emit(gmFans, "NewShop")
.withArgs("2", "10", "100", artist.address);
console.log("add shop");
//add commission
await expect(
gmFans
.connect(usr)
.commission("hi", 1, { value: ethers.utils.parseEther("1") })
)
.to.emit(gmFans, "NewCommission")
.withArgs("1", "hi", "1", ethers.utils.parseEther("1"), usr.address);
await expect(
gmFans
.connect(usr)
.commission("test2", 2, { value: ethers.utils.parseEther("1") })
)
.to.emit(gmFans, "NewCommission")
.withArgs("2", "test2", "2", ethers.utils.parseEther("1"), usr.address);
console.log(
"new commission 2",
await ethers.provider.getBalance(usr.address)
);
await expect(
await gmFans
.connect(usr)
.commission("test2", 2, { value: ethers.utils.parseEther("1") })
).to.changeEtherBalance(usr, ethers.utils.parseEther("-1"));
console.log("only owner could accept commission");
await expect(
gmFans.connect(usr).processCommissions([1])
).to.be.revertedWith("Only shop owner could accept commission");
console.log("owner accept commission");
await expect(gmFans.connect(artist).processCommissions([1]))
.to.emit(gmFans, "CommissionProcessed")
.withArgs("1", 1);
// admin settle comission
await expect(
await gmFans.connect(admin).settleCommissions([1])
).to.changeEtherBalance(artist, ethers.utils.parseEther("0.95"));
// settled comission will be set finished
await expect(
gmFans.connect(admin).settleCommissions([1])
).to.be.revertedWith("commission not in the queue");
// await expect(await gmFans.connect(admin).processCommissions([2])).to.changeEtherBalance(dao, ethers.utils.parseEther('0.1'));
await expect(
gmFans.connect(admin).rescindCommissionByAdmin(2)
).to.be.revertedWith("commission not in queue");
await expect(gmFans.connect(artist).processCommissions([2]));
let usrBalanceBefore = await ethers.provider.getBalance(usr.address);
console.log("only admin could rescind accepted commission");
await expect(gmFans.connect(admin).rescindCommissionByAdmin(2))
.to.emit(gmFans, "CommissionRescinded")
.withArgs("2", ethers.utils.parseEther("1"));
let usrBalanceAfter = await ethers.provider.getBalance(usr.address);
expect(
usrBalanceAfter.eq(usrBalanceBefore.add(ethers.utils.parseEther("1")))
);
await expect(
await gmFans
.connect(usr)
.increaseCommissionBid([3], { value: ethers.utils.parseEther("2") })
)
.to.emit(gmFans, "CommissionBidUpdated")
.withArgs(
"3",
ethers.utils.parseEther("2"),
ethers.utils.parseEther("3")
);
// await expect(await gmFans.connect(usr).rescindCommission([3])).to.emit(gmFans, 'CommissionRescinded').withArgs('3', ethers.utils.parseEther('3'));
await expect(
await gmFans.connect(usr).rescindCommission([3])
).to.changeEtherBalance(usr, ethers.utils.parseEther("3"));
await expect((await gmFans.commissions(3)).status).to.eq(2);
await expect(await gmFans.connect(artist).updateShopOwner(1, admin.address))
.to.emit(gmFans, "OwnerUpdated")
.withArgs("1", admin.address);
// await expect(await gmFans.shops(1));
});
});