difftreelog
Cleanup approve tests
in: master
2 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth348 TokenValueTooLow,348 TokenValueTooLow,349 /// Size of item is too large.349 /// Size of item is too large.350 NftSizeLimitExceeded,350 NftSizeLimitExceeded,351 /// Owned amount is lesser than tried to approve352 CantAfford,353 /// No approve found351 /// No approve found354 ApproveNotFound,352 ApproveNotFound,355 /// Requested value more than approved.353 /// Requested value more than approved.1111 allowance += <Allowances<T>>::get(collection_id, (item_id, &sender, &spender));1109 allowance += <Allowances<T>>::get(collection_id, (item_id, &sender, &spender));1112 }1110 }1113 if let Some(limit) = allowance_limit {1111 if let Some(limit) = allowance_limit {1114 ensure!(limit >= allowance, Error::<T>::CantAfford);1112 ensure!(limit >= allowance, Error::<T>::TokenValueTooLow);1115 }1113 }1116 <Allowances<T>>::insert(collection_id, (item_id, sender.clone(), spender.clone()), allowance);1114 <Allowances<T>>::insert(collection_id, (item_id, sender.clone(), spender.clone()), allowance);11171115tests/src/approve.test.tsdiffbeforeafterboth4//4//5import { IKeyringPair } from '@polkadot/types/types';5import { IKeyringPair } from '@polkadot/types/types';6import { ApiPromise } from '@polkadot/api';6import { ApiPromise } from '@polkadot/api';7import BN from 'bn.js';8import chai from 'chai';7import chai from 'chai';9import chaiAsPromised from 'chai-as-promised';8import chaiAsPromised from 'chai-as-promised';10import privateKey from './substrate/privateKey';9import privateKey from './substrate/privateKey';13 approveExpectFail,12 approveExpectFail,14 approveExpectSuccess,13 approveExpectSuccess,15 createCollectionExpectSuccess,14 createCollectionExpectSuccess,16 createFungibleItemExpectSuccess,17 createItemExpectSuccess,15 createItemExpectSuccess,18 destroyCollectionExpectSuccess,16 destroyCollectionExpectSuccess,19 transferExpectSuccess,17 transferExpectSuccess,20 transferFromExpectSuccess,21 U128_MAX,22} from './util/helpers';18} from './util/helpers';231924chai.use(chaiAsPromised);20chai.use(chaiAsPromised);2125const expect = chai.expect;22let Alice: IKeyringPair;23let Bob: IKeyringPair;262427describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {25describe.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 });3228 it('Execute the extrinsic and check approvedList', async () => {33 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();34 const nftCollectionId = await createCollectionExpectSuccess();33 // nft35 // nft34 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');36 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');42 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});44 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});43 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');45 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');44 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);46 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);45 });46 });47 });474848 it('Remove approval by using 0 amount', async () => {49 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();50 const nftCollectionId = await createCollectionExpectSuccess();53 // nft51 // nft54 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');52 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');65 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');63 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');66 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 1);64 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 1);67 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 0);65 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 0);68 });69 });66 });70});67});716872describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {69describe.only('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {73 let Alice: IKeyringPair;74 let Bob: IKeyringPair;7576 before(async () => {70 before(async () => {77 await usingApi(async (api) => {71 await usingApi(async (api) => {96 });89 });979098 it('Approve for a collection that was destroyed', async () => {91 it('Approve for a collection that was destroyed', async () => {99 await usingApi(async (api: ApiPromise) => {100 // nft92 // nft101 const nftCollectionId = await createCollectionExpectSuccess();93 const nftCollectionId = await createCollectionExpectSuccess();102 await destroyCollectionExpectSuccess(nftCollectionId);94 await destroyCollectionExpectSuccess(nftCollectionId);110 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});102 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});111 await destroyCollectionExpectSuccess(reFungibleCollectionId);103 await destroyCollectionExpectSuccess(reFungibleCollectionId);112 await approveExpectFail(reFungibleCollectionId, 1, Alice, Bob);104 await approveExpectFail(reFungibleCollectionId, 1, Alice, Bob);113 });114 });105 });115106116 it('Approve transfer of a token that does not exist', async () => {107 it('Approve transfer of a token that does not exist', async () => {117 await usingApi(async (api: ApiPromise) => {118 // nft108 // nft119 const nftCollectionId = await createCollectionExpectSuccess();109 const nftCollectionId = await createCollectionExpectSuccess();120 await approveExpectFail(nftCollectionId, 2, Alice, Bob);110 await approveExpectFail(nftCollectionId, 2, Alice, Bob);125 const reFungibleCollectionId =115 const reFungibleCollectionId =126 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});116 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});127 await approveExpectFail(reFungibleCollectionId, 2, Alice, Bob);117 await approveExpectFail(reFungibleCollectionId, 2, Alice, Bob);128 });129 });118 });130119131 it('Approve using the address that does not own the approved token', async () => {120 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();121 const nftCollectionId = await createCollectionExpectSuccess();136 // nft122 // nft137 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');123 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');145 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});131 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});146 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');132 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');147 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice);133 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice);148 });149 });134 });150135151 it('should fail if approved more NFTs than owned', async () => {136 it('should fail if approved more NFTs than owned', async () => {