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

difftreelog

Merge pull request #46 from usetech-llc/feature/NFTPAR-242_destroy_collection_test

str-mv2020-12-22parents: #73f8e68 #f682871.patch.diff
in: master
NFTPAR-242 Add destroy collection integration tests

4 files changed

modifiednode/src/chain_spec.rsdiffbeforeafterboth
--- a/node/src/chain_spec.rs
+++ b/node/src/chain_spec.rs
@@ -45,7 +45,7 @@
 	let mut properties = Map::new();
 	properties.insert("tokenSymbol".into(), "UniqueTest".into());
 	properties.insert("tokenDecimals".into(), 15.into());
-	properties.insert("ss58Format".into(), 0.into());
+	properties.insert("ss58Format".into(), 42.into()); // Generic Substrate wildcard (SS58 checksum preimage)
 
 	Ok(ChainSpec::from_genesis(
 		// Name
modifiedtests/src/accounts.tsdiffbeforeafterboth
--- a/tests/src/accounts.ts
+++ b/tests/src/accounts.ts
@@ -1,3 +1,4 @@
 export const bobsPublicKey = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty';
 export const alicesPublicKey = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
 export const ferdiesPublicKey = '5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL';
+export const nullPublicKey = '5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM';
\ No newline at end of file
addedtests/src/destroyCollection.test.tsdiffbeforeafterboth
after · tests/src/destroyCollection.test.ts
1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';3import { default as usingApi, submitTransactionAsync } from "./substrate/substrate-api";4import { createCollectionExpectSuccess, createCollectionExpectFailure } from "./util/helpers";5import type { AccountId, EventRecord } from '@polkadot/types/interfaces';6import privateKey from './substrate/privateKey';7import { nullPublicKey } from './accounts'; 89chai.use(chaiAsPromised);10const expect = chai.expect;1112function getDestroyResult(events: EventRecord[]): boolean {13  let success: boolean = false;14  events.forEach(({ phase, event: { data, method, section } }) => {15    // console.log(`    ${phase}: ${section}.${method}:: ${data}`);16    if (method == 'ExtrinsicSuccess') {17      success = true;18    }19  });20  return success;21}2223async function destroyCollectionExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {24  await usingApi(async (api) => {25    // Run the DestroyCollection transaction26    const alicePrivateKey = privateKey(senderSeed);27    const tx = api.tx.nft.destroyCollection(collectionId);28    const events = await submitTransactionAsync(alicePrivateKey, tx);29    const result = getDestroyResult(events);3031    // Get the collection 32    const collection: any = (await api.query.nft.collection(collectionId)).toJSON();3334    // What to expect35    expect(result).to.be.true;36    expect(collection).to.be.not.null;37    expect(collection.Owner).to.be.equal(nullPublicKey);38  });39}4041async function destroyCollectionExpectFailure(collectionId: number, senderSeed: string = '//Alice') {42  await usingApi(async (api) => {43    // Run the DestroyCollection transaction44    const alicePrivateKey = privateKey(senderSeed);45    const tx = api.tx.nft.destroyCollection(collectionId);46    const events = await submitTransactionAsync(alicePrivateKey, tx);47    const result = getDestroyResult(events);4849    // What to expect50    expect(result).to.be.false;51  });52}5354describe('integration test: ext. destroyCollection():', () => {55  it('NFT collection can be destroyed', async () => {56    const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');57    await destroyCollectionExpectSuccess(collectionId);58  });59  it('Fungible collection can be destroyed', async () => {60    const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'Fungible');61    await destroyCollectionExpectSuccess(collectionId);62  });63  it('ReFungible collection can be destroyed', async () => {64    const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'ReFungible');65    await destroyCollectionExpectSuccess(collectionId);66  });67});6869describe('(!negative test!) integration test: ext. destroyCollection():', () => {70  it('(!negative test!) Destroy a collection that never existed', async () => {71    await usingApi(async (api) => {72      // Find the collection that never existed73      const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;74      await destroyCollectionExpectFailure(collectionId);75    });76  });77  it('(!negative test!) Destroy a collection that has already been destroyed', async () => {78    const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');79    await destroyCollectionExpectSuccess(collectionId);80    await destroyCollectionExpectFailure(collectionId);81  });82  it('(!negative test!) Destroy a collection using non-owner account', async () => {83    const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');84    await destroyCollectionExpectFailure(collectionId, '//Bob');85    await destroyCollectionExpectSuccess(collectionId, '//Alice');86  });87});
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -52,7 +52,8 @@
   return result;
 }
 
-export async function createCollectionExpectSuccess(name: string, description: string, tokenPrefix: string, mode: string) {
+export async function createCollectionExpectSuccess(name: string, description: string, tokenPrefix: string, mode: string): Promise<number> {
+  let collectionId: number = 0;
   await usingApi(async (api) => {
     // Get number of collections before the transaction
     const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());
@@ -78,7 +79,11 @@
     expect(utf16ToStr(collection.Name)).to.be.equal(name);
     expect(utf16ToStr(collection.Description)).to.be.equal(description);
     expect(hexToStr(collection.TokenPrefix)).to.be.equal(tokenPrefix);
+
+    collectionId = result.collectionId;
   });
+
+  return collectionId;
 }
   
 export async function createCollectionExpectFailure(name: string, description: string, tokenPrefix: string, mode: string) {