difftreelog
Confirm sponsorship tests in progress
in: master
4 files changed
tests/src/confirmSponsorship.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/confirmSponsorship.test.ts
@@ -0,0 +1,120 @@
+//
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE', which is part of this source code package.
+//
+
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import { default as usingApi, submitTransactionAsync } from "./substrate/substrate-api";
+import {
+ createCollectionExpectSuccess,
+ setCollectionSponsorExpectSuccess,
+ destroyCollectionExpectSuccess,
+ setCollectionSponsorExpectFailure,
+ confirmSponsorshipExpectSuccess,
+ confirmSponsorshipExpectFailure,
+} from "./util/helpers";
+import { Keyring } from "@polkadot/api";
+import { IKeyringPair } from "@polkadot/types/types";
+import type { AccountId } from '@polkadot/types/interfaces';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+let alice: IKeyringPair;
+let bob: IKeyringPair;
+let charlie: IKeyringPair;
+
+describe('integration test: ext. confirmSponsorship():', () => {
+
+ before(async () => {
+ await usingApi(async (api) => {
+ const keyring = new Keyring({ type: 'sr25519' });
+ bob = keyring.addFromUri(`//Bob`);
+ charlie = keyring.addFromUri(`//Charlie`);
+ });
+ });
+
+ it('Confirm collection sponsorship', async () => {
+ const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ await setCollectionSponsorExpectSuccess(collectionId, bob.address);
+ await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
+ });
+ it('Add sponsor to a collection after the same sponsor was already added and confirmed', async () => {
+ const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ await setCollectionSponsorExpectSuccess(collectionId, bob.address);
+ await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
+ await setCollectionSponsorExpectSuccess(collectionId, bob.address);
+ });
+ it('Add new sponsor to a collection after another sponsor was already added and confirmed', async () => {
+ const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ await setCollectionSponsorExpectSuccess(collectionId, bob.address);
+ await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
+ await setCollectionSponsorExpectSuccess(collectionId, charlie.address);
+ });
+
+ it.skip('Transfer 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');
+ expect(false).to.be.true;
+ });
+
+ it.skip('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');
+ expect(false).to.be.true;
+ });
+
+});
+
+describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {
+ before(async () => {
+ await usingApi(async (api) => {
+ const keyring = new Keyring({ type: 'sr25519' });
+ alice = keyring.addFromUri(`//Alice`);
+ bob = keyring.addFromUri(`//Bob`);
+ charlie = keyring.addFromUri(`//Charlie`);
+ });
+ });
+
+ it('(!negative test!) Confirm sponsorship for a collection that never existed', async () => {
+ // Find the collection that never existed
+ const collectionId = 0;
+ await usingApi(async (api) => {
+ const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;
+ });
+
+ await confirmSponsorshipExpectFailure(collectionId, '//Bob');
+ });
+
+ it('(!negative test!) Confirm sponsorship using a non-sponsor address', async () => {
+ const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ await setCollectionSponsorExpectSuccess(collectionId, bob.address);
+
+ await usingApi(async (api) => {
+ const transfer = api.tx.balances.transfer(charlie.address, 1e15);
+ await submitTransactionAsync(alice, transfer);
+ });
+
+ await confirmSponsorshipExpectFailure(collectionId, '//Charlie');
+ });
+
+ it('(!negative test!) Confirm sponsorship using owner address', async () => {
+ const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ await setCollectionSponsorExpectSuccess(collectionId, bob.address);
+ await confirmSponsorshipExpectFailure(collectionId, '//Alice');
+ });
+
+ it('(!negative test!) Confirm sponsorship without sponsor being set with setCollectionSponsor', async () => {
+ const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ await confirmSponsorshipExpectFailure(collectionId, '//Bob');
+ });
+
+ it('(!negative test!) Confirm sponsorship in a collection that was destroyed', async () => {
+ const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ await destroyCollectionExpectSuccess(collectionId);
+ await confirmSponsorshipExpectFailure(collectionId, '//Bob');
+ });
+});
tests/src/createMultipleItems.test.tsdiffbeforeafterboth--- a/tests/src/createMultipleItems.test.ts
+++ b/tests/src/createMultipleItems.test.ts
@@ -11,7 +11,7 @@
const idCollection = 12;
-describe('integration test: ext. createMultipleItems():', () => {
+describe.skip('integration test: ext. createMultipleItems():', () => {
it('Create two NFT tokens in active NFT collection', async () => {
await usingApi(async (api) => {
const AitemListIndex = await api.query.nft.itemListIndex(idCollection);
tests/src/setCollectionSponsor.test.tsdiffbeforeafterboth--- a/tests/src/setCollectionSponsor.test.ts
+++ b/tests/src/setCollectionSponsor.test.ts
@@ -61,6 +61,10 @@
});
});
+ it('(!negative test!) Add sponsor with a non-owner', async () => {
+ const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
+ await setCollectionSponsorExpectFailure(collectionId, bob.address, '//Bob');
+ });
it('(!negative test!) Add sponsor to a collection that never existed', async () => {
// Find the collection that never existed
const collectionId = 0;
tests/src/util/helpers.tsdiffbeforeafterboth134 return success;134 return success;135}135}136137export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string) {138 await usingApi(async (api) => {139140 // Run the transaction141 const alicePrivateKey = privateKey('//Alice');142 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);143 const events = await submitTransactionAsync(alicePrivateKey, tx);144 const result = getGenericResult(events);145146 // Get the collection 147 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();148149 // What to expect150 expect(result.success).to.be.true;151 expect(collection.Sponsor.toString()).to.be.equal(sponsor.toString());152 expect(collection.SponsorConfirmed).to.be.false;153 });154}155136156export async function destroyCollectionExpectFailure(collectionId: number, senderSeed: string = '//Alice') {137export async function destroyCollectionExpectFailure(collectionId: number, senderSeed: string = '//Alice') {157 await usingApi(async (api) => {138 await usingApi(async (api) => {184 });165 });185}166}167168export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string) {169 await usingApi(async (api) => {170171 // Run the transaction172 const alicePrivateKey = privateKey('//Alice');173 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);174 const events = await submitTransactionAsync(alicePrivateKey, tx);175 const result = getGenericResult(events);176177 // Get the collection 178 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();179180 // What to expect181 expect(result.success).to.be.true;182 expect(collection.Sponsor.toString()).to.be.equal(sponsor.toString());183 expect(collection.SponsorConfirmed).to.be.false;184 });185}186186187export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string) {187export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string, senderSeed: string = '//Alice') {188 await usingApi(async (api) => {188 await usingApi(async (api) => {189189190 // Run the transaction190 // Run the transaction191 const alicePrivateKey = privateKey('//Alice');191 const alicePrivateKey = privateKey(senderSeed);192 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);192 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);193 const events = await submitTransactionAsync(alicePrivateKey, tx);193 const events = await submitTransactionAsync(alicePrivateKey, tx);194 const result = getGenericResult(events);194 const result = getGenericResult(events);198 });198 });199}199}200201export async function confirmSponsorshipExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {202 await usingApi(async (api) => {203204 // Run the transaction205 const sender = privateKey(senderSeed);206 const tx = api.tx.nft.confirmSponsorship(collectionId);207 const events = await submitTransactionAsync(sender, tx);208 const result = getGenericResult(events);209210 // Get the collection 211 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();212213 // What to expect214 expect(result.success).to.be.true;215 expect(collection.Sponsor).to.be.equal(sender.address);216 expect(collection.SponsorConfirmed).to.be.true;217 });218}219220export async function confirmSponsorshipExpectFailure(collectionId: number, senderSeed: string = '//Alice') {221 await usingApi(async (api) => {222223 // Run the transaction224 const sender = privateKey(senderSeed);225 const tx = api.tx.nft.confirmSponsorship(collectionId);226 const events = await submitTransactionAsync(sender, tx);227 const result = getGenericResult(events);228229 // What to expect230 expect(result.success).to.be.false;231 });232}200233234