difftreelog
Add test for public minti sponsoring
in: master
3 files changed
tests/src/confirmSponsorship.test.tsdiffbeforeafterboth17 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;323433describe('integration test: ext. confirmSponsorship():', () => {35describe.only('integration test: ext. confirmSponsorship():', () => {343635 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);727473 // Mint token for unused address75 // Mint token for unused address74 const itemId = await createItemExpectSuccess(collectionId, 'NFT', zeroBalance.address, '//Alice');76 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);757776 // Transfer this tokens from unused address to Alice78 // Transfer this tokens from unused address to Alice77 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);99101100 // Mint token for unused address102 // Mint token for unused address101 const itemId = await createItemExpectSuccess(collectionId, 'Fungible', zeroBalance.address, '//Alice');103 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', zeroBalance.address);102104103 // Transfer this tokens from unused address to Alice105 // Transfer this tokens from unused address to Alice104 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);125127126 // Mint token for unused address128 // Mint token for unused address127 const itemId = await createItemExpectSuccess(collectionId, 'ReFungible', zeroBalance.address, '//Alice');129 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', zeroBalance.address);128130129 // Transfer this tokens from unused address to Alice131 // Transfer this tokens from unused address to Alice130 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 });140142141 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');145147146 // Enable collection white list 148 // Enable collection white list 147 await enableWhiteListExpectSuccess(collectionId);149 await enableWhiteListExpectSuccess(alice, collectionId);148150149 // Enable public minting151 // Enable public minting152 await enablePublicMintingExpectSuccess(alice, collectionId);150153151 // Create Item154 // Create Item 152155 await usingApi(async (api) => {153156 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());154157158 // Find unused address159 const zeroBalance = await findUnusedAddress(api);160161 // Add zeroBalance address to white list162 await addToWhiteListExpectSuccess(alice, collectionId, zeroBalance.address);163164 // Mint token using unused address as signer165 const tokenId = await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);166167 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());168169 expect(BsponsorBalance.lt(AsponsorBalance)).to.be.true;170 });155 });171 });156172157 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);165181166 // Mint token for alice182 // Mint token for alice167 const itemId = await createItemExpectSuccess(collectionId, 'NFT', alice.address, '//Alice');183 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);168184169 // Transfer this token from Alice to unused address and back185 // Transfer this token from Alice to unused address and back170 // Alice to Zero gets sponsored186 // Alice to Zero gets sponsored207 const zeroBalance = await findUnusedAddress(api);223 const zeroBalance = await findUnusedAddress(api);208224209 // Mint token for unused address225 // Mint token for unused address210 const itemId = await createItemExpectSuccess(collectionId, 'Fungible', zeroBalance.address, '//Alice');226 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', zeroBalance.address);211227212 // Transfer this tokens in parts from unused address to Alice228 // Transfer this tokens in parts from unused address to Alice213 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);249265250 // Mint token for alice266 // Mint token for alice251 const itemId = await createItemExpectSuccess(collectionId, 'ReFungible', alice.address, '//Alice');267 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', alice.address);252268253 // Transfer this token from Alice to unused address and back269 // Transfer this token from Alice to unused address and back254 // Alice to Zero gets sponsored270 // Alice to Zero gets sponsored283299284});300});285301286describe('(!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' });tests/src/createItem.test.tsdiffbeforeafterboth1import { 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});
2835tests/src/util/helpers.tsdiffbeforeafterboth273 ReFungible: CreateReFungibleData273 ReFungible: CreateReFungibleData274};274};275275276export 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);282282283 const sender = privateKey(senderSeed);284 if (owner === '') owner = sender.address;283 if (owner === '') owner = sender.address;285284286 let tx;285 let tx;313 return newItemId;312 return newItemId;314}313}315314316export 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) => {318317319 // Run the transaction318 // Run the transaction320 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}331332export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {333 await usingApi(async (api) => {334335 // Run the transaction336 const tx = api.tx.nft.setMintPermission(collectionId, true);337 const events = await submitTransactionAsync(sender, tx);338 const result = getGenericResult(events);339340 // Get the collection 341 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();342343 // What to expect344 expect(result.success).to.be.true;345 expect(collection.MintMode).to.be.equal(true);346 });347}348349export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {350 await usingApi(async (api) => {351352 // Run the transaction353 const tx = api.tx.nft.addToWhiteList(collectionId, address);354 const events = await submitTransactionAsync(sender, tx);355 const result = getGenericResult(events);356357 // Get the collection 358 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();359360 // What to expect361 expect(result.success).to.be.true;362 expect(collection.MintMode).to.be.equal(true);363 });364}333365366