difftreelog
misk: add tests for FT and RFT
in: master
2 files changed
tests/src/eth/events.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import { expect } from 'chai';18import {IKeyringPair} from '@polkadot/types/types';19import { itEth, usingEthPlaygrounds } from './util';2021describe('NFT events', () => {22 let donor: IKeyringPair;23 24 before(async function () {25 await usingEthPlaygrounds(async (_helper, privateKey) => {26 donor = await privateKey({filename: __filename});27 });28 });2930 itEth('Create event', async ({helper}) => {31 const owner = await helper.eth.createAccountWithBalance(donor);32 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionCreated']}]);33 const {collectionAddress, events: ethEvents} = await helper.eth.createCollecion('createNFTCollection', 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 {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([78 {79 event: 'CollectionChanged',80 returnValues: {81 collectionId: collectionAddress82 }83 }84 ]);85 expect(subEvents).to.be.like([{method: 'CollectionPropertySet'}]);86 subEvents.pop();87 }88 {89 const ethEvents: any = [];90 collectionHelper.events.allEvents((_: any, event: any) => {91 ethEvents.push(event);92 });93 await collection.methods.deleteCollectionProperties(['A']).send({from:owner});94 expect(ethEvents).to.be.like([95 {96 event: 'CollectionChanged',97 returnValues: {98 collectionId: collectionAddress99 }100 }101 ]);102 expect(subEvents).to.be.like([{method: 'CollectionPropertyDeleted'}]);103 }104 unsubscribe();105 });106 107 itEth('CollectionChanged event for PropertyPermissionSet', async ({helper}) => {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);111 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);112 const eethEvents: any = [];113 collectionHelper.events.allEvents((_: any, event: any) => {114 eethEvents.push(event);115 });116 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['PropertyPermissionSet']}]);117 await collection.methods.setTokenPropertyPermission('testKey', true, true, true).send({from: owner});118 expect(eethEvents).to.be.like([119 {120 event: 'CollectionChanged',121 returnValues: {122 collectionId: collectionAddress123 }124 }125 ]);126 expect(subEvents).to.be.like([{method: 'PropertyPermissionSet'}]);127 unsubscribe();128 });129 130 itEth('CollectionChanged event for AllowListAddressAdded, AllowListAddressRemoved', async ({helper}) => {131 const owner = await helper.eth.createAccountWithBalance(donor);132 const user = helper.ethCrossAccount.createAccount();133 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');134 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);135 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);136 const ethEvents: any[] = [];137 collectionHelper.events.allEvents((_: any, event: any) => {138 ethEvents.push(event);139 });140141 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['AllowListAddressAdded', 'AllowListAddressRemoved']}]);142 {143 await collection.methods.addToCollectionAllowListCross(user).send({from: owner});144 expect(ethEvents).to.be.like([145 {146 event: 'CollectionChanged',147 returnValues: {148 collectionId: collectionAddress149 }150 }151 ]);152 expect(subEvents).to.be.like([{method: 'AllowListAddressAdded'}]);153 ethEvents.pop();154 subEvents.pop();155 }156 {157 await collection.methods.removeFromCollectionAllowListCross(user).send({from: owner});158 expect(ethEvents.length).to.be.eq(1);159 expect(ethEvents).to.be.like([160 {161 event: 'CollectionChanged',162 returnValues: {163 collectionId: collectionAddress164 }165 }166 ]);167 expect(subEvents).to.be.like([{method: 'AllowListAddressRemoved'}]);168 }169 unsubscribe();170 });171 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 {184 await collection.methods.addCollectionAdminCross(user).send({from: owner});185 expect(ethEvents).to.be.like([186 {187 event: 'CollectionChanged',188 returnValues: {189 collectionId: collectionAddress190 }191 }192 ]);193 expect(subEvents).to.be.like([{method: 'CollectionAdminAdded'}]);194 ethEvents.pop();195 subEvents.pop();196 }197 {198 await collection.methods.removeCollectionAdminCross(user).send({from: owner});199 expect(ethEvents).to.be.like([200 {201 event: 'CollectionChanged',202 returnValues: {203 collectionId: collectionAddress204 }205 }206 ]);207 expect(subEvents).to.be.like([{method: 'CollectionAdminRemoved'}]);208 }209 unsubscribe();210 });211 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 {223 await collection.methods.setCollectionLimit('ownerCanTransfer', 0n).send({from: owner});224 expect(ethEvents).to.be.like([225 {226 event: 'CollectionChanged',227 returnValues: {228 collectionId: collectionAddress229 }230 }231 ]);232 expect(subEvents).to.be.like([{method: 'CollectionLimitSet'}]);233 }234 unsubscribe();235 });236 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 {249 await collection.methods.changeCollectionOwnerCross(new_owner).send({from: owner});250 expect(ethEvents).to.be.like([251 {252 event: 'CollectionChanged',253 returnValues: {254 collectionId: collectionAddress255 }256 }257 ]);258 expect(subEvents).to.be.like([{method: 'CollectionOwnedChanged'}]);259 }260 unsubscribe();261 });262 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 {274 await collection.methods.setCollectionMintMode(true).send({from: owner});275 expect(ethEvents).to.be.like([276 {277 event: 'CollectionChanged',278 returnValues: {279 collectionId: collectionAddress280 }281 }282 ]);283 expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);284 ethEvents.pop();285 subEvents.pop();286 }287 {288 await collection.methods.setCollectionAccess(1).send({from: owner});289 expect(ethEvents).to.be.like([290 {291 event: 'CollectionChanged',292 returnValues: {293 collectionId: collectionAddress294 }295 }296 ]);297 expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);298 }299 unsubscribe();300 });301302 itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => {303 const owner = await helper.eth.createAccountWithBalance(donor);304 const sponsor = await helper.ethCrossAccount.createAccountWithBalance(donor);305 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');306 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);307 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);308 const ethEvents: any = [];309 collectionHelper.events.allEvents((_: any, event: any) => {310 ethEvents.push(event);311 });312 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{313 section: 'common', names: ['CollectionSponsorSet', 'SponsorshipConfirmed', 'CollectionSponsorRemoved'314 ]}]);315 {316 await collection.methods.setCollectionSponsorCross(sponsor).send({from: owner});317 expect(ethEvents).to.be.like([318 {319 event: 'CollectionChanged',320 returnValues: {321 collectionId: collectionAddress322 }323 }324 ]);325 expect(subEvents).to.be.like([{method: 'CollectionSponsorSet'}]);326 ethEvents.pop();327 subEvents.pop();328 }329 {330 await collection.methods.confirmCollectionSponsorship().send({from: sponsor.eth});331 expect(ethEvents).to.be.like([332 {333 event: 'CollectionChanged',334 returnValues: {335 collectionId: collectionAddress336 }337 }338 ]);339 expect(subEvents).to.be.like([{method: 'SponsorshipConfirmed'}]);340 ethEvents.pop();341 subEvents.pop();342 }343 {344 await collection.methods.removeCollectionSponsor().send({from: owner});345 expect(ethEvents).to.be.like([346 {347 event: 'CollectionChanged',348 returnValues: {349 collectionId: collectionAddress350 }351 }352 ]);353 expect(subEvents).to.be.like([{method: 'CollectionSponsorRemoved'}]);354 }355 unsubscribe();356 });357 358 itEth('CollectionChanged event for TokenPropertySet, TokenPropertyDeleted', async ({helper}) => {359 const owner = await helper.eth.createAccountWithBalance(donor);360 const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');361 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);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});366367368 const ethEvents: any = [];369 collectionHelper.events.allEvents((_: any, event: any) => {370 ethEvents.push(event);371 });372 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['TokenPropertySet', 'TokenPropertyDeleted']}]);373 {374 await collection.methods.setProperties(tokenId, [{key: 'A', value: [1,2,3]}]).send({from: owner});375 expect(ethEvents).to.be.like([376 {377 event: 'TokenChanged',378 returnValues: {379 collectionId: collectionAddress380 }381 }382 ]);383 expect(subEvents).to.be.like([{method: 'TokenPropertySet'}]);384 ethEvents.pop();385 subEvents.pop();386 }387 {388 await collection.methods.deleteProperties(tokenId, ['A']).send({from: owner});389 expect(ethEvents).to.be.like([390 {391 event: 'TokenChanged',392 returnValues: {393 collectionId: collectionAddress394 }395 }396 ]);397 expect(subEvents).to.be.like([{method: 'TokenPropertyDeleted'}]);398 }399 unsubscribe();400 });401});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import { expect } from 'chai';18import {IKeyringPair} from '@polkadot/types/types';19import { EthUniqueHelper, itEth, usingEthPlaygrounds } from './util';20import { TCollectionMode } from '../util/playgrounds/types';2122let donor: IKeyringPair;23 24before(async function () {25 await usingEthPlaygrounds(async (_helper, privateKey) => {26 donor = await privateKey({filename: __filename});27 });28});2930async function testCollectionCreatedAndDestroy(helper: EthUniqueHelper, mode: TCollectionMode) {31 const owner = await helper.eth.createAccountWithBalance(donor);32 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionCreated', 'CollectionDestroyed']}]);33 const {collectionAddress, events: ethEvents} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');34 {35 expect(ethEvents).to.be.like([36 {37 event: 'CollectionCreated',38 args: {39 owner: owner,40 collectionId: collectionAddress41 }42 }43 ]);44 expect(subEvents).to.be.like([{method: 'CollectionCreated'}]);45 ethEvents.pop();46 subEvents.pop();47 }48 {49 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);50 let result = await collectionHelper.methods.destroyCollection(collectionAddress).send({from:owner});51 expect(result.events).to.be.like({52 CollectionDestroyed: {53 returnValues: {54 collectionId: collectionAddress55 }56 }57 });58 expect(subEvents).to.be.like([{method: 'CollectionDestroyed'}]);59 }60 unsubscribe();61}6263async 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);68 69 let {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionPropertySet', 'CollectionPropertyDeleted']}]);70 {71 const ethEvents: any = [];72 collectionHelper.events.allEvents((_: any, event: any) => {73 ethEvents.push(event);74 });75 await collection.methods.setCollectionProperties([{key: 'A', value: [0,1,2,3]}]).send({from:owner});76 expect(ethEvents).to.be.like([77 {78 event: 'CollectionChanged',79 returnValues: {80 collectionId: collectionAddress81 }82 }83 ]);84 expect(subEvents).to.be.like([{method: 'CollectionPropertySet'}]);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);114 });115 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['PropertyPermissionSet']}]);116 await collection.methods.setTokenPropertyPermission('testKey', true, true, true).send({from: owner});117 expect(eethEvents).to.be.like([118 {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);131 const user = helper.ethCrossAccount.createAccount();132 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');133 const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);134 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);135 const ethEvents: any[] = [];136 collectionHelper.events.allEvents((_: any, event: any) => {137 ethEvents.push(event);138 });139140 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['AllowListAddressAdded', 'AllowListAddressRemoved']}]);141 {142 await collection.methods.addToCollectionAllowListCross(user).send({from: owner});143 expect(ethEvents).to.be.like([144 {145 event: 'CollectionChanged',146 returnValues: {147 collectionId: collectionAddress148 }149 }150 ]);151 expect(subEvents).to.be.like([{method: 'AllowListAddressAdded'}]);152 ethEvents.pop();153 subEvents.pop();154 }155 {156 await collection.methods.removeFromCollectionAllowListCross(user).send({from: owner});157 expect(ethEvents.length).to.be.eq(1);158 expect(ethEvents).to.be.like([159 {160 event: 'CollectionChanged',161 returnValues: {162 collectionId: collectionAddress163 }164 }165 ]);166 expect(subEvents).to.be.like([{method: 'AllowListAddressRemoved'}]);167 }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);180 });181 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionAdminAdded', 'CollectionAdminRemoved']}]);182 {183 await collection.methods.addCollectionAdminCross(user).send({from: owner});184 expect(ethEvents).to.be.like([185 {186 event: 'CollectionChanged',187 returnValues: {188 collectionId: collectionAddress189 }190 }191 ]);192 expect(subEvents).to.be.like([{method: 'CollectionAdminAdded'}]);193 ethEvents.pop();194 subEvents.pop();195 }196 {197 await collection.methods.removeCollectionAdminCross(user).send({from: owner});198 expect(ethEvents).to.be.like([199 {200 event: 'CollectionChanged',201 returnValues: {202 collectionId: collectionAddress203 }204 }205 ]);206 expect(subEvents).to.be.like([{method: 'CollectionAdminRemoved'}]);207 }208 unsubscribe();209}210211async 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);219 });220 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionLimitSet']}]);221 {222 await collection.methods.setCollectionLimit('ownerCanTransfer', 0n).send({from: owner});223 expect(ethEvents).to.be.like([224 {225 event: 'CollectionChanged',226 returnValues: {227 collectionId: collectionAddress228 }229 }230 ]);231 expect(subEvents).to.be.like([{method: 'CollectionLimitSet'}]);232 }233 unsubscribe();234}235236async 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);245 });246 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionOwnedChanged']}]);247 {248 await collection.methods.changeCollectionOwnerCross(new_owner).send({from: owner});249 expect(ethEvents).to.be.like([250 {251 event: 'CollectionChanged',252 returnValues: {253 collectionId: collectionAddress254 }255 }256 ]);257 expect(subEvents).to.be.like([{method: 'CollectionOwnedChanged'}]);258 }259 unsubscribe();260}261262async 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);270 });271 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionPermissionSet']}]);272 {273 await collection.methods.setCollectionMintMode(true).send({from: owner});274 expect(ethEvents).to.be.like([275 {276 event: 'CollectionChanged',277 returnValues: {278 collectionId: collectionAddress279 }280 }281 ]);282 expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);283 ethEvents.pop();284 subEvents.pop();285 }286 {287 await collection.methods.setCollectionAccess(1).send({from: owner});288 expect(ethEvents).to.be.like([289 {290 event: 'CollectionChanged',291 returnValues: {292 collectionId: collectionAddress293 }294 }295 ]);296 expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);297 }298 unsubscribe();299}300301async function testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper: EthUniqueHelper, mode: TCollectionMode) {302 const owner = await helper.eth.createAccountWithBalance(donor);303 const sponsor = await helper.ethCrossAccount.createAccountWithBalance(donor);304 const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');305 const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);306 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);307 const ethEvents: any = [];308 collectionHelper.events.allEvents((_: any, event: any) => {309 ethEvents.push(event);310 });311 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{312 section: 'common', names: ['CollectionSponsorSet', 'SponsorshipConfirmed', 'CollectionSponsorRemoved'313 ]}]);314 {315 await collection.methods.setCollectionSponsorCross(sponsor).send({from: owner});316 expect(ethEvents).to.be.like([317 {318 event: 'CollectionChanged',319 returnValues: {320 collectionId: collectionAddress321 }322 }323 ]);324 expect(subEvents).to.be.like([{method: 'CollectionSponsorSet'}]);325 ethEvents.pop();326 subEvents.pop();327 }328 {329 await collection.methods.confirmCollectionSponsorship().send({from: sponsor.eth});330 expect(ethEvents).to.be.like([331 {332 event: 'CollectionChanged',333 returnValues: {334 collectionId: collectionAddress335 }336 }337 ]);338 expect(subEvents).to.be.like([{method: 'SponsorshipConfirmed'}]);339 ethEvents.pop();340 subEvents.pop();341 }342 {343 await collection.methods.removeCollectionSponsor().send({from: owner});344 expect(ethEvents).to.be.like([345 {346 event: 'CollectionChanged',347 returnValues: {348 collectionId: collectionAddress349 }350 }351 ]);352 expect(subEvents).to.be.like([{method: 'CollectionSponsorRemoved'}]);353 }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);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 });475 476 itEth('CollectionChanged event for TokenPropertySet, TokenPropertyDeleted', async ({helper}) => {477 await testTokenPropertySetAndTokenPropertyDeleted(helper, mode);478 });479});480481describe('[RFT] Sync sub & eth events', () => {482 const mode: TCollectionMode = 'rft';483484 itEth('CollectionCreated and CollectionDestroyed events', async ({helper}) => {485 await testCollectionCreatedAndDestroy(helper, mode);486 });487488 itEth('CollectionChanged event for CollectionPropertySet and CollectionPropertyDeleted', async ({helper}) => {489 await testCollectionPropertySetAndCollectionPropertyDeleted(helper, mode);490 });491 492 itEth('CollectionChanged event for PropertyPermissionSet', async ({helper}) => {493 await testPropertyPermissionSet(helper, mode);494 });495 496 itEth('CollectionChanged event for AllowListAddressAdded, AllowListAddressRemoved', async ({helper}) => {497 await testAllowListAddressAddedAndAllowListAddressRemoved(helper, mode);498 });499 500 itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => {501 await testCollectionAdminAddedAndCollectionAdminRemoved(helper, mode);502 });503 504 itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => {505 await testCollectionLimitSet(helper, mode);506 });507 508 itEth('CollectionChanged event for CollectionOwnedChanged', async ({helper}) => {509 await testCollectionOwnedChanged(helper, mode);510 });511 512 itEth('CollectionChanged event for CollectionPermissionSet', async ({helper}) => {513 await testCollectionPermissionSet(helper, mode);514 });515516 itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => {517 await testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper, mode);518 });519 520 itEth('CollectionChanged event for TokenPropertySet, TokenPropertyDeleted', async ({helper}) => {521 await testTokenPropertySetAndTokenPropertyDeleted(helper, mode);522 });523});tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -186,9 +186,21 @@
return await this.helper.callRpc('api.rpc.eth.call', [{from: signer, to: contractAddress, data: abi}]);
}
- async createCollecion(functionName: 'createNFTCollection' | 'createRFTCollection' | 'createFTCollection', signer: string, name: string, description: string, tokenPrefix: string, decimals?: number): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {
+ createCollectionMethodName(mode: TCollectionMode) {
+ switch (mode) {
+ case 'ft':
+ return 'createFTCollection';
+ case 'nft':
+ return 'createNFTCollection';
+ case 'rft':
+ return 'createRFTCollection';
+ }
+ }
+
+ async createCollection(mode: TCollectionMode, signer: string, name: string, description: string, tokenPrefix: string, decimals: number = 18): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {
const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
+ const functionName: string = this.createCollectionMethodName(mode);
const functionParams = functionName === 'createFTCollection' ? [name, decimals, description, tokenPrefix] : [name, description, tokenPrefix];
const result = await collectionHelper.methods[functionName](...functionParams).send({value: Number(collectionCreationPrice)});
@@ -201,13 +213,13 @@
}
createNFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {
- return this.createCollecion('createNFTCollection', signer, name, description, tokenPrefix);
+ return this.createCollection('nft', signer, name, description, tokenPrefix);
}
async createERC721MetadataCompatibleNFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {
const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
- const {collectionId, collectionAddress, events} = await this.createCollecion('createNFTCollection', signer, name, description, tokenPrefix);
+ const {collectionId, collectionAddress, events} = await this.createCollection('nft', signer, name, description, tokenPrefix);
await collectionHelper.methods.makeCollectionERC721MetadataCompatible(collectionAddress, baseUri).send();
@@ -215,7 +227,7 @@
}
createRFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> {
- return this.createCollecion('createRFTCollection', signer, name, description, tokenPrefix);
+ return this.createCollection('rft', signer, name, description, tokenPrefix);
}
createFungibleCollection(signer: string, name: string, decimals: number, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> {
@@ -225,7 +237,7 @@
async createERC721MetadataCompatibleRFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {
const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
- const {collectionId, collectionAddress, events} = await this.createCollecion('createRFTCollection', signer, name, description, tokenPrefix);
+ const {collectionId, collectionAddress, events} = await this.createCollection('rft', signer, name, description, tokenPrefix);
await collectionHelper.methods.makeCollectionERC721MetadataCompatible(collectionAddress, baseUri).send();