difftreelog
Add test for public minti sponsoring
in: master
3 files changed
tests/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' });
tests/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);
});
});
tests/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