polkamarkets-js 1.0.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/.openzeppelin/unknown-1337.json +2056 -0
  2. package/CONTRIBUTING.md +36 -0
  3. package/README.md +24 -25
  4. package/_book/README.md +590 -0
  5. package/_book/core.md +50 -0
  6. package/_book/gitbook/fonts/fontawesome/FontAwesome.otf +0 -0
  7. package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.eot +0 -0
  8. package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.svg +685 -0
  9. package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.ttf +0 -0
  10. package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.woff +0 -0
  11. package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.woff2 +0 -0
  12. package/_book/gitbook/gitbook-plugin-fontsettings/fontsettings.js +240 -0
  13. package/_book/gitbook/gitbook-plugin-fontsettings/website.css +291 -0
  14. package/_book/gitbook/gitbook-plugin-highlight/ebook.css +135 -0
  15. package/_book/gitbook/gitbook-plugin-highlight/website.css +434 -0
  16. package/_book/gitbook/gitbook-plugin-lunr/lunr.min.js +7 -0
  17. package/_book/gitbook/gitbook-plugin-lunr/search-lunr.js +59 -0
  18. package/_book/gitbook/gitbook-plugin-search/lunr.min.js +7 -0
  19. package/_book/gitbook/gitbook-plugin-search/search-engine.js +50 -0
  20. package/_book/gitbook/gitbook-plugin-search/search.css +35 -0
  21. package/_book/gitbook/gitbook-plugin-search/search.js +213 -0
  22. package/_book/gitbook/gitbook-plugin-sharing/buttons.js +90 -0
  23. package/_book/gitbook/gitbook.js +4 -0
  24. package/_book/gitbook/images/apple-touch-icon-precomposed-152.png +0 -0
  25. package/_book/gitbook/images/favicon.ico +0 -0
  26. package/_book/gitbook/style.css +9 -0
  27. package/_book/gitbook/theme.js +4 -0
  28. package/_book/index.html +705 -0
  29. package/_book/intro.md +32 -0
  30. package/_book/search_index.json +1 -0
  31. package/book.json +8 -0
  32. package/build/contracts/AccessControl.json +1 -0
  33. package/build/contracts/AccessControlEnumerable.json +1 -0
  34. package/build/contracts/Achievements.json +1 -0
  35. package/build/contracts/Address.json +1 -0
  36. package/build/contracts/BalanceHolder.json +1 -0
  37. package/build/contracts/BalanceHolder_ERC20.json +1 -0
  38. package/build/contracts/CeilDiv.json +1 -0
  39. package/build/contracts/Clones.json +1 -0
  40. package/build/contracts/Context.json +1 -0
  41. package/build/contracts/Counters.json +1 -0
  42. package/build/contracts/ERC165.json +1 -0
  43. package/build/contracts/ERC20.json +1 -0
  44. package/build/contracts/ERC20Burnable.json +1 -0
  45. package/build/contracts/ERC20Pausable.json +1 -0
  46. package/build/contracts/ERC20PresetMinterPauser.json +1 -0
  47. package/build/contracts/ERC721.json +1 -0
  48. package/build/contracts/EnumerableMap.json +1 -0
  49. package/build/contracts/EnumerableSet.json +1 -0
  50. package/build/contracts/FantasyERC20.json +1 -0
  51. package/build/contracts/IAccessControl.json +1 -0
  52. package/build/contracts/IAccessControlEnumerable.json +1 -0
  53. package/build/contracts/IBalanceHolder_ERC20.json +1 -0
  54. package/build/contracts/IERC165.json +1 -0
  55. package/build/contracts/IERC20.json +1 -0
  56. package/build/contracts/IERC20Metadata.json +1 -0
  57. package/build/contracts/IERC20Permit.json +1 -0
  58. package/build/contracts/IERC721.json +1 -0
  59. package/build/contracts/IERC721Enumerable.json +1 -0
  60. package/build/contracts/IERC721Metadata.json +1 -0
  61. package/build/contracts/IERC721Receiver.json +1 -0
  62. package/build/contracts/IFantasyERC20.json +1 -0
  63. package/build/contracts/IPredictionMarketV3.json +1 -0
  64. package/build/contracts/IPredictionMarketV3Factory.json +1 -0
  65. package/build/contracts/IPredictionMarketV3Manager.json +1 -0
  66. package/build/contracts/IRealityETH_ERC20.json +1 -0
  67. package/build/contracts/IRealityETH_IERC20.json +1 -0
  68. package/build/contracts/IWETH.json +1 -0
  69. package/build/contracts/LandFactory.json +1 -0
  70. package/build/contracts/Math.json +1 -0
  71. package/build/contracts/Migrations.json +1 -0
  72. package/build/contracts/Ownable.json +1 -0
  73. package/build/contracts/Pausable.json +1 -0
  74. package/build/contracts/PredictionMarket.json +1 -0
  75. package/build/contracts/PredictionMarketV2.json +1 -0
  76. package/build/contracts/PredictionMarketV3.json +1 -0
  77. package/build/contracts/PredictionMarketV3Controller.json +1 -0
  78. package/build/contracts/PredictionMarketV3Factory.json +1 -0
  79. package/build/contracts/PredictionMarketV3Manager.json +1 -0
  80. package/build/contracts/PredictionMarketV3Querier.json +1 -0
  81. package/build/contracts/RealitioERC20.json +1 -0
  82. package/build/contracts/RealitioForeignArbitrationProxyWithAppeals.json +1 -0
  83. package/build/contracts/RealitioHomeArbitrationProxy.json +1 -0
  84. package/build/contracts/RealitioSafeMath256.json +1 -0
  85. package/build/contracts/RealitioSafeMath32.json +1 -0
  86. package/build/contracts/RealityETH_ERC20_Factory.json +1 -0
  87. package/build/contracts/RealityETH_ERC20_v3_0.json +1 -0
  88. package/build/contracts/ReentrancyGuard.json +1 -0
  89. package/build/contracts/SafeERC20.json +1 -0
  90. package/build/contracts/SafeMath.json +1 -0
  91. package/build/contracts/Strings.json +1 -0
  92. package/build/contracts/Voting.json +1 -0
  93. package/build/contracts/WETH9.json +1 -0
  94. package/build/contracts/test.json +1 -0
  95. package/cleanContracts.js +22 -0
  96. package/contracts/FantasyERC20.sol +81 -0
  97. package/contracts/IFantasyERC20.sol +20 -0
  98. package/contracts/IPredictionMarketV3.sol +207 -0
  99. package/contracts/IPredictionMarketV3Factory.sol +10 -0
  100. package/contracts/IPredictionMarketV3Manager.sol +12 -0
  101. package/contracts/IRealityETH_ERC20.sol +64 -0
  102. package/contracts/LandFactory.sol +248 -0
  103. package/contracts/Migrations.sol +24 -0
  104. package/contracts/PredictionMarketV3.sol +1332 -0
  105. package/contracts/PredictionMarketV3Controller.sol +87 -0
  106. package/contracts/PredictionMarketV3Factory.sol +205 -0
  107. package/contracts/PredictionMarketV3Manager.sol +45 -0
  108. package/contracts/PredictionMarketV3Querier.sol +79 -0
  109. package/contracts/RealityETH_ERC20_Factory.sol +54 -0
  110. package/contracts/Voting.sol +153 -0
  111. package/contracts/WETH9.sol +62 -0
  112. package/help.txt +8 -0
  113. package/index.js +3 -0
  114. package/migrations/10_deploy_weth.js +5 -0
  115. package/migrations/11_deploy_full_flow.js +99 -0
  116. package/migrations/12_deploy_pm_v3_querier.js +7 -0
  117. package/migrations/13_deploy_pm_v3_factory.js +14 -0
  118. package/migrations/1_initial_migration.js +5 -0
  119. package/migrations/2_deploy_erc20.js +10 -0
  120. package/migrations/3_deploy_realitio.js +11 -0
  121. package/migrations/4_deploy_pm.js +20 -0
  122. package/migrations/5_seed_markets.js +51 -0
  123. package/migrations/6_deploy_achievements.js +5 -0
  124. package/migrations/7_deploy_voting.js +14 -0
  125. package/migrations/8_deploy_pm_v2.js +20 -0
  126. package/migrations/9_seed_markets_v2.js +68 -0
  127. package/package.json +106 -13
  128. package/src/Application.js +421 -0
  129. package/src/interfaces/index.js +19 -0
  130. package/src/models/AchievementsContract.js +217 -0
  131. package/src/models/ArbitrationContract.js +69 -0
  132. package/src/models/ArbitrationProxyContract.js +32 -0
  133. package/src/models/ERC20Contract.js +156 -0
  134. package/src/models/FantasyERC20Contract.js +92 -0
  135. package/src/models/IContract.js +1002 -0
  136. package/src/models/PolkamarketsSmartAccount.js +100 -0
  137. package/src/models/PredictionMarketContract.js +562 -0
  138. package/src/models/PredictionMarketV2Contract.js +830 -0
  139. package/src/models/PredictionMarketV3Contract.js +233 -0
  140. package/src/models/PredictionMarketV3ControllerContract.js +102 -0
  141. package/src/models/PredictionMarketV3FactoryContract.js +96 -0
  142. package/src/models/PredictionMarketV3ManagerContract.js +111 -0
  143. package/src/models/PredictionMarketV3QuerierContract.js +24 -0
  144. package/src/models/RealitioERC20Contract.js +286 -0
  145. package/src/models/VotingContract.js +182 -0
  146. package/src/models/WETH9Contract.js +92 -0
  147. package/src/models/index.js +33 -0
  148. package/src/utils/Account.js +40 -0
  149. package/src/utils/Contract.js +120 -0
  150. package/src/utils/Numbers.js +94 -0
  151. package/tests/fantasyERC20Contract.js +225 -0
  152. package/tests/index.js +10 -0
  153. package/tests/predictionMarketContract.js +466 -0
  154. package/tests/predictionMarketV2Contract.js +1042 -0
  155. package/tests/predictionMarketV3Contract.js +1079 -0
  156. package/tests/predictionMarketV3ControllerContract.js +613 -0
  157. package/tests/predictionMarketV3FactoryContract.js +469 -0
  158. package/tests/predictionMarketV3ManagerContract.js +610 -0
  159. package/tests/utils.js +16 -0
  160. package/tests/votingContract.js +490 -0
  161. package/tooling/docs/jsdoc.json +6 -0
  162. package/truffle-config.js +134 -0
  163. package/polkamarkets.js +0 -422
