git.delta.rocks / unique-network / refs/commits / e090dfbfaad2

difftreelog

Cleanup approve tests

Greg Zaitsev2021-02-26parent: #bdf204a.patch.diff
in: master

2 files changed

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
348 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 approve
352 CantAfford,
353 /// No approve found351 /// No approve found
354 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);
11171115
modifiedtests/src/approve.test.tsdiffbeforeafterboth
4//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';
2319
24chai.use(chaiAsPromised);20chai.use(chaiAsPromised);
21
25const expect = chai.expect;22let Alice: IKeyringPair;
23let Bob: IKeyringPair;
2624
27describe('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 });
32
28 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 // nft
34 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 });
4748
48 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 // nft
54 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});
7168
72describe('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;
75
76 before(async () => {70 before(async () => {
77 await usingApi(async (api) => {71 await usingApi(async (api) => {
96 });89 });
9790
98 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 // nft
101 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 });
115106
116 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 // nft
119 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 });
130119
131 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 // nft
137 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 });
150135
151 it('should fail if approved more NFTs than owned', async () => {136 it('should fail if approved more NFTs than owned', async () => {