difftreelog
fix PR
in: master
2 files changed
tests/src/eth/events.test.tsdiffbeforeafterboth17import {expect} from 'chai';17import {expect} from 'chai';18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';19import {EthUniqueHelper, itEth, usingEthPlaygrounds} from './util';19import {EthUniqueHelper, itEth, usingEthPlaygrounds} from './util';20import {TCollectionMode} from '../util/playgrounds/types';20import {IEvent, TCollectionMode} from '../util/playgrounds/types';21import {Pallets, requirePalletsOrSkip} from '../util';21import {Pallets, requirePalletsOrSkip} from '../util';22import {NormalizedEvent} from './util/playgrounds/types';222323let donor: IKeyringPair;24let donor: IKeyringPair;24 25 28 });29 });29});30});3132function clearEvents(ethEvents: NormalizedEvent[], subEvents: IEvent[]) {33 ethEvents.splice(0);34 subEvents.splice(0);35}303631async function testCollectionCreatedAndDestroy(helper: EthUniqueHelper, mode: TCollectionMode) {37async function testCollectionCreatedAndDestroy(helper: EthUniqueHelper, mode: TCollectionMode) {32 const owner = await helper.eth.createAccountWithBalance(donor);38 const owner = await helper.eth.createAccountWithBalance(donor);44 },50 },45 ]);51 ]);46 expect(subEvents).to.be.like([{method: 'CollectionCreated'}]);52 expect(subEvents).to.be.like([{method: 'CollectionCreated'}]);47 ethEvents.pop();53 clearEvents(ethEvents, subEvents);48 subEvents.pop();49 }54 }50 {55 {51 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);56 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);69 const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);74 const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);70 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);75 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);71 76 72 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionPropertySet', 'CollectionPropertyDeleted']}]);73 {74 const ethEvents: any = [];77 const ethEvents: any = [];75 collectionHelper.events.allEvents((_: any, event: any) => {78 collectionHelper.events.allEvents((_: any, event: any) => {76 ethEvents.push(event);79 ethEvents.push(event);77 });80 });81 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionPropertySet', 'CollectionPropertyDeleted']}]);82 {78 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});79 await helper.wait.newBlocks(1);84 await helper.wait.newBlocks(1);80 expect(ethEvents).to.be.like([85 expect(ethEvents).to.be.like([86 },91 },87 ]);92 ]);88 expect(subEvents).to.be.like([{method: 'CollectionPropertySet'}]);93 expect(subEvents).to.be.like([{method: 'CollectionPropertySet'}]);89 subEvents.pop();94 clearEvents(ethEvents, subEvents);90 }95 }91 {96 {92 const ethEvents: any = [];93 collectionHelper.events.allEvents((_: any, event: any) => {94 ethEvents.push(event);95 });96 await collection.methods.deleteCollectionProperties(['A']).send({from:owner});97 await collection.methods.deleteCollectionProperties(['A']).send({from:owner});97 await helper.wait.newBlocks(1);98 await helper.wait.newBlocks(1);98 expect(ethEvents).to.be.like([99 expect(ethEvents).to.be.like([113 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');114 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');114 const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);115 const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);115 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);116 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);116 const eethEvents: any = [];117 const ethEvents: any = [];117 collectionHelper.events.allEvents((_: any, event: any) => {118 collectionHelper.events.allEvents((_: any, event: any) => {118 eethEvents.push(event);119 ethEvents.push(event);119 });120 });120 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['PropertyPermissionSet']}]);121 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['PropertyPermissionSet']}]);121 await collection.methods.setTokenPropertyPermission('testKey', true, true, true).send({from: owner});122 await collection.methods.setTokenPropertyPermission('testKey', true, true, true).send({from: owner});122 await helper.wait.newBlocks(1);123 await helper.wait.newBlocks(1);123 expect(eethEvents).to.be.like([124 expect(ethEvents).to.be.like([124 {125 {125 event: 'CollectionChanged',126 event: 'CollectionChanged',126 returnValues: {127 returnValues: {156 },157 },157 ]);158 ]);158 expect(subEvents).to.be.like([{method: 'AllowListAddressAdded'}]);159 expect(subEvents).to.be.like([{method: 'AllowListAddressAdded'}]);159 ethEvents.pop();160 clearEvents(ethEvents, subEvents);160 subEvents.pop();161 }161 }162 {162 {163 await collection.methods.removeFromCollectionAllowListCross(user).send({from: owner});163 await collection.methods.removeFromCollectionAllowListCross(user).send({from: owner});176 unsubscribe();176 unsubscribe();177}177}178178179async function testCollectionAdminAddedAndCollectionAdminRemoved(helper: EthUniqueHelper, mode: TCollectionMode) {179async function testCollectionAdminAddedAndRemoved(helper: EthUniqueHelper, mode: TCollectionMode) {180 const owner = await helper.eth.createAccountWithBalance(donor);180 const owner = await helper.eth.createAccountWithBalance(donor);181 const user = helper.ethCrossAccount.createAccount();181 const user = helper.ethCrossAccount.createAccount();182 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');182 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');199 },199 },200 ]);200 ]);201 expect(subEvents).to.be.like([{method: 'CollectionAdminAdded'}]);201 expect(subEvents).to.be.like([{method: 'CollectionAdminAdded'}]);202 ethEvents.pop();202 clearEvents(ethEvents, subEvents);203 subEvents.pop();204 }203 }205 {204 {206 await collection.methods.removeCollectionAdminCross(user).send({from: owner});205 await collection.methods.removeCollectionAdminCross(user).send({from: owner});293 },292 },294 ]);293 ]);295 expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);294 expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);296 ethEvents.pop();295 clearEvents(ethEvents, subEvents);297 subEvents.pop();298 }296 }299 {297 {300 await collection.methods.setCollectionAccess(1).send({from: owner});298 await collection.methods.setCollectionAccess(1).send({from: owner});312 unsubscribe();310 unsubscribe();313}311}314312315async function testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper: EthUniqueHelper, mode: TCollectionMode) {313async function testCollectionSponsorSetAndConfirmedAndThenRemoved(helper: EthUniqueHelper, mode: TCollectionMode) {316 const owner = await helper.eth.createAccountWithBalance(donor);314 const owner = await helper.eth.createAccountWithBalance(donor);317 const sponsor = await helper.ethCrossAccount.createAccountWithBalance(donor);315 const sponsor = await helper.ethCrossAccount.createAccountWithBalance(donor);318 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');316 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');337 },335 },338 ]);336 ]);339 expect(subEvents).to.be.like([{method: 'CollectionSponsorSet'}]);337 expect(subEvents).to.be.like([{method: 'CollectionSponsorSet'}]);340 ethEvents.pop();338 clearEvents(ethEvents, subEvents);341 subEvents.pop();342 }339 }343 {340 {344 await collection.methods.confirmCollectionSponsorship().send({from: sponsor.eth});341 await collection.methods.confirmCollectionSponsorship().send({from: sponsor.eth});352 },349 },353 ]);350 ]);354 expect(subEvents).to.be.like([{method: 'SponsorshipConfirmed'}]);351 expect(subEvents).to.be.like([{method: 'SponsorshipConfirmed'}]);355 ethEvents.pop();352 clearEvents(ethEvents, subEvents);356 subEvents.pop();357 }353 }358 {354 {359 await collection.methods.removeCollectionSponsor().send({from: owner});355 await collection.methods.removeCollectionSponsor().send({from: owner});371 unsubscribe();367 unsubscribe();372}368}373369374async function testTokenPropertySetAndTokenPropertyDeleted(helper: EthUniqueHelper, mode: TCollectionMode) {370async function testTokenPropertySetAndDeleted(helper: EthUniqueHelper, mode: TCollectionMode) {375 const owner = await helper.eth.createAccountWithBalance(donor);371 const owner = await helper.eth.createAccountWithBalance(donor);376 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');372 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');377 const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);373 const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);398 },394 },399 ]);395 ]);400 expect(subEvents).to.be.like([{method: 'TokenPropertySet'}]);396 expect(subEvents).to.be.like([{method: 'TokenPropertySet'}]);401 ethEvents.pop();397 clearEvents(ethEvents, subEvents);402 subEvents.pop();403 }398 }404 {399 {405 await collection.methods.deleteProperties(tokenId, ['A']).send({from: owner});400 await collection.methods.deleteProperties(tokenId, ['A']).send({from: owner});417 unsubscribe();412 unsubscribe();418}413}419414420describe('[FT] Sync sub & eth events', () => {415describe.only('[FT] Sync sub & eth events', () => {421 const mode: TCollectionMode = 'ft';416 const mode: TCollectionMode = 'ft';422417423 itEth('CollectionCreated and CollectionDestroyed events', async ({helper}) => {418 itEth('CollectionCreated and CollectionDestroyed events', async ({helper}) => {433 });428 });434 429 435 itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => {430 itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => {436 await testCollectionAdminAddedAndCollectionAdminRemoved(helper, mode);431 await testCollectionAdminAddedAndRemoved(helper, mode);437 });432 });438 433 439 itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => {434 itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => {449 });444 });450445451 itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => {446 itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => {452 await testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper, mode);447 await testCollectionSponsorSetAndConfirmedAndThenRemoved(helper, mode);453 });448 });454});449});455450456describe('[NFT] Sync sub & eth events', () => {451describe.only('[NFT] Sync sub & eth events', () => {457 const mode: TCollectionMode = 'nft';452 const mode: TCollectionMode = 'nft';458453459 itEth('CollectionCreated and CollectionDestroyed events', async ({helper}) => {454 itEth('CollectionCreated and CollectionDestroyed events', async ({helper}) => {473 });468 });474 469 475 itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => {470 itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => {476 await testCollectionAdminAddedAndCollectionAdminRemoved(helper, mode);471 await testCollectionAdminAddedAndRemoved(helper, mode);477 });472 });478 473 479 itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => {474 itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => {489 });484 });490485491 itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => {486 itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => {492 await testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper, mode);487 await testCollectionSponsorSetAndConfirmedAndThenRemoved(helper, mode);493 });488 });494 489 495 itEth('CollectionChanged event for TokenPropertySet, TokenPropertyDeleted', async ({helper}) => {490 itEth('CollectionChanged event for TokenPropertySet, TokenPropertyDeleted', async ({helper}) => {496 await testTokenPropertySetAndTokenPropertyDeleted(helper, mode);491 await testTokenPropertySetAndDeleted(helper, mode);497 });492 });498});493});499494500describe('[RFT] Sync sub & eth events', () => {495describe.only('[RFT] Sync sub & eth events', () => {501 const mode: TCollectionMode = 'rft';496 const mode: TCollectionMode = 'rft';502497503 before(async function() {498 before(async function() {524 });519 });525 520 526 itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => {521 itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => {527 await testCollectionAdminAddedAndCollectionAdminRemoved(helper, mode);522 await testCollectionAdminAddedAndRemoved(helper, mode);528 });523 });529 524 530 itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => {525 itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => {540 });535 });541536542 itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => {537 itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => {543 await testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper, mode);538 await testCollectionSponsorSetAndConfirmedAndThenRemoved(helper, mode);544 });539 });545 540 546 itEth('CollectionChanged event for TokenPropertySet, TokenPropertyDeleted', async ({helper}) => {541 itEth('CollectionChanged event for TokenPropertySet, TokenPropertyDeleted', async ({helper}) => {547 await testTokenPropertySetAndTokenPropertyDeleted(helper, mode);542 await testTokenPropertySetAndDeleted(helper, mode);548 });543 });549});544});550545tests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth70 await expect(collection.removeSponsor(alice)).to.not.be.rejected;70 await expect(collection.removeSponsor(alice)).to.not.be.rejected;71 });71 });727273 itSub('Remove sponsor for a collection with collection admin permissions', async ({helper}) => {73 itSub('Remove a sponsor from a collection with collection admin permissions', async ({helper}) => {74 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-1', tokenPrefix: 'RCS'});74 const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionSponsor-Neg-1', tokenPrefix: 'RCS'});75 await collection.setSponsor(alice, bob.address);75 await collection.setSponsor(alice, bob.address);76 await collection.addAdmin(alice, {Substrate: charlie.address});76 await collection.addAdmin(alice, {Substrate: charlie.address});