difftreelog
Add test for public minti sponsoring
in: master
3 files changed
tests/src/confirmSponsorship.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import { default as usingApi, submitTransactionAsync } from "./substrate/substrate-api";9import { 10 createCollectionExpectSuccess, 11 setCollectionSponsorExpectSuccess, 12 destroyCollectionExpectSuccess, 13 setCollectionSponsorExpectFailure,14 confirmSponsorshipExpectSuccess,15 confirmSponsorshipExpectFailure,16 createItemExpectSuccess,17 findUnusedAddress,18 getGenericResult,19 enableWhiteListExpectSuccess,20} from "./util/helpers";21import { Keyring } from "@polkadot/api";22import { IKeyringPair } from "@polkadot/types/types";23import type { AccountId } from '@polkadot/types/interfaces';24import { BigNumber } from 'bignumber.js';2526chai.use(chaiAsPromised);27const expect = chai.expect;2829let alice: IKeyringPair;30let bob: IKeyringPair;31let charlie: IKeyringPair;3233describe('integration test: ext. confirmSponsorship():', () => {3435 before(async () => {36 await usingApi(async (api) => {37 const keyring = new Keyring({ type: 'sr25519' });38 alice = keyring.addFromUri(`//Alice`);39 bob = keyring.addFromUri(`//Bob`);40 charlie = keyring.addFromUri(`//Charlie`);41 });42 });4344 it('Confirm collection sponsorship', async () => {45 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');46 await setCollectionSponsorExpectSuccess(collectionId, bob.address);47 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');48 });49 it('Add sponsor to a collection after the same sponsor was already added and confirmed', async () => {50 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');51 await setCollectionSponsorExpectSuccess(collectionId, bob.address);52 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');53 await setCollectionSponsorExpectSuccess(collectionId, bob.address);54 });55 it('Add new sponsor to a collection after another sponsor was already added and confirmed', async () => {56 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');57 await setCollectionSponsorExpectSuccess(collectionId, bob.address);58 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');59 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);60 });6162 it('NFT: Transfer fees are paid by the sponsor after confirmation', async () => {63 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');64 await setCollectionSponsorExpectSuccess(collectionId, bob.address);65 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');6667 await usingApi(async (api) => {68 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());6970 // Find unused address71 const zeroBalance = await findUnusedAddress(api);7273 // Mint token for unused address74 const itemId = await createItemExpectSuccess(collectionId, 'NFT', zeroBalance.address, '//Alice');7576 // Transfer this tokens from unused address to Alice77 const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 0);78 const events = await submitTransactionAsync(zeroBalance, zeroToAlice);79 const result = getGenericResult(events);8081 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());8283 expect(result.success).to.be.true;84 expect(BsponsorBalance.lt(AsponsorBalance)).to.be.true;85 });8687 });8889 it('Fungible: Transfer fees are paid by the sponsor after confirmation', async () => {90 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'Fungible');91 await setCollectionSponsorExpectSuccess(collectionId, bob.address);92 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');9394 await usingApi(async (api) => {95 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());9697 // Find unused address98 const zeroBalance = await findUnusedAddress(api);99100 // Mint token for unused address101 const itemId = await createItemExpectSuccess(collectionId, 'Fungible', zeroBalance.address, '//Alice');102103 // Transfer this tokens from unused address to Alice104 const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 1);105 const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);106 const result1 = getGenericResult(events1);107108 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());109110 expect(result1.success).to.be.true;111 expect(BsponsorBalance.lt(AsponsorBalance)).to.be.true;112 });113 });114115 it('ReFungible: Transfer fees are paid by the sponsor after confirmation', async () => {116 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'ReFungible');117 await setCollectionSponsorExpectSuccess(collectionId, bob.address);118 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');119120 await usingApi(async (api) => {121 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());122123 // Find unused address124 const zeroBalance = await findUnusedAddress(api);125126 // Mint token for unused address127 const itemId = await createItemExpectSuccess(collectionId, 'ReFungible', zeroBalance.address, '//Alice');128129 // Transfer this tokens from unused address to Alice130 const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 1);131 const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);132 const result1 = getGenericResult(events1);133134 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());135136 expect(result1.success).to.be.true;137 expect(BsponsorBalance.lt(AsponsorBalance)).to.be.true;138 });139 });140141 it.only('CreateItem fees are paid by the sponsor after confirmation', async () => {142 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');143 await setCollectionSponsorExpectSuccess(collectionId, bob.address);144 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');145146 // Enable collection white list 147 await enableWhiteListExpectSuccess(collectionId);148149 // Enable public minting150151 // Create Item152153154155 });156157 it('NFT: Sponsoring is rate limited', async () => {158 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');159 await setCollectionSponsorExpectSuccess(collectionId, bob.address);160 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');161162 await usingApi(async (api) => {163 // Find unused address164 const zeroBalance = await findUnusedAddress(api);165166 // Mint token for alice167 const itemId = await createItemExpectSuccess(collectionId, 'NFT', alice.address, '//Alice');168169 // Transfer this token from Alice to unused address and back170 // Alice to Zero gets sponsored171 const aliceToZero = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 0);172 const events1 = await submitTransactionAsync(alice, aliceToZero);173 const result1 = getGenericResult(events1);174175 // Second transfer should fail176 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());177 const zeroToAlice = api.tx.nft.transfer(alice.address, collectionId, itemId, 0);178 const badTransaction = async function () { 179 console.log = function () {};180 console.error = function () {};181 await submitTransactionAsync(zeroBalance, zeroToAlice);182 delete console.log;183 delete console.error;184 };185 await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");186 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());187188 // Try again after Zero gets some balance - now it should succeed189 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);190 await submitTransactionAsync(alice, balancetx);191 const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);192 const result2 = getGenericResult(events2);193194 expect(result1.success).to.be.true;195 expect(result2.success).to.be.true;196 expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;197 });198 });199200 it('Fungible: Sponsoring is rate limited', async () => {201 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'Fungible');202 await setCollectionSponsorExpectSuccess(collectionId, bob.address);203 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');204205 await usingApi(async (api) => {206 // Find unused address207 const zeroBalance = await findUnusedAddress(api);208209 // Mint token for unused address210 const itemId = await createItemExpectSuccess(collectionId, 'Fungible', zeroBalance.address, '//Alice');211212 // Transfer this tokens in parts from unused address to Alice213 const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 1);214 const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);215 const result1 = getGenericResult(events1);216217 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());218219 const badTransaction = async function () { 220 console.log = function () {};221 console.error = function () {};222 await submitTransactionAsync(zeroBalance, zeroToAlice);223 delete console.log;224 delete console.error;225 };226227 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());228229 // Try again after Zero gets some balance - now it should succeed230 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);231 await submitTransactionAsync(alice, balancetx);232 const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);233 const result2 = getGenericResult(events2);234235 expect(result1.success).to.be.true;236 expect(result2.success).to.be.true;237 expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;238 });239 });240241 it('ReFungible: Sponsoring is rate limited', async () => {242 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'ReFungible');243 await setCollectionSponsorExpectSuccess(collectionId, bob.address);244 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');245246 await usingApi(async (api) => {247 // Find unused address248 const zeroBalance = await findUnusedAddress(api);249250 // Mint token for alice251 const itemId = await createItemExpectSuccess(collectionId, 'ReFungible', alice.address, '//Alice');252253 // Transfer this token from Alice to unused address and back254 // Alice to Zero gets sponsored255 const aliceToZero = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 1);256 const events1 = await submitTransactionAsync(alice, aliceToZero);257 const result1 = getGenericResult(events1);258259 // Second transfer should fail260 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());261 const zeroToAlice = api.tx.nft.transfer(alice.address, collectionId, itemId, 1);262 const badTransaction = async function () { 263 console.log = function () {};264 console.error = function () {};265 await submitTransactionAsync(zeroBalance, zeroToAlice);266 delete console.log;267 delete console.error;268 };269 await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");270 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());271272 // Try again after Zero gets some balance - now it should succeed273 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);274 await submitTransactionAsync(alice, balancetx);275 const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);276 const result2 = getGenericResult(events2);277278 expect(result1.success).to.be.true;279 expect(result2.success).to.be.true;280 expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;281 });282 });283284});285286describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {287 before(async () => {288 await usingApi(async (api) => {289 const keyring = new Keyring({ type: 'sr25519' });290 alice = keyring.addFromUri(`//Alice`);291 bob = keyring.addFromUri(`//Bob`);292 charlie = keyring.addFromUri(`//Charlie`);293 });294 });295296 it('(!negative test!) Confirm sponsorship for a collection that never existed', async () => {297 // Find the collection that never existed298 const collectionId = 0;299 await usingApi(async (api) => {300 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;301 });302303 await confirmSponsorshipExpectFailure(collectionId, '//Bob');304 });305306 it('(!negative test!) Confirm sponsorship using a non-sponsor address', async () => {307 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');308 await setCollectionSponsorExpectSuccess(collectionId, bob.address);309310 await usingApi(async (api) => {311 const transfer = api.tx.balances.transfer(charlie.address, 1e15);312 await submitTransactionAsync(alice, transfer);313 });314315 await confirmSponsorshipExpectFailure(collectionId, '//Charlie');316 });317318 it('(!negative test!) Confirm sponsorship using owner address', async () => {319 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');320 await setCollectionSponsorExpectSuccess(collectionId, bob.address);321 await confirmSponsorshipExpectFailure(collectionId, '//Alice');322 });323324 it('(!negative test!) Confirm sponsorship without sponsor being set with setCollectionSponsor', async () => {325 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');326 await confirmSponsorshipExpectFailure(collectionId, '//Bob');327 });328 329 it('(!negative test!) Confirm sponsorship in a collection that was destroyed', async () => {330 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');331 await destroyCollectionExpectSuccess(collectionId);332 await confirmSponsorshipExpectFailure(collectionId, '//Bob');333 });334});1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import { default as usingApi, submitTransactionAsync } from "./substrate/substrate-api";9import { 10 createCollectionExpectSuccess, 11 setCollectionSponsorExpectSuccess, 12 destroyCollectionExpectSuccess, 13 setCollectionSponsorExpectFailure,14 confirmSponsorshipExpectSuccess,15 confirmSponsorshipExpectFailure,16 createItemExpectSuccess,17 findUnusedAddress,18 getGenericResult,19 enableWhiteListExpectSuccess,20 enablePublicMintingExpectSuccess,21 addToWhiteListExpectSuccess,22} from "./util/helpers";23import { Keyring } from "@polkadot/api";24import { IKeyringPair } from "@polkadot/types/types";25import type { AccountId } from '@polkadot/types/interfaces';26import { BigNumber } from 'bignumber.js';2728chai.use(chaiAsPromised);29const expect = chai.expect;3031let alice: IKeyringPair;32let bob: IKeyringPair;33let charlie: IKeyringPair;3435describe.only('integration test: ext. confirmSponsorship():', () => {3637 before(async () => {38 await usingApi(async (api) => {39 const keyring = new Keyring({ type: 'sr25519' });40 alice = keyring.addFromUri(`//Alice`);41 bob = keyring.addFromUri(`//Bob`);42 charlie = keyring.addFromUri(`//Charlie`);43 });44 });4546 it('Confirm collection sponsorship', async () => {47 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');48 await setCollectionSponsorExpectSuccess(collectionId, bob.address);49 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');50 });51 it('Add sponsor to a collection after the same sponsor was already added and confirmed', async () => {52 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');53 await setCollectionSponsorExpectSuccess(collectionId, bob.address);54 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');55 await setCollectionSponsorExpectSuccess(collectionId, bob.address);56 });57 it('Add new sponsor to a collection after another sponsor was already added and confirmed', async () => {58 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');59 await setCollectionSponsorExpectSuccess(collectionId, bob.address);60 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');61 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);62 });6364 it('NFT: Transfer fees are paid by the sponsor after confirmation', async () => {65 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');66 await setCollectionSponsorExpectSuccess(collectionId, bob.address);67 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');6869 await usingApi(async (api) => {70 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());7172 // Find unused address73 const zeroBalance = await findUnusedAddress(api);7475 // Mint token for unused address76 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);7778 // Transfer this tokens from unused address to Alice79 const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 0);80 const events = await submitTransactionAsync(zeroBalance, zeroToAlice);81 const result = getGenericResult(events);8283 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());8485 expect(result.success).to.be.true;86 expect(BsponsorBalance.lt(AsponsorBalance)).to.be.true;87 });8889 });9091 it('Fungible: Transfer fees are paid by the sponsor after confirmation', async () => {92 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'Fungible');93 await setCollectionSponsorExpectSuccess(collectionId, bob.address);94 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');9596 await usingApi(async (api) => {97 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());9899 // Find unused address100 const zeroBalance = await findUnusedAddress(api);101102 // Mint token for unused address103 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', zeroBalance.address);104105 // Transfer this tokens from unused address to Alice106 const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 1);107 const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);108 const result1 = getGenericResult(events1);109110 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());111112 expect(result1.success).to.be.true;113 expect(BsponsorBalance.lt(AsponsorBalance)).to.be.true;114 });115 });116117 it('ReFungible: Transfer fees are paid by the sponsor after confirmation', async () => {118 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'ReFungible');119 await setCollectionSponsorExpectSuccess(collectionId, bob.address);120 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');121122 await usingApi(async (api) => {123 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());124125 // Find unused address126 const zeroBalance = await findUnusedAddress(api);127128 // Mint token for unused address129 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', zeroBalance.address);130131 // Transfer this tokens from unused address to Alice132 const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 1);133 const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);134 const result1 = getGenericResult(events1);135136 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());137138 expect(result1.success).to.be.true;139 expect(BsponsorBalance.lt(AsponsorBalance)).to.be.true;140 });141 });142143 it('CreateItem fees are paid by the sponsor after confirmation', async () => {144 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');145 await setCollectionSponsorExpectSuccess(collectionId, bob.address);146 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');147148 // Enable collection white list 149 await enableWhiteListExpectSuccess(alice, collectionId);150151 // Enable public minting152 await enablePublicMintingExpectSuccess(alice, collectionId);153154 // Create Item 155 await usingApi(async (api) => {156 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());157158 // 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 });171 });172173 it('NFT: Sponsoring is rate limited', async () => {174 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');175 await setCollectionSponsorExpectSuccess(collectionId, bob.address);176 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');177178 await usingApi(async (api) => {179 // Find unused address180 const zeroBalance = await findUnusedAddress(api);181182 // Mint token for alice183 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);184185 // Transfer this token from Alice to unused address and back186 // Alice to Zero gets sponsored187 const aliceToZero = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 0);188 const events1 = await submitTransactionAsync(alice, aliceToZero);189 const result1 = getGenericResult(events1);190191 // Second transfer should fail192 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());193 const zeroToAlice = api.tx.nft.transfer(alice.address, collectionId, itemId, 0);194 const badTransaction = async function () { 195 console.log = function () {};196 console.error = function () {};197 await submitTransactionAsync(zeroBalance, zeroToAlice);198 delete console.log;199 delete console.error;200 };201 await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");202 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());203204 // Try again after Zero gets some balance - now it should succeed205 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);206 await submitTransactionAsync(alice, balancetx);207 const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);208 const result2 = getGenericResult(events2);209210 expect(result1.success).to.be.true;211 expect(result2.success).to.be.true;212 expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;213 });214 });215216 it('Fungible: Sponsoring is rate limited', async () => {217 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'Fungible');218 await setCollectionSponsorExpectSuccess(collectionId, bob.address);219 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');220221 await usingApi(async (api) => {222 // Find unused address223 const zeroBalance = await findUnusedAddress(api);224225 // Mint token for unused address226 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', zeroBalance.address);227228 // Transfer this tokens in parts from unused address to Alice229 const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 1);230 const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);231 const result1 = getGenericResult(events1);232233 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());234235 const badTransaction = async function () { 236 console.log = function () {};237 console.error = function () {};238 await submitTransactionAsync(zeroBalance, zeroToAlice);239 delete console.log;240 delete console.error;241 };242243 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());244245 // Try again after Zero gets some balance - now it should succeed246 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);247 await submitTransactionAsync(alice, balancetx);248 const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);249 const result2 = getGenericResult(events2);250251 expect(result1.success).to.be.true;252 expect(result2.success).to.be.true;253 expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;254 });255 });256257 it('ReFungible: Sponsoring is rate limited', async () => {258 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'ReFungible');259 await setCollectionSponsorExpectSuccess(collectionId, bob.address);260 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');261262 await usingApi(async (api) => {263 // Find unused address264 const zeroBalance = await findUnusedAddress(api);265266 // Mint token for alice267 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', alice.address);268269 // Transfer this token from Alice to unused address and back270 // Alice to Zero gets sponsored271 const aliceToZero = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 1);272 const events1 = await submitTransactionAsync(alice, aliceToZero);273 const result1 = getGenericResult(events1);274275 // Second transfer should fail276 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());277 const zeroToAlice = api.tx.nft.transfer(alice.address, collectionId, itemId, 1);278 const badTransaction = async function () { 279 console.log = function () {};280 console.error = function () {};281 await submitTransactionAsync(zeroBalance, zeroToAlice);282 delete console.log;283 delete console.error;284 };285 await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");286 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());287288 // Try again after Zero gets some balance - now it should succeed289 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1e15);290 await submitTransactionAsync(alice, balancetx);291 const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);292 const result2 = getGenericResult(events2);293294 expect(result1.success).to.be.true;295 expect(result2.success).to.be.true;296 expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;297 });298 });299300});301302describe.only('(!negative test!) integration test: ext. setCollectionSponsor():', () => {303 before(async () => {304 await usingApi(async (api) => {305 const keyring = new Keyring({ type: 'sr25519' });306 alice = keyring.addFromUri(`//Alice`);307 bob = keyring.addFromUri(`//Bob`);308 charlie = keyring.addFromUri(`//Charlie`);309 });310 });311312 it('(!negative test!) Confirm sponsorship for a collection that never existed', async () => {313 // Find the collection that never existed314 const collectionId = 0;315 await usingApi(async (api) => {316 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;317 });318319 await confirmSponsorshipExpectFailure(collectionId, '//Bob');320 });321322 it('(!negative test!) Confirm sponsorship using a non-sponsor address', async () => {323 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');324 await setCollectionSponsorExpectSuccess(collectionId, bob.address);325326 await usingApi(async (api) => {327 const transfer = api.tx.balances.transfer(charlie.address, 1e15);328 await submitTransactionAsync(alice, transfer);329 });330331 await confirmSponsorshipExpectFailure(collectionId, '//Charlie');332 });333334 it('(!negative test!) Confirm sponsorship using owner address', async () => {335 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');336 await setCollectionSponsorExpectSuccess(collectionId, bob.address);337 await confirmSponsorshipExpectFailure(collectionId, '//Alice');338 });339340 it('(!negative test!) Confirm sponsorship without sponsor being set with setCollectionSponsor', async () => {341 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');342 await confirmSponsorshipExpectFailure(collectionId, '//Bob');343 });344 345 it('(!negative test!) Confirm sponsorship in a collection that was destroyed', async () => {346 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');347 await destroyCollectionExpectSuccess(collectionId);348 await confirmSponsorshipExpectFailure(collectionId, '//Bob');349 });350});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.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);
+ });
+}
+