12345import { ApiPromise } from '@polkadot/api';6import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import privateKey from './substrate/privateKey';9import { default as usingApi } from './substrate/substrate-api';10import {11 approveExpectFail,12 approveExpectSuccess,13 createCollectionExpectSuccess,14 createItemExpectSuccess,15 destroyCollectionExpectSuccess,16 transferFromExpectFail,17 transferFromExpectSuccess,18 burnItemExpectSuccess,19} from './util/helpers';2021chai.use(chaiAsPromised);22const expect = chai.expect;2324describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {25 it('Execute the extrinsic and check nftItemList - owner of token', async () => {26 await usingApi(async (api: ApiPromise) => {27 const Alice = privateKey('//Alice');28 const Bob = privateKey('//Bob');29 const Charlie = privateKey('//Charlie');30 31 const nftCollectionId = await createCollectionExpectSuccess();32 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');33 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);3435 await transferFromExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1, 'NFT');3637 38 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});39 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');40 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);41 await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1, 'Fungible');42 43 const reFungibleCollectionId = await44 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});45 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');46 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 100);47 await transferFromExpectSuccess(reFungibleCollectionId,48 newReFungibleTokenId, Bob, Alice, Charlie, 100, 'ReFungible');49 });50 });51});5253describe('Negative Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {54 it('transferFrom for a collection that does not exist', async () => {55 await usingApi(async (api: ApiPromise) => {56 const Alice = privateKey('//Alice');57 const Bob = privateKey('//Bob');58 const Charlie = privateKey('//Charlie');59 60 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;61 await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);6263 await transferFromExpectFail(nftCollectionCount + 1, 1, Bob, Alice, Charlie, 1);6465 66 const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;67 await approveExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob);6869 await transferFromExpectFail(fungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);70 71 const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;72 await approveExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob);7374 await transferFromExpectFail(reFungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);75 });76 });7778 798081828384 858687888990 919293949596 it('transferFrom for not approved address', async () => {97 await usingApi(async (api: ApiPromise) => {98 const Alice = privateKey('//Alice');99 const Bob = privateKey('//Bob');100 const Charlie = privateKey('//Charlie');101 102 const nftCollectionId = await createCollectionExpectSuccess();103 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');104105 await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);106107 108 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});109 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');110 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);111 112 const reFungibleCollectionId = await113 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});114 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');115 await transferFromExpectFail(reFungibleCollectionId,116 newReFungibleTokenId, Bob, Alice, Charlie, 1);117 });118 });119120 it('transferFrom incorrect token count', async () => {121 await usingApi(async (api: ApiPromise) => {122 const Alice = privateKey('//Alice');123 const Bob = privateKey('//Bob');124 const Charlie = privateKey('//Charlie');125 126 const nftCollectionId = await createCollectionExpectSuccess();127 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');128 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);129130 await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 2);131132 133 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});134 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');135 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);136 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 2);137 138 const reFungibleCollectionId = await139 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});140 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');141 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);142 await transferFromExpectFail(reFungibleCollectionId,143 newReFungibleTokenId, Bob, Alice, Charlie, 2);144 });145 });146147 it('execute transferFrom from account that is not owner of collection', async () => {148 await usingApi(async (api: ApiPromise) => {149 const Alice = privateKey('//Alice');150 const Bob = privateKey('//Bob');151 const Charlie = privateKey('//Charlie');152 const Dave = privateKey('//Dave');153 154 const nftCollectionId = await createCollectionExpectSuccess();155 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');156 try {157 await approveExpectFail(nftCollectionId, newNftTokenId, Dave, Bob);158 await transferFromExpectFail(nftCollectionId, newNftTokenId, Dave, Alice, Charlie, 1);159 } catch (e) {160 161 expect(e).to.be.exist;162 }163164 165166 167 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});168 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');169 try {170 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Bob);171 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Alice, Charlie, 1);172 } catch (e) {173 174 expect(e).to.be.exist;175 }176 177 const reFungibleCollectionId = await178 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});179 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');180 try {181 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Bob);182 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Alice, Charlie, 1);183 } catch (e) {184 185 expect(e).to.be.exist;186 }187 });188 });189 it( 'transferFrom burnt token before approve NFT', async () => {190 await usingApi(async (api: ApiPromise) => {191 const Alice = privateKey('//Alice');192 const Bob = privateKey('//Bob');193 const Charlie = privateKey('//Charlie');194 195 const nftCollectionId = await createCollectionExpectSuccess();196 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');197 await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);198 await approveExpectFail(nftCollectionId, newNftTokenId, Alice, Bob);199 await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1); 200 });201 });202 it( 'transferFrom burnt token before approve Fungible', async () => {203 await usingApi(async (api: ApiPromise) => {204 const Alice = privateKey('//Alice');205 const Bob = privateKey('//Bob');206 const Charlie = privateKey('//Charlie');207 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});208 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');209 await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);210 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob);211 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);212 213 });214 }); 215 it( 'transferFrom burnt token before approve ReFungible', async () => {216 await usingApi(async (api: ApiPromise) => {217 const Alice = privateKey('//Alice');218 const Bob = privateKey('//Bob');219 const Charlie = privateKey('//Charlie');220 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});221 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');222 await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);223 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);224 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);225 226 });227 });228 229 it( 'transferFrom burnt token after approve NFT', async () => {230 await usingApi(async (api: ApiPromise) => {231 const Alice = privateKey('//Alice');232 const Bob = privateKey('//Bob');233 const Charlie = privateKey('//Charlie');234 235 const nftCollectionId = await createCollectionExpectSuccess();236 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');237 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);238 await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);239 await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1); 240 });241 });242 it( 'transferFrom burnt token after approve Fungible', async () => {243 await usingApi(async (api: ApiPromise) => {244 const Alice = privateKey('//Alice');245 const Bob = privateKey('//Bob');246 const Charlie = privateKey('//Charlie');247 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});248 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');249 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);250 await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);251 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);252 253 });254 }); 255 it( 'transferFrom burnt token after approve ReFungible', async () => {256 await usingApi(async (api: ApiPromise) => {257 const Alice = privateKey('//Alice');258 const Bob = privateKey('//Bob');259 const Charlie = privateKey('//Charlie');260 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});261 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');262 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);263 await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);264 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);265 266 });267 }); 268});