forked from DappStarter/succinct-klulufscek-FTz6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fast-floward-tests.js
326 lines (258 loc) · 11.8 KB
/
fast-floward-tests.js
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
const assert = require('chai').assert;
const DappLib = require('../src/dapp-lib.js');
const fkill = require('fkill');
describe('Flow Dapp Tests', async () => {
let config = null;
before('setup contract', async () => {
// Setup tasks for tests
config = DappLib.getConfig();
});
after(() => {
fkill(':3570');
});
describe('Fast Floward Tests', async () => {
it(`sets up two accounts`, async () => {
let testData1 = {
signer: config.accounts[0]
}
let testData2 = {
signer: config.accounts[1]
}
await DappLib.kibbleSetupAccount(testData1);
await DappLib.kibbleSetupAccount(testData2);
await DappLib.kittyItemsSetupAccount(testData1);
await DappLib.kittyItemsSetupAccount(testData2);
await DappLib.kittyItemsMarketSetupAccount(testData1);
await DappLib.kittyItemsMarketSetupAccount(testData2);
});
it(`mints kibble into the admin account and has the correct balance in the account`, async () => {
let testData1 = {
amount: "30.0",
recipient: config.accounts[0]
}
let testData2 = {
address: config.accounts[0]
}
await DappLib.kibbleMintTokens(testData1)
let res1 = await DappLib.kibbleGetBalance(testData2)
let res2 = await DappLib.kibbleGetSupply({})
assert.equal(res1.result, 30.0, "Admin has incorrect balance")
assert.equal(res2.result, 30.0, "Incorrect total number of Kibble")
})
it(`cannot mint 0 kibble and doesn't affect supply`, async () => {
let testData1 = {
amount: "0.0",
recipient: config.accounts[0]
}
try {
await DappLib.kibbleMintTokens(testData1)
} catch (e) {
let res = await DappLib.kibbleGetSupply({})
assert.equal(res.result, 30.0, "Incorrect total number of Kibble")
}
})
it(`cannot withdraw more than vault has but balances and supply remain the same`, async () => {
let testData1 = {
signer: config.accounts[0],
amount: "100.0",
to: config.accounts[1]
}
let testData2 = {
address: config.accounts[0]
}
let testData3 = {
address: config.accounts[1]
}
try {
await DappLib.kibbleTransferTokens(testData1)
} catch (e) {
let res1 = await DappLib.kibbleGetBalance(testData2)
let res2 = await DappLib.kibbleGetBalance(testData3)
let res3 = await DappLib.kibbleGetSupply({})
assert.equal(res1.result, 30.0, "Admin has incorrect balance")
assert.equal(res2.result, 0.0, "User has incorrect balance")
assert.equal(res3.result, 30.0, "Incorrect total number of Kibble")
}
})
it(`transfers kibble from admin to user`, async () => {
let testData1 = {
signer: config.accounts[0],
amount: "10.0",
recipient: config.accounts[1]
}
let testData2 = {
address: config.accounts[0]
}
let testData3 = {
address: config.accounts[1]
}
await DappLib.kibbleTransferTokens(testData1)
let res1 = await DappLib.kibbleGetBalance(testData2)
let res2 = await DappLib.kibbleGetBalance(testData3)
let res3 = await DappLib.kibbleGetSupply({})
assert.equal(res1.result, 20.0, "Admin has incorrect balance")
assert.equal(res2.result, 10.0, "User has incorrect balance")
assert.equal(res3.result, 30.0, "Incorrect total number of Kibble")
})
it(`has 0 initial kittyitems in the supply`, async () => {
let res = await DappLib.kittyItemsReadKittyItemsSupply({})
assert.equal(res.result, 0, "There should be 0 initial KittyItems")
})
it(`mints 2 kittyitems into admin account and has correct collection information`, async () => {
let testData1 = {
recipient: config.accounts[0],
typeID: "5"
}
let testData2 = {
address: config.accounts[0]
}
await DappLib.kittyItemsMintKittyItem(testData1)
await DappLib.kittyItemsMintKittyItem(testData1)
let res1 = await DappLib.kittyItemsReadCollectionIDs(testData2)
let res2 = await DappLib.kittyItemsReadCollectionLength(testData2)
assert.equal(res1.result[0], 0, "Incorrect ID in KittyItems collection")
assert.equal(res1.result[1], 1, "Incorrect ID in KittyItems collection")
assert.equal(res2.result, 2, "Incorrect length of KittyItems collection")
})
it(`has correct total number of kittyitems and kittyitem typeID is correct`, async () => {
let testData = {
address: config.accounts[0],
itemID: "0"
}
let res1 = await DappLib.kittyItemsReadKittyItemsSupply({})
let res2 = await DappLib.kittyItemsReadKittyItemTypeID(testData)
assert.equal(res1.result, 2, "Incorrect total number of KittyItems")
assert.equal(res2.result, 5, "KittyItem has incorrect typeID")
})
it(`safely fails when withdrawing kittyitem with wrong id`, async () => {
let testData1 = {
signer: config.accounts[0],
recipient: config.accounts[1],
withdrawID: "10"
}
let testData2 = {
address: config.accounts[0]
}
let testData3 = {
address: config.accounts[1]
}
try {
await DappLib.kittyItemsTransferKittyItem(testData1)
} catch (e) {
let res1 = await DappLib.kittyItemsReadCollectionLength(testData2)
let res2 = await DappLib.kittyItemsReadCollectionLength(testData3)
assert.equal(res1.result, 2, "Admin should have 2 KittyItems after fail")
assert.equal(res2.result, 0, "User should have 0 KittyItems after fail")
}
})
it(`transfers 2 kittyitems from admin to user and has correct collection information`, async () => {
let testData1 = {
signer: config.accounts[0],
recipient: config.accounts[1],
withdrawID: "0"
}
let testData2 = {
signer: config.accounts[0],
recipient: config.accounts[1],
withdrawID: "1"
}
let testData3 = {
address: config.accounts[0]
}
let testData4 = {
address: config.accounts[1]
}
await DappLib.kittyItemsTransferKittyItem(testData1)
await DappLib.kittyItemsTransferKittyItem(testData2)
let res1 = await DappLib.kittyItemsReadCollectionLength(testData3)
let res2 = await DappLib.kittyItemsReadCollectionLength(testData4)
let res3 = await DappLib.kittyItemsReadCollectionIDs(testData4)
assert.equal(res1.result, 0, "Admin should have no KittyItems left")
assert.equal(res2.result, 2, "User should have a KittyItem")
assert.equal(res3.result[0], 0, "User should have a KittyItem")
assert.equal(res3.result[1], 1, "User should have a KittyItem")
})
it(`lists 2 kittyitems for sale`, async () => {
let testData1 = {
signer: config.accounts[1],
itemID: "0",
price: "15.0"
}
let testData2 = {
signer: config.accounts[1],
itemID: "1",
price: "15.0"
}
let testData3 = {
marketCollectionAddress: config.accounts[1]
}
let testData4 = {
marketCollectionAddress: config.accounts[1]
}
await DappLib.kittyItemsMarketSellMarketItem(testData1)
await DappLib.kittyItemsMarketSellMarketItem(testData2)
let res1 = await DappLib.kittyItemsMarketReadSaleCollectionIDs(testData3)
let res2 = await DappLib.kittyItemsMarketReadSaleCollectionLength(testData4)
assert.equal(res1.result[0], 0, "User's Market collection should have a KittyItem with itemID 0")
assert.equal(res1.result[1], 1, "User's Market collection should have a KittyItem with itemID 1")
assert.equal(res2.result, 2, "User should have 2 KittyItems up for sale")
})
// TODO: implement this test
//
// Your goal here is to remove a Kitty Item with itemID == 0
// from config.accounts[1]'s SaleCollection.
//
// Then, add two assert statements that check to see if
// config.account[1]'s SaleCollection has the correct length (1) and
// NFT IDs in it (only an itemID == 1).
//
it(`removes a kittyitem from sale`, async () => {
// 1) add testData1 to call kittyItemsMarketRemoveMarketItem
// 2) add testData2 to call kittyItemsMarketReadSaleCollectionLength
// 3) add testData3 to call kittyItemsMarketReadSaleCollectionIDs
// 4) call kittyItemsMarketRemoveMarketItem with testData1
// 5) call kittyItemsMarketReadSaleCollectionLength with testData2 and store the result
// 6) call kittyItemsMarketReadSaleCollectionIDs with testData3 and store the result
// 7) assert the result from step 5) shows the SaleCollection has length 1
// 8) assert the result (an array) from step 6) shows the SaleCollection has
// an itemID == 1 in it at index 0
})
it(`buys a kittyitem`, async () => {
let testData1 = {
signer: config.accounts[0],
itemID: "1",
marketCollectionAddress: config.accounts[1]
}
let testData2 = {
marketCollectionAddress: config.accounts[1]
}
try {
await DappLib.kittyItemsMarketBuyMarketItem(testData1)
} catch (e) {
console.log(e)
}
})
it(`checks admin actually has a kittyitem in collection`, async () => {
let testData = {
address: config.accounts[0]
}
let res1 = await DappLib.kittyItemsReadCollectionIDs(testData)
let res2 = await DappLib.kittyItemsReadCollectionLength(testData)
assert.equal(res1.result[0], 1, "Incorrect ID in KittyItem collection")
assert.equal(res2.result, 1, "Incorrect length of KittyItem collection")
})
// TODO: implement this test
//
// Your goal here is to check that config.accounts[0] has a Kibble Balance
// of 5.0, and config.accounts[1] has a Kibble Balance of 25.0.
//
it(`checks both admin and user have correct balances after purchase`, async () => {
// 1) add testData1 to call kibbleGetBalance for config.accounts[0]
// 2) add testData2 to call kibbleGetBalance for config.accounts[1]
// 3) call kibbleGetBalance with testData1 and store the result
// 4) call kibbleGetBalance with testData2 and store the result
// 5) assert the result from step 3) equals 5.0
// 6) assert the result from step 4) equals 25.0
})
});
});