git.delta.rocks / unique-network / refs/commits / ade4bc204310

difftreelog

source

js-packages/tests/src/eth/createNFTCollection.seqtest.ts3.4 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.8//9// 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 type {IKeyringPair} from '@polkadot/types/types';18import {expect, itEth, usingEthPlaygrounds} from './util/index.js';192021describe('Create NFT collection from EVM', () => {22  let donor: IKeyringPair;2324  before(async function () {25    await usingEthPlaygrounds(async (_helper, privateKey) => {26      donor = await privateKey({url: import.meta.url});27    });28  });2930  itEth('Create collection', async ({helper}) => {31    const owner = await helper.eth.createAccountWithBalance(donor);3233    const name = 'CollectionEVM';34    const description = 'Some description';35    const prefix = 'token prefix';3637    // todo:playgrounds this might fail when in async environment.38    const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;39    const {collectionId, collectionAddress, events} = await helper.eth.createNFTCollection(owner, name, description, prefix);4041    expect(events).to.be.deep.equal([42      {43        address: '0x6C4E9fE1AE37a41E93CEE429e8E1881aBdcbb54F',44        event: 'CollectionCreated',45        args: {46          owner: owner,47          collectionId: collectionAddress,48        },49      },50    ]);5152    const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;5354    const collection = helper.nft.getCollectionObject(collectionId);55    const data = (await collection.getData())!;5657    expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);58    expect(collectionId).to.be.eq(collectionCountAfter);59    expect(data.name).to.be.eq(name);60    expect(data.description).to.be.eq(description);61    expect(data.raw.tokenPrefix).to.be.eq(prefix);62    expect(data.raw.mode).to.be.eq('NFT');6364    const options = await collection.getOptions();6566    expect(options.tokenPropertyPermissions).to.be.empty;67  });6869  // this test will occasionally fail when in async environment.70  itEth('Check collection address exist', async ({helper}) => {71    const owner = await helper.eth.createAccountWithBalance(donor);7273    const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;74    const expectedCollectionAddress = helper.ethAddress.fromCollectionId(expectedCollectionId);75    const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);7677    expect(await collectionHelpers.methods78      .isCollectionExist(expectedCollectionAddress)79      .call()).to.be.false;8081    await collectionHelpers.methods82      .createNFTCollection('A', 'A', 'A')83      .send({value: Number(2n * helper.balance.getOneTokenNominal())});8485    expect(await collectionHelpers.methods86      .isCollectionExist(expectedCollectionAddress)87      .call()).to.be.true;88  });89});