difftreelog
tests: approve respects OwnerCanTransfer
in: master
1 file changed
tests/src/approve.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 BN from 'bn.js';7import BN from 'bn.js';7import chai from 'chai';8import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import chaiAsPromised from 'chai-as-promised';15 createFungibleItemExpectSuccess,16 createFungibleItemExpectSuccess,16 createItemExpectSuccess,17 createItemExpectSuccess,17 destroyCollectionExpectSuccess,18 destroyCollectionExpectSuccess,19 setCollectionLimitsExpectSuccess,18 transferFromExpectSuccess,20 transferFromExpectSuccess,19 U128_MAX,21 U128_MAX,20} from './util/helpers';22} from './util/helpers';23const expect = chai.expect;25const expect = chai.expect;242625describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {27describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {28 let Alice: IKeyringPair;29 let Bob: IKeyringPair;30 let Charlie: IKeyringPair;3132 before(async () => {33 await usingApi(async (api) => {34 Alice = privateKey('//Alice');35 Bob = privateKey('//Bob');36 Charlie = privateKey('//Charlie');37 });38 });3926 it('Execute the extrinsic and check approvedList', async () => {40 it('Execute the extrinsic and check approvedList', async () => {27 await usingApi(async (api: ApiPromise) => {41 await usingApi(async (api: ApiPromise) => {28 const Alice = privateKey('//Alice');29 const Bob = privateKey('//Bob');30 const nftCollectionId = await createCollectionExpectSuccess();42 const nftCollectionId = await createCollectionExpectSuccess();31 // nft43 // nft32 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');44 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');455746 it('Remove approval by using 0 amount', async () => {58 it('Remove approval by using 0 amount', async () => {47 await usingApi(async (api: ApiPromise) => {59 await usingApi(async (api: ApiPromise) => {48 const Alice = privateKey('//Alice');49 const Bob = privateKey('//Bob');50 const nftCollectionId = await createCollectionExpectSuccess();60 const nftCollectionId = await createCollectionExpectSuccess();51 // nft61 // nft52 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');62 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');66 });76 });67 });77 });7879 it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {80 const collectionId = await createCollectionExpectSuccess();81 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);8283 await approveExpectSuccess(collectionId, itemId, Alice, Charlie);84 });68});85});698670describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {87describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {88 let Alice: IKeyringPair;89 let Bob: IKeyringPair;90 let Charlie: IKeyringPair;9192 before(async () => {93 await usingApi(async (api) => {94 Alice = privateKey('//Alice');95 Bob = privateKey('//Bob');96 Charlie = privateKey('//Charlie');97 });98 });9971 it('Approve for a collection that does not exist', async () => {100 it('Approve for a collection that does not exist', async () => {72 await usingApi(async (api: ApiPromise) => {101 await usingApi(async (api: ApiPromise) => {73 const Alice = privateKey('//Alice');74 const Bob = privateKey('//Bob');75 // nft102 // nft76 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;103 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;77 await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);104 await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);8611387 it('Approve for a collection that was destroyed', async () => {114 it('Approve for a collection that was destroyed', async () => {88 await usingApi(async (api: ApiPromise) => {115 await usingApi(async (api: ApiPromise) => {89 const Alice = privateKey('//Alice');90 const Bob = privateKey('//Bob');91 // nft116 // nft92 const nftCollectionId = await createCollectionExpectSuccess();117 const nftCollectionId = await createCollectionExpectSuccess();93 await destroyCollectionExpectSuccess(nftCollectionId);118 await destroyCollectionExpectSuccess(nftCollectionId);106131107 it('Approve transfer of a token that does not exist', async () => {132 it('Approve transfer of a token that does not exist', async () => {108 await usingApi(async (api: ApiPromise) => {133 await usingApi(async (api: ApiPromise) => {109 const Alice = privateKey('//Alice');110 const Bob = privateKey('//Bob');111 // nft134 // nft112 const nftCollectionId = await createCollectionExpectSuccess();135 const nftCollectionId = await createCollectionExpectSuccess();113 await approveExpectFail(nftCollectionId, 2, Alice, Bob);136 await approveExpectFail(nftCollectionId, 2, Alice, Bob);123146124 it('Approve using the address that does not own the approved token', async () => {147 it('Approve using the address that does not own the approved token', async () => {125 await usingApi(async (api: ApiPromise) => {148 await usingApi(async (api: ApiPromise) => {126 const Alice = privateKey('//Alice');127 const Bob = privateKey('//Bob');128 const nftCollectionId = await createCollectionExpectSuccess();149 const nftCollectionId = await createCollectionExpectSuccess();129 // nft150 // nft130 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');151 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');141 });162 });142 });163 });164165 it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {166 const collectionId = await createCollectionExpectSuccess();167 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);168 await setCollectionLimitsExpectSuccess(Alice, collectionId, { OwnerCanTransfer: false });169170 await approveExpectFail(collectionId, itemId, Alice, Charlie);171 });143});172});144173