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
17 findUnusedAddress,17 findUnusedAddress,
18 getGenericResult,18 getGenericResult,
19 enableWhiteListExpectSuccess,19 enableWhiteListExpectSuccess,
20 enablePublicMintingExpectSuccess,
21 addToWhiteListExpectSuccess,
20} from "./util/helpers";22} from "./util/helpers";
21import { Keyring } from "@polkadot/api";23import { Keyring } from "@polkadot/api";
22import { IKeyringPair } from "@polkadot/types/types";24import { IKeyringPair } from "@polkadot/types/types";
30let bob: IKeyringPair;32let bob: IKeyringPair;
31let charlie: IKeyringPair;33let charlie: IKeyringPair;
3234
33describe('integration test: ext. confirmSponsorship():', () => {35describe.only('integration test: ext. confirmSponsorship():', () => {
3436
35 before(async () => {37 before(async () => {
36 await usingApi(async (api) => {38 await usingApi(async (api) => {
71 const zeroBalance = await findUnusedAddress(api);73 const zeroBalance = await findUnusedAddress(api);
7274
73 // Mint token for unused address75 // Mint token for unused address
74 const itemId = await createItemExpectSuccess(collectionId, 'NFT', zeroBalance.address, '//Alice');76 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);
7577
76 // Transfer this tokens from unused address to Alice78 // Transfer this tokens from unused address to Alice
77 const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 0);79 const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 0);
98 const zeroBalance = await findUnusedAddress(api);100 const zeroBalance = await findUnusedAddress(api);
99101
100 // Mint token for unused address102 // Mint token for unused address
101 const itemId = await createItemExpectSuccess(collectionId, 'Fungible', zeroBalance.address, '//Alice');103 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', zeroBalance.address);
102104
103 // Transfer this tokens from unused address to Alice105 // Transfer this tokens from unused address to Alice
104 const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 1);106 const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 1);
124 const zeroBalance = await findUnusedAddress(api);126 const zeroBalance = await findUnusedAddress(api);
125127
126 // Mint token for unused address128 // Mint token for unused address
127 const itemId = await createItemExpectSuccess(collectionId, 'ReFungible', zeroBalance.address, '//Alice');129 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', zeroBalance.address);
128130
129 // Transfer this tokens from unused address to Alice131 // Transfer this tokens from unused address to Alice
130 const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 1);132 const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 1);
138 });140 });
139 });141 });
140142
141 it.only('CreateItem fees are paid by the sponsor after confirmation', async () => {143 it('CreateItem fees are paid by the sponsor after confirmation', async () => {
142 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');144 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
143 await setCollectionSponsorExpectSuccess(collectionId, bob.address);145 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
144 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');146 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
145147
146 // Enable collection white list 148 // Enable collection white list
147 await enableWhiteListExpectSuccess(collectionId);149 await enableWhiteListExpectSuccess(alice, collectionId);
148150
149 // Enable public minting151 // Enable public minting
152 await enablePublicMintingExpectSuccess(alice, collectionId);
150153
151 // Create Item154 // Create Item
152155 await usingApi(async (api) => {
153156 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
154157
158 // Find unused address
159 const zeroBalance = await findUnusedAddress(api);
160
161 // Add zeroBalance address to white list
162 await addToWhiteListExpectSuccess(alice, collectionId, zeroBalance.address);
163
164 // Mint token using unused address as signer
165 const tokenId = await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);
166
167 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
168
169 expect(BsponsorBalance.lt(AsponsorBalance)).to.be.true;
170 });
155 });171 });
156172
157 it('NFT: Sponsoring is rate limited', async () => {173 it('NFT: Sponsoring is rate limited', async () => {
164 const zeroBalance = await findUnusedAddress(api);180 const zeroBalance = await findUnusedAddress(api);
165181
166 // Mint token for alice182 // Mint token for alice
167 const itemId = await createItemExpectSuccess(collectionId, 'NFT', alice.address, '//Alice');183 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
168184
169 // Transfer this token from Alice to unused address and back185 // Transfer this token from Alice to unused address and back
170 // Alice to Zero gets sponsored186 // Alice to Zero gets sponsored
207 const zeroBalance = await findUnusedAddress(api);223 const zeroBalance = await findUnusedAddress(api);
208224
209 // Mint token for unused address225 // Mint token for unused address
210 const itemId = await createItemExpectSuccess(collectionId, 'Fungible', zeroBalance.address, '//Alice');226 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', zeroBalance.address);
211227
212 // Transfer this tokens in parts from unused address to Alice228 // Transfer this tokens in parts from unused address to Alice
213 const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 1);229 const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 1);
248 const zeroBalance = await findUnusedAddress(api);264 const zeroBalance = await findUnusedAddress(api);
249265
250 // Mint token for alice266 // Mint token for alice
251 const itemId = await createItemExpectSuccess(collectionId, 'ReFungible', alice.address, '//Alice');267 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', alice.address);
252268
253 // Transfer this token from Alice to unused address and back269 // Transfer this token from Alice to unused address and back
254 // Alice to Zero gets sponsored270 // Alice to Zero gets sponsored
283299
284});300});
285301
286describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {302describe.only('(!negative test!) integration test: ext. setCollectionSponsor():', () => {
287 before(async () => {303 before(async () => {
288 await usingApi(async (api) => {304 await usingApi(async (api) => {
289 const keyring = new Keyring({ type: 'sr25519' });305 const keyring = new Keyring({ type: 'sr25519' });
modifiedtests/src/createItem.test.tsdiffbeforeafterboth
--- a/tests/src/createItem.test.ts
+++ b/tests/src/createItem.test.ts
@@ -1,27 +1,34 @@
-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 { Keyring } from "@polkadot/api";
+import { IKeyringPair } from "@polkadot/types/types";
 import { 
   createCollectionExpectSuccess, 
   createItemExpectSuccess
 } from './util/helpers';
 
+let alice: IKeyringPair;
+
 describe('integration test: ext. createItem():', () => {
+  before(async () => {
+    await usingApi(async (api) => {
+      const keyring = new Keyring({ type: 'sr25519' });
+      alice = keyring.addFromUri(`//Alice`);
+    });
+  });
+
   it('Create new item in NFT collection', async () => {
     const createMode = 'NFT';
     const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
-    await createItemExpectSuccess(newCollectionID, createMode);
+    await createItemExpectSuccess(alice, newCollectionID, createMode);
   });
   it('Create new item in Fungible collection', async () => {
     const createMode = 'Fungible';
     const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
-    await createItemExpectSuccess(newCollectionID, createMode);
+    await createItemExpectSuccess(alice, newCollectionID, createMode);
   });
   it('Create new item in ReFungible collection', async () => {
     const createMode = 'ReFungible';
     const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
-    await createItemExpectSuccess(newCollectionID, createMode);
+    await createItemExpectSuccess(alice, newCollectionID, createMode);
   });
 });
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);
+  });
+}
+