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

difftreelog

tests: add tests for approval limit

Yaroslav Bolyukin2021-02-19parent: #1284e5a.patch.diff
in: master

1 file changed

modifiedtests/src/approve.test.tsdiffbeforeafterboth
2// This file is subject to the terms and conditions defined in2// This file is subject to the terms and conditions defined in
3// file 'LICENSE', which is part of this source code package.3// file 'LICENSE', which is part of this source code package.
4//4//
5import { IKeyringPair } from '@polkadot/types/types';
5import { ApiPromise } from '@polkadot/api';6import { ApiPromise } from '@polkadot/api';
6import BN from 'bn.js';7import BN from 'bn.js';
7import chai from 'chai';8import chai from 'chai';
15 createFungibleItemExpectSuccess,16 createFungibleItemExpectSuccess,
16 createItemExpectSuccess,17 createItemExpectSuccess,
17 destroyCollectionExpectSuccess,18 destroyCollectionExpectSuccess,
19 transferExpectSuccess,
18 transferFromExpectSuccess,20 transferFromExpectSuccess,
19 U128_MAX,21 U128_MAX,
20} from './util/helpers';22} from './util/helpers';
68});70});
6971
70describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {72describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {
73 let Alice: IKeyringPair;
74 let Bob: IKeyringPair;
75
76 before(async () => {
77 await usingApi(async (api) => {
78 Alice = privateKey('//Alice');
79 Bob = privateKey('//Bob');
80 });
81 });
82
71 it('Approve for a collection that does not exist', async () => {83 it('Approve for a collection that does not exist', async () => {
72 await usingApi(async (api: ApiPromise) => {84 await usingApi(async (api: ApiPromise) => {
73 const Alice = privateKey('//Alice');85
74 const Bob = privateKey('//Bob');
75 // nft86 // nft
76 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;87 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
77 await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);88 await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);
8697
87 it('Approve for a collection that was destroyed', async () => {98 it('Approve for a collection that was destroyed', async () => {
88 await usingApi(async (api: ApiPromise) => {99 await usingApi(async (api: ApiPromise) => {
89 const Alice = privateKey('//Alice');
90 const Bob = privateKey('//Bob');
91 // nft100 // nft
92 const nftCollectionId = await createCollectionExpectSuccess();101 const nftCollectionId = await createCollectionExpectSuccess();
93 await destroyCollectionExpectSuccess(nftCollectionId);102 await destroyCollectionExpectSuccess(nftCollectionId);
106115
107 it('Approve transfer of a token that does not exist', async () => {116 it('Approve transfer of a token that does not exist', async () => {
108 await usingApi(async (api: ApiPromise) => {117 await usingApi(async (api: ApiPromise) => {
109 const Alice = privateKey('//Alice');
110 const Bob = privateKey('//Bob');
111 // nft118 // nft
112 const nftCollectionId = await createCollectionExpectSuccess();119 const nftCollectionId = await createCollectionExpectSuccess();
113 await approveExpectFail(nftCollectionId, 2, Alice, Bob);120 await approveExpectFail(nftCollectionId, 2, Alice, Bob);
141 });148 });
142 });149 });
150
151 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 });
158
159 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 });
166
167 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 });
143});174});
144175