git.delta.rocks / unique-network / refs/commits / 1f2b5fa5290d

difftreelog

source

tests/src/eth/events.test.ts5.9 KiBsourcehistory
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 {IKeyringPair} from '@polkadot/types/types';18import { expect } from 'chai';19import { itEth, usingEthPlaygrounds } from './util';2021describe.only('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 {collectionAddress, events} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');33        expect(events).to.be.like([34            {35                event: 'CollectionCreated',36                args: {37                    owner: owner,38                    collectionId: collectionAddress39                }40            }41        ]);42    });4344    itEth('Destroy event', async ({helper}) => {45        const owner = await helper.eth.createAccountWithBalance(donor);46        const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');47        const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);48        let resutl = await collectionHelper.methods.destroyCollection(collectionAddress).send({from:owner});49        expect(resutl.events).to.be.like({50            CollectionDestroyed: {51                returnValues: {52                    collectionId: collectionAddress53                }54            }55        });56    });57    58    itEth('CollectionChanged event for CollectionPropertySet and CollectionPropertyDeleted', async ({helper}) => {59        const owner = await helper.eth.createAccountWithBalance(donor);60        const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');61        const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);62        const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);63        64        {65            const events: any = [];66            collectionHelper.events.allEvents((_: any, event: any) => {67                events.push(event);68            });69            await collection.methods.setCollectionProperties([{key: 'A', value: [0,1,2,3]}]).send({from:owner});70            expect(events).to.be.like([71                {72                    event: 'CollectionChanged',73                    returnValues: {74                        collectionId: collectionAddress75                    }76                }77            ]);78        }79        {80            const events: any = [];81            collectionHelper.events.allEvents((_: any, event: any) => {82                events.push(event);83            });84            await collection.methods.deleteCollectionProperties(['A']).send({from:owner});85            expect(events).to.be.like([86                {87                    event: 'CollectionChanged',88                    returnValues: {89                        collectionId: collectionAddress90                    }91                }92            ]);93        }9495    });96    97    itEth('CollectionChanged event for PropertyPermissionSet', async ({helper}) => {98        const owner = await helper.eth.createAccountWithBalance(donor);99        const {collectionAddress} = await helper.eth.createCollecion('createNFTCollection', owner, 'A', 'B', 'C');100        const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);101        const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);102        const events: any = [];103        collectionHelper.events.allEvents((_: any, event: any) => {104            events.push(event);105        });106        await collection.methods.setTokenPropertyPermission('testKey', true, true, true).send({from: owner});107        expect(events).to.be.like([108            {109                event: 'CollectionChanged',110                returnValues: {111                    collectionId: collectionAddress112                }113            }114        ]);115    });116    117    // itEth('CollectionChanged event for AllowListAddressAdded', async ({helper}) => {118    //     const owner = await helper.eth.createAccountWithBalance(donor);119    //     const user = await helper.eth.createAccount();120    //     const userCross = helper.ethCrossAccount.fromAddress(user);121    //     const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});122    //   // allow list does not need to be enabled to add someone in advance123    //     const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);124    //     const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);125    //     const events: any = [];126    //     collectionHelper.events.allEvents((_: any, event: any) => {127    //         events.push(event);128    //     });129    //     await helper.nft.addToAllowList(alice, collectionId, {Substrate: bob.address});130    //     expect(events).to.be.like([131    //         {132    //             event: 'CollectionChanged',133    //             returnValues: {134    //                 collectionId: collectionAddress135    //             }136    //         }137    //     ]);138    // });139});