git.delta.rocks / unique-network / refs/commits / a01203dd54a0

difftreelog

Use chai-subset to test events

Max Andreev2022-12-21parent: #534b1e6.patch.diff
in: master

5 files changed

modifiedtests/package.jsondiffbeforeafterboth
8 "@types/chai": "^4.3.3",8 "@types/chai": "^4.3.3",
9 "@types/chai-as-promised": "^7.1.5",9 "@types/chai-as-promised": "^7.1.5",
10 "@types/chai-like": "^1.1.1",10 "@types/chai-like": "^1.1.1",
11 "@types/chai-subset": "^1.3.3",
11 "@types/mocha": "^10.0.0",12 "@types/mocha": "^10.0.0",
12 "@types/node": "^18.11.2",13 "@types/node": "^18.11.2",
13 "@typescript-eslint/eslint-plugin": "^5.40.1",14 "@typescript-eslint/eslint-plugin": "^5.40.1",
14 "@typescript-eslint/parser": "^5.40.1",15 "@typescript-eslint/parser": "^5.40.1",
15 "chai": "^4.3.6",16 "chai": "^4.3.6",
17 "chai-subset": "^1.6.0",
16 "eslint": "^8.25.0",18 "eslint": "^8.25.0",
17 "eslint-plugin-mocha": "^10.1.0",19 "eslint-plugin-mocha": "^10.1.0",
18 "mocha": "^10.1.0",20 "mocha": "^10.1.0",
modifiedtests/src/eth/events.test.tsdiffbeforeafterboth
40 const {collectionAddress, events: ethEvents} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');40 const {collectionAddress, events: ethEvents} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
41 await helper.wait.newBlocks(1);41 await helper.wait.newBlocks(1);
42 {42 {
43 expect(ethEvents).to.be.like([43 expect(ethEvents).to.containSubset([
44 {44 {
45 event: 'CollectionCreated',45 event: 'CollectionCreated',
46 args: {46 args: {
49 },49 },
50 },50 },
51 ]);51 ]);
52 expect(subEvents).to.be.like([{method: 'CollectionCreated'}]);52 expect(subEvents).to.containSubset([{method: 'CollectionCreated'}]);
53 clearEvents(ethEvents, subEvents);53 clearEvents(ethEvents, subEvents);
54 }54 }
55 {55 {
56 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);56 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
57 const result = await collectionHelper.methods.destroyCollection(collectionAddress).send({from:owner});57 const result = await collectionHelper.methods.destroyCollection(collectionAddress).send({from:owner});
58 await helper.wait.newBlocks(1);58 await helper.wait.newBlocks(1);
59 expect(result.events).to.be.like({59 expect(result.events).to.containSubset({
60 CollectionDestroyed: {60 CollectionDestroyed: {
61 returnValues: {61 returnValues: {
62 collectionId: collectionAddress,62 collectionId: collectionAddress,
63 },63 },
64 },64 },
65 });65 });
66 expect(subEvents).to.be.like([{method: 'CollectionDestroyed'}]);66 expect(subEvents).to.containSubset([{method: 'CollectionDestroyed'}]);
67 }67 }
68 unsubscribe();68 unsubscribe();
69}69}
82 {82 {
83 await collection.methods.setCollectionProperties([{key: 'A', value: [0,1,2,3]}]).send({from:owner});83 await collection.methods.setCollectionProperties([{key: 'A', value: [0,1,2,3]}]).send({from:owner});
84 await helper.wait.newBlocks(1);84 await helper.wait.newBlocks(1);
85 expect(ethEvents).to.be.like([85 expect(ethEvents).to.containSubset([
86 {86 {
87 event: 'CollectionChanged',87 event: 'CollectionChanged',
88 returnValues: {88 returnValues: {
89 collectionId: collectionAddress,89 collectionId: collectionAddress,
90 },90 },
91 },91 },
92 ]);92 ]);
93 expect(subEvents).to.be.like([{method: 'CollectionPropertySet'}]);93 expect(subEvents).to.containSubset([{method: 'CollectionPropertySet'}]);
94 clearEvents(ethEvents, subEvents);94 clearEvents(ethEvents, subEvents);
95 }95 }
96 {96 {
97 await collection.methods.deleteCollectionProperties(['A']).send({from:owner});97 await collection.methods.deleteCollectionProperties(['A']).send({from:owner});
98 await helper.wait.newBlocks(1);98 await helper.wait.newBlocks(1);
99 expect(ethEvents).to.be.like([99 expect(ethEvents).to.containSubset([
100 {100 {
101 event: 'CollectionChanged',101 event: 'CollectionChanged',
102 returnValues: {102 returnValues: {
103 collectionId: collectionAddress,103 collectionId: collectionAddress,
104 },104 },
105 },105 },
106 ]);106 ]);
107 expect(subEvents).to.be.like([{method: 'CollectionPropertyDeleted'}]);107 expect(subEvents).to.containSubset([{method: 'CollectionPropertyDeleted'}]);
108 }108 }
109 unsubscribe();109 unsubscribe();
110}110}
127 ],127 ],
128 ]).send({from: owner});128 ]).send({from: owner});
129 await helper.wait.newBlocks(1);129 await helper.wait.newBlocks(1);
130 expect(ethEvents).to.be.like([130 expect(ethEvents).to.containSubset([
131 {131 {
132 event: 'CollectionChanged',132 event: 'CollectionChanged',
133 returnValues: {133 returnValues: {
134 collectionId: collectionAddress,134 collectionId: collectionAddress,
135 },135 },
136 },136 },
137 ]);137 ]);
138 expect(subEvents).to.be.like([{method: 'PropertyPermissionSet'}]);138 expect(subEvents).to.containSubset([{method: 'PropertyPermissionSet'}]);
139 unsubscribe();139 unsubscribe();
140}140}
141141
154 {154 {
155 await collection.methods.addToCollectionAllowListCross(user).send({from: owner});155 await collection.methods.addToCollectionAllowListCross(user).send({from: owner});
156 await helper.wait.newBlocks(1);156 await helper.wait.newBlocks(1);
157 expect(ethEvents).to.be.like([157 expect(ethEvents).to.containSubset([
158 {158 {
159 event: 'CollectionChanged',159 event: 'CollectionChanged',
160 returnValues: {160 returnValues: {
161 collectionId: collectionAddress,161 collectionId: collectionAddress,
162 },162 },
163 },163 },
164 ]);164 ]);
165 expect(subEvents).to.be.like([{method: 'AllowListAddressAdded'}]);165 expect(subEvents).to.containSubset([{method: 'AllowListAddressAdded'}]);
166 clearEvents(ethEvents, subEvents);166 clearEvents(ethEvents, subEvents);
167 }167 }
168 {168 {
169 await collection.methods.removeFromCollectionAllowListCross(user).send({from: owner});169 await collection.methods.removeFromCollectionAllowListCross(user).send({from: owner});
170 await helper.wait.newBlocks(1);170 await helper.wait.newBlocks(1);
171 expect(ethEvents.length).to.be.eq(1);171 expect(ethEvents.length).to.be.eq(1);
172 expect(ethEvents).to.be.like([172 expect(ethEvents).to.containSubset([
173 {173 {
174 event: 'CollectionChanged',174 event: 'CollectionChanged',
175 returnValues: {175 returnValues: {
176 collectionId: collectionAddress,176 collectionId: collectionAddress,
177 },177 },
178 },178 },
179 ]);179 ]);
180 expect(subEvents).to.be.like([{method: 'AllowListAddressRemoved'}]);180 expect(subEvents).to.containSubset([{method: 'AllowListAddressRemoved'}]);
181 }181 }
182 unsubscribe();182 unsubscribe();
183}183}
196 {196 {
197 await collection.methods.addCollectionAdminCross(user).send({from: owner});197 await collection.methods.addCollectionAdminCross(user).send({from: owner});
198 await helper.wait.newBlocks(1);198 await helper.wait.newBlocks(1);
199 expect(ethEvents).to.be.like([199 expect(ethEvents).to.containSubset([
200 {200 {
201 event: 'CollectionChanged',201 event: 'CollectionChanged',
202 returnValues: {202 returnValues: {
203 collectionId: collectionAddress,203 collectionId: collectionAddress,
204 },204 },
205 },205 },
206 ]);206 ]);
207 expect(subEvents).to.be.like([{method: 'CollectionAdminAdded'}]);207 expect(subEvents).to.containSubset([{method: 'CollectionAdminAdded'}]);
208 clearEvents(ethEvents, subEvents);208 clearEvents(ethEvents, subEvents);
209 }209 }
210 {210 {
211 await collection.methods.removeCollectionAdminCross(user).send({from: owner});211 await collection.methods.removeCollectionAdminCross(user).send({from: owner});
212 await helper.wait.newBlocks(1);212 await helper.wait.newBlocks(1);
213 expect(ethEvents).to.be.like([213 expect(ethEvents).to.containSubset([
214 {214 {
215 event: 'CollectionChanged',215 event: 'CollectionChanged',
216 returnValues: {216 returnValues: {
217 collectionId: collectionAddress,217 collectionId: collectionAddress,
218 },218 },
219 },219 },
220 ]);220 ]);
221 expect(subEvents).to.be.like([{method: 'CollectionAdminRemoved'}]);221 expect(subEvents).to.containSubset([{method: 'CollectionAdminRemoved'}]);
222 }222 }
223 unsubscribe();223 unsubscribe();
224}224}
236 {236 {
237 await collection.methods.setCollectionLimit(CollectionLimits.OwnerCanTransfer, true, 0).send({from: owner});237 await collection.methods.setCollectionLimit(CollectionLimits.OwnerCanTransfer, true, 0).send({from: owner});
238 await helper.wait.newBlocks(1);238 await helper.wait.newBlocks(1);
239 expect(ethEvents).to.be.like([239 expect(ethEvents).to.containSubset([
240 {240 {
241 event: 'CollectionChanged',241 event: 'CollectionChanged',
242 returnValues: {242 returnValues: {
243 collectionId: collectionAddress,243 collectionId: collectionAddress,
244 },244 },
245 },245 },
246 ]);246 ]);
247 expect(subEvents).to.be.like([{method: 'CollectionLimitSet'}]);247 expect(subEvents).to.containSubset([{method: 'CollectionLimitSet'}]);
248 }248 }
249 unsubscribe();249 unsubscribe();
250}250}
263 {263 {
264 await collection.methods.changeCollectionOwnerCross(newOwner).send({from: owner});264 await collection.methods.changeCollectionOwnerCross(newOwner).send({from: owner});
265 await helper.wait.newBlocks(1);265 await helper.wait.newBlocks(1);
266 expect(ethEvents).to.be.like([266 expect(ethEvents).to.containSubset([
267 {267 {
268 event: 'CollectionChanged',268 event: 'CollectionChanged',
269 returnValues: {269 returnValues: {
270 collectionId: collectionAddress,270 collectionId: collectionAddress,
271 },271 },
272 },272 },
273 ]);273 ]);
274 expect(subEvents).to.be.like([{method: 'CollectionOwnerChanged'}]);274 expect(subEvents).to.containSubset([{method: 'CollectionOwnerChanged'}]);
275 }275 }
276 unsubscribe();276 unsubscribe();
277}277}
289 {289 {
290 await collection.methods.setCollectionMintMode(true).send({from: owner});290 await collection.methods.setCollectionMintMode(true).send({from: owner});
291 await helper.wait.newBlocks(1);291 await helper.wait.newBlocks(1);
292 expect(ethEvents).to.be.like([292 expect(ethEvents).to.containSubset([
293 {293 {
294 event: 'CollectionChanged',294 event: 'CollectionChanged',
295 returnValues: {295 returnValues: {
296 collectionId: collectionAddress,296 collectionId: collectionAddress,
297 },297 },
298 },298 },
299 ]);299 ]);
300 expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);300 expect(subEvents).to.containSubset([{method: 'CollectionPermissionSet'}]);
301 clearEvents(ethEvents, subEvents);301 clearEvents(ethEvents, subEvents);
302 }302 }
303 {303 {
304 await collection.methods.setCollectionAccess(1).send({from: owner});304 await collection.methods.setCollectionAccess(1).send({from: owner});
305 await helper.wait.newBlocks(1);305 await helper.wait.newBlocks(1);
306 expect(ethEvents).to.be.like([306 expect(ethEvents).to.containSubset([
307 {307 {
308 event: 'CollectionChanged',308 event: 'CollectionChanged',
309 returnValues: {309 returnValues: {
310 collectionId: collectionAddress,310 collectionId: collectionAddress,
311 },311 },
312 },312 },
313 ]);313 ]);
314 expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);314 expect(subEvents).to.containSubset([{method: 'CollectionPermissionSet'}]);
315 }315 }
316 unsubscribe();316 unsubscribe();
317}317}
320 const owner = await helper.eth.createAccountWithBalance(donor);320 const owner = await helper.eth.createAccountWithBalance(donor);
321 const sponsor = await helper.ethCrossAccount.createAccountWithBalance(donor);321 const sponsor = await helper.ethCrossAccount.createAccountWithBalance(donor);
322 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');322 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
323 const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);323 const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
324 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);324 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
325 const ethEvents: any = [];325 const ethEvents: any = [];
326 collectionHelper.events.allEvents((_: any, event: any) => {326 collectionHelper.events.allEvents((_: any, event: any) => {
332 {332 {
333 await collection.methods.setCollectionSponsorCross(sponsor).send({from: owner});333 await collection.methods.setCollectionSponsorCross(sponsor).send({from: owner});
334 await helper.wait.newBlocks(1);334 await helper.wait.newBlocks(1);
335 expect(ethEvents).to.be.like([335 expect(ethEvents).to.containSubset([{
336 {
337 event: 'CollectionChanged',336 event: 'CollectionChanged',
338 returnValues: {337 returnValues: {
339 collectionId: collectionAddress,338 collectionId: collectionAddress,
340 },339 },
341 },340 }]);
342 ]);
343 expect(subEvents).to.be.like([{method: 'CollectionSponsorSet'}]);341 expect(subEvents).to.containSubset([{method: 'CollectionSponsorSet'}]);
344 clearEvents(ethEvents, subEvents);342 clearEvents(ethEvents, subEvents);
345 }343 }
346 {344 {
347 await collection.methods.confirmCollectionSponsorship().send({from: sponsor.eth});345 await collection.methods.confirmCollectionSponsorship().send({from: sponsor.eth});
348 await helper.wait.newBlocks(1);346 await helper.wait.newBlocks(1);
349 expect(ethEvents).to.be.like([347 expect(ethEvents).to.containSubset([
350 {348 {
351 event: 'CollectionChanged',349 event: 'CollectionChanged',
352 returnValues: {350 returnValues: {
353 collectionId: collectionAddress,351 collectionId: collectionAddress,
354 },352 },
355 },353 },
356 ]);354 ]);
357 expect(subEvents).to.be.like([{method: 'SponsorshipConfirmed'}]);355 expect(subEvents).to.containSubset([{method: 'SponsorshipConfirmed'}]);
358 clearEvents(ethEvents, subEvents);356 clearEvents(ethEvents, subEvents);
359 }357 }
360 {358 {
361 await collection.methods.removeCollectionSponsor().send({from: owner});359 await collection.methods.removeCollectionSponsor().send({from: owner});
362 await helper.wait.newBlocks(1);360 await helper.wait.newBlocks(1);
363 expect(ethEvents).to.be.like([361 expect(ethEvents).to.containSubset([
364 {362 {
365 event: 'CollectionChanged',363 event: 'CollectionChanged',
366 returnValues: {364 returnValues: {
367 collectionId: collectionAddress,365 collectionId: collectionAddress,
368 },366 },
369 },367 },
370 ]);368 ]);
371 expect(subEvents).to.be.like([{method: 'CollectionSponsorRemoved'}]);369 expect(subEvents).to.containSubset([{method: 'CollectionSponsorRemoved'}]);
372 }370 }
373 unsubscribe();371 unsubscribe();
374}372}
375373
376async function testTokenPropertySetAndDeleted(helper: EthUniqueHelper, mode: TCollectionMode) {374async function testTokenPropertySetAndDeleted(helper: EthUniqueHelper, mode: TCollectionMode) {
377 const owner = await helper.eth.createAccountWithBalance(donor);375 const owner = await helper.eth.createAccountWithBalance(donor);
378 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');376 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
379 const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);377 const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
380 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);378 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
381 const result = await collection.methods.mint(owner).send({from: owner});379 const result = await collection.methods.mint(owner).send({from: owner});
382 const tokenId = result.events.Transfer.returnValues.tokenId;380 const tokenId = result.events.Transfer.returnValues.tokenId;
397 {395 {
398 await collection.methods.setProperties(tokenId, [{key: 'A', value: [1,2,3]}]).send({from: owner});396 await collection.methods.setProperties(tokenId, [{key: 'A', value: [1,2,3]}]).send({from: owner});
399 await helper.wait.newBlocks(1);397 await helper.wait.newBlocks(1);
400 expect(ethEvents).to.be.like([398 expect(ethEvents).to.containSubset([
401 {399 {
402 event: 'TokenChanged',400 event: 'TokenChanged',
403 returnValues: {401 returnValues: {
404 collectionId: collectionAddress,402 collectionId: collectionAddress,
405 },403 },
406 },404 },
407 ]);405 ]);
408 expect(subEvents).to.be.like([{method: 'TokenPropertySet'}]);406 expect(subEvents).to.containSubset([{method: 'TokenPropertySet'}]);
409 clearEvents(ethEvents, subEvents);407 clearEvents(ethEvents, subEvents);
410 }408 }
411 {409 {
412 await collection.methods.deleteProperties(tokenId, ['A']).send({from: owner});410 await collection.methods.deleteProperties(tokenId, ['A']).send({from: owner});
413 await helper.wait.newBlocks(1);411 await helper.wait.newBlocks(1);
414 expect(ethEvents).to.be.like([412 expect(ethEvents).to.containSubset([
415 {413 {
416 event: 'TokenChanged',414 event: 'TokenChanged',
417 returnValues: {415 returnValues: {
418 collectionId: collectionAddress,416 collectionId: collectionAddress,
419 },417 },
420 },418 },
421 ]);419 ]);
422 expect(subEvents).to.be.like([{method: 'TokenPropertyDeleted'}]);420 expect(subEvents).to.containSubset([{method: 'TokenPropertyDeleted'}]);
423 }421 }
424 unsubscribe();422 unsubscribe();
425}423}
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
403 });403 });
404 }404 }
405
406 expect(await helper.nft.doesTokenExist(collection.collectionId, token.tokenId)).to.be.false;
405 });407 });
406 408
407 itEth('Can perform transfer with ApprovalForAll', async ({helper}) => {409 itEth('Can perform transfer with ApprovalForAll', async ({helper}) => {
modifiedtests/src/util/index.tsdiffbeforeafterboth
6import {IKeyringPair} from '@polkadot/types/types/interfaces';6import {IKeyringPair} from '@polkadot/types/types/interfaces';
7import chai from 'chai';7import chai from 'chai';
8import chaiAsPromised from 'chai-as-promised';8import chaiAsPromised from 'chai-as-promised';
9import chaiSubset from 'chai-subset';
9import {Context} from 'mocha';10import {Context} from 'mocha';
10import config from '../config';11import config from '../config';
11import {ChainHelperBase} from './playgrounds/unique';12import {ChainHelperBase} from './playgrounds/unique';
12import {ILogger} from './playgrounds/types';13import {ILogger} from './playgrounds/types';
13import {DevUniqueHelper, SilentLogger, SilentConsole, DevMoonbeamHelper, DevMoonriverHelper, DevAcalaHelper, DevKaruraHelper, DevRelayHelper, DevWestmintHelper} from './playgrounds/unique.dev';14import {DevUniqueHelper, SilentLogger, SilentConsole, DevMoonbeamHelper, DevMoonriverHelper, DevAcalaHelper, DevKaruraHelper, DevRelayHelper, DevWestmintHelper} from './playgrounds/unique.dev';
1415
15chai.use(chaiAsPromised);16chai.use(chaiAsPromised);
17chai.use(chaiSubset);
16export const expect = chai.expect;18export const expect = chai.expect;
1719
18const getTestHash = (filename: string) => {20const getTestHash = (filename: string) => {
modifiedtests/yarn.lockdiffbeforeafterboth
979 dependencies:979 dependencies:
980 "@types/chai" "*"980 "@types/chai" "*"
981981
982"@types/chai-subset@^1.3.3":
983 version "1.3.3"
984 resolved "https://registry.yarnpkg.com/@types/chai-subset/-/chai-subset-1.3.3.tgz#97893814e92abd2c534de422cb377e0e0bdaac94"
985 integrity sha512-frBecisrNGz+F4T6bcc+NLeolfiojh5FxW2klu669+8BARtyQv2C/GkNW6FUodVe4BroGMP/wER/YDGc7rEllw==
986 dependencies:
987 "@types/chai" "*"
988
982"@types/chai@*", "@types/chai@^4.3.3":989"@types/chai@*", "@types/chai@^4.3.3":
983 version "4.3.4"990 version "4.3.4"
984 resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.4.tgz#e913e8175db8307d78b4e8fa690408ba6b65dee4"991 resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.4.tgz#e913e8175db8307d78b4e8fa690408ba6b65dee4"
1568 version "1.1.1"1575 version "1.1.1"
1569 resolved "https://registry.yarnpkg.com/chai-like/-/chai-like-1.1.1.tgz#8c558a414c34514e814d497c772547ceb7958f64"1576 resolved "https://registry.yarnpkg.com/chai-like/-/chai-like-1.1.1.tgz#8c558a414c34514e814d497c772547ceb7958f64"
1570 integrity sha512-VKa9z/SnhXhkT1zIjtPACFWSoWsqVoaz1Vg+ecrKo5DCKVlgL30F/pEyEvXPBOVwCgLZcWUleCM/C1okaKdTTA==1577 integrity sha512-VKa9z/SnhXhkT1zIjtPACFWSoWsqVoaz1Vg+ecrKo5DCKVlgL30F/pEyEvXPBOVwCgLZcWUleCM/C1okaKdTTA==
1578
1579chai-subset@^1.6.0:
1580 version "1.6.0"
1581 resolved "https://registry.yarnpkg.com/chai-subset/-/chai-subset-1.6.0.tgz#a5d0ca14e329a79596ed70058b6646bd6988cfe9"
1582 integrity sha512-K3d+KmqdS5XKW5DWPd5sgNffL3uxdDe+6GdnJh3AYPhwnBGRY5urfvfcbRtWIvvpz+KxkL9FeBB6MZewLUNwug==
15711583
1572chai@^4.3.6:1584chai@^4.3.6:
1573 version "4.3.7"1585 version "4.3.7"