difftreelog
Fix transfer test (with burned tokens)
in: master
2 files changed
tests/src/transfer.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import { ApiPromise } from '@polkadot/api';7import { expect } from 'chai';8import { alicesPublicKey, bobsPublicKey } from './accounts';9import getBalance from './substrate/get-balance';10import privateKey from './substrate/privateKey';11import { default as usingApi, submitTransactionAsync } from './substrate/substrate-api';12import {13 burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess,14 destroyCollectionExpectSuccess,15 findUnusedAddress,16 getCreateCollectionResult,17 getCreateItemResult,18 transferExpectFail,19 transferExpectSuccess,20} from './util/helpers';2122describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {23 it('Balance transfers and check balance', async () => {24 await usingApi(async (api: ApiPromise) => {25 const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);2627 const alicePrivateKey = privateKey('//Alice');2829 const transfer = api.tx.balances.transfer(bobsPublicKey, 1n);30 const events = await submitTransactionAsync(alicePrivateKey, transfer);31 const result = getCreateItemResult(events);32 // tslint:disable-next-line:no-unused-expression33 expect(result.success).to.be.true;3435 const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);3637 // tslint:disable-next-line:no-unused-expression38 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;39 // tslint:disable-next-line:no-unused-expression40 expect(bobsBalanceAfter > bobsBalanceBefore).to.be.true;41 });42 });4344 it('Inability to pay fees error message is correct', async () => {45 await usingApi(async (api) => {46 // Find unused address47 const pk = await findUnusedAddress(api);4849 const badTransfer = api.tx.balances.transfer(bobsPublicKey, 1n);50 // const events = await submitTransactionAsync(pk, badTransfer);51 const badTransaction = async () => {52 const events = await submitTransactionAsync(pk, badTransfer);53 const result = getCreateCollectionResult(events);54 // tslint:disable-next-line:no-unused-expression55 expect(result.success).to.be.false;56 };57 expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees , e.g. account balance too low');58 });59 });6061 it('Create collection, balance transfers and check balance', async () => {62 await usingApi(async (api) => {63 const Alice = privateKey('//Alice');64 const Bob = privateKey('//Bob');65 // nft66 const nftCollectionId = await createCollectionExpectSuccess();67 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');68 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');69 // fungible70 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});71 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');72 await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');73 // reFungible74 const reFungibleCollectionId = await75 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});76 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');77 await transferExpectSuccess(reFungibleCollectionId,78 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');79 });80 });81});8283describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {84 it('Transfer with not existed collection_id', async () => {85 await usingApi(async (api: ApiPromise) => {86 const Alice = privateKey('//Alice');87 const Bob = privateKey('//Bob');88 // nft89 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;90 await transferExpectFail(nftCollectionCount + 1, 1, Alice, Bob, 1);91 // fungible92 const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;93 await transferExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob, 1);94 // reFungible95 const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;96 await transferExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob, 1);97 });98 });99 it('Transfer with deleted collection_id', async () => {100 await usingApi(async (api: ApiPromise) => {101 const Alice = privateKey('//Alice');102 const Bob = privateKey('//Bob');103 // nft104 const nftCollectionId = await createCollectionExpectSuccess();105 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');106 await destroyCollectionExpectSuccess(nftCollectionId);107 await transferExpectFail(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');108 // fungible109 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});110 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');111 await destroyCollectionExpectSuccess(fungibleCollectionId);112 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');113 // reFungible114 const reFungibleCollectionId = await115 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});116 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');117 await destroyCollectionExpectSuccess(reFungibleCollectionId);118 await transferExpectFail(reFungibleCollectionId,119 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');120 });121 });122 it('Transfer with not existed item_id', async () => {123 await usingApi(async (api: ApiPromise) => {124 const Alice = privateKey('//Alice');125 const Bob = privateKey('//Bob');126 // nft127 const nftCollectionId = await createCollectionExpectSuccess();128 await transferExpectFail(nftCollectionId, 2, Alice, Bob, 1, 'NFT');129 // fungible130 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});131 await transferExpectFail(fungibleCollectionId, 2, Alice, Bob, 1, 'Fungible');132 // reFungible133 const reFungibleCollectionId = await134 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});135 await transferExpectFail(reFungibleCollectionId,136 2, Alice, Bob, 1, 'ReFungible');137 });138 });139 it('Transfer with deleted item_id', async () => {140 await usingApi(async (api: ApiPromise) => {141 const Alice = privateKey('//Alice');142 const Bob = privateKey('//Bob');143 // nft144 const nftCollectionId = await createCollectionExpectSuccess();145 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');146 await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);147 await transferExpectFail(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');148 // fungible149 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});150 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');151 await burnItemExpectSuccess(Alice, fungibleCollectionId, newFungibleTokenId, 1);152 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');153 // reFungible154 const reFungibleCollectionId = await155 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});156 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');157 await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);158 await transferExpectFail(reFungibleCollectionId,159 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');160 });161 });162 it('Transfer with recipient that is not owner', async () => {163 await usingApi(async (api: ApiPromise) => {164 const Alice = privateKey('//Alice');165 const Bob = privateKey('//Bob');166 const Charlie = privateKey('//CHARLIE');167 // nft168 const nftCollectionId = await createCollectionExpectSuccess();169 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');170 await transferExpectFail(nftCollectionId, newNftTokenId, Charlie, Bob, 1, 'NFT');171 // fungible172 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});173 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');174 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Charlie, Bob, 1, 'Fungible');175 // reFungible176 const reFungibleCollectionId = await177 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});178 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');179 await transferExpectFail(reFungibleCollectionId,180 newReFungibleTokenId, Charlie, Bob, 1, 'ReFungible');181 });182 });183});1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import { ApiPromise } from '@polkadot/api';7import { IKeyringPair } from '@polkadot/types/types';8import { expect } from 'chai';9import { alicesPublicKey, bobsPublicKey } from './accounts';10import getBalance from './substrate/get-balance';11import privateKey from './substrate/privateKey';12import { default as usingApi, submitTransactionAsync } from './substrate/substrate-api';13import {14 burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess,15 destroyCollectionExpectSuccess,16 findUnusedAddress,17 getCreateCollectionResult,18 getCreateItemResult,19 transferExpectFail,20 transferExpectSuccess,21} from './util/helpers';2223let Alice: IKeyringPair;24let Bob: IKeyringPair;25let Charlie: IKeyringPair;2627describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {28 it('Balance transfers and check balance', async () => {29 await usingApi(async (api: ApiPromise) => {30 const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);3132 const alicePrivateKey = privateKey('//Alice');3334 const transfer = api.tx.balances.transfer(bobsPublicKey, 1n);35 const events = await submitTransactionAsync(alicePrivateKey, transfer);36 const result = getCreateItemResult(events);37 // tslint:disable-next-line:no-unused-expression38 expect(result.success).to.be.true;3940 const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);4142 // tslint:disable-next-line:no-unused-expression43 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;44 // tslint:disable-next-line:no-unused-expression45 expect(bobsBalanceAfter > bobsBalanceBefore).to.be.true;46 });47 });4849 it('Inability to pay fees error message is correct', async () => {50 await usingApi(async (api) => {51 // Find unused address52 const pk = await findUnusedAddress(api);5354 const badTransfer = api.tx.balances.transfer(bobsPublicKey, 1n);55 // const events = await submitTransactionAsync(pk, badTransfer);56 const badTransaction = async () => {57 const events = await submitTransactionAsync(pk, badTransfer);58 const result = getCreateCollectionResult(events);59 // tslint:disable-next-line:no-unused-expression60 expect(result.success).to.be.false;61 };62 expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees , e.g. account balance too low');63 });64 });6566 it('Create collection, balance transfers and check balance', async () => {67 await usingApi(async (api) => {68 const Alice = privateKey('//Alice');69 const Bob = privateKey('//Bob');70 // nft71 const nftCollectionId = await createCollectionExpectSuccess();72 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');73 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');74 // fungible75 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});76 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');77 await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');78 // reFungible79 const reFungibleCollectionId = await80 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});81 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');82 await transferExpectSuccess(reFungibleCollectionId,83 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');84 });85 });86});8788describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {89 before(async () => {90 await usingApi(async (api: ApiPromise) => {91 Alice = privateKey('//Alice');92 Bob = privateKey('//Bob');93 Charlie = privateKey('//Charlie');94 });95 });96 it('Transfer with not existed collection_id', async () => {97 await usingApi(async (api) => {98 // nft99 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;100 await transferExpectFail(nftCollectionCount + 1, 1, Alice, Bob, 1);101 // fungible102 const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;103 await transferExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob, 1);104 // reFungible105 const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;106 await transferExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob, 1);107 });108 });109 it('Transfer with deleted collection_id', async () => {110 // nft111 const nftCollectionId = await createCollectionExpectSuccess();112 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');113 await destroyCollectionExpectSuccess(nftCollectionId);114 await transferExpectFail(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');115 // fungible116 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});117 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');118 await destroyCollectionExpectSuccess(fungibleCollectionId);119 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');120 // reFungible121 const reFungibleCollectionId = await122 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});123 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');124 await destroyCollectionExpectSuccess(reFungibleCollectionId);125 await transferExpectFail(reFungibleCollectionId,126 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');127 });128 it('Transfer with not existed item_id', async () => {129 // nft130 const nftCollectionId = await createCollectionExpectSuccess();131 await transferExpectFail(nftCollectionId, 2, Alice, Bob, 1, 'NFT');132 // fungible133 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});134 await transferExpectFail(fungibleCollectionId, 2, Alice, Bob, 1, 'Fungible');135 // reFungible136 const reFungibleCollectionId = await137 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});138 await transferExpectFail(reFungibleCollectionId,139 2, Alice, Bob, 1, 'ReFungible');140 });141 it('Transfer with deleted item_id', async () => {142 // nft143 const nftCollectionId = await createCollectionExpectSuccess();144 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');145 await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);146 await transferExpectFail(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');147 // fungible148 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});149 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');150 await burnItemExpectSuccess(Alice, fungibleCollectionId, newFungibleTokenId, 10);151 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');152 // reFungible153 const reFungibleCollectionId = await154 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});155 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');156 await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);157 await transferExpectFail(reFungibleCollectionId,158 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');159 });160 it('Transfer with recipient that is not owner', async () => {161 // nft162 const nftCollectionId = await createCollectionExpectSuccess();163 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');164 await transferExpectFail(nftCollectionId, newNftTokenId, Charlie, Bob, 1, 'NFT');165 // fungible166 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});167 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');168 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Charlie, Bob, 1, 'Fungible');169 // reFungible170 const reFungibleCollectionId = await171 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});172 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');173 await transferExpectFail(reFungibleCollectionId,174 newReFungibleTokenId, Charlie, Bob, 1, 'ReFungible');175 });176});tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -393,7 +393,7 @@
export async function burnItemExpectSuccess(owner: IKeyringPair, collectionId: number, tokenId: number, value = 0) {
await usingApi(async (api) => {
- const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+ const tx = api.tx.nft.burnItem(collectionId, tokenId, value);
const events = await submitTransactionAsync(owner, tx);
const result = getGenericResult(events);
// Get the item