git.delta.rocks / unique-network / refs/commits / f16723a5aa89

difftreelog

Merge pull request #51 from usetech-llc/feature/NFTPAR-246_remove_sponsor_tests

str-mv2020-12-25parents: #cd29302 #bd903ea.patch.diff
in: master
NFTPAR-246 remove sponsor tests

3 files changed

modifiedtests/src/confirmSponsorship.test.tsdiffbeforeafterboth
--- a/tests/src/confirmSponsorship.test.ts
+++ b/tests/src/confirmSponsorship.test.ts
@@ -32,7 +32,7 @@
 let bob: IKeyringPair;
 let charlie: IKeyringPair;
 
-describe.only('integration test: ext. confirmSponsorship():', () => {
+describe('integration test: ext. confirmSponsorship():', () => {
 
   before(async () => {
     await usingApi(async (api) => {
@@ -299,7 +299,7 @@
 
 });
 
-describe.only('(!negative test!) integration test: ext. setCollectionSponsor():', () => {
+describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {
   before(async () => {
     await usingApi(async (api) => {
       const keyring = new Keyring({ type: 'sr25519' });
addedtests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth
after · tests/src/removeCollectionSponsor.test.ts
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  removeCollectionSponsorExpectSuccess,23  removeCollectionSponsorExpectFailure,24} from "./util/helpers";25import { Keyring } from "@polkadot/api";26import { IKeyringPair } from "@polkadot/types/types";27import type { AccountId } from '@polkadot/types/interfaces';28import { BigNumber } from 'bignumber.js';2930chai.use(chaiAsPromised);31const expect = chai.expect;3233let alice: IKeyringPair;34let bob: IKeyringPair;35let charlie: IKeyringPair;3637describe('integration test: ext. removeCollectionSponsor():', () => {3839  before(async () => {40    await usingApi(async (api) => {41      const keyring = new Keyring({ type: 'sr25519' });42      alice = keyring.addFromUri(`//Alice`);43      bob = keyring.addFromUri(`//Bob`);44      charlie = keyring.addFromUri(`//Charlie`);45    });46  });4748  it('Remove NFT collection sponsor stops sponsorship', async () => {49    const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');50    await setCollectionSponsorExpectSuccess(collectionId, bob.address);51    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');52    await removeCollectionSponsorExpectSuccess(collectionId);5354    await usingApi(async (api) => {55      // Find unused address56      const zeroBalance = await findUnusedAddress(api);5758      // Mint token for unused address59      const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);6061      // Transfer this tokens from unused address to Alice - should fail62      const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());63      const zeroToAlice = api.tx.nft.transfer(alice.address, collectionId, itemId, 0);64      const badTransaction = async function () { 65        console.log = function () {};66        console.error = function () {};67        await submitTransactionAsync(zeroBalance, zeroToAlice);68        delete console.log;69        delete console.error;70      };71      await expect(badTransaction()).to.be.rejectedWith("Inability to pay some fees");72      const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());7374      expect(BsponsorBalance.isEqualTo(AsponsorBalance)).to.be.true;75    });76  });7778  it('Remove a sponsor after it was already removed', async () => {79    const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');80    await setCollectionSponsorExpectSuccess(collectionId, bob.address);81    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');82    await removeCollectionSponsorExpectSuccess(collectionId);83    await removeCollectionSponsorExpectSuccess(collectionId);84  });8586  it('Remove sponsor in a collection that never had the sponsor set', async () => {87    const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');88    await removeCollectionSponsorExpectSuccess(collectionId);89  });9091  it('Remove sponsor for a collection that had the sponsor set, but not confirmed', async () => {92    const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');93    await setCollectionSponsorExpectSuccess(collectionId, bob.address);94    await removeCollectionSponsorExpectSuccess(collectionId);95  });9697});9899describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {100  before(async () => {101    await usingApi(async (api) => {102      const keyring = new Keyring({ type: 'sr25519' });103      alice = keyring.addFromUri(`//Alice`);104      bob = keyring.addFromUri(`//Bob`);105      charlie = keyring.addFromUri(`//Charlie`);106    });107  });108109  it('(!negative test!) Remove sponsor for a collection that never existed', async () => {110    // Find the collection that never existed111    const collectionId = 0;112    await usingApi(async (api) => {113      const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;114    });115116    await removeCollectionSponsorExpectFailure(collectionId);117  });118119  it('(!negative test!) Remove sponsor in a destroyed collection', async () => {120    const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');121    await setCollectionSponsorExpectSuccess(collectionId, bob.address);122    await destroyCollectionExpectSuccess(collectionId);123    await removeCollectionSponsorExpectFailure(collectionId);124  });125126  it('Set - remove - confirm: fails', async () => {127    const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');128    await setCollectionSponsorExpectSuccess(collectionId, bob.address);129    await removeCollectionSponsorExpectSuccess(collectionId);130    await confirmSponsorshipExpectFailure(collectionId, '//Bob');131  });132133  it('Set - confirm - remove - confirm: Sponsor cannot come back', async () => {134    const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');135    await setCollectionSponsorExpectSuccess(collectionId, bob.address);136    await confirmSponsorshipExpectSuccess(collectionId, '//Bob');137    await removeCollectionSponsorExpectSuccess(collectionId);138    await confirmSponsorshipExpectFailure(collectionId, '//Bob');139  });140141});
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -213,6 +213,39 @@
   });
 }
 
+export async function removeCollectionSponsorExpectSuccess(collectionId: number) {
+  await usingApi(async (api) => {
+
+    // Run the transaction
+    const alicePrivateKey = privateKey('//Alice');
+    const tx = api.tx.nft.removeCollectionSponsor(collectionId);
+    const events = await submitTransactionAsync(alicePrivateKey, 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.Sponsor).to.be.equal(nullPublicKey);
+    expect(collection.SponsorConfirmed).to.be.false;
+  });
+}
+
+export async function removeCollectionSponsorExpectFailure(collectionId: number) {
+  await usingApi(async (api) => {
+
+    // Run the transaction
+    const alicePrivateKey = privateKey('//Alice');
+    const tx = api.tx.nft.removeCollectionSponsor(collectionId);
+    const events = await submitTransactionAsync(alicePrivateKey, tx);
+    const result = getGenericResult(events);
+
+    // What to expect
+    expect(result.success).to.be.false;
+  });
+}
+
 export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string, senderSeed: string = '//Alice') {
   await usingApi(async (api) => {