git.delta.rocks / unique-network / refs/commits / 9b1ad2d3650d

difftreelog

Confirm sponsorship tests in progress

Greg Zaitsev2020-12-23parents: #474b3ae #c3c0503.patch.diff
in: master

3 files changed

modifiedtests/src/confirmSponsorship.test.tsdiffbeforeafterboth
13 setCollectionSponsorExpectFailure,13 setCollectionSponsorExpectFailure,
14 confirmSponsorshipExpectSuccess,14 confirmSponsorshipExpectSuccess,
15 confirmSponsorshipExpectFailure,15 confirmSponsorshipExpectFailure,
16 createItemExpectSuccess,
17 findUnusedAddress,
18 getGenericResult,
16} from "./util/helpers";19} from "./util/helpers";
17import { Keyring } from "@polkadot/api";20import { Keyring } from "@polkadot/api";
18import { IKeyringPair } from "@polkadot/types/types";21import { IKeyringPair } from "@polkadot/types/types";
19import type { AccountId } from '@polkadot/types/interfaces';22import type { AccountId } from '@polkadot/types/interfaces';
23import { BigNumber } from 'bignumber.js';
2024
21chai.use(chaiAsPromised);25chai.use(chaiAsPromised);
22const expect = chai.expect;26const expect = chai.expect;
30 before(async () => {34 before(async () => {
31 await usingApi(async (api) => {35 await usingApi(async (api) => {
32 const keyring = new Keyring({ type: 'sr25519' });36 const keyring = new Keyring({ type: 'sr25519' });
37 alice = keyring.addFromUri(`//Alice`);
33 bob = keyring.addFromUri(`//Bob`);38 bob = keyring.addFromUri(`//Bob`);
34 charlie = keyring.addFromUri(`//Charlie`);39 charlie = keyring.addFromUri(`//Charlie`);
35 });40 });
53 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);58 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);
54 });59 });
5560
56 it.skip('Transfer fees are paid by the sponsor after confirmation', async () => {61 it.only('Transfer fees are paid by the sponsor after confirmation', async () => {
57 // const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');62 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
58 // await setCollectionSponsorExpectSuccess(collectionId, bob.address);63 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
59 // await confirmSponsorshipExpectSuccess(collectionId, '//Bob');64 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
65 const itemId = await createItemExpectSuccess(collectionId, 'NFT', '//Alice');
66
67 await usingApi(async (api) => {
68 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).toString());
69
70 // Find unused address
71 const zeroBalance = await findUnusedAddress(api);
72
73 const aliceToZero = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 0);
74 await submitTransactionAsync(alice, aliceToZero);
75
76 const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 0);
77 const events = await submitTransactionAsync(zeroBalance, zeroToAlice);
78 const result = getGenericResult(events);
79
80 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).toString());
81
60 expect(false).to.be.true;82 expect(result.success).to.be.true;
83 expect(BsponsorBalance.toNumber()).to.be.lessThan(AsponsorBalance.toNumber());
84 });
85
61 });86 });
6287
addedtests/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');
+  });
+});
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -26,6 +26,12 @@
   collectionId: number
 };
 
+type CreateItemResult = {
+  success: boolean,
+  collectionId: number,
+  itemId: number
+};
+
 export function getGenericResult(events: EventRecord[]): GenericResult {
   let result: GenericResult = {
     success: false
@@ -57,6 +63,27 @@
   return result;
 }
 
+function getCreateItemResult(events: EventRecord[]): CreateItemResult {
+  let success = false;
+  let collectionId: number = 0;
+  let itemId: number = 0;
+  events.forEach(({ phase, event: { data, method, section } }) => {
+    // console.log(`    ${phase}: ${section}.${method}:: ${data}`);
+    if (method == 'ExtrinsicSuccess') {
+      success = true;
+    } else if ((section == 'nft') && (method == 'ItemCreated')) {
+      collectionId = parseInt(data[0].toString());
+      itemId = parseInt(data[1].toString());
+    }
+  });
+  let result: CreateItemResult = {
+    success,
+    collectionId,
+    itemId
+  }
+  return result;
+}
+
 export async function createCollectionExpectSuccess(name: string, description: string, tokenPrefix: string, mode: string): Promise<number> {
   let collectionId: number = 0;
   await usingApi(async (api) => {
@@ -231,3 +258,24 @@
   });
 }
 
+export async function createItemExpectSuccess(collectionId: number, createMode: string, senderSeed: string = '//Alice') {
+  let newItemId: number = 0;
+  await usingApi(async (api) => {
+    const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString());
+
+    const sender = privateKey(senderSeed);
+    const tx = api.tx.nft.createItem(collectionId, sender.address, createMode);
+    const events = await submitTransactionAsync(sender, tx);
+    const result = getCreateItemResult(events);
+  
+    const BItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString());
+
+    // What to expect
+    expect(result.success).to.be.true;
+    expect(BItemCount).to.be.equal(AItemCount+1);
+    expect(collectionId).to.be.equal(result.collectionId);
+    expect(BItemCount).to.be.equal(result.itemId);
+    newItemId = result.itemId;
+  });
+  return newItemId;
+}