difftreelog
splitted test into multiple test cases
in: master
1 file changed
tests/src/refungible.test.tsdiffbeforeafterboth1// 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 {default as usingApi} from './substrate/substrate-api';18import {IKeyringPair} from '@polkadot/types/types';19import {20 createCollectionExpectSuccess,21 createItemExpectSuccess,22 transferExpectSuccess,23 transferExpectFailure,24 getBalance,25 burnItemExpectSuccess,26 createMultipleItemsExpectSuccess,27 approveExpectSuccess,28 transferFromExpectSuccess,29 isTokenExists,30 getLastTokenId,31 getAllowance,32} from './util/helpers';3334import chai from 'chai';35import chaiAsPromised from 'chai-as-promised';36chai.use(chaiAsPromised);37const expect = chai.expect;3839let alice: IKeyringPair;40let bob: IKeyringPair;4142describe('integration test: Refungible functionality:', () => {43 before(async () => {44 await usingApi(async (api, privateKeyWrapper) => {45 alice = privateKeyWrapper('//Alice');46 bob = privateKeyWrapper('//Bob');47 });48 });4950 it('Create refungible collection and token. Token pieces transfer. Token repartition.', async () => {51 const createMode = 'ReFungible';52 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});53 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);5455 const args = [56 {ReFungible: {pieces: 1}},57 {ReFungible: {pieces: 2}},58 {ReFungible: {pieces: 3}},59 ];60 await createMultipleItemsExpectSuccess(alice, collectionId, args);6162 let aliceBalance = BigInt(0);63 await usingApi(async api => {64 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;65 66 const itemsListIndexAfter = await getLastTokenId(api, collectionId);67 expect(itemsListIndexAfter).to.be.equal(4);6869 aliceBalance = await getBalance(api, collectionId, alice.address, tokenId);70 });71 const transferAmount = BigInt(60);72 await transferExpectSuccess(collectionId, tokenId, alice, bob, transferAmount, 'ReFungible');73 aliceBalance = aliceBalance - transferAmount;74 await transferExpectFailure(collectionId, tokenId, alice, bob, aliceBalance + BigInt(1));75 await burnItemExpectSuccess(alice, collectionId, tokenId, aliceBalance - BigInt(1));76 await approveExpectSuccess(collectionId, tokenId, bob, alice.address, transferAmount);77 const bobBalance = transferAmount;78 const allowedAmount = BigInt(60);79 await transferFromExpectSuccess(collectionId, tokenId, alice, bob, alice, 40, 'ReFungible');8081 await usingApi(async api => {82 expect(await getAllowance(api, collectionId, bob.address, alice.address, 0)).to.equal(bobBalance - allowedAmount);83 });84 85 });86});