--- a/tests/src/eth/events.test.ts +++ b/tests/src/eth/events.test.ts @@ -16,106 +16,64 @@ import { expect } from 'chai'; import {IKeyringPair} from '@polkadot/types/types'; -import { itEth, usingEthPlaygrounds } from './util'; +import { EthUniqueHelper, itEth, usingEthPlaygrounds } from './util'; +import { TCollectionMode } from '../util/playgrounds/types'; -describe('NFT events', () => { - let donor: IKeyringPair; +let donor: IKeyringPair; - before(async function () { - await usingEthPlaygrounds(async (_helper, privateKey) => { - donor = await privateKey({filename: __filename}); - }); - }); - - itEth('Create event', async ({helper}) => { - const owner = await helper.eth.createAccountWithBalance(donor); - const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionCreated']}]); - const {collectionAddress, events: ethEvents} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C'); - expect(ethEvents).to.be.like([ - { - event: 'CollectionCreated', - args: { - owner: owner, - collectionId: collectionAddress - } - } - ]); - expect(subEvents).to.be.like([{method: 'CollectionCreated'}]); - unsubscribe(); +before(async function () { + await usingEthPlaygrounds(async (_helper, privateKey) => { + donor = await privateKey({filename: __filename}); }); +}); - itEth('Destroy event', async ({helper}) => { - const owner = await helper.eth.createAccountWithBalance(donor); - const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C'); - const collectionHelper = helper.ethNativeContract.collectionHelpers(owner); - const {unsubscribe, collectedEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionDestroyed']}]); - let result = await collectionHelper.methods.destroyCollection(collectionAddress).send({from:owner}); - expect(result.events).to.be.like({ - CollectionDestroyed: { - returnValues: { - collectionId: collectionAddress - } - } - }); - expect(collectedEvents).to.be.like([{method: 'CollectionDestroyed'}]); - unsubscribe(); - }); - - itEth('CollectionChanged event for CollectionPropertySet and CollectionPropertyDeleted', async ({helper}) => { - const owner = await helper.eth.createAccountWithBalance(donor); - const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C'); - const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner); - const collectionHelper = helper.ethNativeContract.collectionHelpers(owner); - - let {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionPropertySet', 'CollectionPropertyDeleted']}]); +async function testCollectionCreatedAndDestroy(helper: EthUniqueHelper, mode: TCollectionMode) { + const owner = await helper.eth.createAccountWithBalance(donor); + const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionCreated', 'CollectionDestroyed']}]); + const {collectionAddress, events: ethEvents} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C'); { - const ethEvents: any = []; - collectionHelper.events.allEvents((_: any, event: any) => { - ethEvents.push(event); - }); - await collection.methods.setCollectionProperties([{key: 'A', value: [0,1,2,3]}]).send({from:owner}); expect(ethEvents).to.be.like([ { - event: 'CollectionChanged', - returnValues: { + event: 'CollectionCreated', + args: { + owner: owner, collectionId: collectionAddress } } ]); - expect(subEvents).to.be.like([{method: 'CollectionPropertySet'}]); + expect(subEvents).to.be.like([{method: 'CollectionCreated'}]); + ethEvents.pop(); subEvents.pop(); } { - const ethEvents: any = []; - collectionHelper.events.allEvents((_: any, event: any) => { - ethEvents.push(event); - }); - await collection.methods.deleteCollectionProperties(['A']).send({from:owner}); - expect(ethEvents).to.be.like([ - { - event: 'CollectionChanged', + const collectionHelper = helper.ethNativeContract.collectionHelpers(owner); + let result = await collectionHelper.methods.destroyCollection(collectionAddress).send({from:owner}); + expect(result.events).to.be.like({ + CollectionDestroyed: { returnValues: { collectionId: collectionAddress } } - ]); - expect(subEvents).to.be.like([{method: 'CollectionPropertyDeleted'}]); + }); + expect(subEvents).to.be.like([{method: 'CollectionDestroyed'}]); } unsubscribe(); - }); +} + +async function testCollectionPropertySetAndCollectionPropertyDeleted(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 collectionHelper = helper.ethNativeContract.collectionHelpers(owner); - itEth('CollectionChanged event for PropertyPermissionSet', async ({helper}) => { - const owner = await helper.eth.createAccountWithBalance(donor); - const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C'); - const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner); - const collectionHelper = helper.ethNativeContract.collectionHelpers(owner); - const eethEvents: any = []; + let {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionPropertySet', 'CollectionPropertyDeleted']}]); + { + const ethEvents: any = []; collectionHelper.events.allEvents((_: any, event: any) => { - eethEvents.push(event); + ethEvents.push(event); }); - const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['PropertyPermissionSet']}]); - await collection.methods.setTokenPropertyPermission('testKey', true, true, true).send({from: owner}); - expect(eethEvents).to.be.like([ + await collection.methods.setCollectionProperties([{key: 'A', value: [0,1,2,3]}]).send({from:owner}); + expect(ethEvents).to.be.like([ { event: 'CollectionChanged', returnValues: { @@ -123,15 +81,56 @@ } } ]); - expect(subEvents).to.be.like([{method: 'PropertyPermissionSet'}]); - unsubscribe(); + expect(subEvents).to.be.like([{method: 'CollectionPropertySet'}]); + subEvents.pop(); + } + { + const ethEvents: any = []; + collectionHelper.events.allEvents((_: any, event: any) => { + ethEvents.push(event); + }); + await collection.methods.deleteCollectionProperties(['A']).send({from:owner}); + expect(ethEvents).to.be.like([ + { + event: 'CollectionChanged', + returnValues: { + collectionId: collectionAddress + } + } + ]); + expect(subEvents).to.be.like([{method: 'CollectionPropertyDeleted'}]); + } + unsubscribe(); +} + +async function testPropertyPermissionSet(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 collectionHelper = helper.ethNativeContract.collectionHelpers(owner); + const eethEvents: any = []; + collectionHelper.events.allEvents((_: any, event: any) => { + eethEvents.push(event); }); - - itEth('CollectionChanged event for AllowListAddressAdded, AllowListAddressRemoved', async ({helper}) => { - const owner = await helper.eth.createAccountWithBalance(donor); + const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['PropertyPermissionSet']}]); + await collection.methods.setTokenPropertyPermission('testKey', true, true, true).send({from: owner}); + expect(eethEvents).to.be.like([ + { + event: 'CollectionChanged', + returnValues: { + collectionId: collectionAddress + } + } + ]); + expect(subEvents).to.be.like([{method: 'PropertyPermissionSet'}]); + unsubscribe(); +} + +async function testAllowListAddressAddedAndAllowListAddressRemoved(helper: EthUniqueHelper, mode: TCollectionMode) { + const owner = await helper.eth.createAccountWithBalance(donor); const user = helper.ethCrossAccount.createAccount(); - const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C'); - const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner); + const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C'); + const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner); const collectionHelper = helper.ethNativeContract.collectionHelpers(owner); const ethEvents: any[] = []; collectionHelper.events.allEvents((_: any, event: any) => { @@ -167,143 +166,143 @@ expect(subEvents).to.be.like([{method: 'AllowListAddressRemoved'}]); } unsubscribe(); +} + +async function testCollectionAdminAddedAndCollectionAdminRemoved(helper: EthUniqueHelper, mode: TCollectionMode) { + const owner = await helper.eth.createAccountWithBalance(donor); + const user = helper.ethCrossAccount.createAccount(); + const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C'); + const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner); + const collectionHelper = helper.ethNativeContract.collectionHelpers(owner); + const ethEvents: any = []; + collectionHelper.events.allEvents((_: any, event: any) => { + ethEvents.push(event); }); - - itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => { - const owner = await helper.eth.createAccountWithBalance(donor); - const user = helper.ethCrossAccount.createAccount(); - const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C'); - const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner); - const collectionHelper = helper.ethNativeContract.collectionHelpers(owner); - const ethEvents: any = []; - collectionHelper.events.allEvents((_: any, event: any) => { - ethEvents.push(event); - }); - const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionAdminAdded', 'CollectionAdminRemoved']}]); - { - await collection.methods.addCollectionAdminCross(user).send({from: owner}); - expect(ethEvents).to.be.like([ - { - event: 'CollectionChanged', - returnValues: { - collectionId: collectionAddress - } + const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionAdminAdded', 'CollectionAdminRemoved']}]); + { + await collection.methods.addCollectionAdminCross(user).send({from: owner}); + expect(ethEvents).to.be.like([ + { + event: 'CollectionChanged', + returnValues: { + collectionId: collectionAddress } - ]); - expect(subEvents).to.be.like([{method: 'CollectionAdminAdded'}]); - ethEvents.pop(); - subEvents.pop(); - } - { - await collection.methods.removeCollectionAdminCross(user).send({from: owner}); - expect(ethEvents).to.be.like([ - { - event: 'CollectionChanged', - returnValues: { - collectionId: collectionAddress - } + } + ]); + expect(subEvents).to.be.like([{method: 'CollectionAdminAdded'}]); + ethEvents.pop(); + subEvents.pop(); + } + { + await collection.methods.removeCollectionAdminCross(user).send({from: owner}); + expect(ethEvents).to.be.like([ + { + event: 'CollectionChanged', + returnValues: { + collectionId: collectionAddress } - ]); - expect(subEvents).to.be.like([{method: 'CollectionAdminRemoved'}]); - } - unsubscribe(); + } + ]); + expect(subEvents).to.be.like([{method: 'CollectionAdminRemoved'}]); + } + unsubscribe(); +} + +async function testCollectionLimitSet(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 collectionHelper = helper.ethNativeContract.collectionHelpers(owner); + const ethEvents: any = []; + collectionHelper.events.allEvents((_: any, event: any) => { + ethEvents.push(event); }); - - itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => { - const owner = await helper.eth.createAccountWithBalance(donor); - const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C'); - const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner); - const collectionHelper = helper.ethNativeContract.collectionHelpers(owner); - const ethEvents: any = []; - collectionHelper.events.allEvents((_: any, event: any) => { - ethEvents.push(event); - }); - const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionLimitSet']}]); - { - await collection.methods.setCollectionLimit('ownerCanTransfer', 0n).send({from: owner}); - expect(ethEvents).to.be.like([ - { - event: 'CollectionChanged', - returnValues: { - collectionId: collectionAddress - } + const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionLimitSet']}]); + { + await collection.methods.setCollectionLimit('ownerCanTransfer', 0n).send({from: owner}); + expect(ethEvents).to.be.like([ + { + event: 'CollectionChanged', + returnValues: { + collectionId: collectionAddress } - ]); - expect(subEvents).to.be.like([{method: 'CollectionLimitSet'}]); - } - unsubscribe(); + } + ]); + expect(subEvents).to.be.like([{method: 'CollectionLimitSet'}]); + } + unsubscribe(); +} + +async function testCollectionOwnedChanged(helper: EthUniqueHelper, mode: TCollectionMode) { + const owner = await helper.eth.createAccountWithBalance(donor); + const new_owner = helper.ethCrossAccount.createAccount(); + const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C'); + const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner); + const collectionHelper = helper.ethNativeContract.collectionHelpers(owner); + const ethEvents: any = []; + collectionHelper.events.allEvents((_: any, event: any) => { + ethEvents.push(event); }); - - itEth('CollectionChanged event for CollectionOwnedChanged', async ({helper}) => { - const owner = await helper.eth.createAccountWithBalance(donor); - const new_owner = helper.ethCrossAccount.createAccount(); - const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C'); - const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner); - const collectionHelper = helper.ethNativeContract.collectionHelpers(owner); - const ethEvents: any = []; - collectionHelper.events.allEvents((_: any, event: any) => { - ethEvents.push(event); - }); - const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionOwnedChanged']}]); - { - await collection.methods.changeCollectionOwnerCross(new_owner).send({from: owner}); - expect(ethEvents).to.be.like([ - { - event: 'CollectionChanged', - returnValues: { - collectionId: collectionAddress - } + const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionOwnedChanged']}]); + { + await collection.methods.changeCollectionOwnerCross(new_owner).send({from: owner}); + expect(ethEvents).to.be.like([ + { + event: 'CollectionChanged', + returnValues: { + collectionId: collectionAddress } - ]); - expect(subEvents).to.be.like([{method: 'CollectionOwnedChanged'}]); - } - unsubscribe(); + } + ]); + expect(subEvents).to.be.like([{method: 'CollectionOwnedChanged'}]); + } + unsubscribe(); +} + +async function testCollectionPermissionSet(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 collectionHelper = helper.ethNativeContract.collectionHelpers(owner); + const ethEvents: any = []; + collectionHelper.events.allEvents((_: any, event: any) => { + ethEvents.push(event); }); - - itEth('CollectionChanged event for CollectionPermissionSet', async ({helper}) => { - const owner = await helper.eth.createAccountWithBalance(donor); - const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C'); - const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner); - const collectionHelper = helper.ethNativeContract.collectionHelpers(owner); - const ethEvents: any = []; - collectionHelper.events.allEvents((_: any, event: any) => { - ethEvents.push(event); - }); - const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionPermissionSet']}]); - { - await collection.methods.setCollectionMintMode(true).send({from: owner}); - expect(ethEvents).to.be.like([ - { - event: 'CollectionChanged', - returnValues: { - collectionId: collectionAddress - } + const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['CollectionPermissionSet']}]); + { + await collection.methods.setCollectionMintMode(true).send({from: owner}); + expect(ethEvents).to.be.like([ + { + event: 'CollectionChanged', + returnValues: { + collectionId: collectionAddress } - ]); - expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]); - ethEvents.pop(); - subEvents.pop(); - } - { - await collection.methods.setCollectionAccess(1).send({from: owner}); - expect(ethEvents).to.be.like([ - { - event: 'CollectionChanged', - returnValues: { - collectionId: collectionAddress - } + } + ]); + expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]); + ethEvents.pop(); + subEvents.pop(); + } + { + await collection.methods.setCollectionAccess(1).send({from: owner}); + expect(ethEvents).to.be.like([ + { + event: 'CollectionChanged', + returnValues: { + collectionId: collectionAddress } - ]); - expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]); - } - unsubscribe(); - }); + } + ]); + expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]); + } + unsubscribe(); +} - itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => { - const owner = await helper.eth.createAccountWithBalance(donor); +async function testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper: EthUniqueHelper, mode: TCollectionMode) { + const owner = await helper.eth.createAccountWithBalance(donor); const sponsor = await helper.ethCrossAccount.createAccountWithBalance(donor); - const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C'); - const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner); + const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C'); + const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner); const collectionHelper = helper.ethNativeContract.collectionHelpers(owner); const ethEvents: any = []; collectionHelper.events.allEvents((_: any, event: any) => { @@ -353,49 +352,172 @@ expect(subEvents).to.be.like([{method: 'CollectionSponsorRemoved'}]); } unsubscribe(); +} + +async function testTokenPropertySetAndTokenPropertyDeleted(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 collectionHelper = helper.ethNativeContract.collectionHelpers(owner); + const result = await collection.methods.mint(owner).send({from: owner}); + const tokenId = result.events.Transfer.returnValues.tokenId; + await collection.methods.setTokenPropertyPermission('A', true, true, true).send({from: owner}); + + + const ethEvents: any = []; + collectionHelper.events.allEvents((_: any, event: any) => { + ethEvents.push(event); + }); + const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['TokenPropertySet', 'TokenPropertyDeleted']}]); + { + await collection.methods.setProperties(tokenId, [{key: 'A', value: [1,2,3]}]).send({from: owner}); + expect(ethEvents).to.be.like([ + { + event: 'TokenChanged', + returnValues: { + collectionId: collectionAddress + } + } + ]); + expect(subEvents).to.be.like([{method: 'TokenPropertySet'}]); + ethEvents.pop(); + subEvents.pop(); + } + { + await collection.methods.deleteProperties(tokenId, ['A']).send({from: owner}); + expect(ethEvents).to.be.like([ + { + event: 'TokenChanged', + returnValues: { + collectionId: collectionAddress + } + } + ]); + expect(subEvents).to.be.like([{method: 'TokenPropertyDeleted'}]); + } + unsubscribe(); +} + +describe('[FT] Sync sub & eth events', () => { + const mode: TCollectionMode = 'ft'; + + itEth('CollectionCreated and CollectionDestroyed events', async ({helper}) => { + await testCollectionCreatedAndDestroy(helper, mode); + }); + + itEth('CollectionChanged event for CollectionPropertySet and CollectionPropertyDeleted', async ({helper}) => { + await testCollectionPropertySetAndCollectionPropertyDeleted(helper, mode); + }); + + itEth('CollectionChanged event for AllowListAddressAdded, AllowListAddressRemoved', async ({helper}) => { + await testAllowListAddressAddedAndAllowListAddressRemoved(helper, mode); + }); + + itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => { + await testCollectionAdminAddedAndCollectionAdminRemoved(helper, mode); + }); + + itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => { + await testCollectionLimitSet(helper, mode); + }); + + itEth('CollectionChanged event for CollectionOwnedChanged', async ({helper}) => { + await testCollectionOwnedChanged(helper, mode); + }); + + itEth('CollectionChanged event for CollectionPermissionSet', async ({helper}) => { + await testCollectionPermissionSet(helper, mode); + }); + + itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => { + await testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper, mode); + }); +}); + +describe('[NFT] Sync sub & eth events', () => { + const mode: TCollectionMode = 'nft'; + + itEth('CollectionCreated and CollectionDestroyed events', async ({helper}) => { + await testCollectionCreatedAndDestroy(helper, mode); + }); + + itEth('CollectionChanged event for CollectionPropertySet and CollectionPropertyDeleted', async ({helper}) => { + await testCollectionPropertySetAndCollectionPropertyDeleted(helper, mode); + }); + + itEth('CollectionChanged event for PropertyPermissionSet', async ({helper}) => { + await testPropertyPermissionSet(helper, mode); + }); + + itEth('CollectionChanged event for AllowListAddressAdded, AllowListAddressRemoved', async ({helper}) => { + await testAllowListAddressAddedAndAllowListAddressRemoved(helper, mode); + }); + + itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => { + await testCollectionAdminAddedAndCollectionAdminRemoved(helper, mode); + }); + + itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => { + await testCollectionLimitSet(helper, mode); }); + + itEth('CollectionChanged event for CollectionOwnedChanged', async ({helper}) => { + await testCollectionOwnedChanged(helper, mode); + }); + + itEth('CollectionChanged event for CollectionPermissionSet', async ({helper}) => { + await testCollectionPermissionSet(helper, mode); + }); + + itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => { + await testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper, mode); + }); itEth('CollectionChanged event for TokenPropertySet, TokenPropertyDeleted', async ({helper}) => { - const owner = await helper.eth.createAccountWithBalance(donor); - const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C'); - const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner); - const collectionHelper = helper.ethNativeContract.collectionHelpers(owner); - const result = await collection.methods.mint(owner).send({from: owner}); - const tokenId = result.events.Transfer.returnValues.tokenId; - await collection.methods.setTokenPropertyPermission('A', true, true, true).send({from: owner}); + await testTokenPropertySetAndTokenPropertyDeleted(helper, mode); + }); +}); +describe('[RFT] Sync sub & eth events', () => { + const mode: TCollectionMode = 'rft'; - const ethEvents: any = []; - collectionHelper.events.allEvents((_: any, event: any) => { - ethEvents.push(event); - }); - const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['TokenPropertySet', 'TokenPropertyDeleted']}]); - { - await collection.methods.setProperties(tokenId, [{key: 'A', value: [1,2,3]}]).send({from: owner}); - expect(ethEvents).to.be.like([ - { - event: 'TokenChanged', - returnValues: { - collectionId: collectionAddress - } - } - ]); - expect(subEvents).to.be.like([{method: 'TokenPropertySet'}]); - ethEvents.pop(); - subEvents.pop(); - } - { - await collection.methods.deleteProperties(tokenId, ['A']).send({from: owner}); - expect(ethEvents).to.be.like([ - { - event: 'TokenChanged', - returnValues: { - collectionId: collectionAddress - } - } - ]); - expect(subEvents).to.be.like([{method: 'TokenPropertyDeleted'}]); - } - unsubscribe(); + itEth('CollectionCreated and CollectionDestroyed events', async ({helper}) => { + await testCollectionCreatedAndDestroy(helper, mode); }); -}); \ No newline at end of file + + itEth('CollectionChanged event for CollectionPropertySet and CollectionPropertyDeleted', async ({helper}) => { + await testCollectionPropertySetAndCollectionPropertyDeleted(helper, mode); + }); + + itEth('CollectionChanged event for PropertyPermissionSet', async ({helper}) => { + await testPropertyPermissionSet(helper, mode); + }); + + itEth('CollectionChanged event for AllowListAddressAdded, AllowListAddressRemoved', async ({helper}) => { + await testAllowListAddressAddedAndAllowListAddressRemoved(helper, mode); + }); + + itEth('CollectionChanged event for CollectionAdminAdded, CollectionAdminRemoved', async ({helper}) => { + await testCollectionAdminAddedAndCollectionAdminRemoved(helper, mode); + }); + + itEth('CollectionChanged event for CollectionLimitSet', async ({helper}) => { + await testCollectionLimitSet(helper, mode); + }); + + itEth('CollectionChanged event for CollectionOwnedChanged', async ({helper}) => { + await testCollectionOwnedChanged(helper, mode); + }); + + itEth('CollectionChanged event for CollectionPermissionSet', async ({helper}) => { + await testCollectionPermissionSet(helper, mode); + }); + + itEth('CollectionChanged event for CollectionSponsorSet, SponsorshipConfirmed, CollectionSponsorRemoved', async ({helper}) => { + await testCollectionSponsorSetAndSponsorshipConfirmedAndCollectionSponsorRemoved(helper, mode); + }); + + itEth('CollectionChanged event for TokenPropertySet, TokenPropertyDeleted', async ({helper}) => { + await testTokenPropertySetAndTokenPropertyDeleted(helper, mode); + }); +}); --- 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();