@@ -0,0 +1,469 @@
1
+
2
+
3
+ import { expect } from 'chai';
4
+
5
+ import { mochaAsync } from './utils';
6
+ import { Application } from '..';
7
+
8
+ context('Prediction Market Factory V3 Contract', async () => {
9
+ require('dotenv').config();
10
+
11
+ const TOKEN_AMOUNT_TO_CLAIM = 10;
12
+ const LOCK_AMOUNT = 5;
13
+ const NEW_LOCK_AMOUNT = 1;
14
+
15
+ const USER1_ADDRESS = process.env.TEST_USER1_ADDRESS;
16
+ const USER1_PRIVATE_KEY = process.env.TEST_USER1_PRIVATE_KEY;
17
+ const USER2_ADDRESS = process.env.TEST_USER2_ADDRESS;
18
+
19
+ let app;
20
+ let accountAddress;
21
+ let predictionMarketFactoryContract;
22
+ let predictionMarketContract;
23
+ let pmfTokenContract;
24
+ let realitioERC20Contract;
25
+
26
+ context('Contract Deployment', async () => {
27
+ it('should start the Application', mochaAsync(async () => {
28
+ app = new Application({
29
+ web3Provider: process.env.WEB3_PROVIDER,
30
+ web3PrivateKey: process.env.WEB3_PRIVATE_KEY
31
+ });
32
+ expect(app).to.not.equal(null);
33
+ }));
34
+
35
+ it('should deploy Prediction Market Factory Contract', mochaAsync(async () => {
36
+ accountAddress = await app.getAddress();
37
+
38
+ // Create Contract
39
+ predictionMarketContract = app.getPredictionMarketV3Contract({});
40
+ pmfTokenContract = app.getERC20Contract({});
41
+ realitioERC20Contract = app.getRealitioERC20Contract({});
42
+
43
+ await realitioERC20Contract.deploy({});
44
+
45
+ // Deploy
46
+ await pmfTokenContract.deploy({ params: ['Polkamarkets', 'POLK'] });
47
+ const pmfTokenContractAddress = pmfTokenContract.getAddress();
48
+
49
+ predictionMarketFactoryContract = app.getPredictionMarketV3FactoryContract({});
50
+ // Deploy
51
+ await predictionMarketContract.deploy({
52
+ params: [
53
+ '0x0000000000000000000000000000000000000000'
54
+ ]
55
+ });
56
+ const predictionMarketContractAddress = predictionMarketContract.getAddress();
57
+
58
+ await predictionMarketFactoryContract.deploy({params:
59
+ [
60
+ pmfTokenContractAddress,
61
+ (LOCK_AMOUNT * 10**18).toString(), // TODO: improve this
62
+ predictionMarketContractAddress,
63
+ realitioERC20Contract.getAddress()
64
+ ]});
65
+ const predictionMarketFactoryContractAddress = predictionMarketFactoryContract.getAddress();
66
+
67
+ await pmfTokenContract.mint({
68
+ address: accountAddress,
69
+ amount: '1000'
70
+ });
71
+ await pmfTokenContract.approve({
72
+ address: predictionMarketFactoryContractAddress,
73
+ amount: '1000000'
74
+ });
75
+
76
+ expect(predictionMarketContractAddress).to.not.equal(null);
77
+ expect(pmfTokenContractAddress).to.not.equal(null);
78
+ }));
79
+ });
80
+
81
+ context('Prediction Controller Management', async () => {
82
+ context('Create Controller', async () => {
83
+ it('should create a Prediction Controller', mochaAsync(async () => {
84
+ const currentControllerIndex = await predictionMarketFactoryContract.getControllersLength();
85
+ const currentPmfTokenBalance = await pmfTokenContract.balanceOf({ address: accountAddress });
86
+
87
+ await predictionMarketFactoryContract.createPMController({
88
+ PMV3: '0x0000000000000000000000000000000000000000',
89
+ });
90
+
91
+ const pmController = await predictionMarketFactoryContract.getPMControllerById({ id: currentControllerIndex });
92
+ const newControllerIndex = await predictionMarketFactoryContract.getControllersLength();
93
+ const newPmfTokenBalance = await pmfTokenContract.balanceOf({ address: accountAddress });
94
+
95
+ expect(newPmfTokenBalance).to.equal(currentPmfTokenBalance - LOCK_AMOUNT);
96
+ expect(newControllerIndex).to.equal(currentControllerIndex + 1);
97
+ expect(pmController.active).to.equal(true);
98
+ expect(pmController.lockAmount).to.equal(LOCK_AMOUNT);
99
+ expect(pmController.lockUser).to.equal(accountAddress);
100
+
101
+ const pmControllerAddress = await predictionMarketFactoryContract.getPMControllerAddressById({ id: currentControllerIndex });
102
+
103
+ expect(pmControllerAddress).not.to.equal('0x0000000000000000000000000000000000000000');
104
+
105
+ const predictionMarketControllerContract = app.getPredictionMarketV3ControllerContract({ contractAddress: pmControllerAddress});
106
+ const landTokensLenght = await predictionMarketControllerContract.getLandTokensLength();
107
+
108
+ expect(landTokensLenght).to.equal(0);
109
+ }));
110
+
111
+ it('should create another Controller', mochaAsync(async () => {
112
+ const currentControllerIndex = await predictionMarketFactoryContract.getControllersLength();
113
+ const currentPmfTokenBalance = await pmfTokenContract.balanceOf({ address: accountAddress });
114
+
115
+ await predictionMarketFactoryContract.createPMController({
116
+ PMV3: '0x0000000000000000000000000000000000000000',
117
+ });
118
+
119
+ const pmController = await predictionMarketFactoryContract.getPMControllerById({ id: currentControllerIndex });
120
+ const newControllerIndex = await predictionMarketFactoryContract.getControllersLength();
121
+ const newPmfTokenBalance = await pmfTokenContract.balanceOf({ address: accountAddress });
122
+
123
+ expect(newPmfTokenBalance).to.equal(currentPmfTokenBalance - LOCK_AMOUNT);
124
+ expect(newControllerIndex).to.equal(currentControllerIndex + 1);
125
+ expect(pmController.active).to.equal(true);
126
+ expect(pmController.lockAmount).to.equal(LOCK_AMOUNT);
127
+ expect(pmController.lockUser).to.equal(accountAddress);
128
+
129
+ const pmControllerAddress = await predictionMarketFactoryContract.getPMControllerAddressById({ id: currentControllerIndex });
130
+
131
+ expect(pmControllerAddress).not.to.equal('0x0000000000000000000000000000000000000000');
132
+
133
+ const predictionMarketControllerContract = app.getPredictionMarketV3ControllerContract({ contractAddress: pmControllerAddress });
134
+ const landTokensLenght = await predictionMarketControllerContract.getLandTokensLength();
135
+
136
+ expect(landTokensLenght).to.equal(0);
137
+ }));
138
+ });
139
+
140
+ context('Controller Admins', async () => {
141
+ let controllerId = 0;
142
+ let controllerAddress;
143
+
144
+ const user1 = USER1_ADDRESS;
145
+ const user2 = USER2_ADDRESS;
146
+
147
+ let user1App;
148
+ let user1PredictionMarketFactoryContract;
149
+
150
+ before(mochaAsync(async () => {
151
+ controllerAddress = await predictionMarketFactoryContract.getPMControllerAddressById({ id: controllerId });
152
+
153
+ user1App = new Application({
154
+ web3Provider: process.env.WEB3_PROVIDER,
155
+ web3PrivateKey: USER1_PRIVATE_KEY
156
+ });
157
+
158
+ user1PredictionMarketFactoryContract = user1App.getPredictionMarketV3FactoryContract({
159
+ contractAddress: predictionMarketFactoryContract.getAddress()
160
+ });
161
+ }));
162
+
163
+ it('should add an admin to a Controller', mochaAsync(async () => {
164
+ const currentIsAdmin = await predictionMarketFactoryContract.isPMControllerAdmin({ controllerAddress, user: user2 });
165
+
166
+ await predictionMarketFactoryContract.addAdminToPMController({
167
+ controllerAddress,
168
+ user: user2
169
+ });
170
+
171
+ const newIsAdmin = await predictionMarketFactoryContract.isPMControllerAdmin({ controllerAddress, user: user2 });
172
+
173
+ expect(currentIsAdmin).to.equal(false);
174
+ expect(newIsAdmin).to.equal(true);
175
+ }));
176
+
177
+ it('should remove an admin from a Controller', mochaAsync(async () => {
178
+ const currentIsAdmin = await predictionMarketFactoryContract.isPMControllerAdmin({ controllerAddress, user: user2 });
179
+ await predictionMarketFactoryContract.removeAdminFromPMController({
180
+ controllerAddress,
181
+ user: user2
182
+ });
183
+ const newIsAdmin = await predictionMarketFactoryContract.isPMControllerAdmin({ controllerAddress, user: user2 });
184
+
185
+ expect(currentIsAdmin).to.equal(true);
186
+ expect(newIsAdmin).to.equal(false);
187
+ }));
188
+
189
+ it('should not remove from admin the user that locked the tokens from a Controller', mochaAsync(async () => {
190
+ const currentIsAdmin = await predictionMarketFactoryContract.isPMControllerAdmin({ controllerAddress, user: accountAddress });
191
+ try {
192
+ await predictionMarketFactoryContract.removeAdminFromPMController({
193
+ controllerAddress,
194
+ user: accountAddress
195
+ });
196
+ } catch(e) {
197
+ // not logging error, as tx is expected to fail
198
+ }
199
+ const newIsAdmin = await predictionMarketFactoryContract.isPMControllerAdmin({ controllerAddress, user: accountAddress });
200
+
201
+ expect(currentIsAdmin).to.equal(true);
202
+ expect(newIsAdmin).to.equal(true);
203
+ }));
204
+
205
+ it('should not be able to add an admin to a Controller if not an admin making the call', mochaAsync(async () => {
206
+ const currentIsAdmin = await predictionMarketFactoryContract.isPMControllerAdmin({ controllerAddress, user: user2 });
207
+ try {
208
+ await user1PredictionMarketFactoryContract.addAdminToPMController({
209
+ controllerAddress,
210
+ user: user2
211
+ });
212
+ } catch(e) {
213
+ // not logging error, as tx is expected to fail
214
+ }
215
+ const newIsAdmin = await predictionMarketFactoryContract.isPMControllerAdmin({ controllerAddress, user: user2 });
216
+
217
+ expect(currentIsAdmin).to.equal(false);
218
+ expect(newIsAdmin).to.equal(false);
219
+ }));
220
+
221
+ it('should be able to add/remove an admin to a Controller after being made admin', mochaAsync(async () => {
222
+ await predictionMarketFactoryContract.addAdminToPMController({
223
+ controllerAddress,
224
+ user: user1
225
+ });
226
+
227
+ const currentIsAdmin = await predictionMarketFactoryContract.isPMControllerAdmin({ controllerAddress, user: user2 });
228
+ await user1PredictionMarketFactoryContract.addAdminToPMController({
229
+ controllerAddress,
230
+ user: user2
231
+ });
232
+ const newIsAdmin = await predictionMarketFactoryContract.isPMControllerAdmin({ controllerAddress, user: user2 });
233
+
234
+ expect(currentIsAdmin).to.equal(false);
235
+ expect(newIsAdmin).to.equal(true);
236
+
237
+ await user1PredictionMarketFactoryContract.removeAdminFromPMController({
238
+ controllerAddress,
239
+ user: user2
240
+ });
241
+ const lastNewIsAdmin = await predictionMarketFactoryContract.isPMControllerAdmin({ controllerAddress, user: user2 });
242
+
243
+ expect(lastNewIsAdmin).to.equal(false);
244
+
245
+ // resetting user1 admin status
246
+ await predictionMarketFactoryContract.removeAdminFromPMController({
247
+ controllerAddress,
248
+ user: user1
249
+ });
250
+ }));
251
+
252
+
253
+
254
+ it('should be able to create a land if admin of a Controller', mochaAsync(async () => {
255
+ const currentIsAdmin = await predictionMarketFactoryContract.isPMControllerAdmin({ controllerAddress, user: accountAddress });
256
+
257
+ const predictionMarketControllerContract = app.getPredictionMarketV3ControllerContract({ contractAddress: controllerAddress });
258
+
259
+ const currentLandIndex = await predictionMarketControllerContract.getLandTokensLength();
260
+
261
+ await predictionMarketControllerContract.createLand({
262
+ name: 'Token',
263
+ symbol: 'TOKEN',
264
+ tokenAmountToClaim: TOKEN_AMOUNT_TO_CLAIM,
265
+ tokenToAnswer: pmfTokenContract.getAddress(),
266
+ everyoneCanCreateMarkets: false,
267
+ });
268
+
269
+ const land = await predictionMarketControllerContract.getLandById({ id: currentLandIndex });
270
+ const newLandIndex = await predictionMarketControllerContract.getLandTokensLength();
271
+
272
+ expect(currentIsAdmin).to.equal(true);
273
+ expect(newLandIndex).to.equal(currentLandIndex + 1);
274
+ expect(land.token).to.not.equal('0x0000000000000000000000000000000000000000');
275
+ expect(land.active).to.equal(true);
276
+ expect(land.realitio).to.not.equal('0x0000000000000000000000000000000000000000');
277
+ }));
278
+
279
+ it('should not be able to create a land if not admin of a Controller', mochaAsync(async () => {
280
+ const predictionMarketControllerContract = user1App.getPredictionMarketV3ControllerContract({ contractAddress: controllerAddress });
281
+ const currentIsAdmin = await predictionMarketFactoryContract.isPMControllerAdmin({ controllerAddress, user: user1 });
282
+
283
+
284
+ const currentLandIndex = await predictionMarketControllerContract.getLandTokensLength();
285
+
286
+ try {
287
+ await predictionMarketControllerContract.createLand({
288
+ name: 'Token',
289
+ symbol: 'TOKEN',
290
+ tokenAmountToClaim: TOKEN_AMOUNT_TO_CLAIM,
291
+ tokenToAnswer: pmfTokenContract.getAddress()
292
+ });
293
+ } catch (e) {
294
+ // not logging error, as tx is expected to fail
295
+ }
296
+ const newLandIndex = await predictionMarketControllerContract.getLandTokensLength();
297
+
298
+ expect(currentIsAdmin).to.equal(false);
299
+ expect(newLandIndex).to.equal(currentLandIndex);
300
+ }));
301
+ });
302
+
303
+ context('Controller Disabling + Enabling + Offset', async () => {
304
+ let controllerId = 0;
305
+ let controller;
306
+ let controllerAddress;
307
+
308
+ let user1App;
309
+ let user1PredictionMarketFactoryContract;
310
+
311
+ let landTokenContract;
312
+
313
+ before(mochaAsync(async () => {
314
+ controllerAddress = await predictionMarketFactoryContract.getPMControllerAddressById({ id: controllerId });
315
+ controller = await predictionMarketFactoryContract.getPMControllerByAddress({ controllerAddress });
316
+
317
+ user1App = new Application({
318
+ web3Provider: process.env.WEB3_PROVIDER,
319
+ web3PrivateKey: USER1_PRIVATE_KEY
320
+ });
321
+ user1PredictionMarketFactoryContract = user1App.getPredictionMarketV3FactoryContract({
322
+ contractAddress: predictionMarketFactoryContract.getAddress()
323
+ });
324
+
325
+ const pmControllerAddress = await predictionMarketFactoryContract.getPMControllerAddressById({ id: controllerId });
326
+ const predictionMarketControllerContract = app.getPredictionMarketV3ControllerContract({ contractAddress: pmControllerAddress });
327
+ const land = await predictionMarketControllerContract.getLandById({ id: 0 });
328
+ landTokenContract = app.getFantasyERC20Contract({ contractAddress: land.token });
329
+ }));
330
+
331
+ it('should not be able to disable a Controller if not an admin making the call', mochaAsync(async () => {
332
+ try {
333
+ await user1PredictionMarketFactoryContract.disablePMController({
334
+ controllerAddress
335
+ });
336
+ } catch(e) {
337
+ // not logging error, as tx is expected to fail
338
+ }
339
+
340
+ const refreshedController = await user1PredictionMarketFactoryContract.getPMControllerByAddress({ controllerAddress });
341
+
342
+ expect(controller.active).to.equal(true);
343
+ expect(refreshedController.active).to.equal(true);
344
+ }));
345
+
346
+ it('should disable a Controller', mochaAsync(async () => {
347
+ const currentPmfTokenBalance = await pmfTokenContract.balanceOf({ address: accountAddress });
348
+ const currentPaused = await landTokenContract.paused();
349
+ await predictionMarketFactoryContract.disablePMController({
350
+ controllerAddress
351
+ });
352
+
353
+ const refreshedController = await user1PredictionMarketFactoryContract.getPMControllerByAddress({ controllerAddress });
354
+ const newPmfTokenBalance = await pmfTokenContract.balanceOf({ address: accountAddress });
355
+ const newPaused = await landTokenContract.paused();
356
+
357
+ expect(controller.active).to.equal(true);
358
+ expect(currentPaused).to.equal(false);
359
+ expect(newPaused).to.equal(true);
360
+ expect(newPmfTokenBalance).to.equal(currentPmfTokenBalance + LOCK_AMOUNT);
361
+ expect(refreshedController.token).to.equal(controller.token);
362
+ expect(refreshedController.active).to.equal(false);
363
+ expect(refreshedController.lockAmount).to.equal(0);
364
+ expect(refreshedController.lockUser).to.equal('0x0000000000000000000000000000000000000000');
365
+ }));
366
+
367
+ it('should not be able to disable a Controller if already disabled', mochaAsync(async () => {
368
+ const currentPmfTokenBalance = await pmfTokenContract.balanceOf({ address: accountAddress });
369
+ try {
370
+ await predictionMarketFactoryContract.disablePMController({
371
+ controllerAddress
372
+ });
373
+ } catch(e) {
374
+ // not logging error, as tx is expected to fail
375
+ }
376
+
377
+ const refreshedController = await user1PredictionMarketFactoryContract.getPMControllerByAddress({ controllerAddress });
378
+ const newPmfTokenBalance = await pmfTokenContract.balanceOf({ address: accountAddress });
379
+
380
+ expect(refreshedController.active).to.equal(false);
381
+ expect(newPmfTokenBalance).to.equal(currentPmfTokenBalance);
382
+ }));
383
+
384
+ it('should enable a Controller', mochaAsync(async () => {
385
+ const currentPmfTokenBalance = await pmfTokenContract.balanceOf({ address: accountAddress });
386
+ const currentPaused = await landTokenContract.paused();
387
+ await predictionMarketFactoryContract.enablePMController({
388
+ controllerAddress
389
+ });
390
+
391
+ const refreshedController = await user1PredictionMarketFactoryContract.getPMControllerByAddress({ controllerAddress });
392
+ const newPmfTokenBalance = await pmfTokenContract.balanceOf({ address: accountAddress });
393
+ const newPaused = await landTokenContract.paused();
394
+
395
+ expect(currentPaused).to.equal(true);
396
+ expect(newPaused).to.equal(false);
397
+ expect(newPmfTokenBalance).to.equal(currentPmfTokenBalance - LOCK_AMOUNT);
398
+ expect(refreshedController.token).to.equal(controller.token);
399
+ expect(refreshedController.active).to.equal(true);
400
+ expect(refreshedController.lockAmount).to.equal(LOCK_AMOUNT);
401
+ expect(refreshedController.lockUser).to.equal(accountAddress);
402
+ }));
403
+
404
+ it('should not be able to update lock amount if not the contract owner', mochaAsync(async () => {
405
+ const currentLockAmount = await predictionMarketFactoryContract.lockAmount();
406
+ expect(currentLockAmount).to.equal(LOCK_AMOUNT);
407
+
408
+ try {
409
+ await user1PredictionMarketFactoryContract.updateLockAmount({
410
+ amount: NEW_LOCK_AMOUNT,
411
+ });
412
+ } catch(e) {
413
+ // not logging error, as tx is expected to fail
414
+ }
415
+
416
+ const newLockAmount = await predictionMarketFactoryContract.lockAmount();
417
+ expect(newLockAmount).to.equal(LOCK_AMOUNT);
418
+ }));
419
+
420
+ it('should be able to update lock amount', mochaAsync(async () => {
421
+ const currentLockAmount = await predictionMarketFactoryContract.lockAmount();
422
+ expect(currentLockAmount).to.equal(LOCK_AMOUNT);
423
+
424
+ await predictionMarketFactoryContract.updateLockAmount({
425
+ amount: NEW_LOCK_AMOUNT,
426
+ });
427
+
428
+ const newLockAmount = await predictionMarketFactoryContract.lockAmount();
429
+ expect(newLockAmount).to.equal(NEW_LOCK_AMOUNT);
430
+ }));
431
+
432
+ it('should not be able to unlock offset from Controller if not an admin', mochaAsync(async () => {
433
+ const currentLockAmount = await predictionMarketFactoryContract.lockAmount();
434
+ expect(currentLockAmount).to.equal(NEW_LOCK_AMOUNT);
435
+ const currentPmfTokenBalance = await pmfTokenContract.balanceOf({ address: accountAddress });
436
+
437
+ try {
438
+ await user1PredictionMarketFactoryContract.unlockOffsetFromPMController({
439
+ controllerAddress
440
+ });
441
+ } catch(e) {
442
+ // not logging error, as tx is expected to fail
443
+ }
444
+
445
+ const refreshedController = await user1PredictionMarketFactoryContract.getPMControllerByAddress({ controllerAddress });
446
+ const newPmfTokenBalance = await pmfTokenContract.balanceOf({ address: accountAddress });
447
+
448
+ expect(newPmfTokenBalance).to.equal(currentPmfTokenBalance);
449
+ expect(refreshedController.lockAmount).to.equal(LOCK_AMOUNT);
450
+ }));
451
+
452
+ it('should be able to unlock offset from Controller', mochaAsync(async () => {
453
+ const currentLockAmount = await predictionMarketFactoryContract.lockAmount();
454
+ expect(currentLockAmount).to.equal(NEW_LOCK_AMOUNT);
455
+ const currentPmfTokenBalance = await pmfTokenContract.balanceOf({ address: accountAddress });
456
+
457
+ await predictionMarketFactoryContract.unlockOffsetFromPMController({
458
+ controllerAddress
459
+ });
460
+
461
+ const refreshedController = await user1PredictionMarketFactoryContract.getPMControllerByAddress({ controllerAddress });
462
+ const newPmfTokenBalance = await pmfTokenContract.balanceOf({ address: accountAddress });
463
+
464
+ expect(newPmfTokenBalance).to.equal(currentPmfTokenBalance + LOCK_AMOUNT - NEW_LOCK_AMOUNT);
465
+ expect(refreshedController.lockAmount).to.equal(NEW_LOCK_AMOUNT);
466
+ }));
467
+ });
468
+ });
469
+ });