difftreelog
Use chai-subset to test events
in: master
5 files changed
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -8,11 +8,13 @@
"@types/chai": "^4.3.3",
"@types/chai-as-promised": "^7.1.5",
"@types/chai-like": "^1.1.1",
+ "@types/chai-subset": "^1.3.3",
"@types/mocha": "^10.0.0",
"@types/node": "^18.11.2",
"@typescript-eslint/eslint-plugin": "^5.40.1",
"@typescript-eslint/parser": "^5.40.1",
"chai": "^4.3.6",
+ "chai-subset": "^1.6.0",
"eslint": "^8.25.0",
"eslint-plugin-mocha": "^10.1.0",
"mocha": "^10.1.0",
tests/src/eth/events.test.tsdiffbeforeafterboth--- a/tests/src/eth/events.test.ts
+++ b/tests/src/eth/events.test.ts
@@ -40,7 +40,7 @@
const {collectionAddress, events: ethEvents} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
await helper.wait.newBlocks(1);
{
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionCreated',
args: {
@@ -49,21 +49,21 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionCreated'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionCreated'}]);
clearEvents(ethEvents, subEvents);
}
{
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const result = await collectionHelper.methods.destroyCollection(collectionAddress).send({from:owner});
await helper.wait.newBlocks(1);
- expect(result.events).to.be.like({
+ expect(result.events).to.containSubset({
CollectionDestroyed: {
returnValues: {
collectionId: collectionAddress,
},
},
});
- expect(subEvents).to.be.like([{method: 'CollectionDestroyed'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionDestroyed'}]);
}
unsubscribe();
}
@@ -82,7 +82,7 @@
{
await collection.methods.setCollectionProperties([{key: 'A', value: [0,1,2,3]}]).send({from:owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -90,13 +90,13 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionPropertySet'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionPropertySet'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.deleteCollectionProperties(['A']).send({from:owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -104,7 +104,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionPropertyDeleted'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionPropertyDeleted'}]);
}
unsubscribe();
}
@@ -127,7 +127,7 @@
],
]).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -135,7 +135,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'PropertyPermissionSet'}]);
+ expect(subEvents).to.containSubset([{method: 'PropertyPermissionSet'}]);
unsubscribe();
}
@@ -154,7 +154,7 @@
{
await collection.methods.addToCollectionAllowListCross(user).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -162,14 +162,14 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'AllowListAddressAdded'}]);
+ expect(subEvents).to.containSubset([{method: 'AllowListAddressAdded'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.removeFromCollectionAllowListCross(user).send({from: owner});
await helper.wait.newBlocks(1);
expect(ethEvents.length).to.be.eq(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -177,7 +177,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'AllowListAddressRemoved'}]);
+ expect(subEvents).to.containSubset([{method: 'AllowListAddressRemoved'}]);
}
unsubscribe();
}
@@ -196,7 +196,7 @@
{
await collection.methods.addCollectionAdminCross(user).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -204,13 +204,13 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionAdminAdded'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionAdminAdded'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.removeCollectionAdminCross(user).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -218,7 +218,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionAdminRemoved'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionAdminRemoved'}]);
}
unsubscribe();
}
@@ -236,7 +236,7 @@
{
await collection.methods.setCollectionLimit(CollectionLimits.OwnerCanTransfer, true, 0).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -244,7 +244,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionLimitSet'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionLimitSet'}]);
}
unsubscribe();
}
@@ -263,7 +263,7 @@
{
await collection.methods.changeCollectionOwnerCross(newOwner).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -271,7 +271,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionOwnerChanged'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionOwnerChanged'}]);
}
unsubscribe();
}
@@ -289,7 +289,7 @@
{
await collection.methods.setCollectionMintMode(true).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -297,13 +297,13 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionPermissionSet'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.setCollectionAccess(1).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -311,7 +311,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionPermissionSet'}]);
}
unsubscribe();
}
@@ -320,7 +320,7 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const sponsor = await helper.ethCrossAccount.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const ethEvents: any = [];
collectionHelper.events.allEvents((_: any, event: any) => {
@@ -332,21 +332,19 @@
{
await collection.methods.setCollectionSponsorCross(sponsor).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
- {
- event: 'CollectionChanged',
- returnValues: {
- collectionId: collectionAddress,
- },
+ expect(ethEvents).to.containSubset([{
+ event: 'CollectionChanged',
+ returnValues: {
+ collectionId: collectionAddress,
},
- ]);
- expect(subEvents).to.be.like([{method: 'CollectionSponsorSet'}]);
+ }]);
+ expect(subEvents).to.containSubset([{method: 'CollectionSponsorSet'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.confirmCollectionSponsorship().send({from: sponsor.eth});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -354,13 +352,13 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'SponsorshipConfirmed'}]);
+ expect(subEvents).to.containSubset([{method: 'SponsorshipConfirmed'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.removeCollectionSponsor().send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -368,7 +366,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionSponsorRemoved'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionSponsorRemoved'}]);
}
unsubscribe();
}
@@ -376,7 +374,7 @@
async function testTokenPropertySetAndDeleted(helper: EthUniqueHelper, mode: TCollectionMode) {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const result = await collection.methods.mint(owner).send({from: owner});
const tokenId = result.events.Transfer.returnValues.tokenId;
@@ -397,7 +395,7 @@
{
await collection.methods.setProperties(tokenId, [{key: 'A', value: [1,2,3]}]).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'TokenChanged',
returnValues: {
@@ -405,13 +403,13 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'TokenPropertySet'}]);
+ expect(subEvents).to.containSubset([{method: 'TokenPropertySet'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.deleteProperties(tokenId, ['A']).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'TokenChanged',
returnValues: {
@@ -419,7 +417,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'TokenPropertyDeleted'}]);
+ expect(subEvents).to.containSubset([{method: 'TokenPropertyDeleted'}]);
}
unsubscribe();
}
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -402,6 +402,8 @@
},
});
}
+
+ expect(await helper.nft.doesTokenExist(collection.collectionId, token.tokenId)).to.be.false;
});
itEth('Can perform transfer with ApprovalForAll', async ({helper}) => {
tests/src/util/index.tsdiffbeforeafterboth6import {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';141515chai.use(chaiAsPromised);16chai.use(chaiAsPromised);17chai.use(chaiSubset);16export const expect = chai.expect;18export const expect = chai.expect;171918const getTestHash = (filename: string) => {20const getTestHash = (filename: string) => {tests/yarn.lockdiffbeforeafterboth--- a/tests/yarn.lock
+++ b/tests/yarn.lock
@@ -979,6 +979,13 @@
dependencies:
"@types/chai" "*"
+"@types/chai-subset@^1.3.3":
+ version "1.3.3"
+ resolved "https://registry.yarnpkg.com/@types/chai-subset/-/chai-subset-1.3.3.tgz#97893814e92abd2c534de422cb377e0e0bdaac94"
+ integrity sha512-frBecisrNGz+F4T6bcc+NLeolfiojh5FxW2klu669+8BARtyQv2C/GkNW6FUodVe4BroGMP/wER/YDGc7rEllw==
+ dependencies:
+ "@types/chai" "*"
+
"@types/chai@*", "@types/chai@^4.3.3":
version "4.3.4"
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.4.tgz#e913e8175db8307d78b4e8fa690408ba6b65dee4"
@@ -1569,6 +1576,11 @@
resolved "https://registry.yarnpkg.com/chai-like/-/chai-like-1.1.1.tgz#8c558a414c34514e814d497c772547ceb7958f64"
integrity sha512-VKa9z/SnhXhkT1zIjtPACFWSoWsqVoaz1Vg+ecrKo5DCKVlgL30F/pEyEvXPBOVwCgLZcWUleCM/C1okaKdTTA==
+chai-subset@^1.6.0:
+ version "1.6.0"
+ resolved "https://registry.yarnpkg.com/chai-subset/-/chai-subset-1.6.0.tgz#a5d0ca14e329a79596ed70058b6646bd6988cfe9"
+ integrity sha512-K3d+KmqdS5XKW5DWPd5sgNffL3uxdDe+6GdnJh3AYPhwnBGRY5urfvfcbRtWIvvpz+KxkL9FeBB6MZewLUNwug==
+
chai@^4.3.6:
version "4.3.7"
resolved "https://registry.yarnpkg.com/chai/-/chai-4.3.7.tgz#ec63f6df01829088e8bf55fca839bcd464a8ec51"