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
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
273 ReFungible: CreateReFungibleData273 ReFungible: CreateReFungibleData
274};274};
275275
276export async function createItemExpectSuccess(collectionId: number, createMode: string, owner: string = '', senderSeed: string = '//Alice') {276export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: string = '') {
277 let newItemId: number = 0;277 let newItemId: number = 0;
278 await usingApi(async (api) => {278 await usingApi(async (api) => {
279 const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString());279 const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString());
280 const Aitem: any = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON(); 280 const Aitem: any = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON();
281 const AItemBalance = new BigNumber(Aitem.Value);281 const AItemBalance = new BigNumber(Aitem.Value);
282282
283 const sender = privateKey(senderSeed);
284 if (owner === '') owner = sender.address;283 if (owner === '') owner = sender.address;
285284
286 let tx;285 let tx;
313 return newItemId;312 return newItemId;
314}313}
315314
316export async function enableWhiteListExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {315export async function enableWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number) {
317 await usingApi(async (api) => {316 await usingApi(async (api) => {
318317
319 // Run the transaction318 // Run the transaction
320 const sender = privateKey(senderSeed);
321 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');319 const tx = api.tx.nft.setPublicAccessMode(collectionId, 'WhiteList');
322 const events = await submitTransactionAsync(sender, tx);320 const events = await submitTransactionAsync(sender, tx);
323 const result = getGenericResult(events);321 const result = getGenericResult(events);
331 });329 });
332}330}
331
332export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {
333 await usingApi(async (api) => {
334
335 // Run the transaction
336 const tx = api.tx.nft.setMintPermission(collectionId, true);
337 const events = await submitTransactionAsync(sender, tx);
338 const result = getGenericResult(events);
339
340 // Get the collection
341 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
342
343 // What to expect
344 expect(result.success).to.be.true;
345 expect(collection.MintMode).to.be.equal(true);
346 });
347}
348
349export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {
350 await usingApi(async (api) => {
351
352 // Run the transaction
353 const tx = api.tx.nft.addToWhiteList(collectionId, address);
354 const events = await submitTransactionAsync(sender, tx);
355 const result = getGenericResult(events);
356
357 // Get the collection
358 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
359
360 // What to expect
361 expect(result.success).to.be.true;
362 expect(collection.MintMode).to.be.equal(true);
363 });
364}
333365
366