polkamarkets-js 1.0.2 → 3.1.1
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.
- package/.openzeppelin/unknown-1337.json +2056 -0
- package/CONTRIBUTING.md +36 -0
- package/README.md +24 -25
- package/_book/README.md +590 -0
- package/_book/core.md +50 -0
- package/_book/gitbook/fonts/fontawesome/FontAwesome.otf +0 -0
- package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.eot +0 -0
- package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.svg +685 -0
- package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.ttf +0 -0
- package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.woff +0 -0
- package/_book/gitbook/fonts/fontawesome/fontawesome-webfont.woff2 +0 -0
- package/_book/gitbook/gitbook-plugin-fontsettings/fontsettings.js +240 -0
- package/_book/gitbook/gitbook-plugin-fontsettings/website.css +291 -0
- package/_book/gitbook/gitbook-plugin-highlight/ebook.css +135 -0
- package/_book/gitbook/gitbook-plugin-highlight/website.css +434 -0
- package/_book/gitbook/gitbook-plugin-lunr/lunr.min.js +7 -0
- package/_book/gitbook/gitbook-plugin-lunr/search-lunr.js +59 -0
- package/_book/gitbook/gitbook-plugin-search/lunr.min.js +7 -0
- package/_book/gitbook/gitbook-plugin-search/search-engine.js +50 -0
- package/_book/gitbook/gitbook-plugin-search/search.css +35 -0
- package/_book/gitbook/gitbook-plugin-search/search.js +213 -0
- package/_book/gitbook/gitbook-plugin-sharing/buttons.js +90 -0
- package/_book/gitbook/gitbook.js +4 -0
- package/_book/gitbook/images/apple-touch-icon-precomposed-152.png +0 -0
- package/_book/gitbook/images/favicon.ico +0 -0
- package/_book/gitbook/style.css +9 -0
- package/_book/gitbook/theme.js +4 -0
- package/_book/index.html +705 -0
- package/_book/intro.md +32 -0
- package/_book/search_index.json +1 -0
- package/book.json +8 -0
- package/build/contracts/AccessControl.json +1 -0
- package/build/contracts/AccessControlEnumerable.json +1 -0
- package/build/contracts/Achievements.json +1 -0
- package/build/contracts/Address.json +1 -0
- package/build/contracts/BalanceHolder.json +1 -0
- package/build/contracts/BalanceHolder_ERC20.json +1 -0
- package/build/contracts/CeilDiv.json +1 -0
- package/build/contracts/Clones.json +1 -0
- package/build/contracts/Context.json +1 -0
- package/build/contracts/Counters.json +1 -0
- package/build/contracts/ERC165.json +1 -0
- package/build/contracts/ERC20.json +1 -0
- package/build/contracts/ERC20Burnable.json +1 -0
- package/build/contracts/ERC20Pausable.json +1 -0
- package/build/contracts/ERC20PresetMinterPauser.json +1 -0
- package/build/contracts/ERC721.json +1 -0
- package/build/contracts/EnumerableMap.json +1 -0
- package/build/contracts/EnumerableSet.json +1 -0
- package/build/contracts/FantasyERC20.json +1 -0
- package/build/contracts/IAccessControl.json +1 -0
- package/build/contracts/IAccessControlEnumerable.json +1 -0
- package/build/contracts/IBalanceHolder_ERC20.json +1 -0
- package/build/contracts/IERC165.json +1 -0
- package/build/contracts/IERC20.json +1 -0
- package/build/contracts/IERC20Metadata.json +1 -0
- package/build/contracts/IERC20Permit.json +1 -0
- package/build/contracts/IERC721.json +1 -0
- package/build/contracts/IERC721Enumerable.json +1 -0
- package/build/contracts/IERC721Metadata.json +1 -0
- package/build/contracts/IERC721Receiver.json +1 -0
- package/build/contracts/IFantasyERC20.json +1 -0
- package/build/contracts/IPredictionMarketV3.json +1 -0
- package/build/contracts/IPredictionMarketV3Factory.json +1 -0
- package/build/contracts/IPredictionMarketV3Manager.json +1 -0
- package/build/contracts/IRealityETH_ERC20.json +1 -0
- package/build/contracts/IRealityETH_IERC20.json +1 -0
- package/build/contracts/IWETH.json +1 -0
- package/build/contracts/LandFactory.json +1 -0
- package/build/contracts/Math.json +1 -0
- package/build/contracts/Migrations.json +1 -0
- package/build/contracts/Ownable.json +1 -0
- package/build/contracts/Pausable.json +1 -0
- package/build/contracts/PredictionMarket.json +1 -0
- package/build/contracts/PredictionMarketV2.json +1 -0
- package/build/contracts/PredictionMarketV3.json +1 -0
- package/build/contracts/PredictionMarketV3Controller.json +1 -0
- package/build/contracts/PredictionMarketV3Factory.json +1 -0
- package/build/contracts/PredictionMarketV3Manager.json +1 -0
- package/build/contracts/PredictionMarketV3Querier.json +1 -0
- package/build/contracts/RealitioERC20.json +1 -0
- package/build/contracts/RealitioForeignArbitrationProxyWithAppeals.json +1 -0
- package/build/contracts/RealitioHomeArbitrationProxy.json +1 -0
- package/build/contracts/RealitioSafeMath256.json +1 -0
- package/build/contracts/RealitioSafeMath32.json +1 -0
- package/build/contracts/RealityETH_ERC20_Factory.json +1 -0
- package/build/contracts/RealityETH_ERC20_v3_0.json +1 -0
- package/build/contracts/ReentrancyGuard.json +1 -0
- package/build/contracts/SafeERC20.json +1 -0
- package/build/contracts/SafeMath.json +1 -0
- package/build/contracts/Strings.json +1 -0
- package/build/contracts/Voting.json +1 -0
- package/build/contracts/WETH9.json +1 -0
- package/build/contracts/test.json +1 -0
- package/cleanContracts.js +22 -0
- package/contracts/FantasyERC20.sol +81 -0
- package/contracts/IFantasyERC20.sol +20 -0
- package/contracts/IPredictionMarketV3.sol +207 -0
- package/contracts/IPredictionMarketV3Factory.sol +10 -0
- package/contracts/IPredictionMarketV3Manager.sol +12 -0
- package/contracts/IRealityETH_ERC20.sol +64 -0
- package/contracts/LandFactory.sol +248 -0
- package/contracts/Migrations.sol +24 -0
- package/contracts/PredictionMarketV3.sol +1332 -0
- package/contracts/PredictionMarketV3Controller.sol +87 -0
- package/contracts/PredictionMarketV3Factory.sol +205 -0
- package/contracts/PredictionMarketV3Manager.sol +45 -0
- package/contracts/PredictionMarketV3Querier.sol +79 -0
- package/contracts/RealityETH_ERC20_Factory.sol +54 -0
- package/contracts/Voting.sol +153 -0
- package/contracts/WETH9.sol +62 -0
- package/hardhat.config.js +4 -0
- package/help.txt +8 -0
- package/index.js +3 -0
- package/migrations/10_deploy_weth.js +5 -0
- package/migrations/11_deploy_full_flow.js +99 -0
- package/migrations/12_deploy_pm_v3_querier.js +7 -0
- package/migrations/13_deploy_pm_v3_factory.js +14 -0
- package/migrations/1_initial_migration.js +5 -0
- package/migrations/2_deploy_erc20.js +10 -0
- package/migrations/3_deploy_realitio.js +11 -0
- package/migrations/4_deploy_pm.js +20 -0
- package/migrations/5_seed_markets.js +51 -0
- package/migrations/6_deploy_achievements.js +5 -0
- package/migrations/7_deploy_voting.js +14 -0
- package/migrations/8_deploy_pm_v2.js +20 -0
- package/migrations/9_seed_markets_v2.js +68 -0
- package/package.json +106 -13
- package/src/Application.js +421 -0
- package/src/interfaces/index.js +19 -0
- package/src/models/AchievementsContract.js +217 -0
- package/src/models/ArbitrationContract.js +69 -0
- package/src/models/ArbitrationProxyContract.js +32 -0
- package/src/models/ERC20Contract.js +156 -0
- package/src/models/FantasyERC20Contract.js +92 -0
- package/src/models/IContract.js +1002 -0
- package/src/models/PolkamarketsSmartAccount.js +100 -0
- package/src/models/PredictionMarketContract.js +562 -0
- package/src/models/PredictionMarketV2Contract.js +830 -0
- package/src/models/PredictionMarketV3Contract.js +256 -0
- package/src/models/PredictionMarketV3ControllerContract.js +102 -0
- package/src/models/PredictionMarketV3FactoryContract.js +96 -0
- package/src/models/PredictionMarketV3ManagerContract.js +111 -0
- package/src/models/PredictionMarketV3QuerierContract.js +24 -0
- package/src/models/RealitioERC20Contract.js +286 -0
- package/src/models/VotingContract.js +182 -0
- package/src/models/WETH9Contract.js +92 -0
- package/src/models/index.js +33 -0
- package/src/utils/Account.js +40 -0
- package/src/utils/Contract.js +120 -0
- package/src/utils/Numbers.js +94 -0
- package/tests/fantasyERC20Contract.js +225 -0
- package/tests/index.js +10 -0
- package/tests/predictionMarketContract.js +466 -0
- package/tests/predictionMarketV2Contract.js +1042 -0
- package/tests/predictionMarketV3Contract.js +1079 -0
- package/tests/predictionMarketV3ControllerContract.js +613 -0
- package/tests/predictionMarketV3FactoryContract.js +469 -0
- package/tests/predictionMarketV3ManagerContract.js +610 -0
- package/tests/utils.js +16 -0
- package/tests/votingContract.js +490 -0
- package/tooling/docs/jsdoc.json +6 -0
- package/truffle-config.js +134 -0
- package/polkamarkets.js +0 -436
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { expect } from 'chai';
|
|
4
|
+
|
|
5
|
+
import { mochaAsync } from './utils';
|
|
6
|
+
import { Application } from '..';
|
|
7
|
+
|
|
8
|
+
context('Voting Contract', async () => {
|
|
9
|
+
require('dotenv').config();
|
|
10
|
+
|
|
11
|
+
let app;
|
|
12
|
+
let votingContract;
|
|
13
|
+
let ERC20Contract;
|
|
14
|
+
|
|
15
|
+
context('Contract Deployment', async () => {
|
|
16
|
+
it('should start the Application', mochaAsync(async () => {
|
|
17
|
+
app = new Application({
|
|
18
|
+
web3Provider: process.env.WEB3_PROVIDER,
|
|
19
|
+
web3PrivateKey: process.env.WEB3_PRIVATE_KEY,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
expect(app).to.not.equal(null);
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
it('should deploy Voting Contract', mochaAsync(async () => {
|
|
26
|
+
// Create Contract
|
|
27
|
+
votingContract = app.getVotingContract({});
|
|
28
|
+
ERC20Contract = app.getERC20Contract({});
|
|
29
|
+
// // Deploy
|
|
30
|
+
await ERC20Contract.deploy({ params: ['Polkamarkets', 'POLK'] });
|
|
31
|
+
|
|
32
|
+
const ERC20ContractAddress = ERC20Contract.getAddress();
|
|
33
|
+
|
|
34
|
+
await votingContract.deploy({
|
|
35
|
+
params: [
|
|
36
|
+
ERC20ContractAddress,
|
|
37
|
+
0
|
|
38
|
+
]
|
|
39
|
+
});
|
|
40
|
+
const votingContractAddress = votingContract.getAddress();
|
|
41
|
+
|
|
42
|
+
expect(votingContractAddress).to.not.equal(null);
|
|
43
|
+
}));
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
context('Voting Items', async () => {
|
|
47
|
+
it('should upvote an Item', mochaAsync(async () => {
|
|
48
|
+
let itemId = 0;
|
|
49
|
+
|
|
50
|
+
// chek if there are no votes
|
|
51
|
+
let itemVotes = await votingContract.getItemVotes({ itemId });
|
|
52
|
+
|
|
53
|
+
expect(itemVotes.upvotes).to.equal(0);
|
|
54
|
+
expect(itemVotes.downvotes).to.equal(0);
|
|
55
|
+
|
|
56
|
+
const user = await votingContract.getMyAccount();
|
|
57
|
+
|
|
58
|
+
let userVoted = await votingContract.hasUserVotedItem({ itemId, user });
|
|
59
|
+
|
|
60
|
+
expect(userVoted.upvoted).to.equal(false);
|
|
61
|
+
expect(userVoted.downvoted).to.equal(false);
|
|
62
|
+
|
|
63
|
+
const res = await votingContract.upvoteItem({
|
|
64
|
+
itemId,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
expect(res.status).to.equal(true);
|
|
68
|
+
|
|
69
|
+
itemVotes = await votingContract.getItemVotes({ itemId });
|
|
70
|
+
|
|
71
|
+
expect(itemVotes.upvotes).to.equal(1);
|
|
72
|
+
expect(itemVotes.downvotes).to.equal(0);
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
userVoted = await votingContract.hasUserVotedItem({ itemId, user });
|
|
76
|
+
|
|
77
|
+
expect(userVoted.upvoted).to.equal(true);
|
|
78
|
+
expect(userVoted.downvoted).to.equal(false);
|
|
79
|
+
|
|
80
|
+
// Validate User Votes
|
|
81
|
+
const userVotes = await votingContract.getUserVotes({ user });
|
|
82
|
+
expect(Object.keys(userVotes).length).to.equal(1);
|
|
83
|
+
expect(userVotes[0].upvoted).to.equal(true);
|
|
84
|
+
expect(userVotes[0].downvoted).to.equal(false);
|
|
85
|
+
}));
|
|
86
|
+
|
|
87
|
+
it('should downvote an Item', mochaAsync(async () => {
|
|
88
|
+
let itemId = 1;
|
|
89
|
+
|
|
90
|
+
// chek if there are no votes
|
|
91
|
+
let itemVotes = await votingContract.getItemVotes({ itemId });
|
|
92
|
+
|
|
93
|
+
expect(itemVotes.upvotes).to.equal(0);
|
|
94
|
+
expect(itemVotes.downvotes).to.equal(0);
|
|
95
|
+
|
|
96
|
+
const user = await votingContract.getMyAccount();
|
|
97
|
+
|
|
98
|
+
let userVoted = await votingContract.hasUserVotedItem({ itemId, user });
|
|
99
|
+
|
|
100
|
+
expect(userVoted.upvoted).to.equal(false);
|
|
101
|
+
expect(userVoted.downvoted).to.equal(false);
|
|
102
|
+
|
|
103
|
+
const res = await votingContract.downvoteItem({
|
|
104
|
+
itemId,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
expect(res.status).to.equal(true);
|
|
108
|
+
|
|
109
|
+
itemVotes = await votingContract.getItemVotes({ itemId });
|
|
110
|
+
|
|
111
|
+
expect(itemVotes.upvotes).to.equal(0);
|
|
112
|
+
expect(itemVotes.downvotes).to.equal(1);
|
|
113
|
+
|
|
114
|
+
userVoted = await votingContract.hasUserVotedItem({ itemId, user });
|
|
115
|
+
|
|
116
|
+
expect(userVoted.upvoted).to.equal(false);
|
|
117
|
+
expect(userVoted.downvoted).to.equal(true);
|
|
118
|
+
|
|
119
|
+
// Validate User Votes
|
|
120
|
+
const userVotes = await votingContract.getUserVotes({ user });
|
|
121
|
+
expect(Object.keys(userVotes).length).to.equal(2);
|
|
122
|
+
expect(userVotes[0].upvoted).to.equal(true);
|
|
123
|
+
expect(userVotes[0].downvoted).to.equal(false);
|
|
124
|
+
expect(userVotes[1].upvoted).to.equal(false);
|
|
125
|
+
expect(userVotes[1].downvoted).to.equal(true);
|
|
126
|
+
}));
|
|
127
|
+
|
|
128
|
+
it('should upvote an Item when there is already a downvote', mochaAsync(async () => {
|
|
129
|
+
let itemId = 1;
|
|
130
|
+
|
|
131
|
+
// check first if user has a downvote
|
|
132
|
+
let itemVotes = await votingContract.getItemVotes({ itemId });
|
|
133
|
+
|
|
134
|
+
expect(itemVotes.upvotes).to.equal(0);
|
|
135
|
+
expect(itemVotes.downvotes).to.equal(1);
|
|
136
|
+
|
|
137
|
+
const user = await votingContract.getMyAccount();
|
|
138
|
+
|
|
139
|
+
let userVoted = await votingContract.hasUserVotedItem({ itemId, user });
|
|
140
|
+
|
|
141
|
+
expect(userVoted.upvoted).to.equal(false);
|
|
142
|
+
expect(userVoted.downvoted).to.equal(true);
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
const res = await votingContract.upvoteItem({
|
|
146
|
+
itemId,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
expect(res.status).to.equal(true);
|
|
150
|
+
|
|
151
|
+
itemVotes = await votingContract.getItemVotes({ itemId });
|
|
152
|
+
|
|
153
|
+
expect(itemVotes.upvotes).to.equal(1);
|
|
154
|
+
expect(itemVotes.downvotes).to.equal(0);
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
userVoted = await votingContract.hasUserVotedItem({ itemId, user });
|
|
158
|
+
|
|
159
|
+
expect(userVoted.upvoted).to.equal(true);
|
|
160
|
+
expect(userVoted.downvoted).to.equal(false);
|
|
161
|
+
|
|
162
|
+
// Validate User Votes
|
|
163
|
+
const userVotes = await votingContract.getUserVotes({ user });
|
|
164
|
+
expect(Object.keys(userVotes).length).to.equal(2);
|
|
165
|
+
expect(userVotes[0].upvoted).to.equal(true);
|
|
166
|
+
expect(userVotes[0].downvoted).to.equal(false);
|
|
167
|
+
expect(userVotes[1].upvoted).to.equal(true);
|
|
168
|
+
expect(userVotes[1].downvoted).to.equal(false);
|
|
169
|
+
}));
|
|
170
|
+
|
|
171
|
+
it('should downvote an Item when there is already an upvote', mochaAsync(async () => {
|
|
172
|
+
let itemId = 0;
|
|
173
|
+
|
|
174
|
+
// check first if user has an upvote
|
|
175
|
+
let itemVotes = await votingContract.getItemVotes({ itemId });
|
|
176
|
+
|
|
177
|
+
expect(itemVotes.upvotes).to.equal(1);
|
|
178
|
+
expect(itemVotes.downvotes).to.equal(0);
|
|
179
|
+
|
|
180
|
+
const user = await votingContract.getMyAccount();
|
|
181
|
+
|
|
182
|
+
let userVoted = await votingContract.hasUserVotedItem({ itemId, user });
|
|
183
|
+
|
|
184
|
+
expect(userVoted.upvoted).to.equal(true);
|
|
185
|
+
expect(userVoted.downvoted).to.equal(false);
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
const res = await votingContract.downvoteItem({
|
|
189
|
+
itemId,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
expect(res.status).to.equal(true);
|
|
193
|
+
|
|
194
|
+
itemVotes = await votingContract.getItemVotes({ itemId });
|
|
195
|
+
|
|
196
|
+
expect(itemVotes.upvotes).to.equal(0);
|
|
197
|
+
expect(itemVotes.downvotes).to.equal(1);
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
userVoted = await votingContract.hasUserVotedItem({ itemId, user });
|
|
201
|
+
|
|
202
|
+
expect(userVoted.upvoted).to.equal(false);
|
|
203
|
+
expect(userVoted.downvoted).to.equal(true);
|
|
204
|
+
|
|
205
|
+
// Validate User Votes
|
|
206
|
+
const userVotes = await votingContract.getUserVotes({ user });
|
|
207
|
+
expect(Object.keys(userVotes).length).to.equal(2);
|
|
208
|
+
expect(userVotes[0].upvoted).to.equal(false);
|
|
209
|
+
expect(userVotes[0].downvoted).to.equal(true);
|
|
210
|
+
expect(userVotes[1].upvoted).to.equal(true);
|
|
211
|
+
expect(userVotes[1].downvoted).to.equal(false);
|
|
212
|
+
}));
|
|
213
|
+
|
|
214
|
+
it('should not allow to upvote an already upvoted item', mochaAsync(async () => {
|
|
215
|
+
let itemId = 1;
|
|
216
|
+
|
|
217
|
+
// check first if user has an upvote
|
|
218
|
+
let itemVotes = await votingContract.getItemVotes({ itemId });
|
|
219
|
+
|
|
220
|
+
expect(itemVotes.upvotes).to.equal(1);
|
|
221
|
+
expect(itemVotes.downvotes).to.equal(0);
|
|
222
|
+
|
|
223
|
+
const user = await votingContract.getMyAccount();
|
|
224
|
+
|
|
225
|
+
let userVoted = await votingContract.hasUserVotedItem({ itemId, user });
|
|
226
|
+
|
|
227
|
+
expect(userVoted.upvoted).to.equal(true);
|
|
228
|
+
expect(userVoted.downvoted).to.equal(false);
|
|
229
|
+
|
|
230
|
+
let res
|
|
231
|
+
try {
|
|
232
|
+
res = await votingContract.upvoteItem({
|
|
233
|
+
itemId,
|
|
234
|
+
});
|
|
235
|
+
} catch (error) {
|
|
236
|
+
res = { status: false };
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
expect(res.status).to.equal(false);
|
|
240
|
+
|
|
241
|
+
itemVotes = await votingContract.getItemVotes({ itemId });
|
|
242
|
+
|
|
243
|
+
expect(itemVotes.upvotes).to.equal(1);
|
|
244
|
+
expect(itemVotes.downvotes).to.equal(0);
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
userVoted = await votingContract.hasUserVotedItem({ itemId, user });
|
|
248
|
+
|
|
249
|
+
expect(userVoted.upvoted).to.equal(true);
|
|
250
|
+
expect(userVoted.downvoted).to.equal(false);
|
|
251
|
+
|
|
252
|
+
// Validate User Votes
|
|
253
|
+
const userVotes = await votingContract.getUserVotes({ user });
|
|
254
|
+
expect(Object.keys(userVotes).length).to.equal(2);
|
|
255
|
+
expect(userVotes[0].upvoted).to.equal(false);
|
|
256
|
+
expect(userVotes[0].downvoted).to.equal(true);
|
|
257
|
+
expect(userVotes[1].upvoted).to.equal(true);
|
|
258
|
+
expect(userVotes[1].downvoted).to.equal(false);
|
|
259
|
+
}));
|
|
260
|
+
|
|
261
|
+
it('should not allow to downvote an already downvoted item', mochaAsync(async () => {
|
|
262
|
+
let itemId = 0;
|
|
263
|
+
|
|
264
|
+
// check first if user has a downvote
|
|
265
|
+
let itemVotes = await votingContract.getItemVotes({ itemId });
|
|
266
|
+
|
|
267
|
+
expect(itemVotes.upvotes).to.equal(0);
|
|
268
|
+
expect(itemVotes.downvotes).to.equal(1);
|
|
269
|
+
|
|
270
|
+
const user = await votingContract.getMyAccount();
|
|
271
|
+
|
|
272
|
+
let userVoted = await votingContract.hasUserVotedItem({ itemId, user });
|
|
273
|
+
|
|
274
|
+
expect(userVoted.upvoted).to.equal(false);
|
|
275
|
+
expect(userVoted.downvoted).to.equal(true);
|
|
276
|
+
|
|
277
|
+
let res
|
|
278
|
+
try {
|
|
279
|
+
res = await votingContract.downvoteItem({
|
|
280
|
+
itemId,
|
|
281
|
+
});
|
|
282
|
+
} catch (error) {
|
|
283
|
+
res = { status: false };
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
expect(res.status).to.equal(false);
|
|
287
|
+
|
|
288
|
+
itemVotes = await votingContract.getItemVotes({ itemId });
|
|
289
|
+
|
|
290
|
+
expect(itemVotes.upvotes).to.equal(0);
|
|
291
|
+
expect(itemVotes.downvotes).to.equal(1);
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
userVoted = await votingContract.hasUserVotedItem({ itemId, user });
|
|
295
|
+
|
|
296
|
+
expect(userVoted.upvoted).to.equal(false);
|
|
297
|
+
expect(userVoted.downvoted).to.equal(true);
|
|
298
|
+
|
|
299
|
+
// Validate User Votes
|
|
300
|
+
const userVotes = await votingContract.getUserVotes({ user });
|
|
301
|
+
expect(Object.keys(userVotes).length).to.equal(2);
|
|
302
|
+
expect(userVotes[0].upvoted).to.equal(false);
|
|
303
|
+
expect(userVotes[0].downvoted).to.equal(true);
|
|
304
|
+
expect(userVotes[1].upvoted).to.equal(true);
|
|
305
|
+
expect(userVotes[1].downvoted).to.equal(false);
|
|
306
|
+
}));
|
|
307
|
+
|
|
308
|
+
it('should allow to remove upvote of an already upvoted item', mochaAsync(async () => {
|
|
309
|
+
let itemId = 1;
|
|
310
|
+
|
|
311
|
+
// check first if user has an upvote
|
|
312
|
+
let itemVotes = await votingContract.getItemVotes({ itemId });
|
|
313
|
+
|
|
314
|
+
expect(itemVotes.upvotes).to.equal(1);
|
|
315
|
+
expect(itemVotes.downvotes).to.equal(0);
|
|
316
|
+
|
|
317
|
+
const user = await votingContract.getMyAccount();
|
|
318
|
+
|
|
319
|
+
let userVoted = await votingContract.hasUserVotedItem({ itemId, user });
|
|
320
|
+
|
|
321
|
+
expect(userVoted.upvoted).to.equal(true);
|
|
322
|
+
expect(userVoted.downvoted).to.equal(false);
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
const res = await votingContract.removeUpvoteItem({
|
|
326
|
+
itemId,
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
expect(res.status).to.equal(true);
|
|
330
|
+
|
|
331
|
+
itemVotes = await votingContract.getItemVotes({ itemId });
|
|
332
|
+
|
|
333
|
+
expect(itemVotes.upvotes).to.equal(0);
|
|
334
|
+
expect(itemVotes.downvotes).to.equal(0);
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
userVoted = await votingContract.hasUserVotedItem({ itemId, user });
|
|
338
|
+
|
|
339
|
+
expect(userVoted.upvoted).to.equal(false);
|
|
340
|
+
expect(userVoted.downvoted).to.equal(false);
|
|
341
|
+
|
|
342
|
+
// Validate User Votes
|
|
343
|
+
const userVotes = await votingContract.getUserVotes({ user });
|
|
344
|
+
expect(Object.keys(userVotes).length).to.equal(2);
|
|
345
|
+
expect(userVotes[0].upvoted).to.equal(false);
|
|
346
|
+
expect(userVotes[0].downvoted).to.equal(true);
|
|
347
|
+
expect(userVotes[1].upvoted).to.equal(false);
|
|
348
|
+
expect(userVotes[1].downvoted).to.equal(false);
|
|
349
|
+
}));
|
|
350
|
+
|
|
351
|
+
it('should allow to remove downvote of an already downvoted item', mochaAsync(async () => {
|
|
352
|
+
let itemId = 0;
|
|
353
|
+
|
|
354
|
+
// check first if user has a downvote
|
|
355
|
+
let itemVotes = await votingContract.getItemVotes({ itemId });
|
|
356
|
+
|
|
357
|
+
expect(itemVotes.upvotes).to.equal(0);
|
|
358
|
+
expect(itemVotes.downvotes).to.equal(1);
|
|
359
|
+
|
|
360
|
+
const user = await votingContract.getMyAccount();
|
|
361
|
+
|
|
362
|
+
let userVoted = await votingContract.hasUserVotedItem({ itemId, user });
|
|
363
|
+
|
|
364
|
+
expect(userVoted.upvoted).to.equal(false);
|
|
365
|
+
expect(userVoted.downvoted).to.equal(true);
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
const res = await votingContract.removeDownvoteItem({
|
|
369
|
+
itemId,
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
expect(res.status).to.equal(true);
|
|
373
|
+
|
|
374
|
+
itemVotes = await votingContract.getItemVotes({ itemId });
|
|
375
|
+
|
|
376
|
+
expect(itemVotes.upvotes).to.equal(0);
|
|
377
|
+
expect(itemVotes.downvotes).to.equal(0);
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
userVoted = await votingContract.hasUserVotedItem({ itemId, user });
|
|
381
|
+
|
|
382
|
+
expect(userVoted.upvoted).to.equal(false);
|
|
383
|
+
expect(userVoted.downvoted).to.equal(false);
|
|
384
|
+
|
|
385
|
+
// Validate User Votes
|
|
386
|
+
const userVotes = await votingContract.getUserVotes({ user });
|
|
387
|
+
expect(Object.keys(userVotes).length).to.equal(2);
|
|
388
|
+
expect(userVotes[0].upvoted).to.equal(false);
|
|
389
|
+
expect(userVotes[0].downvoted).to.equal(false);
|
|
390
|
+
expect(userVotes[1].upvoted).to.equal(false);
|
|
391
|
+
expect(userVotes[1].downvoted).to.equal(false);
|
|
392
|
+
}));
|
|
393
|
+
|
|
394
|
+
it('should not allow to remove upvote of an item not upvoted', mochaAsync(async () => {
|
|
395
|
+
let itemId = 1;
|
|
396
|
+
|
|
397
|
+
// check first if user does not have an upvote
|
|
398
|
+
let itemVotes = await votingContract.getItemVotes({ itemId });
|
|
399
|
+
|
|
400
|
+
expect(itemVotes.upvotes).to.equal(0);
|
|
401
|
+
expect(itemVotes.downvotes).to.equal(0);
|
|
402
|
+
|
|
403
|
+
const user = await votingContract.getMyAccount();
|
|
404
|
+
|
|
405
|
+
let userVoted = await votingContract.hasUserVotedItem({ itemId, user });
|
|
406
|
+
|
|
407
|
+
expect(userVoted.upvoted).to.equal(false);
|
|
408
|
+
expect(userVoted.downvoted).to.equal(false);
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
let res
|
|
412
|
+
try {
|
|
413
|
+
res = await votingContract.removeUpvoteItem({
|
|
414
|
+
itemId,
|
|
415
|
+
});
|
|
416
|
+
} catch (error) {
|
|
417
|
+
res = { status: false };
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
expect(res.status).to.equal(false);
|
|
421
|
+
|
|
422
|
+
itemVotes = await votingContract.getItemVotes({ itemId });
|
|
423
|
+
|
|
424
|
+
expect(itemVotes.upvotes).to.equal(0);
|
|
425
|
+
expect(itemVotes.downvotes).to.equal(0);
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
userVoted = await votingContract.hasUserVotedItem({ itemId, user });
|
|
429
|
+
|
|
430
|
+
expect(userVoted.upvoted).to.equal(false);
|
|
431
|
+
expect(userVoted.downvoted).to.equal(false);
|
|
432
|
+
|
|
433
|
+
// Validate User Votes
|
|
434
|
+
const userVotes = await votingContract.getUserVotes({ user });
|
|
435
|
+
expect(Object.keys(userVotes).length).to.equal(2);
|
|
436
|
+
expect(userVotes[0].upvoted).to.equal(false);
|
|
437
|
+
expect(userVotes[0].downvoted).to.equal(false);
|
|
438
|
+
expect(userVotes[1].upvoted).to.equal(false);
|
|
439
|
+
expect(userVotes[1].downvoted).to.equal(false);
|
|
440
|
+
}));
|
|
441
|
+
|
|
442
|
+
it('should not allow to remove downvote of an item not downvoted', mochaAsync(async () => {
|
|
443
|
+
let itemId = 0;
|
|
444
|
+
|
|
445
|
+
// check first if user does not have a downvote
|
|
446
|
+
let itemVotes = await votingContract.getItemVotes({ itemId });
|
|
447
|
+
|
|
448
|
+
expect(itemVotes.upvotes).to.equal(0);
|
|
449
|
+
expect(itemVotes.downvotes).to.equal(0);
|
|
450
|
+
|
|
451
|
+
const user = await votingContract.getMyAccount();
|
|
452
|
+
|
|
453
|
+
let userVoted = await votingContract.hasUserVotedItem({ itemId, user });
|
|
454
|
+
|
|
455
|
+
expect(userVoted.upvoted).to.equal(false);
|
|
456
|
+
expect(userVoted.downvoted).to.equal(false);
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
let res
|
|
460
|
+
try {
|
|
461
|
+
res = await votingContract.removeDownvoteItem({
|
|
462
|
+
itemId,
|
|
463
|
+
});
|
|
464
|
+
} catch (error) {
|
|
465
|
+
res = { status: false };
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
expect(res.status).to.equal(false);
|
|
469
|
+
|
|
470
|
+
itemVotes = await votingContract.getItemVotes({ itemId });
|
|
471
|
+
|
|
472
|
+
expect(itemVotes.upvotes).to.equal(0);
|
|
473
|
+
expect(itemVotes.downvotes).to.equal(0);
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
userVoted = await votingContract.hasUserVotedItem({ itemId, user });
|
|
477
|
+
|
|
478
|
+
expect(userVoted.upvoted).to.equal(false);
|
|
479
|
+
expect(userVoted.downvoted).to.equal(false);
|
|
480
|
+
|
|
481
|
+
// Validate User Votes
|
|
482
|
+
const userVotes = await votingContract.getUserVotes({ user });
|
|
483
|
+
expect(Object.keys(userVotes).length).to.equal(2);
|
|
484
|
+
expect(userVotes[0].upvoted).to.equal(false);
|
|
485
|
+
expect(userVotes[0].downvoted).to.equal(false);
|
|
486
|
+
expect(userVotes[1].upvoted).to.equal(false);
|
|
487
|
+
expect(userVotes[1].downvoted).to.equal(false);
|
|
488
|
+
}));
|
|
489
|
+
});
|
|
490
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
require('dotenv').config()
|
|
2
|
+
const HDWalletProvider = require("@truffle/hdwallet-provider");
|
|
3
|
+
const mnemonic = process.env.TRUFFLE_MNEMONIC;
|
|
4
|
+
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY;
|
|
5
|
+
const POLYGONSCAN_API_KEY = process.env.POLYGONSCAN_API_KEY;
|
|
6
|
+
const GNOSIS_API_KEY = process.env.GNOSIS_API_KEY;
|
|
7
|
+
const CELO_API_KEY = process.env.CELO_API_KEY;
|
|
8
|
+
const INFURA_API_KEY = process.env.INFURA_API_KEY;
|
|
9
|
+
const ARBITRUM_API_KEY = process.env.ARBITRUM_API_KEY;
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
networks: {
|
|
13
|
+
development: {
|
|
14
|
+
host: "127.0.0.1",
|
|
15
|
+
port: 8545,
|
|
16
|
+
network_id: "*", // Match any network id
|
|
17
|
+
gasLimit: 10000000,
|
|
18
|
+
gas: 10000000
|
|
19
|
+
},
|
|
20
|
+
live: {
|
|
21
|
+
provider: new HDWalletProvider(mnemonic, "https://mainnet.infura.io/v3/" + INFURA_API_KEY),
|
|
22
|
+
network_id: 1,
|
|
23
|
+
gasPrice: 100000000000,
|
|
24
|
+
websockets: true
|
|
25
|
+
},
|
|
26
|
+
chiado: {
|
|
27
|
+
provider: function () {
|
|
28
|
+
return new HDWalletProvider(mnemonic, "https://rpc.chiadochain.net")
|
|
29
|
+
},
|
|
30
|
+
network_id: 10200,
|
|
31
|
+
gas: 5000000,
|
|
32
|
+
gasPrice: 10000000
|
|
33
|
+
},
|
|
34
|
+
gnosis: {
|
|
35
|
+
provider: function () {
|
|
36
|
+
return new HDWalletProvider(mnemonic, "https://rpc.gnosischain.com")
|
|
37
|
+
},
|
|
38
|
+
network_id: 100,
|
|
39
|
+
gas: 5000000,
|
|
40
|
+
gasPrice: 10000000000
|
|
41
|
+
},
|
|
42
|
+
alfajores: {
|
|
43
|
+
provider: function () {
|
|
44
|
+
return new HDWalletProvider(
|
|
45
|
+
mnemonic,
|
|
46
|
+
"https://alfajores-forno.celo-testnet.org/")
|
|
47
|
+
},
|
|
48
|
+
network_id: 44787,
|
|
49
|
+
gas: 5000000,
|
|
50
|
+
gasPrice: 10000000000
|
|
51
|
+
},
|
|
52
|
+
celo: {
|
|
53
|
+
provider: function () {
|
|
54
|
+
return new HDWalletProvider(
|
|
55
|
+
mnemonic,
|
|
56
|
+
"https://forno.celo.org")
|
|
57
|
+
},
|
|
58
|
+
network_id: 42220,
|
|
59
|
+
gas: 5000000,
|
|
60
|
+
gasPrice: 10000000000
|
|
61
|
+
},
|
|
62
|
+
moonriver: {
|
|
63
|
+
provider: new HDWalletProvider(mnemonic, "https://rpc.api.moonriver.moonbeam.network/"),
|
|
64
|
+
network_id: 1285
|
|
65
|
+
},
|
|
66
|
+
moonbeam: {
|
|
67
|
+
provider: new HDWalletProvider(mnemonic, "https://rpc.api.moonbeam.network"),
|
|
68
|
+
network_id: 1284
|
|
69
|
+
},
|
|
70
|
+
polygon: {
|
|
71
|
+
provider: new HDWalletProvider(mnemonic, "https://polygon-rpc.com"),
|
|
72
|
+
network_id: "137",
|
|
73
|
+
gasPrice: 200000000000,
|
|
74
|
+
skipDryRun: true,
|
|
75
|
+
networkCheckTimeout: 10000,
|
|
76
|
+
timeoutBlocks: 200,
|
|
77
|
+
gas: 25000000,
|
|
78
|
+
},
|
|
79
|
+
arbitrum: {
|
|
80
|
+
provider: new HDWalletProvider(mnemonic, "https://arb1.arbitrum.io/rpc"),
|
|
81
|
+
network_id: 42161,
|
|
82
|
+
gasPrice: 200000000,
|
|
83
|
+
skipDryRun: true,
|
|
84
|
+
networkCheckTimeout: 10000,
|
|
85
|
+
timeoutBlocks: 200,
|
|
86
|
+
gas: 25000000,
|
|
87
|
+
},
|
|
88
|
+
arbitrum_sepolia: {
|
|
89
|
+
provider: new HDWalletProvider(mnemonic, "https://sepolia-rollup.arbitrum.io/rpc"),
|
|
90
|
+
network_id: 421614,
|
|
91
|
+
gasPrice: 200000000,
|
|
92
|
+
skipDryRun: true,
|
|
93
|
+
networkCheckTimeout: 10000,
|
|
94
|
+
timeoutBlocks: 200,
|
|
95
|
+
gas: 25000000,
|
|
96
|
+
verify: {
|
|
97
|
+
apiUrl: 'https://api-sepolia.arbiscan.io/api',
|
|
98
|
+
apiKey: ARBITRUM_API_KEY,
|
|
99
|
+
explorerUrl: 'https://sepolia.arbiscan.io/address',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
// Configure your compilers
|
|
104
|
+
compilers: {
|
|
105
|
+
solc: {
|
|
106
|
+
version: "0.8.18", // Fetch exact version from solc-bin (default: truffle's version)
|
|
107
|
+
// docker: true, // Use "0.5.1" you've installed locally with docker (default: false)
|
|
108
|
+
// settings: { // See the solidity docs for advice about optimization and evmVersion
|
|
109
|
+
// optimizer: {
|
|
110
|
+
// enabled: false,
|
|
111
|
+
// runs: 200
|
|
112
|
+
// },
|
|
113
|
+
// evmVersion: "byzantium"
|
|
114
|
+
// }
|
|
115
|
+
settings: {
|
|
116
|
+
optimizer: {
|
|
117
|
+
enabled: true,
|
|
118
|
+
runs: 200
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
plugins: [
|
|
124
|
+
'truffle-contract-size',
|
|
125
|
+
'truffle-plugin-verify'
|
|
126
|
+
],
|
|
127
|
+
api_keys: {
|
|
128
|
+
etherscan: ETHERSCAN_API_KEY,
|
|
129
|
+
polygonscan: POLYGONSCAN_API_KEY,
|
|
130
|
+
gnosisscan: GNOSIS_API_KEY,
|
|
131
|
+
celoscan: CELO_API_KEY,
|
|
132
|
+
arbiscan: ARBITRUM_API_KEY,
|
|
133
|
+
}
|
|
134
|
+
};
|