-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIntegrationGovernanceShareholders.ts
179 lines (153 loc) · 5.67 KB
/
IntegrationGovernanceShareholders.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import chai from "chai";
import chaiAsPromised from "chai-as-promised";
import { solidity } from "ethereum-waffle";
import { parseEther } from "ethers/lib/utils";
import { ethers, network } from "hardhat";
import { GovernanceToken, ShareholderRegistry, Voting } from "../typechain";
import { DEPLOY_SEQUENCE, generateDeployContext } from "../lib";
import { NeokingdomDAOMemory } from "../lib/environment/memory";
chai.use(solidity);
chai.use(chaiAsPromised);
const { expect } = chai;
const e = (v: number) => parseEther(v.toString());
describe("Integration", async () => {
let snapshotId: string;
let voting: Voting;
let governanceToken: GovernanceToken;
let shareholderRegistry: ShareholderRegistry;
let managingBoardStatus: string;
let contributorStatus: string;
let investorStatus: string;
let deployer: SignerWithAddress;
let board: SignerWithAddress;
let reserve: SignerWithAddress;
let user1: SignerWithAddress;
let user2: SignerWithAddress;
let user3: SignerWithAddress;
let free1: SignerWithAddress;
let free2: SignerWithAddress;
let free3: SignerWithAddress;
before(async () => {
[deployer, board, reserve, user1, user2, user3, free1, free2, free3] =
await ethers.getSigners();
const neokingdom = await NeokingdomDAOMemory.initialize({
deployer,
reserve: reserve.address,
});
await neokingdom.run(generateDeployContext, DEPLOY_SEQUENCE);
({ voting, governanceToken, shareholderRegistry } =
await neokingdom.loadContracts());
managingBoardStatus = await shareholderRegistry.MANAGING_BOARD_STATUS();
contributorStatus = await shareholderRegistry.CONTRIBUTOR_STATUS();
investorStatus = await shareholderRegistry.INVESTOR_STATUS();
});
beforeEach(async () => {
snapshotId = await network.provider.send("evm_snapshot");
});
afterEach(async () => {
await network.provider.send("evm_revert", [snapshotId]);
});
it("shares + tokens = voting power", async () => {
async function check({
totalVotingPower = 0,
boardVotingPower = 0,
user1VotingPower = 0,
user2VotingPower = 0,
}) {
expect(await voting.getTotalVotingPower()).equal(e(totalVotingPower));
expect(await voting.getVotingPower(board.address)).equal(
e(boardVotingPower)
);
expect(await voting.getVotingPower(user1.address)).equal(
e(user1VotingPower)
);
expect(await voting.getVotingPower(user2.address)).equal(
e(user2VotingPower)
);
}
// In a real world scenario some shares are held by the DAO, others by the founder
await shareholderRegistry.mint(shareholderRegistry.address, e(3000));
await shareholderRegistry.mint(board.address, e(7000));
await shareholderRegistry.setStatus(managingBoardStatus, board.address);
await check({
totalVotingPower: 7000,
boardVotingPower: 7000,
});
// A share is transferred from the managing board to user1
await shareholderRegistry.transferFrom(board.address, user1.address, e(1));
// User1 is not a contributor yet, so the total voting power is
// decremented
await check({
totalVotingPower: 7000 - 1,
boardVotingPower: 7000 - 1,
});
// user1 is promoted to contributor
await shareholderRegistry.setStatus(contributorStatus, user1.address);
// Total voting power goes back to 7000
await check({
totalVotingPower: 7000,
boardVotingPower: 7000 - 1,
user1VotingPower: 1,
});
// user1 is rewarded with 6000 tokens
await governanceToken.mint(user1.address, e(6000));
await check({
totalVotingPower: 7000 + 6000,
boardVotingPower: 7000 - 1,
user1VotingPower: 1 + 6000,
});
// A share is transferred from the managing board to user2
await shareholderRegistry.transferFrom(board.address, user2.address, e(1));
// user2 is promoted to contributor
await shareholderRegistry.setStatus(contributorStatus, user2.address);
// user2 is rewarded with 3000 tokens
await governanceToken.mint(user2.address, e(3000));
await check({
totalVotingPower: 7000 + 6000 + 3000,
boardVotingPower: 7000 - 1 - 1,
user1VotingPower: 1 + 6000,
user2VotingPower: 1 + 3000,
});
// user2 misbehaves and is demoted to investor
await shareholderRegistry.setStatus(investorStatus, user2.address);
await check({
totalVotingPower: 7000 + 6000 - 1,
boardVotingPower: 7000 - 1 - 1,
user1VotingPower: 1 + 6000,
});
// user2 comes back!
await shareholderRegistry.setStatus(contributorStatus, user2.address);
await check({
totalVotingPower: 7000 + 6000 + 3000,
boardVotingPower: 7000 - 1 - 1,
user1VotingPower: 1 + 6000,
user2VotingPower: 1 + 3000,
});
// user2 delegates user1
await voting.connect(user2).delegate(user1.address);
await check({
totalVotingPower: 7000 + 6000 + 3000,
boardVotingPower: 7000 - 1 - 1,
user1VotingPower: 1 + 6000 + 1 + 3000,
user2VotingPower: 0,
});
// user2 receives more shares (not a real use case, but needed to check the
// logic doesn't fail calculating the totals)
await shareholderRegistry.mint(user2.address, e(2));
await check({
totalVotingPower: 7000 + 6000 + 3000 + 2,
boardVotingPower: 7000 - 1 - 1,
user1VotingPower: 1 + 6000 + 1 + 3000 + 2,
user2VotingPower: 0,
});
// user2 delegates user2
await voting.connect(user2).delegate(user2.address);
await check({
totalVotingPower: 7000 + 6000 + 3000 + 2,
boardVotingPower: 7000 - 1 - 1,
user1VotingPower: 1 + 6000,
user2VotingPower: 1 + 3000 + 2,
});
});
});