--- a/tests/src/approve.test.ts +++ b/tests/src/approve.test.ts @@ -2,6 +2,7 @@ // This file is subject to the terms and conditions defined in // file 'LICENSE', which is part of this source code package. // +import { IKeyringPair } from '@polkadot/types/types'; import { ApiPromise } from '@polkadot/api'; import BN from 'bn.js'; import chai from 'chai'; @@ -15,6 +16,7 @@ createFungibleItemExpectSuccess, createItemExpectSuccess, destroyCollectionExpectSuccess, + transferExpectSuccess, transferFromExpectSuccess, U128_MAX, } from './util/helpers'; @@ -68,10 +70,19 @@ }); describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => { + let Alice: IKeyringPair; + let Bob: IKeyringPair; + + before(async () => { + await usingApi(async (api) => { + Alice = privateKey('//Alice'); + Bob = privateKey('//Bob'); + }); + }); + it('Approve for a collection that does not exist', async () => { await usingApi(async (api: ApiPromise) => { - const Alice = privateKey('//Alice'); - const Bob = privateKey('//Bob'); + // nft const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number; await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob); @@ -86,8 +97,6 @@ it('Approve for a collection that was destroyed', async () => { await usingApi(async (api: ApiPromise) => { - const Alice = privateKey('//Alice'); - const Bob = privateKey('//Bob'); // nft const nftCollectionId = await createCollectionExpectSuccess(); await destroyCollectionExpectSuccess(nftCollectionId); @@ -106,8 +115,6 @@ it('Approve transfer of a token that does not exist', async () => { await usingApi(async (api: ApiPromise) => { - const Alice = privateKey('//Alice'); - const Bob = privateKey('//Bob'); // nft const nftCollectionId = await createCollectionExpectSuccess(); await approveExpectFail(nftCollectionId, 2, Alice, Bob); @@ -140,4 +147,28 @@ await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice); }); }); + + it('should fail if approved more NFTs than owned', async () => { + const nftCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } }); + const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT'); + await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT'); + await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice); + await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice); + }); + + it('should fail if approved more ReFungibles than owned', async () => { + const nftCollectionId = await createCollectionExpectSuccess({ mode: { type: 'ReFungible' } }); + const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'ReFungible'); + await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 100, 'ReFungible'); + await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, 100); + await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, 1); + }); + + it('should fail if approved more Fungibles than owned', async () => { + const nftCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } }); + const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'Fungible'); + await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 10, 'Fungible'); + await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, 10); + await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, 1); + }); });