difftreelog
misk: add tests for FT and RFT
in: master
2 files changed
tests/src/eth/events.test.tsdiffbeforeafterboth--- 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);
+ });
+});
tests/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