git.delta.rocks / unique-network / refs/commits / 7fa45b56518f

difftreelog

source

tests/src/nativeFungible.test.ts8.9 KiBsourcehistory
1// Copyright 2019-2023 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, itSub, usingPlaygrounds} from './util';1920describe('Native fungible', () => {21  let root: IKeyringPair;22  let alice: IKeyringPair;23  let bob: IKeyringPair;2425  before(async () => {26    await usingPlaygrounds(async (helper, privateKey) => {27      root = await privateKey('//Alice');28      const donor = await privateKey({url: import.meta.url});29      [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);30    });31  });3233  itSub('destroy_collection()', async ({helper}) => {34    const collection = helper.ft.getCollectionObject(0);35    await expect(collection.burn(alice)).to.be.rejectedWith('common.UnsupportedOperation');36    await expect(helper.executeExtrinsic(alice, 'api.tx.unique.destroyCollection', [0])).to.be.rejectedWith('common.UnsupportedOperation');37  });3839  itSub('add_to_allow_list()', async ({helper}) => {40    const collection = helper.ft.getCollectionObject(0);41    await expect(collection.addToAllowList(alice, {Substrate: bob.address})).to.be.rejectedWith('common.UnsupportedOperation');42  });4344  itSub('remove_from_allow_list()', async ({helper}) => {45    const collection = helper.ft.getCollectionObject(0);46    await expect(collection.removeFromAllowList(alice, {Substrate: bob.address})).to.be.rejectedWith('common.UnsupportedOperation');47  });4849  itSub('change_collection_owner()', async ({helper}) => {50    const collection = helper.ft.getCollectionObject(0);51    await expect(collection.changeOwner(alice, bob.address)).to.be.rejectedWith('common.UnsupportedOperation');52  });5354  itSub('add_collection_admin()', async ({helper}) => {55    const collection = helper.ft.getCollectionObject(0);56    await expect(collection.addAdmin(alice, {Substrate: bob.address})).to.be.rejectedWith('common.UnsupportedOperation');57  });5859  itSub('remove_collection_admin()', async ({helper}) => {60    const collection = helper.ft.getCollectionObject(0);61    await expect(collection.removeAdmin(alice, {Substrate: bob.address})).to.be.rejectedWith('common.UnsupportedOperation');62  });6364  itSub('set_collection_sponsor()', async ({helper}) => {65    const collection = helper.ft.getCollectionObject(0);66    await expect(collection.setSponsor(alice, bob.address)).to.be.rejectedWith('common.UnsupportedOperation');67  });6869  itSub('confirm_sponsorship()', async ({helper}) => {70    const collection = helper.ft.getCollectionObject(0);71    await expect(collection.confirmSponsorship(alice)).to.be.rejectedWith('common.UnsupportedOperation');72  });7374  itSub('remove_collection_sponsor()', async ({helper}) => {75    const collection = helper.ft.getCollectionObject(0);76    await expect(collection.removeSponsor(alice)).to.be.rejectedWith('common.UnsupportedOperation');77  });7879  itSub('create_item()', async ({helper}) => {80    const collection = helper.ft.getCollectionObject(0);81    await expect(collection.mint(alice, 100n, {Substrate: bob.address})).to.be.rejectedWith('common.UnsupportedOperation');82  });8384  itSub('set_collection_properties()', async ({helper}) => {85    const collection = helper.ft.getCollectionObject(0);86    await expect(collection.setProperties(alice, [{key: 'value'}])).to.be.rejectedWith('common.UnsupportedOperation');87  });8889  itSub('delete_collection_properties()', async ({helper}) => {90    const collection = helper.ft.getCollectionObject(0);91    await expect(collection.deleteProperties(alice, ['key'])).to.be.rejectedWith('common.UnsupportedOperation');92  });9394  itSub('set_token_properties()', async ({helper}) => {95    await expect(helper.executeExtrinsic(96      alice,97      'api.tx.unique.setTokenProperties',98      [0, 0, [{key: 'value'}]],99      true,100    )).to.be.rejectedWith('common.UnsupportedOperation');101  });102103  itSub('delete_token_properties()', async ({helper}) => {104    await expect(helper.executeExtrinsic(105      alice,106      'api.tx.unique.deleteTokenProperties',107      [0, 0, ['key']],108      true,109    )).to.be.rejectedWith('common.UnsupportedOperation');110  });111112  itSub('set_transfers_enabled_flag()', async ({helper}) => {113    await expect(helper.executeExtrinsic(114      alice,115      'api.tx.unique.setTransfersEnabledFlag',116      [0, true],117      true,118    )).to.be.rejectedWith('common.UnsupportedOperation');119  });120121  itSub('burn_item()', async ({helper}) => {122    await expect(helper.executeExtrinsic(123      alice,124      'api.tx.unique.burnItem',125      [0, 0, 100n],126      true,127    )).to.be.rejectedWith('common.UnsupportedOperation');128  });129130  itSub('burn_from()', async ({helper}) => {131    const collection = helper.ft.getCollectionObject(0);132    await expect(collection.burnTokens(alice, 100n)).to.be.rejectedWith('common.UnsupportedOperation');133  });134135  itSub('transfer()', async ({helper}) => {136    const collection = helper.ft.getCollectionObject(0);137    const balanceAliceBefore = await helper.balance.getSubstrate(alice.address);138    const balanceBobBefore = await helper.balance.getSubstrate(bob.address);139    await collection.transfer(alice, {Substrate: bob.address}, 100n);140    const balanceAliceAfter = await helper.balance.getSubstrate(alice.address);141    const balanceBobAfter = await helper.balance.getSubstrate(bob.address);142    expect(balanceAliceBefore - balanceAliceAfter > 100n).to.be.true;143    expect(balanceBobAfter - balanceBobBefore === 100n).to.be.true;144  });145146  itSub('transfer_from()', async ({helper}) => {147    const collection = helper.ft.getCollectionObject(0);148    const balanceAliceBefore = await helper.balance.getSubstrate(alice.address);149    const balanceBobBefore = await helper.balance.getSubstrate(bob.address);150151    await collection.transferFrom(alice, {Substrate: alice.address}, {Substrate: bob.address}, 100n);152153    const balanceAliceAfter = await helper.balance.getSubstrate(alice.address);154    const balanceBobAfter = await helper.balance.getSubstrate(bob.address);155    expect(balanceAliceBefore - balanceAliceAfter > 100n).to.be.true;156    expect(balanceBobAfter - balanceBobBefore === 100n).to.be.true;157158    await expect(collection.transferFrom(alice, {Substrate: bob.address}, {Substrate: alice.address}, 100n)).to.be.rejectedWith('common.ApprovedValueTooLow');159  });160161  itSub('approve()', async ({helper}) => {162    const collection = helper.ft.getCollectionObject(0);163    await expect(collection.approveTokens(alice, {Substrate: bob.address}, 100n)).to.be.rejectedWith('common.UnsupportedOperation');164  });165166  itSub('approve_from()', async ({helper}) => {167    await expect(helper.executeExtrinsic(168      alice,169      'api.tx.unique.approveFrom',170      [{Substrate: alice.address}, {Substrate: bob.address}, 0, 0, 100n],171      true,172    )).to.be.rejectedWith('common.UnsupportedOperation');173  });174175  itSub('set_collection_limits()', async ({helper}) => {176    const collection = helper.ft.getCollectionObject(0);177    await expect(collection.setLimits(alice, {accountTokenOwnershipLimit: 1})).to.be.rejectedWith('common.UnsupportedOperation');178  });179180  itSub('set_collection_permissions()', async ({helper}) => {181    const collection = helper.ft.getCollectionObject(0);182    await expect(collection.setPermissions(alice, {access: 'AllowList'})).to.be.rejectedWith('common.UnsupportedOperation');183  });184185  itSub('repartition()', async ({helper}) => {186    await expect(helper.executeExtrinsic(187      alice,188      'api.tx.unique.repartition',189      [0, 0, 100n],190      true,191    )).to.be.rejectedWith('unique.RepartitionCalledOnNonRefungibleCollection');192  });193194  itSub('force_repair_collection()', async ({helper}) => {195    await expect(helper.executeExtrinsic(196      alice,197      'api.tx.unique.forceRepairCollection',198      [0],199      true,200    )).to.be.rejectedWith('common.UnsupportedOperation');201  });202203  itSub('force_repair_item()', async ({helper}) => {204    await expect(helper.getSudo().executeExtrinsic(205      root,206      'api.tx.unique.forceRepairItem',207      [0, 0],208      true,209    )).to.be.rejectedWith('common.UnsupportedOperation');210  });211212  itSub('Nest into NFT token()', async ({helper}) => {213    const nftCollection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});214    const targetToken = await nftCollection.mintToken(alice);215216    const collection = helper.ft.getCollectionObject(0);217    await collection.transfer(alice, targetToken.nestingAccount(), 100n);218219    await collection.transferFrom(alice, targetToken.nestingAccount(), {Substrate: alice.address}, 100n);220  });221});