--- 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' }); --- 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); }); }); --- 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); + }); +} +