difftreelog
tests: transferFrom respects OwnerCanTransfer
in: master
1 file changed
tests/src/transferFrom.test.tsdiffbeforeafterboth3// file 'LICENSE', which is part of this source code package.3// file 'LICENSE', which is part of this source code package.4//4//5import { ApiPromise } from '@polkadot/api';5import { ApiPromise } from '@polkadot/api';6import { IKeyringPair } from '@polkadot/types/types';6import chai from 'chai';7import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import chaiAsPromised from 'chai-as-promised';8import privateKey from './substrate/privateKey';9import privateKey from './substrate/privateKey';18 transferFromExpectFail,19 transferFromExpectFail,19 transferFromExpectSuccess,20 transferFromExpectSuccess,20 burnItemExpectSuccess,21 burnItemExpectSuccess,22 setCollectionLimitsExpectSuccess,21} from './util/helpers';23} from './util/helpers';222423chai.use(chaiAsPromised);25chai.use(chaiAsPromised);24const expect = chai.expect;26const expect = chai.expect;252726describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {28describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {29 let Alice: IKeyringPair;30 let Bob: IKeyringPair;31 let Charlie: IKeyringPair;3233 before(async () => {34 await usingApi(async (api) => {35 Alice = privateKey('//Alice');36 Bob = privateKey('//Bob');37 Charlie = privateKey('//Charlie');38 });39 });4027 it('Execute the extrinsic and check nftItemList - owner of token', async () => {41 it('Execute the extrinsic and check nftItemList - owner of token', async () => {28 await usingApi(async (api: ApiPromise) => {42 await usingApi(async (api: ApiPromise) => {29 const Alice = privateKey('//Alice');30 const Bob = privateKey('//Bob');31 const Charlie = privateKey('//Charlie');32 // nft43 // nft33 const nftCollectionId = await createCollectionExpectSuccess();44 const nftCollectionId = await createCollectionExpectSuccess();34 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');45 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');67 });78 });68 });79 });8081 it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {82 const collectionId = await createCollectionExpectSuccess();83 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);8485 await transferFromExpectSuccess(collectionId, itemId, Alice, Bob, Charlie);86 });69});87});708871describe('Negative Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {89describe('Negative Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {90 let Alice: IKeyringPair;91 let Bob: IKeyringPair;92 let Charlie: IKeyringPair;9394 before(async () => {95 await usingApi(async (api) => {96 Alice = privateKey('//Alice');97 Bob = privateKey('//Bob');98 Charlie = privateKey('//Charlie');99 });100 });10172 it('transferFrom for a collection that does not exist', async () => {102 it('transferFrom for a collection that does not exist', async () => {73 await usingApi(async (api: ApiPromise) => {103 await usingApi(async (api: ApiPromise) => {74 const Alice = privateKey('//Alice');75 const Bob = privateKey('//Bob');76 const Charlie = privateKey('//Charlie');77 // nft104 // nft78 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;105 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;79 await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);106 await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);113140114 it('transferFrom for not approved address', async () => {141 it('transferFrom for not approved address', async () => {115 await usingApi(async (api: ApiPromise) => {142 await usingApi(async (api: ApiPromise) => {116 const Alice = privateKey('//Alice');117 const Bob = privateKey('//Bob');118 const Charlie = privateKey('//Charlie');119 // nft143 // nft120 const nftCollectionId = await createCollectionExpectSuccess();144 const nftCollectionId = await createCollectionExpectSuccess();121 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');145 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');137161138 it('transferFrom incorrect token count', async () => {162 it('transferFrom incorrect token count', async () => {139 await usingApi(async (api: ApiPromise) => {163 await usingApi(async (api: ApiPromise) => {140 const Alice = privateKey('//Alice');141 const Bob = privateKey('//Bob');142 const Charlie = privateKey('//Charlie');143 // nft164 // nft144 const nftCollectionId = await createCollectionExpectSuccess();165 const nftCollectionId = await createCollectionExpectSuccess();145 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');166 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');164185165 it('execute transferFrom from account that is not owner of collection', async () => {186 it('execute transferFrom from account that is not owner of collection', async () => {166 await usingApi(async (api: ApiPromise) => {187 await usingApi(async (api: ApiPromise) => {167 const Alice = privateKey('//Alice');168 const Bob = privateKey('//Bob');169 const Charlie = privateKey('//Charlie');170 const Dave = privateKey('//Dave');188 const Dave = privateKey('//Dave');171 // nft189 // nft172 const nftCollectionId = await createCollectionExpectSuccess();190 const nftCollectionId = await createCollectionExpectSuccess();206 });224 });207 it( 'transferFrom burnt token before approve NFT', async () => {225 it( 'transferFrom burnt token before approve NFT', async () => {208 await usingApi(async (api: ApiPromise) => {226 await usingApi(async (api: ApiPromise) => {209 const Alice = privateKey('//Alice');210 const Bob = privateKey('//Bob');211 const Charlie = privateKey('//Charlie');212 // nft227 // nft213 const nftCollectionId = await createCollectionExpectSuccess();228 const nftCollectionId = await createCollectionExpectSuccess();214 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');229 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');219 });234 });220 it( 'transferFrom burnt token before approve Fungible', async () => {235 it( 'transferFrom burnt token before approve Fungible', async () => {221 await usingApi(async (api: ApiPromise) => {236 await usingApi(async (api: ApiPromise) => {222 const Alice = privateKey('//Alice');223 const Bob = privateKey('//Bob');224 const Charlie = privateKey('//Charlie');225 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});237 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});226 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');238 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');227 await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);239 await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);232 }); 244 }); 233 it( 'transferFrom burnt token before approve ReFungible', async () => {245 it( 'transferFrom burnt token before approve ReFungible', async () => {234 await usingApi(async (api: ApiPromise) => {246 await usingApi(async (api: ApiPromise) => {235 const Alice = privateKey('//Alice');236 const Bob = privateKey('//Bob');237 const Charlie = privateKey('//Charlie');238 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});247 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});239 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');248 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');240 await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);249 await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);246 255 247 it( 'transferFrom burnt token after approve NFT', async () => {256 it( 'transferFrom burnt token after approve NFT', async () => {248 await usingApi(async (api: ApiPromise) => {257 await usingApi(async (api: ApiPromise) => {249 const Alice = privateKey('//Alice');250 const Bob = privateKey('//Bob');251 const Charlie = privateKey('//Charlie');252 // nft258 // nft253 const nftCollectionId = await createCollectionExpectSuccess();259 const nftCollectionId = await createCollectionExpectSuccess();254 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');260 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');259 });265 });260 it( 'transferFrom burnt token after approve Fungible', async () => {266 it( 'transferFrom burnt token after approve Fungible', async () => {261 await usingApi(async (api: ApiPromise) => {267 await usingApi(async (api: ApiPromise) => {262 const Alice = privateKey('//Alice');263 const Bob = privateKey('//Bob');264 const Charlie = privateKey('//Charlie');265 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});268 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});266 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');269 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');267 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);270 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);272 }); 275 }); 273 it( 'transferFrom burnt token after approve ReFungible', async () => {276 it( 'transferFrom burnt token after approve ReFungible', async () => {274 await usingApi(async (api: ApiPromise) => {277 await usingApi(async (api: ApiPromise) => {275 const Alice = privateKey('//Alice');276 const Bob = privateKey('//Bob');277 const Charlie = privateKey('//Charlie');278 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});278 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});279 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');279 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');280 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);280 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);284 });284 });285 }); 285 });286287 it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {288 const collectionId = await createCollectionExpectSuccess();289 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);290 await setCollectionLimitsExpectSuccess(Alice, collectionId, { OwnerCanTransfer: false });291292 await transferFromExpectFail(collectionId, itemId, Alice, Bob, Charlie);293 });286});294});287295