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

difftreelog

source

tests/src/eth/createFTCollection.test.ts12.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.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 {IKeyringPair} from '@polkadot/types/types';18import {Pallets, requirePalletsOrSkip} from '../util';19import {expect, itEth, usingEthPlaygrounds} from './util';2021const DECIMALS = 18;2223describe('Create FT collection from EVM', () => {24  let donor: IKeyringPair;2526  before(async function() {27    await usingEthPlaygrounds(async (helper, privateKey) => {28      requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);29      donor = await privateKey('//Alice');30    });31  });3233  itEth('Create collection', async ({helper}) => {34    const owner = await helper.eth.createAccountWithBalance(donor);35    36    const name = 'CollectionEVM';37    const description = 'Some description';38    const prefix = 'token prefix';39  40    // todo:playgrounds this might fail when in async environment.41    const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;42    43    const collectionCreationPrice = helper.balance.getCollectionCreationPrice();44    const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);45        46    const result = await collectionHelper.methods.createRTCollection(name, DECIMALS, description, prefix).call({value: Number(collectionCreationPrice)});47    console.log(result);48    const {collectionId} = await helper.eth.createFungibleCollection(owner, name, DECIMALS,  description, prefix);49    const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;50  51    const data = (await helper.ft.getData(collectionId))!;5253    expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);54    expect(collectionId).to.be.eq(collectionCountAfter);55    expect(data.name).to.be.eq(name);56    expect(data.description).to.be.eq(description);57    expect(data.raw.tokenPrefix).to.be.eq(prefix);58    expect(data.raw.mode).to.be.deep.eq({Fungible: DECIMALS.toString()});59  });6061  // // todo:playgrounds this test will fail when in async environment.62  // itEth('Check collection address exist', async ({helper}) => {63  //   const owner = await helper.eth.createAccountWithBalance(donor);6465  //   const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;66  //   const expectedCollectionAddress = helper.ethAddress.fromCollectionId(expectedCollectionId);67  //   const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);6869  //   expect(await collectionHelpers.methods70  //     .isCollectionExist(expectedCollectionAddress)71  //     .call()).to.be.false;7273  //   await collectionHelpers.methods74  //     .createRFTCollection('A', 'A', 'A')75  //     .send({value: Number(2n * helper.balance.getOneTokenNominal())});76    77  //   expect(await collectionHelpers.methods78  //     .isCollectionExist(expectedCollectionAddress)79  //     .call()).to.be.true;80  // });81  82  // itEth('Set sponsorship', async ({helper}) => {83  //   const owner = await helper.eth.createAccountWithBalance(donor);84  //   const sponsor = await helper.eth.createAccountWithBalance(donor);85  //   const ss58Format = helper.chain.getChainProperties().ss58Format;86  //   const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Sponsor', 'absolutely anything', 'ENVY');8788  //   const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);89  //   await collection.methods.setCollectionSponsor(sponsor).send();9091  //   let data = (await helper.rft.getData(collectionId))!;92  //   expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));9394  //   await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');9596  //   const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);97  //   await sponsorCollection.methods.confirmCollectionSponsorship().send();9899  //   data = (await helper.rft.getData(collectionId))!;100  //   expect(data.raw.sponsorship.Confirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));101  // });102103  // itEth('Set limits', async ({helper}) => {104  //   const owner = await helper.eth.createAccountWithBalance(donor);105  //   const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Limits', 'absolutely anything', 'INSI');106  //   const limits = {107  //     accountTokenOwnershipLimit: 1000,108  //     sponsoredDataSize: 1024,109  //     sponsoredDataRateLimit: 30,110  //     tokenLimit: 1000000,111  //     sponsorTransferTimeout: 6,112  //     sponsorApproveTimeout: 6,113  //     ownerCanTransfer: false,114  //     ownerCanDestroy: false,115  //     transfersEnabled: false,116  //   };117118  //   const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);119  //   await collection.methods['setCollectionLimit(string,uint32)']('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();120  //   await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataSize', limits.sponsoredDataSize).send();121  //   await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();122  //   await collection.methods['setCollectionLimit(string,uint32)']('tokenLimit', limits.tokenLimit).send();123  //   await collection.methods['setCollectionLimit(string,uint32)']('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();124  //   await collection.methods['setCollectionLimit(string,uint32)']('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();125  //   await collection.methods['setCollectionLimit(string,bool)']('ownerCanTransfer', limits.ownerCanTransfer).send();126  //   await collection.methods['setCollectionLimit(string,bool)']('ownerCanDestroy', limits.ownerCanDestroy).send();127  //   await collection.methods['setCollectionLimit(string,bool)']('transfersEnabled', limits.transfersEnabled).send();128    129  //   const data = (await helper.rft.getData(collectionId))!;130  //   expect(data.raw.limits.accountTokenOwnershipLimit).to.be.eq(limits.accountTokenOwnershipLimit);131  //   expect(data.raw.limits.sponsoredDataSize).to.be.eq(limits.sponsoredDataSize);132  //   expect(data.raw.limits.sponsoredDataRateLimit.blocks).to.be.eq(limits.sponsoredDataRateLimit);133  //   expect(data.raw.limits.tokenLimit).to.be.eq(limits.tokenLimit);134  //   expect(data.raw.limits.sponsorTransferTimeout).to.be.eq(limits.sponsorTransferTimeout);135  //   expect(data.raw.limits.sponsorApproveTimeout).to.be.eq(limits.sponsorApproveTimeout);136  //   expect(data.raw.limits.ownerCanTransfer).to.be.eq(limits.ownerCanTransfer);137  //   expect(data.raw.limits.ownerCanDestroy).to.be.eq(limits.ownerCanDestroy);138  //   expect(data.raw.limits.transfersEnabled).to.be.eq(limits.transfersEnabled);139  // });140141  // itEth('Collection address exist', async ({helper}) => {142  //   const owner = await helper.eth.createAccountWithBalance(donor);143  //   const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';144  //   expect(await helper.ethNativeContract.collectionHelpers(collectionAddressForNonexistentCollection)145  //     .methods.isCollectionExist(collectionAddressForNonexistentCollection).call())146  //     .to.be.false;147    148  //   const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Exister', 'absolutely anything', 'WIWT');149  //   expect(await helper.ethNativeContract.collectionHelpers(collectionAddress)150  //     .methods.isCollectionExist(collectionAddress).call())151  //     .to.be.true;152  // });153});154155// describe('(!negative tests!) Create RFT collection from EVM', () => {156//   let donor: IKeyringPair;157//   let nominal: bigint;158159//   before(async function() {160//     await usingEthPlaygrounds(async (helper, privateKey) => {161//       requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);162//       donor = privateKey('//Alice');163//       nominal = helper.balance.getOneTokenNominal();164//     });165//   });166167//   itEth('(!negative test!) Create collection (bad lengths)', async ({helper}) => {168//     const owner = await helper.eth.createAccountWithBalance(donor);169//     const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);170//     {171//       const MAX_NAME_LENGTH = 64;172//       const collectionName = 'A'.repeat(MAX_NAME_LENGTH + 1);173//       const description = 'A';174//       const tokenPrefix = 'A';175176//       await expect(collectionHelper.methods177//         .createRFTCollection(collectionName, description, tokenPrefix)178//         .call({value: Number(2n * nominal)})).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);179//     }180//     {181//       const MAX_DESCRIPTION_LENGTH = 256;182//       const collectionName = 'A';183//       const description = 'A'.repeat(MAX_DESCRIPTION_LENGTH + 1);184//       const tokenPrefix = 'A';185//       await expect(collectionHelper.methods186//         .createRFTCollection(collectionName, description, tokenPrefix)187//         .call({value: Number(2n * nominal)})).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);188//     }189//     {190//       const MAX_TOKEN_PREFIX_LENGTH = 16;191//       const collectionName = 'A';192//       const description = 'A';193//       const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);194//       await expect(collectionHelper.methods195//         .createRFTCollection(collectionName, description, tokenPrefix)196//         .call({value: Number(2n * nominal)})).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);197//     }198//   });199  200//   itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {201//     const owner = await helper.eth.createAccountWithBalance(donor);202//     const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);203//     await expect(collectionHelper.methods204//       .createRFTCollection('Peasantry', 'absolutely anything', 'TWIW')205//       .call({value: Number(1n * nominal)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');206//   });207208//   itEth('(!negative test!) Check owner', async ({helper}) => {209//     const owner = await helper.eth.createAccountWithBalance(donor);210//     const peasant = helper.eth.createAccount();211//     const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Transgressed', 'absolutely anything', 'YVNE');212//     const peasantCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', peasant);213//     const EXPECTED_ERROR = 'NoPermission';214//     {215//       const sponsor = await helper.eth.createAccountWithBalance(donor);216//       await expect(peasantCollection.methods217//         .setCollectionSponsor(sponsor)218//         .call()).to.be.rejectedWith(EXPECTED_ERROR);219      220//       const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);221//       await expect(sponsorCollection.methods222//         .confirmCollectionSponsorship()223//         .call()).to.be.rejectedWith('caller is not set as sponsor');224//     }225//     {226//       await expect(peasantCollection.methods227//         .setCollectionLimit('account_token_ownership_limit', '1000')228//         .call()).to.be.rejectedWith(EXPECTED_ERROR);229//     }230//   });231232//   itEth('(!negative test!) Set limits', async ({helper}) => {233//     const owner = await helper.eth.createAccountWithBalance(donor);234//     const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Limits', 'absolutely anything', 'ISNI');235//     const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);236//     await expect(collectionEvm.methods237//       .setCollectionLimit('badLimit', 'true')238//       .call()).to.be.rejectedWith('unknown boolean limit "badLimit"');239//   });240  241//   itEth('destroyCollection test', async ({helper}) => {242//     const owner = await helper.eth.createAccountWithBalance(donor);243//     const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Limits', 'absolutely anything', 'OLF');244//     const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);245    246//     await expect(collectionHelper.methods247//       .destroyCollection(collectionAddress)248//       .send({from: owner})).to.be.fulfilled;249    250//     expect(await collectionHelper.methods251//       .isCollectionExist(collectionAddress)252//       .call()).to.be.false;  253//   });254// });