git.delta.rocks / unique-network / refs/commits / 946ee50bbf85

difftreelog

Merge pull request #234 from UniqueNetwork/feature/core-214

kozyrevdev2021-11-22parents: #5846f9c #ffcdfcb.patch.diff
in: master
CORE-214. Zero value transfer tests

1 file changed

modifiedtests/src/transfer.test.tsdiffbeforeafterboth
19 transferExpectFailure,19 transferExpectFailure,
20 transferExpectSuccess,20 transferExpectSuccess,
21 addCollectionAdminExpectSuccess,21 addCollectionAdminExpectSuccess,
22 toSubstrateAddress,
23 getTokenOwner,
24 normalizeAccountId,
25 getBalance as getTokenBalance,
22} from './util/helpers';26} from './util/helpers';
2327
24let alice: IKeyringPair;28let alice: IKeyringPair;
231 });235 });
232});236});
233237
238describe('Zero value transfer(From)', () => {
239 before(async () => {
240 await usingApi(async () => {
241 alice = privateKey('//Alice');
242 bob = privateKey('//Bob');
243 });
244 });
245
246 it('NFT', async () => {
247 await usingApi(async (api: ApiPromise) => {
248 const nftCollectionId = await createCollectionExpectSuccess();
249 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
250
251 const transferTx = api.tx.nft.transfer(normalizeAccountId(bob), nftCollectionId, newNftTokenId, 0);
252 await submitTransactionAsync(alice, transferTx);
253 const address = normalizeAccountId(await getTokenOwner(api, nftCollectionId, newNftTokenId));
254
255 expect(toSubstrateAddress(address)).to.be.equal(alice.address);
256 });
257 });
258
259 it('RFT', async () => {
260 await usingApi(async (api: ApiPromise) => {
261 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
262 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
263 const balanceBeforeAlice = await getTokenBalance(api, reFungibleCollectionId, normalizeAccountId(alice), newReFungibleTokenId);
264 const balanceBeforeBob = await getTokenBalance(api, reFungibleCollectionId, normalizeAccountId(bob), newReFungibleTokenId);
265
266 const transferTx = api.tx.nft.transfer(normalizeAccountId(bob), reFungibleCollectionId, newReFungibleTokenId, 0);
267 await submitTransactionAsync(alice, transferTx);
268
269 const balanceAfterAlice = await getTokenBalance(api, reFungibleCollectionId, normalizeAccountId(alice), newReFungibleTokenId);
270 const balanceAfterBob = await getTokenBalance(api, reFungibleCollectionId, normalizeAccountId(bob), newReFungibleTokenId);
271
272 expect((balanceBeforeAlice)).to.be.equal(balanceAfterAlice);
273 expect((balanceBeforeBob)).to.be.equal(balanceAfterBob);
274 });
275 });
276
277 it('Fungible', async () => {
278 await usingApi(async (api: ApiPromise) => {
279 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
280 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
281 const balanceBeforeAlice = await getTokenBalance(api, fungibleCollectionId, normalizeAccountId(alice), newFungibleTokenId);
282 const balanceBeforeBob = await getTokenBalance(api, fungibleCollectionId, normalizeAccountId(bob), newFungibleTokenId);
283
284 const transferTx = api.tx.nft.transfer(normalizeAccountId(bob), fungibleCollectionId, newFungibleTokenId, 0);
285 await submitTransactionAsync(alice, transferTx);
286
287 const balanceAfterAlice = await getTokenBalance(api, fungibleCollectionId, normalizeAccountId(alice), newFungibleTokenId);
288 const balanceAfterBob = await getTokenBalance(api, fungibleCollectionId, normalizeAccountId(bob), newFungibleTokenId);
289
290 expect((balanceBeforeAlice)).to.be.equal(balanceAfterAlice);
291 expect((balanceBeforeBob)).to.be.equal(balanceAfterBob);
292 });
293 });
294});