difftreelog
transferSuccess
in: master
3 files changed
tests/src/burnItem.test.tsdiffbeforeafterboth--- a/tests/src/burnItem.test.ts
+++ b/tests/src/burnItem.test.ts
@@ -35,16 +35,16 @@
const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
const events = await submitTransactionAsync(alice, tx);
const result = getGenericResult(events);
-
- // Get the item
+ // Get the item
const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();
-
// What to expect
+ // tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
+ // tslint:disable-next-line:no-unused-expression
expect(item).to.be.not.null;
expect(item.Owner).to.be.equal(nullPublicKey);
});
-
+
});
it('Burn item in Fungible collection', async () => {
const createMode = 'Fungible';
tests/src/transfer.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import { ApiPromise } from '@polkadot/api';7import { expect } from 'chai';8import { alicesPublicKey, bobsPublicKey } from './accounts';9import getBalance from './substrate/get-balance';10import privateKey from './substrate/privateKey';11import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';12import {13 approveExpectSuccess,14 createCollectionExpectSuccess, createItemExpectSuccess,15 findUnusedAddress,16 getCreateCollectionResult,17 getCreateItemResult,18 transferExpectSuccess,19} from './util/helpers';2021describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {22 it('Balance transfers and check balance', async () => {23 await usingApi(async (api: ApiPromise) => {24 const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);2526 const alicePrivateKey = privateKey('//Alice');2728 const transfer = api.tx.balances.transfer(bobsPublicKey, 1n);29 const events = await submitTransactionAsync(alicePrivateKey, transfer);30 const result = getCreateItemResult(events);31 // tslint:disable-next-line:no-unused-expression32 expect(result.success).to.be.true;3334 const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);3536 // tslint:disable-next-line:no-unused-expression37 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;38 // tslint:disable-next-line:no-unused-expression39 expect(bobsBalanceAfter > bobsBalanceBefore).to.be.true;40 });41 });4243 it('Inability to pay fees error message is correct', async () => {44 await usingApi(async (api) => {45 // Find unused address46 const pk = await findUnusedAddress(api);4748 const badTransfer = api.tx.balances.transfer(bobsPublicKey, 1n);49 // const events = await submitTransactionAsync(pk, badTransfer);50 const badTransaction = async () => {51 const events = await submitTransactionAsync(pk, badTransfer);52 const result = getCreateCollectionResult(events);53 // tslint:disable-next-line:no-unused-expression54 expect(result.success).to.be.false;55 };56 expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees , e.g. account balance too low');57 });58 });5960 it('Create collection, balance transfers and check balance', async () => {61 const Alice = privateKey('//Alice');62 const Bob = privateKey('//Bob');63 const Charlie = privateKey('//CHARLIE');64 // nft65 const nftCollectionId = await createCollectionExpectSuccess();66 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');6768 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');6970 // fungible71 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});72 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');73 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);74 await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');75 // reFungible76 const reFungibleCollectionId = await77 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});78 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');79 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);80 await transferExpectSuccess(reFungibleCollectionId,81 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');82 });83});8485describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {86 it('Transfer with not existed collection_id', async () => {8788 });89 it('Transfer with deleted collection_id', async () => {9091 });92 it('Transfer with not existed item_id', async () => {9394 });95 it('Transfer with deleted item_id', async () => {9697 });98 it('Transfer with recipient that is not owner', async () => {99100 });101});tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -391,6 +391,22 @@
ReFungible: CreateReFungibleData;
}
+export async function burnItemExpectSuccess(owner: IKeyringPair, collectionId: number, tokenId: number, value = 0) {
+ await usingApi(async (api) => {
+ const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+ const events = await submitTransactionAsync(owner, tx);
+ const result = getGenericResult(events);
+ // Get the item
+ const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();
+ // What to expect
+ // tslint:disable-next-line:no-unused-expression
+ expect(result.success).to.be.true;
+ // tslint:disable-next-line:no-unused-expression
+ expect(item).to.be.not.null;
+ expect(item.Owner).to.be.equal(nullPublicKey);
+ });
+}
+
export async function
approveExpectSuccess(collectionId: number,
tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) {
@@ -496,6 +512,22 @@
}
export async function
+transferExpectFail(collectionId: number,
+ tokenId: number,
+ sender: IKeyringPair,
+ recipient: IKeyringPair,
+ value: number = 1,
+ type: string = 'NFT') {
+ await usingApi(async (api: ApiPromise) => {
+ const transferTx = await api.tx.nft.transfer(recipient.address, collectionId, tokenId, value);
+ const events = await expect(submitTransactionExpectFailAsync(sender, transferTx)).to.be.rejected;
+ const result = getCreateCollectionResult(events);
+ // tslint:disable-next-line:no-unused-expression
+ expect(result.success).to.be.false;
+ });
+}
+
+export async function
approveExpectFail(collectionId: number,
tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) {
await usingApi(async (api: ApiPromise) => {
@@ -507,7 +539,8 @@
});
}
-export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: string = '') {
+export async function createItemExpectSuccess(
+ sender: IKeyringPair, collectionId: number, createMode: string, owner: string = '') {
let newItemId: number = 0;
await usingApi(async (api) => {
const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);
@@ -559,6 +592,7 @@
const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
// What to expect
+ // tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
expect(collection.Access).to.be.equal('WhiteList');
});