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

difftreelog

Fix transfer test (with burned tokens)

Greg Zaitsev2021-01-19parent: #dccf127.patch.diff
in: master

2 files changed

modifiedtests/src/transfer.test.tsdiffbeforeafterboth
4//4//
55
6import { ApiPromise } from '@polkadot/api';6import { ApiPromise } from '@polkadot/api';
7import { IKeyringPair } from '@polkadot/types/types';
7import { expect } from 'chai';8import { expect } from 'chai';
8import { alicesPublicKey, bobsPublicKey } from './accounts';9import { alicesPublicKey, bobsPublicKey } from './accounts';
9import getBalance from './substrate/get-balance';10import getBalance from './substrate/get-balance';
19 transferExpectSuccess,20 transferExpectSuccess,
20} from './util/helpers';21} from './util/helpers';
22
23let Alice: IKeyringPair;
24let Bob: IKeyringPair;
25let Charlie: IKeyringPair;
2126
22describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {27describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
23 it('Balance transfers and check balance', async () => {28 it('Balance transfers and check balance', async () => {
81});86});
8287
83describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {88describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
89 before(async () => {
90 await usingApi(async (api: ApiPromise) => {
91 Alice = privateKey('//Alice');
92 Bob = privateKey('//Bob');
93 Charlie = privateKey('//Charlie');
94 });
95 });
84 it('Transfer with not existed collection_id', async () => {96 it('Transfer with not existed collection_id', async () => {
85 await usingApi(async (api: ApiPromise) => {97 await usingApi(async (api) => {
86 const Alice = privateKey('//Alice');
87 const Bob = privateKey('//Bob');
88 // nft98 // nft
89 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;99 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
90 await transferExpectFail(nftCollectionCount + 1, 1, Alice, Bob, 1);100 await transferExpectFail(nftCollectionCount + 1, 1, Alice, Bob, 1);
97 });107 });
98 });108 });
99 it('Transfer with deleted collection_id', async () => {109 it('Transfer with deleted collection_id', async () => {
100 await usingApi(async (api: ApiPromise) => {
101 const Alice = privateKey('//Alice');
102 const Bob = privateKey('//Bob');
103 // nft110 // nft
104 const nftCollectionId = await createCollectionExpectSuccess();111 const nftCollectionId = await createCollectionExpectSuccess();
105 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');112 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
117 await destroyCollectionExpectSuccess(reFungibleCollectionId);124 await destroyCollectionExpectSuccess(reFungibleCollectionId);
118 await transferExpectFail(reFungibleCollectionId,125 await transferExpectFail(reFungibleCollectionId,
119 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');126 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');
120 });
121 });127 });
122 it('Transfer with not existed item_id', async () => {128 it('Transfer with not existed item_id', async () => {
123 await usingApi(async (api: ApiPromise) => {
124 const Alice = privateKey('//Alice');
125 const Bob = privateKey('//Bob');
126 // nft129 // nft
127 const nftCollectionId = await createCollectionExpectSuccess();130 const nftCollectionId = await createCollectionExpectSuccess();
128 await transferExpectFail(nftCollectionId, 2, Alice, Bob, 1, 'NFT');131 await transferExpectFail(nftCollectionId, 2, Alice, Bob, 1, 'NFT');
134 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});137 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
135 await transferExpectFail(reFungibleCollectionId,138 await transferExpectFail(reFungibleCollectionId,
136 2, Alice, Bob, 1, 'ReFungible');139 2, Alice, Bob, 1, 'ReFungible');
137 });
138 });140 });
139 it('Transfer with deleted item_id', async () => {141 it('Transfer with deleted item_id', async () => {
140 await usingApi(async (api: ApiPromise) => {
141 const Alice = privateKey('//Alice');
142 const Bob = privateKey('//Bob');
143 // nft142 // nft
144 const nftCollectionId = await createCollectionExpectSuccess();143 const nftCollectionId = await createCollectionExpectSuccess();
145 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');144 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
148 // fungible147 // fungible
149 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});148 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
150 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');149 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
151 await burnItemExpectSuccess(Alice, fungibleCollectionId, newFungibleTokenId, 1);150 await burnItemExpectSuccess(Alice, fungibleCollectionId, newFungibleTokenId, 10);
152 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');151 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');
153 // reFungible152 // reFungible
154 const reFungibleCollectionId = await153 const reFungibleCollectionId = await
157 await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);156 await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);
158 await transferExpectFail(reFungibleCollectionId,157 await transferExpectFail(reFungibleCollectionId,
159 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');158 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');
160 });
161 });159 });
162 it('Transfer with recipient that is not owner', async () => {160 it('Transfer with recipient that is not owner', async () => {
163 await usingApi(async (api: ApiPromise) => {
164 const Alice = privateKey('//Alice');
165 const Bob = privateKey('//Bob');
166 const Charlie = privateKey('//CHARLIE');
167 // nft161 // nft
168 const nftCollectionId = await createCollectionExpectSuccess();162 const nftCollectionId = await createCollectionExpectSuccess();
169 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');163 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
178 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');172 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
179 await transferExpectFail(reFungibleCollectionId,173 await transferExpectFail(reFungibleCollectionId,
180 newReFungibleTokenId, Charlie, Bob, 1, 'ReFungible');174 newReFungibleTokenId, Charlie, Bob, 1, 'ReFungible');
181 });
182 });175 });
183});176});
184177
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
393393
394export async function burnItemExpectSuccess(owner: IKeyringPair, collectionId: number, tokenId: number, value = 0) {394export async function burnItemExpectSuccess(owner: IKeyringPair, collectionId: number, tokenId: number, value = 0) {
395 await usingApi(async (api) => {395 await usingApi(async (api) => {
396 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);396 const tx = api.tx.nft.burnItem(collectionId, tokenId, value);
397 const events = await submitTransactionAsync(owner, tx);397 const events = await submitTransactionAsync(owner, tx);
398 const result = getGenericResult(events);398 const result = getGenericResult(events);
399 // Get the item399 // Get the item