difftreelog
Confirm sponsorship tests in progress
in: master
4 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} from "./util/helpers";17import { Keyring } from "@polkadot/api";18import { IKeyringPair } from "@polkadot/types/types";19import type { AccountId } from '@polkadot/types/interfaces';2021chai.use(chaiAsPromised);22const expect = chai.expect;2324let alice: IKeyringPair;25let bob: IKeyringPair;26let charlie: IKeyringPair;2728describe('integration test: ext. confirmSponsorship():', () => {2930 before(async () => {31 await usingApi(async (api) => {32 const keyring = new Keyring({ type: 'sr25519' });33 bob = keyring.addFromUri(`//Bob`);34 charlie = keyring.addFromUri(`//Charlie`);35 });36 });3738 it('Confirm collection sponsorship', async () => {39 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');40 await setCollectionSponsorExpectSuccess(collectionId, bob.address);41 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');42 });43 it('Add sponsor to a collection after the same sponsor was already added and confirmed', async () => {44 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');45 await setCollectionSponsorExpectSuccess(collectionId, bob.address);46 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');47 await setCollectionSponsorExpectSuccess(collectionId, bob.address);48 });49 it('Add new sponsor to a collection after another 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, charlie.address);54 });5556 it.skip('Transfer fees are paid by the sponsor after confirmation', async () => {57 // const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');58 // await setCollectionSponsorExpectSuccess(collectionId, bob.address);59 // await confirmSponsorshipExpectSuccess(collectionId, '//Bob');60 expect(false).to.be.true;61 });6263 it.skip('CreateItem fees are paid by the sponsor after confirmation', async () => {64 // const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');65 // await setCollectionSponsorExpectSuccess(collectionId, bob.address);66 // await confirmSponsorshipExpectSuccess(collectionId, '//Bob');67 expect(false).to.be.true;68 });6970});7172describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {73 before(async () => {74 await usingApi(async (api) => {75 const keyring = new Keyring({ type: 'sr25519' });76 alice = keyring.addFromUri(`//Alice`);77 bob = keyring.addFromUri(`//Bob`);78 charlie = keyring.addFromUri(`//Charlie`);79 });80 });8182 it('(!negative test!) Confirm sponsorship for a collection that never existed', async () => {83 // Find the collection that never existed84 const collectionId = 0;85 await usingApi(async (api) => {86 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;87 });8889 await confirmSponsorshipExpectFailure(collectionId, '//Bob');90 });9192 it('(!negative test!) Confirm sponsorship using a non-sponsor address', async () => {93 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');94 await setCollectionSponsorExpectSuccess(collectionId, bob.address);9596 await usingApi(async (api) => {97 const transfer = api.tx.balances.transfer(charlie.address, 1e15);98 await submitTransactionAsync(alice, transfer);99 });100101 await confirmSponsorshipExpectFailure(collectionId, '//Charlie');102 });103104 it('(!negative test!) Confirm sponsorship using owner address', async () => {105 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');106 await setCollectionSponsorExpectSuccess(collectionId, bob.address);107 await confirmSponsorshipExpectFailure(collectionId, '//Alice');108 });109110 it('(!negative test!) Confirm sponsorship without sponsor being set with setCollectionSponsor', async () => {111 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');112 await confirmSponsorshipExpectFailure(collectionId, '//Bob');113 });114 115 it('(!negative test!) Confirm sponsorship in a collection that was destroyed', async () => {116 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');117 await destroyCollectionExpectSuccess(collectionId);118 await confirmSponsorshipExpectFailure(collectionId, '//Bob');119 });120});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.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -134,6 +134,37 @@
return success;
}
+export async function destroyCollectionExpectFailure(collectionId: number, senderSeed: string = '//Alice') {
+ await usingApi(async (api) => {
+ // Run the DestroyCollection transaction
+ const alicePrivateKey = privateKey(senderSeed);
+ const tx = api.tx.nft.destroyCollection(collectionId);
+ const events = await submitTransactionAsync(alicePrivateKey, tx);
+ const result = getDestroyResult(events);
+
+ // What to expect
+ expect(result).to.be.false;
+ });
+}
+
+export async function destroyCollectionExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {
+ await usingApi(async (api) => {
+ // Run the DestroyCollection transaction
+ const alicePrivateKey = privateKey(senderSeed);
+ const tx = api.tx.nft.destroyCollection(collectionId);
+ const events = await submitTransactionAsync(alicePrivateKey, tx);
+ const result = getDestroyResult(events);
+
+ // Get the collection
+ const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
+
+ // What to expect
+ expect(result).to.be.true;
+ expect(collection).to.be.not.null;
+ expect(collection.Owner).to.be.equal(nullPublicKey);
+ });
+}
+
export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string) {
await usingApi(async (api) => {
@@ -153,47 +184,50 @@
});
}
-export async function destroyCollectionExpectFailure(collectionId: number, senderSeed: string = '//Alice') {
+export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string, senderSeed: string = '//Alice') {
await usingApi(async (api) => {
- // Run the DestroyCollection transaction
+
+ // Run the transaction
const alicePrivateKey = privateKey(senderSeed);
- const tx = api.tx.nft.destroyCollection(collectionId);
+ const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);
const events = await submitTransactionAsync(alicePrivateKey, tx);
- const result = getDestroyResult(events);
+ const result = getGenericResult(events);
// What to expect
- expect(result).to.be.false;
+ expect(result.success).to.be.false;
});
}
-export async function destroyCollectionExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {
+export async function confirmSponsorshipExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {
await usingApi(async (api) => {
- // Run the DestroyCollection transaction
- const alicePrivateKey = privateKey(senderSeed);
- const tx = api.tx.nft.destroyCollection(collectionId);
- const events = await submitTransactionAsync(alicePrivateKey, tx);
- const result = getDestroyResult(events);
+ // Run the transaction
+ const sender = privateKey(senderSeed);
+ const tx = api.tx.nft.confirmSponsorship(collectionId);
+ 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).to.be.true;
- expect(collection).to.be.not.null;
- expect(collection.Owner).to.be.equal(nullPublicKey);
+ expect(result.success).to.be.true;
+ expect(collection.Sponsor).to.be.equal(sender.address);
+ expect(collection.SponsorConfirmed).to.be.true;
});
}
-export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string) {
+export async function confirmSponsorshipExpectFailure(collectionId: number, senderSeed: string = '//Alice') {
await usingApi(async (api) => {
// Run the transaction
- const alicePrivateKey = privateKey('//Alice');
- const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);
- const events = await submitTransactionAsync(alicePrivateKey, tx);
+ const sender = privateKey(senderSeed);
+ const tx = api.tx.nft.confirmSponsorship(collectionId);
+ const events = await submitTransactionAsync(sender, tx);
const result = getGenericResult(events);
// What to expect
expect(result.success).to.be.false;
});
}
+