difftreelog
Confirm sponsorship tests in progress
in: master
3 files changed
tests/src/confirmSponsorship.test.tsdiffbeforeafterboth--- a/tests/src/confirmSponsorship.test.ts
+++ b/tests/src/confirmSponsorship.test.ts
@@ -13,10 +13,14 @@
setCollectionSponsorExpectFailure,
confirmSponsorshipExpectSuccess,
confirmSponsorshipExpectFailure,
+ createItemExpectSuccess,
+ findUnusedAddress,
+ getGenericResult,
} from "./util/helpers";
import { Keyring } from "@polkadot/api";
import { IKeyringPair } from "@polkadot/types/types";
import type { AccountId } from '@polkadot/types/interfaces';
+import { BigNumber } from 'bignumber.js';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -30,6 +34,7 @@
before(async () => {
await usingApi(async (api) => {
const keyring = new Keyring({ type: 'sr25519' });
+ alice = keyring.addFromUri(`//Alice`);
bob = keyring.addFromUri(`//Bob`);
charlie = keyring.addFromUri(`//Charlie`);
});
@@ -53,11 +58,31 @@
await setCollectionSponsorExpectSuccess(collectionId, charlie.address);
});
- it.skip('Transfer fees are paid by the sponsor after confirmation', async () => {
- // const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
- // await setCollectionSponsorExpectSuccess(collectionId, bob.address);
- // await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
- expect(false).to.be.true;
+ it.only('Transfer fees are paid by the sponsor after confirmation', async () => {
+ const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ await setCollectionSponsorExpectSuccess(collectionId, bob.address);
+ await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
+ const itemId = await createItemExpectSuccess(collectionId, 'NFT', '//Alice');
+
+ await usingApi(async (api) => {
+ const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).toString());
+
+ // Find unused address
+ const zeroBalance = await findUnusedAddress(api);
+
+ const aliceToZero = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 0);
+ await submitTransactionAsync(alice, aliceToZero);
+
+ const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 0);
+ const events = await submitTransactionAsync(zeroBalance, zeroToAlice);
+ const result = getGenericResult(events);
+
+ const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).toString());
+
+ expect(result.success).to.be.true;
+ expect(BsponsorBalance.toNumber()).to.be.lessThan(AsponsorBalance.toNumber());
+ });
+
});
it.skip('CreateItem fees are paid by the sponsor after confirmation', async () => {
tests/src/createItem.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/createItem.test.ts
@@ -0,0 +1,27 @@
+import { assert } from 'chai';
+import { alicesPublicKey } from './accounts';
+import privateKey from './substrate/privateKey';
+import { default as usingApi } from './substrate/substrate-api';
+import waitNewBlocks from './substrate/wait-new-blocks';
+import {
+ createCollectionExpectSuccess,
+ createItemExpectSuccess
+} from './util/helpers';
+
+describe('integration test: ext. createItem():', () => {
+ it('Create new item in NFT collection', async () => {
+ const createMode = 'NFT';
+ const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
+ await createItemExpectSuccess(newCollectionID, createMode, '//Alice');
+ });
+ it('Create new item in Fungible collection', async () => {
+ const createMode = 'Fungible';
+ const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
+ await createItemExpectSuccess(newCollectionID, createMode, '//Alice');
+ });
+ it('Create new item in ReFungible collection', async () => {
+ const createMode = 'ReFungible';
+ const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
+ await createItemExpectSuccess(newCollectionID, createMode, '//Alice');
+ });
+});
tests/src/util/helpers.tsdiffbeforeafterboth26 collectionId: number26 collectionId: number27};27};2829type CreateItemResult = {30 success: boolean,31 collectionId: number,32 itemId: number33};283429export function getGenericResult(events: EventRecord[]): GenericResult {35export function getGenericResult(events: EventRecord[]): GenericResult {30 let result: GenericResult = {36 let result: GenericResult = {57 return result;63 return result;58}64}6566function getCreateItemResult(events: EventRecord[]): CreateItemResult {67 let success = false;68 let collectionId: number = 0;69 let itemId: number = 0;70 events.forEach(({ phase, event: { data, method, section } }) => {71 // console.log(` ${phase}: ${section}.${method}:: ${data}`);72 if (method == 'ExtrinsicSuccess') {73 success = true;74 } else if ((section == 'nft') && (method == 'ItemCreated')) {75 collectionId = parseInt(data[0].toString());76 itemId = parseInt(data[1].toString());77 }78 });79 let result: CreateItemResult = {80 success,81 collectionId,82 itemId83 }84 return result;85}598660export async function createCollectionExpectSuccess(name: string, description: string, tokenPrefix: string, mode: string): Promise<number> {87export async function createCollectionExpectSuccess(name: string, description: string, tokenPrefix: string, mode: string): Promise<number> {61 let collectionId: number = 0;88 let collectionId: number = 0;231 });258 });232}259}260261export async function createItemExpectSuccess(collectionId: number, createMode: string, senderSeed: string = '//Alice') {262 let newItemId: number = 0;263 await usingApi(async (api) => {264 const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString());265266 const sender = privateKey(senderSeed);267 const tx = api.tx.nft.createItem(collectionId, sender.address, createMode);268 const events = await submitTransactionAsync(sender, tx);269 const result = getCreateItemResult(events);270 271 const BItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString());272273 // What to expect274 expect(result.success).to.be.true;275 expect(BItemCount).to.be.equal(AItemCount+1);276 expect(collectionId).to.be.equal(result.collectionId);277 expect(BItemCount).to.be.equal(result.itemId);278 newItemId = result.itemId;279 });280 return newItemId;281}233282234