difftreelog
misk: add tests for FT and RFT
in: master
2 files changed
tests/src/eth/events.test.tsdiffbeforeafterboth161617import { expect } from 'chai';17import { expect } from 'chai';18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';19import { itEth, usingEthPlaygrounds } from './util';19import { EthUniqueHelper, itEth, usingEthPlaygrounds } from './util';20import { TCollectionMode } from '../util/playgrounds/types';202121describe('NFT events', () => {22 let donor: IKeyringPair;22let donor: IKeyringPair;23 23 24 before(async function () {24before(async function () {25 await usingEthPlaygrounds(async (_helper, privateKey) => {25 await usingEthPlaygrounds(async (_helper, privateKey) => {26 donor = await privateKey({filename: __filename});26 donor = await privateKey({filename: __filename});27 });28 });27 });28});292930 itEth('Create event', async ({helper}) => {30async function testCollectionCreatedAndDestroy(helper: EthUniqueHelper, mode: TCollectionMode) {31 const owner = await helper.eth.createAccountWithBalance(donor);31 const owner = await helper.eth.createAccountWithBalance(donor);32 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionCreated']}]);32 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionCreated', 'CollectionDestroyed']}]);33 const {collectionAddress, events: ethEvents} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');33 const {collectionAddress, events: ethEvents} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');34 expect(ethEvents).to.be.like([35 {36 event: 'CollectionCreated',37 args: {38 owner: owner,39 collectionId: collectionAddress40 }41 }42 ]);43 expect(subEvents).to.be.like([{method: 'CollectionCreated'}]);44 unsubscribe();45 });4647 itEth('Destroy event', async ({helper}) => {48 const owner = await helper.eth.createAccountWithBalance(donor);49 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');50 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);51 const {unsubscribe, collectedEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionDestroyed']}]);52 let result = await collectionHelper.methods.destroyCollection(collectionAddress).send({from:owner});53 expect(result.events).to.be.like({54 CollectionDestroyed: {55 returnValues: {56 collectionId: collectionAddress57 }58 }59 });60 expect(collectedEvents).to.be.like([{method: 'CollectionDestroyed'}]);61 unsubscribe();62 });63 64 itEth('CollectionChanged event for CollectionPropertySet and CollectionPropertyDeleted', async ({helper}) => {65 const owner = await helper.eth.createAccountWithBalance(donor);66 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');67 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);68 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);69 70 let {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionPropertySet', 'CollectionPropertyDeleted']}]);71 {34 {72 const ethEvents: any = [];73 collectionHelper.events.allEvents((_: any, event: any) => {74 ethEvents.push(event);75 });76 await collection.methods.setCollectionProperties([{key: 'A', value: [0,1,2,3]}]).send({from:owner});77 expect(ethEvents).to.be.like([35 expect(ethEvents).to.be.like([78 {36 {79 event: 'CollectionChanged',37 event: 'CollectionCreated',80 returnValues: {38 args: {39 owner: owner,81 collectionId: collectionAddress40 collectionId: collectionAddress82 }41 }83 }42 }84 ]);43 ]);85 expect(subEvents).to.be.like([{method: 'CollectionPropertySet'}]);44 expect(subEvents).to.be.like([{method: 'CollectionCreated'}]);45 ethEvents.pop();86 subEvents.pop();46 subEvents.pop();87 }47 }88 {48 {89 const ethEvents: any = [];49 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);90 collectionHelper.events.allEvents((_: any, event: any) => {91 ethEvents.push(event);92 });50 let result = await collectionHelper.methods.destroyCollection(collectionAddress).send({from:owner});93 await collection.methods.deleteCollectionProperties(['A']).send({from:owner});94 expect(ethEvents).to.be.like([51 expect(result.events).to.be.like({95 {96 event: 'CollectionChanged',52 CollectionDestroyed: {97 returnValues: {53 returnValues: {98 collectionId: collectionAddress54 collectionId: collectionAddress99 }55 }100 }56 }101 ]);57 });102 expect(subEvents).to.be.like([{method: 'CollectionPropertyDeleted'}]);58 expect(subEvents).to.be.like([{method: 'CollectionDestroyed'}]);103 }59 }104 unsubscribe();60 unsubscribe();61}62105 });63async function testCollectionPropertySetAndCollectionPropertyDeleted(helper: EthUniqueHelper, mode: TCollectionMode) {64 const owner = await helper.eth.createAccountWithBalance(donor);65 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');66 const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);67 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);106 68 107 itEth('CollectionChanged event for PropertyPermissionSet', async ({helper}) => {69 let {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionPropertySet', 'CollectionPropertyDeleted']}]);108 const owner = await helper.eth.createAccountWithBalance(donor);109 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');110 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);70 {111 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);112 const eethEvents: any = [];71 const ethEvents: any = [];113 collectionHelper.events.allEvents((_: any, event: any) => {72 collectionHelper.events.allEvents((_: any, event: any) => {114 eethEvents.push(event);73 ethEvents.push(event);115 });74 });116 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['PropertyPermissionSet']}]);75 await collection.methods.setCollectionProperties([{key: 'A', value: [0,1,2,3]}]).send({from:owner});117 await collection.methods.setTokenPropertyPermission('testKey', true, true, true).send({from: owner});118 expect(eethEvents).to.be.like([76 expect(ethEvents).to.be.like([119 {77 {120 event: 'CollectionChanged',78 event: 'CollectionChanged',121 returnValues: {79 returnValues: {122 collectionId: collectionAddress80 collectionId: collectionAddress123 }81 }124 }82 }125 ]);83 ]);126 expect(subEvents).to.be.like([{method: 'PropertyPermissionSet'}]);84 expect(subEvents).to.be.like([{method: 'CollectionPropertySet'}]);127 unsubscribe();85 subEvents.pop();86 }87 {88 const ethEvents: any = [];89 collectionHelper.events.allEvents((_: any, event: any) => {90 ethEvents.push(event);91 });92 await collection.methods.deleteCollectionProperties(['A']).send({from:owner});93 expect(ethEvents).to.be.like([94 {95 event: 'CollectionChanged',96 returnValues: {97 collectionId: collectionAddress98 }99 }100 ]);101 expect(subEvents).to.be.like([{method: 'CollectionPropertyDeleted'}]);102 }103 unsubscribe();104}105106async function testPropertyPermissionSet(helper: EthUniqueHelper, mode: TCollectionMode) {107 const owner = await helper.eth.createAccountWithBalance(donor);108 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');109 const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);110 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);111 const eethEvents: any = [];112 collectionHelper.events.allEvents((_: any, event: any) => {113 eethEvents.push(event);128 });114 });129 115 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['PropertyPermissionSet']}]);130 itEth('CollectionChanged event for AllowListAddressAdded, AllowListAddressRemoved', async ({helper}) => {116 await collection.methods.setTokenPropertyPermission('testKey', true, true, true).send({from: owner});117 expect(eethEvents).to.be.like([118 {131 const owner = await helper.eth.createAccountWithBalance(donor);119 event: 'CollectionChanged',120 returnValues: {121 collectionId: collectionAddress122 }123 }124 ]);125 expect(subEvents).to.be.like([{method: 'PropertyPermissionSet'}]);126 unsubscribe();127}128129async function testAllowListAddressAddedAndAllowListAddressRemoved(helper: EthUniqueHelper, mode: TCollectionMode) {130 const owner = await helper.eth.createAccountWithBalance(donor);132 const user = helper.ethCrossAccount.createAccount();131 const user = helper.ethCrossAccount.createAccount();133 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');132 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');134 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);133 const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);135 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);134 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);136 const ethEvents: any[] = [];135 const ethEvents: any[] = [];137 collectionHelper.events.allEvents((_: any, event: any) => {136 collectionHelper.events.allEvents((_: any, event: any) => {167 expect(subEvents).to.be.like([{method: 'AllowListAddressRemoved'}]);166 expect(subEvents).to.be.like([{method: 'AllowListAddressRemoved'}]);168 }167 }169 unsubscribe();168 unsubscribe();169}170171async function testCollectionAdminAddedAndCollectionAdminRemoved(helper: EthUniqueHelper, mode: TCollectionMode) {172 const owner = await helper.eth.createAccountWithBalance(donor);173 const user = helper.ethCrossAccount.createAccount();174 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');175 const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);176 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);177 const ethEvents: any = [];178 collectionHelper.events.allEvents((_: any, event: any) => {179 ethEvents.push(event);170 });180 });171 181 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionAdminAdded', 'CollectionAdminRemoved']}]);172 itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => {173 const owner = await helper.eth.createAccountWithBalance(donor);174 const user = helper.ethCrossAccount.createAccount();175 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');176 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);177 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);178 const ethEvents: any = [];179 collectionHelper.events.allEvents((_: any, event: any) => {180 ethEvents.push(event);181 });182 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionAdminAdded', 'CollectionAdminRemoved']}]);183 {182 {184 await collection.methods.addCollectionAdminCross(user).send({from: owner});183 await collection.methods.addCollectionAdminCross(user).send({from: owner});185 expect(ethEvents).to.be.like([184 expect(ethEvents).to.be.like([186 {185 {187 event: 'CollectionChanged',186 event: 'CollectionChanged',188 returnValues: {187 returnValues: {189 collectionId: collectionAddress188 collectionId: collectionAddress190 }191 }189 }192 ]);190 }193 expect(subEvents).to.be.like([{method: 'CollectionAdminAdded'}]);191 ]);192 expect(subEvents).to.be.like([{method: 'CollectionAdminAdded'}]);194 ethEvents.pop();193 ethEvents.pop();195 subEvents.pop();194 subEvents.pop();196 }195 }197 {196 {198 await collection.methods.removeCollectionAdminCross(user).send({from: owner});197 await collection.methods.removeCollectionAdminCross(user).send({from: owner});199 expect(ethEvents).to.be.like([198 expect(ethEvents).to.be.like([200 {199 {201 event: 'CollectionChanged',200 event: 'CollectionChanged',202 returnValues: {201 returnValues: {203 collectionId: collectionAddress202 collectionId: collectionAddress204 }205 }203 }206 ]);204 }207 expect(subEvents).to.be.like([{method: 'CollectionAdminRemoved'}]);205 ]);206 expect(subEvents).to.be.like([{method: 'CollectionAdminRemoved'}]);208 }207 }208 unsubscribe();209}210209 unsubscribe();211async function testCollectionLimitSet(helper: EthUniqueHelper, mode: TCollectionMode) {212 const owner = await helper.eth.createAccountWithBalance(donor);213 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');214 const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);215 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);216 const ethEvents: any = [];217 collectionHelper.events.allEvents((_: any, event: any) => {218 ethEvents.push(event);210 });219 });211 220 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionLimitSet']}]);212 itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => {213 const owner = await helper.eth.createAccountWithBalance(donor);214 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');215 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);216 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);217 const ethEvents: any = [];218 collectionHelper.events.allEvents((_: any, event: any) => {219 ethEvents.push(event);220 });221 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionLimitSet']}]);222 {221 {223 await collection.methods.setCollectionLimit('ownerCanTransfer', 0n).send({from: owner});222 await collection.methods.setCollectionLimit('ownerCanTransfer', 0n).send({from: owner});224 expect(ethEvents).to.be.like([223 expect(ethEvents).to.be.like([225 {224 {226 event: 'CollectionChanged',225 event: 'CollectionChanged',227 returnValues: {226 returnValues: {228 collectionId: collectionAddress227 collectionId: collectionAddress229 }230 }228 }231 ]);229 }232 expect(subEvents).to.be.like([{method: 'CollectionLimitSet'}]);230 ]);231 expect(subEvents).to.be.like([{method: 'CollectionLimitSet'}]);233 }232 }233 unsubscribe();234}235234 unsubscribe();236async function testCollectionOwnedChanged(helper: EthUniqueHelper, mode: TCollectionMode) {237 const owner = await helper.eth.createAccountWithBalance(donor);238 const new_owner = helper.ethCrossAccount.createAccount();239 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');240 const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);241 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);242 const ethEvents: any = [];243 collectionHelper.events.allEvents((_: any, event: any) => {244 ethEvents.push(event);235 });245 });236 246 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionOwnedChanged']}]);237 itEth('CollectionChanged event for CollectionOwnedChanged', async ({helper}) => {238 const owner = await helper.eth.createAccountWithBalance(donor);239 const new_owner = helper.ethCrossAccount.createAccount();240 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');241 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);242 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);243 const ethEvents: any = [];244 collectionHelper.events.allEvents((_: any, event: any) => {245 ethEvents.push(event);246 });247 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionOwnedChanged']}]);248 {247 {249 await collection.methods.changeCollectionOwnerCross(new_owner).send({from: owner});248 await collection.methods.changeCollectionOwnerCross(new_owner).send({from: owner});250 expect(ethEvents).to.be.like([249 expect(ethEvents).to.be.like([251 {250 {252 event: 'CollectionChanged',251 event: 'CollectionChanged',253 returnValues: {252 returnValues: {254 collectionId: collectionAddress253 collectionId: collectionAddress255 }256 }254 }257 ]);255 }258 expect(subEvents).to.be.like([{method: 'CollectionOwnedChanged'}]);256 ]);257 expect(subEvents).to.be.like([{method: 'CollectionOwnedChanged'}]);259 }258 }259 unsubscribe();260}261260 unsubscribe();262async function testCollectionPermissionSet(helper: EthUniqueHelper, mode: TCollectionMode) {263 const owner = await helper.eth.createAccountWithBalance(donor);264 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');265 const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);266 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);267 const ethEvents: any = [];268 collectionHelper.events.allEvents((_: any, event: any) => {269 ethEvents.push(event);261 });270 });262 271 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionPermissionSet']}]);263 itEth('CollectionChanged event for CollectionPermissionSet', async ({helper}) => {264 const owner = await helper.eth.createAccountWithBalance(donor);265 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');266 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);267 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);268 const ethEvents: any = [];269 collectionHelper.events.allEvents((_: any, event: any) => {270 ethEvents.push(event);271 });272 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionPermissionSet']}]);273 {272 {274 await collection.methods.setCollectionMintMode(true).send({from: owner});273 await collection.methods.setCollectionMintMode(true).send({from: owner});275 expect(ethEvents).to.be.like([274 expect(ethEvents).to.be.like([276 {275 {277 event: 'CollectionChanged',276 event: 'CollectionChanged',278 returnValues: {277 returnValues: {279 collectionId: collectionAddress278 collectionId: collectionAddress280 }281 }279 }282 ]);280 }283 expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);281 ]);282 expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);284 ethEvents.pop();283 ethEvents.pop();285 subEvents.pop();284 subEvents.pop();286 }285 }287 {286 {288 await collection.methods.setCollectionAccess(1).send({from: owner});287 await collection.methods.setCollectionAccess(1).send({from: owner});289 expect(ethEvents).to.be.like([288 expect(ethEvents).to.be.like([290 {289 {291 event: 'CollectionChanged',290 event: 'CollectionChanged',292 returnValues: {291 returnValues: {293 collectionId: collectionAddress292 collectionId: collectionAddress294 }295 }293 }296 ]);294 }297 expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);295 ]);296 expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);298 }297 }299 unsubscribe();298 unsubscribe();300 });299}301300302 itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => {301async function testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper: EthUniqueHelper, mode: TCollectionMode) {303 const owner = await helper.eth.createAccountWithBalance(donor);302 const owner = await helper.eth.createAccountWithBalance(donor);304 const sponsor = await helper.ethCrossAccount.createAccountWithBalance(donor);303 const sponsor = await helper.ethCrossAccount.createAccountWithBalance(donor);305 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');304 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');306 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);305 const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);307 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);306 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);308 const ethEvents: any = [];307 const ethEvents: any = [];309 collectionHelper.events.allEvents((_: any, event: any) => {308 collectionHelper.events.allEvents((_: any, event: any) => {353 expect(subEvents).to.be.like([{method: 'CollectionSponsorRemoved'}]);352 expect(subEvents).to.be.like([{method: 'CollectionSponsorRemoved'}]);354 }353 }355 unsubscribe();354 unsubscribe();355}356357async function testTokenPropertySetAndTokenPropertyDeleted(helper: EthUniqueHelper, mode: TCollectionMode) {358 const owner = await helper.eth.createAccountWithBalance(donor);359 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');360 const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);361 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);362 const result = await collection.methods.mint(owner).send({from: owner});363 const tokenId = result.events.Transfer.returnValues.tokenId;364 await collection.methods.setTokenPropertyPermission('A', true, true, true).send({from: owner});365366367 const ethEvents: any = [];368 collectionHelper.events.allEvents((_: any, event: any) => {369 ethEvents.push(event);356 });370 });371 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['TokenPropertySet', 'TokenPropertyDeleted']}]);372 {373 await collection.methods.setProperties(tokenId, [{key: 'A', value: [1,2,3]}]).send({from: owner});374 expect(ethEvents).to.be.like([375 {376 event: 'TokenChanged',377 returnValues: {378 collectionId: collectionAddress379 }380 }381 ]);382 expect(subEvents).to.be.like([{method: 'TokenPropertySet'}]);383 ethEvents.pop();384 subEvents.pop();385 }386 {387 await collection.methods.deleteProperties(tokenId, ['A']).send({from: owner});388 expect(ethEvents).to.be.like([389 {390 event: 'TokenChanged',391 returnValues: {392 collectionId: collectionAddress393 }394 }395 ]);396 expect(subEvents).to.be.like([{method: 'TokenPropertyDeleted'}]);397 }398 unsubscribe();399}400401describe('[FT] Sync sub & eth events', () => {402 const mode: TCollectionMode = 'ft';403404 itEth('CollectionCreated and CollectionDestroyed events', async ({helper}) => {405 await testCollectionCreatedAndDestroy(helper, mode);406 });407408 itEth('CollectionChanged event for CollectionPropertySet and CollectionPropertyDeleted', async ({helper}) => {409 await testCollectionPropertySetAndCollectionPropertyDeleted(helper, mode);410 });411 412 itEth('CollectionChanged event for AllowListAddressAdded, AllowListAddressRemoved', async ({helper}) => {413 await testAllowListAddressAddedAndAllowListAddressRemoved(helper, mode);414 });415 416 itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => {417 await testCollectionAdminAddedAndCollectionAdminRemoved(helper, mode);418 });419 420 itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => {421 await testCollectionLimitSet(helper, mode);422 });423 424 itEth('CollectionChanged event for CollectionOwnedChanged', async ({helper}) => {425 await testCollectionOwnedChanged(helper, mode);426 });427 428 itEth('CollectionChanged event for CollectionPermissionSet', async ({helper}) => {429 await testCollectionPermissionSet(helper, mode);430 });431432 itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => {433 await testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper, mode);434 });435});436437describe('[NFT] Sync sub & eth events', () => {438 const mode: TCollectionMode = 'nft';439440 itEth('CollectionCreated and CollectionDestroyed events', async ({helper}) => {441 await testCollectionCreatedAndDestroy(helper, mode);442 });443444 itEth('CollectionChanged event for CollectionPropertySet and CollectionPropertyDeleted', async ({helper}) => {445 await testCollectionPropertySetAndCollectionPropertyDeleted(helper, mode);446 });447 448 itEth('CollectionChanged event for PropertyPermissionSet', async ({helper}) => {449 await testPropertyPermissionSet(helper, mode);450 });451 452 itEth('CollectionChanged event for AllowListAddressAdded, AllowListAddressRemoved', async ({helper}) => {453 await testAllowListAddressAddedAndAllowListAddressRemoved(helper, mode);454 });455 456 itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => {457 await testCollectionAdminAddedAndCollectionAdminRemoved(helper, mode);458 });459 460 itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => {461 await testCollectionLimitSet(helper, mode);462 });463 464 itEth('CollectionChanged event for CollectionOwnedChanged', async ({helper}) => {465 await testCollectionOwnedChanged(helper, mode);466 });467 468 itEth('CollectionChanged event for CollectionPermissionSet', async ({helper}) => {469 await testCollectionPermissionSet(helper, mode);470 });471472 itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => {473 await testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper, mode);474 });357 475 358 itEth('CollectionChanged event for TokenPropertySet, TokenPropertyDeleted', async ({helper}) => {476 itEth('CollectionChanged event for TokenPropertySet, TokenPropertyDeleted', async ({helper}) => {359 const owner = await helper.eth.createAccountWithBalance(donor);477 await testTokenPropertySetAndTokenPropertyDeleted(helper, mode);360 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');361 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);478 });362 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);363 const result = await collection.methods.mint(owner).send({from: owner});364 const tokenId = result.events.Transfer.returnValues.tokenId;365 await collection.methods.setTokenPropertyPermission('A', true, true, true).send({from: owner});479});366480481describe('[RFT] Sync sub & eth events', () => {482 const mode: TCollectionMode = 'rft';367483368 const ethEvents: any = [];484 itEth('CollectionCreated and CollectionDestroyed events', async ({helper}) => {369 collectionHelper.events.allEvents((_: any, event: any) => {370 ethEvents.push(event);485 await testCollectionCreatedAndDestroy(helper, mode);371 });486 });487372 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['TokenPropertySet', 'TokenPropertyDeleted']}]);488 itEth('CollectionChanged event for CollectionPropertySet and CollectionPropertyDeleted', async ({helper}) => {373 {374 await collection.methods.setProperties(tokenId, [{key: 'A', value: [1,2,3]}]).send({from: owner});489 await testCollectionPropertySetAndCollectionPropertyDeleted(helper, mode);490 });375 expect(ethEvents).to.be.like([491 376 {492 itEth('CollectionChanged event for PropertyPermissionSet', async ({helper}) => {493 await testPropertyPermissionSet(helper, mode);494 });377 event: 'TokenChanged',495 378 returnValues: {496 itEth('CollectionChanged event for AllowListAddressAdded, AllowListAddressRemoved', async ({helper}) => {379 collectionId: collectionAddress497 await testAllowListAddressAddedAndAllowListAddressRemoved(helper, mode);498 });499 380 }500 itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => {381 }501 await testCollectionAdminAddedAndCollectionAdminRemoved(helper, mode);382 ]);502 });383 expect(subEvents).to.be.like([{method: 'TokenPropertySet'}]);503 384 ethEvents.pop();504 itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => {505 await testCollectionLimitSet(helper, mode);385 subEvents.pop();506 });386 }507 387 {508 itEth('CollectionChanged event for CollectionOwnedChanged', async ({helper}) => {388 await collection.methods.deleteProperties(tokenId, ['A']).send({from: owner});509 await testCollectionOwnedChanged(helper, mode);389 expect(ethEvents).to.be.like([510 });390 {511 391 event: 'TokenChanged',512 itEth('CollectionChanged event for CollectionPermissionSet', async ({helper}) => {392 returnValues: {393 collectionId: collectionAddress513 await testCollectionPermissionSet(helper, mode);514 });515394 }516 itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => {395 }517 await testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper, mode);518 });396 ]);519 397 expect(subEvents).to.be.like([{method: 'TokenPropertyDeleted'}]);520 itEth('CollectionChanged event for TokenPropertySet, TokenPropertyDeleted', async ({helper}) => {398 }399 unsubscribe();521 await testTokenPropertySetAndTokenPropertyDeleted(helper, mode);400 });522 });401});523});524tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth186 return await this.helper.callRpc('api.rpc.eth.call', [{from: signer, to: contractAddress, data: abi}]);186 return await this.helper.callRpc('api.rpc.eth.call', [{from: signer, to: contractAddress, data: abi}]);187 }187 }188189 createCollectionMethodName(mode: TCollectionMode) {190 switch (mode) {191 case 'ft':192 return 'createFTCollection';193 case 'nft':194 return 'createNFTCollection';195 case 'rft':196 return 'createRFTCollection';197 }198 }188199189 async createCollecion(functionName: 'createNFTCollection' | 'createRFTCollection' | 'createFTCollection', signer: string, name: string, description: string, tokenPrefix: string, decimals?: number): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {200 async createCollection(mode: TCollectionMode, signer: string, name: string, description: string, tokenPrefix: string, decimals: number = 18): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {190 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();201 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();191 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);202 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);203 const functionName: string = this.createCollectionMethodName(mode);192204193 const functionParams = functionName === 'createFTCollection' ? [name, decimals, description, tokenPrefix] : [name, description, tokenPrefix];205 const functionParams = functionName === 'createFTCollection' ? [name, decimals, description, tokenPrefix] : [name, description, tokenPrefix];194 const result = await collectionHelper.methods[functionName](...functionParams).send({value: Number(collectionCreationPrice)});206 const result = await collectionHelper.methods[functionName](...functionParams).send({value: Number(collectionCreationPrice)});201 }213 }202214203 createNFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {215 createNFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {204 return this.createCollecion('createNFTCollection', signer, name, description, tokenPrefix);216 return this.createCollection('nft', signer, name, description, tokenPrefix);205 }217 }206218207 async createERC721MetadataCompatibleNFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {219 async createERC721MetadataCompatibleNFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {208 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);220 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);209221210 const {collectionId, collectionAddress, events} = await this.createCollecion('createNFTCollection', signer, name, description, tokenPrefix);222 const {collectionId, collectionAddress, events} = await this.createCollection('nft', signer, name, description, tokenPrefix);211223212 await collectionHelper.methods.makeCollectionERC721MetadataCompatible(collectionAddress, baseUri).send();224 await collectionHelper.methods.makeCollectionERC721MetadataCompatible(collectionAddress, baseUri).send();213225214 return {collectionId, collectionAddress, events};226 return {collectionId, collectionAddress, events};215 }227 }216228217 createRFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> {229 createRFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> {218 return this.createCollecion('createRFTCollection', signer, name, description, tokenPrefix);230 return this.createCollection('rft', signer, name, description, tokenPrefix);219 }231 }220232221 createFungibleCollection(signer: string, name: string, decimals: number, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> {233 createFungibleCollection(signer: string, name: string, decimals: number, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> {225 async createERC721MetadataCompatibleRFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {237 async createERC721MetadataCompatibleRFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {226 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);238 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);227239228 const {collectionId, collectionAddress, events} = await this.createCollecion('createRFTCollection', signer, name, description, tokenPrefix);240 const {collectionId, collectionAddress, events} = await this.createCollection('rft', signer, name, description, tokenPrefix);229241230 await collectionHelper.methods.makeCollectionERC721MetadataCompatible(collectionAddress, baseUri).send();242 await collectionHelper.methods.makeCollectionERC721MetadataCompatible(collectionAddress, baseUri).send();231243