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

difftreelog

Add test for public minti sponsoring

Greg Zaitsev2020-12-25parent: #f4dfc50.patch.diff
in: master

3 files changed

modifiedtests/src/confirmSponsorship.test.tsdiffbeforeafterboth
--- a/tests/src/confirmSponsorship.test.ts
+++ b/tests/src/confirmSponsorship.test.ts
@@ -17,6 +17,8 @@
   findUnusedAddress,
   getGenericResult,
   enableWhiteListExpectSuccess,
+  enablePublicMintingExpectSuccess,
+  addToWhiteListExpectSuccess,
 } from "./util/helpers";
 import { Keyring } from "@polkadot/api";
 import { IKeyringPair } from "@polkadot/types/types";
@@ -30,7 +32,7 @@
 let bob: IKeyringPair;
 let charlie: IKeyringPair;
 
-describe('integration test: ext. confirmSponsorship():', () => {
+describe.only('integration test: ext. confirmSponsorship():', () => {
 
   before(async () => {
     await usingApi(async (api) => {
@@ -71,7 +73,7 @@
       const zeroBalance = await findUnusedAddress(api);
 
       // Mint token for unused address
-      const itemId = await createItemExpectSuccess(collectionId, 'NFT', zeroBalance.address, '//Alice');
+      const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);
 
       // Transfer this tokens from unused address to Alice
       const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 0);
@@ -98,7 +100,7 @@
       const zeroBalance = await findUnusedAddress(api);
 
       // Mint token for unused address
-      const itemId = await createItemExpectSuccess(collectionId, 'Fungible', zeroBalance.address, '//Alice');
+      const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', zeroBalance.address);
 
       // Transfer this tokens from unused address to Alice
       const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 1);
@@ -124,7 +126,7 @@
       const zeroBalance = await findUnusedAddress(api);
 
       // Mint token for unused address
-      const itemId = await createItemExpectSuccess(collectionId, 'ReFungible', zeroBalance.address, '//Alice');
+      const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', zeroBalance.address);
 
       // Transfer this tokens from unused address to Alice
       const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 1);
@@ -138,20 +140,34 @@
     });
   });
 
-  it.only('CreateItem fees are paid by the sponsor after confirmation', async () => {
+  it('CreateItem 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');
 
     // Enable collection white list 
-    await enableWhiteListExpectSuccess(collectionId);
+    await enableWhiteListExpectSuccess(alice, collectionId);
 
     // Enable public minting
+    await enablePublicMintingExpectSuccess(alice, collectionId);
+
+    // Create Item 
+    await usingApi(async (api) => {
+      const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
 
-    // Create Item
+      // Find unused address
+      const zeroBalance = await findUnusedAddress(api);
+
+      // Add zeroBalance address to white list
+      await addToWhiteListExpectSuccess(alice, collectionId, zeroBalance.address);
 
+      // Mint token using unused address as signer
+      const tokenId = await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);
 
+      const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
 
+      expect(BsponsorBalance.lt(AsponsorBalance)).to.be.true;
+    });
   });
 
   it('NFT: Sponsoring is rate limited', async () => {
@@ -164,7 +180,7 @@
       const zeroBalance = await findUnusedAddress(api);
 
       // Mint token for alice
-      const itemId = await createItemExpectSuccess(collectionId, 'NFT', alice.address, '//Alice');
+      const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
 
       // Transfer this token from Alice to unused address and back
       // Alice to Zero gets sponsored
@@ -207,7 +223,7 @@
       const zeroBalance = await findUnusedAddress(api);
 
       // Mint token for unused address
-      const itemId = await createItemExpectSuccess(collectionId, 'Fungible', zeroBalance.address, '//Alice');
+      const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', zeroBalance.address);
 
       // Transfer this tokens in parts from unused address to Alice
       const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 1);
@@ -248,7 +264,7 @@
       const zeroBalance = await findUnusedAddress(api);
 
       // Mint token for alice
-      const itemId = await createItemExpectSuccess(collectionId, 'ReFungible', alice.address, '//Alice');
+      const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', alice.address);
 
       // Transfer this token from Alice to unused address and back
       // Alice to Zero gets sponsored
@@ -283,7 +299,7 @@
 
 });
 
-describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {
+describe.only('(!negative test!) integration test: ext. setCollectionSponsor():', () => {
   before(async () => {
     await usingApi(async (api) => {
       const keyring = new Keyring({ type: 'sr25519' });
modifiedtests/src/createItem.test.tsdiffbeforeafterboth
1import { assert } from 'chai';
2import { alicesPublicKey } from './accounts';
3import privateKey from './substrate/privateKey';
4import { default as usingApi } from './substrate/substrate-api'; 1import { default as usingApi } from './substrate/substrate-api';
2import { Keyring } from "@polkadot/api";
5import waitNewBlocks from './substrate/wait-new-blocks'; 3import { IKeyringPair } from "@polkadot/types/types";
6import { 4import {
7 createCollectionExpectSuccess, 5 createCollectionExpectSuccess,
8 createItemExpectSuccess 6 createItemExpectSuccess
9} from './util/helpers'; 7} from './util/helpers';
10 8
9let alice: IKeyringPair;
10
11describe('integration test: ext. createItem():', () => { 11describe('integration test: ext. createItem():', () => {
12 before(async () => {
13 await usingApi(async (api) => {
14 const keyring = new Keyring({ type: 'sr25519' });
15 alice = keyring.addFromUri(`//Alice`);
16 });
17 });
18
12 it('Create new item in NFT collection', async () => { 19 it('Create new item in NFT collection', async () => {
13 const createMode = 'NFT'; 20 const createMode = 'NFT';
14 const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode); 21 const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
15 await createItemExpectSuccess(newCollectionID, createMode); 22 await createItemExpectSuccess(alice, newCollectionID, createMode);
16 }); 23 });
17 it('Create new item in Fungible collection', async () => { 24 it('Create new item in Fungible collection', async () => {
18 const createMode = 'Fungible'; 25 const createMode = 'Fungible';
19 const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode); 26 const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
20 await createItemExpectSuccess(newCollectionID, createMode); 27 await createItemExpectSuccess(alice, newCollectionID, createMode);
21 }); 28 });
22 it('Create new item in ReFungible collection', async () => { 29 it('Create new item in ReFungible collection', async () => {
23 const createMode = 'ReFungible'; 30 const createMode = 'ReFungible';
24 const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode); 31 const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
25 await createItemExpectSuccess(newCollectionID, createMode); 32 await createItemExpectSuccess(alice, newCollectionID, createMode);
26 }); 33 });
27}); 34});
2835
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -273,14 +273,13 @@
   ReFungible: CreateReFungibleData
 };
 
-export async function createItemExpectSuccess(collectionId: number, createMode: string, owner: string = '', senderSeed: string = '//Alice') {
+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());
     const Aitem: any = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON();    
     const AItemBalance = new BigNumber(Aitem.Value);
 
-    const sender = privateKey(senderSeed);
     if (owner === '') owner = sender.address;
 
     let tx;
@@ -313,11 +312,10 @@
   return newItemId;
 }
 
-export async function enableWhiteListExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {
+export async function enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {
   await usingApi(async (api) => {
 
     // Run the transaction
-    const sender = privateKey(senderSeed);
     const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
     const events = await submitTransactionAsync(sender, tx);
     const result = getGenericResult(events);
@@ -330,3 +328,38 @@
     expect(collection.Access).to.be.equal('WhiteList');
   });
 }
+
+export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {
+  await usingApi(async (api) => {
+
+    // Run the transaction
+    const tx = api.tx.nft.setMintPermission(collectionId, true);
+    const events = await submitTransactionAsync(sender, tx);
+    const result = getGenericResult(events);
+
+    // Get the collection 
+    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
+
+    // What to expect
+    expect(result.success).to.be.true;
+    expect(collection.MintMode).to.be.equal(true);
+  });
+}
+
+export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {
+  await usingApi(async (api) => {
+
+    // Run the transaction
+    const tx = api.tx.nft.addToWhiteList(collectionId, address);
+    const events = await submitTransactionAsync(sender, tx);
+    const result = getGenericResult(events);
+
+    // Get the collection 
+    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
+
+    // What to expect
+    expect(result.success).to.be.true;
+    expect(collection.MintMode).to.be.equal(true);
+  });
+}
+