difftreelog
Cleanup approve tests
in: master
2 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -348,8 +348,6 @@
TokenValueTooLow,
/// Size of item is too large.
NftSizeLimitExceeded,
- /// Owned amount is lesser than tried to approve
- CantAfford,
/// No approve found
ApproveNotFound,
/// Requested value more than approved.
@@ -1111,7 +1109,7 @@
allowance += <Allowances<T>>::get(collection_id, (item_id, &sender, &spender));
}
if let Some(limit) = allowance_limit {
- ensure!(limit >= allowance, Error::<T>::CantAfford);
+ ensure!(limit >= allowance, Error::<T>::TokenValueTooLow);
}
<Allowances<T>>::insert(collection_id, (item_id, sender.clone(), spender.clone()), allowance);
tests/src/approve.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//5import { IKeyringPair } from '@polkadot/types/types';6import { ApiPromise } from '@polkadot/api';7import BN from 'bn.js';8import chai from 'chai';9import chaiAsPromised from 'chai-as-promised';10import privateKey from './substrate/privateKey';11import { default as usingApi } from './substrate/substrate-api';12import {13 approveExpectFail,14 approveExpectSuccess,15 createCollectionExpectSuccess,16 createFungibleItemExpectSuccess,17 createItemExpectSuccess,18 destroyCollectionExpectSuccess,19 transferExpectSuccess,20 transferFromExpectSuccess,21 U128_MAX,22} from './util/helpers';2324chai.use(chaiAsPromised);25const expect = chai.expect;2627describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {28 it('Execute the extrinsic and check approvedList', async () => {29 await usingApi(async (api: ApiPromise) => {30 const Alice = privateKey('//Alice');31 const Bob = privateKey('//Bob');32 const nftCollectionId = await createCollectionExpectSuccess();33 // nft34 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');35 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);36 // fungible37 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});38 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');39 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);40 // reFungible41 const reFungibleCollectionId =42 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});43 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');44 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);45 });46 });4748 it('Remove approval by using 0 amount', async () => {49 await usingApi(async (api: ApiPromise) => {50 const Alice = privateKey('//Alice');51 const Bob = privateKey('//Bob');52 const nftCollectionId = await createCollectionExpectSuccess();53 // nft54 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');55 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1);56 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 0);57 // fungible58 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});59 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');60 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1);61 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 0);62 // reFungible63 const reFungibleCollectionId =64 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});65 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');66 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 1);67 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 0);68 });69 });70});7172describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {73 let Alice: IKeyringPair;74 let Bob: IKeyringPair;7576 before(async () => {77 await usingApi(async (api) => {78 Alice = privateKey('//Alice');79 Bob = privateKey('//Bob');80 });81 });8283 it('Approve for a collection that does not exist', async () => {84 await usingApi(async (api: ApiPromise) => {8586 // nft87 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;88 await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);89 // fungible90 const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;91 await approveExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob);92 // reFungible93 const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;94 await approveExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob);95 });96 });9798 it('Approve for a collection that was destroyed', async () => {99 await usingApi(async (api: ApiPromise) => {100 // nft101 const nftCollectionId = await createCollectionExpectSuccess();102 await destroyCollectionExpectSuccess(nftCollectionId);103 await approveExpectFail(nftCollectionId, 1, Alice, Bob);104 // fungible105 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});106 await destroyCollectionExpectSuccess(fungibleCollectionId);107 await approveExpectFail(fungibleCollectionId, 1, Alice, Bob);108 // reFungible109 const reFungibleCollectionId =110 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});111 await destroyCollectionExpectSuccess(reFungibleCollectionId);112 await approveExpectFail(reFungibleCollectionId, 1, Alice, Bob);113 });114 });115116 it('Approve transfer of a token that does not exist', async () => {117 await usingApi(async (api: ApiPromise) => {118 // nft119 const nftCollectionId = await createCollectionExpectSuccess();120 await approveExpectFail(nftCollectionId, 2, Alice, Bob);121 // fungible122 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});123 await approveExpectFail(fungibleCollectionId, 2, Alice, Bob);124 // reFungible125 const reFungibleCollectionId =126 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});127 await approveExpectFail(reFungibleCollectionId, 2, Alice, Bob);128 });129 });130131 it('Approve using the address that does not own the approved token', async () => {132 await usingApi(async (api: ApiPromise) => {133 const Alice = privateKey('//Alice');134 const Bob = privateKey('//Bob');135 const nftCollectionId = await createCollectionExpectSuccess();136 // nft137 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');138 await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice);139 // fungible140 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});141 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');142 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice);143 // reFungible144 const reFungibleCollectionId =145 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});146 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');147 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice);148 });149 });150151 it('should fail if approved more NFTs than owned', async () => {152 const nftCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });153 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');154 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');155 await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice);156 await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice);157 });158159 it('should fail if approved more ReFungibles than owned', async () => {160 const nftCollectionId = await createCollectionExpectSuccess({ mode: { type: 'ReFungible' } });161 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'ReFungible');162 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 100, 'ReFungible');163 await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, 100);164 await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, 1);165 });166167 it('should fail if approved more Fungibles than owned', async () => {168 const nftCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });169 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'Fungible');170 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 10, 'Fungible');171 await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, 10);172 await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, 1);173 });174});1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//5import { IKeyringPair } from '@polkadot/types/types';6import { ApiPromise } from '@polkadot/api';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import { default as usingApi } from './substrate/substrate-api';11import {12 approveExpectFail,13 approveExpectSuccess,14 createCollectionExpectSuccess,15 createItemExpectSuccess,16 destroyCollectionExpectSuccess,17 transferExpectSuccess,18} from './util/helpers';1920chai.use(chaiAsPromised);2122let Alice: IKeyringPair;23let Bob: IKeyringPair;2425describe.only('Integration Test approve(spender, collection_id, item_id, amount):', () => {26 before(async () => {27 await usingApi(async () => {28 Alice = privateKey('//Alice');29 Bob = privateKey('//Bob');30 });31 });3233 it('Execute the extrinsic and check approvedList', async () => {34 const nftCollectionId = await createCollectionExpectSuccess();35 // nft36 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');37 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);38 // fungible39 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});40 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');41 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);42 // reFungible43 const reFungibleCollectionId =44 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});45 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');46 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);47 });4849 it('Remove approval by using 0 amount', async () => {50 const nftCollectionId = await createCollectionExpectSuccess();51 // nft52 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');53 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1);54 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 0);55 // fungible56 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});57 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');58 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1);59 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 0);60 // reFungible61 const reFungibleCollectionId =62 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});63 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');64 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 1);65 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 0);66 });67});6869describe.only('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {70 before(async () => {71 await usingApi(async (api) => {72 Alice = privateKey('//Alice');73 Bob = privateKey('//Bob');74 });75 });7677 it('Approve for a collection that does not exist', async () => {78 await usingApi(async (api: ApiPromise) => {79 // nft80 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;81 await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);82 // fungible83 const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;84 await approveExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob);85 // reFungible86 const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;87 await approveExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob);88 });89 });9091 it('Approve for a collection that was destroyed', async () => {92 // nft93 const nftCollectionId = await createCollectionExpectSuccess();94 await destroyCollectionExpectSuccess(nftCollectionId);95 await approveExpectFail(nftCollectionId, 1, Alice, Bob);96 // fungible97 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});98 await destroyCollectionExpectSuccess(fungibleCollectionId);99 await approveExpectFail(fungibleCollectionId, 1, Alice, Bob);100 // reFungible101 const reFungibleCollectionId =102 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});103 await destroyCollectionExpectSuccess(reFungibleCollectionId);104 await approveExpectFail(reFungibleCollectionId, 1, Alice, Bob);105 });106107 it('Approve transfer of a token that does not exist', async () => {108 // nft109 const nftCollectionId = await createCollectionExpectSuccess();110 await approveExpectFail(nftCollectionId, 2, Alice, Bob);111 // fungible112 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});113 await approveExpectFail(fungibleCollectionId, 2, Alice, Bob);114 // reFungible115 const reFungibleCollectionId =116 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});117 await approveExpectFail(reFungibleCollectionId, 2, Alice, Bob);118 });119120 it('Approve using the address that does not own the approved token', async () => {121 const nftCollectionId = await createCollectionExpectSuccess();122 // nft123 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');124 await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice);125 // fungible126 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});127 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');128 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice);129 // reFungible130 const reFungibleCollectionId =131 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});132 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');133 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice);134 });135136 it('should fail if approved more NFTs than owned', async () => {137 const nftCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });138 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');139 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');140 await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice);141 await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice);142 });143144 it('should fail if approved more ReFungibles than owned', async () => {145 const nftCollectionId = await createCollectionExpectSuccess({ mode: { type: 'ReFungible' } });146 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'ReFungible');147 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 100, 'ReFungible');148 await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, 100);149 await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, 1);150 });151152 it('should fail if approved more Fungibles than owned', async () => {153 const nftCollectionId = await createCollectionExpectSuccess({ mode: { type: 'Fungible', decimalPoints: 0 } });154 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'Fungible');155 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 10, 'Fungible');156 await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, 10);157 await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, 1);158 });159});