From 27800fedbaa6f894535bc379ec03eca552d4deb7 Mon Sep 17 00:00:00 2001 From: Fahrrader Date: Wed, 25 May 2022 10:43:51 +0000 Subject: [PATCH] revert(test): unneeded test additions --- --- a/tests/package.json +++ b/tests/package.json @@ -37,7 +37,6 @@ "testUnnesting": "mocha --timeout 9999999 -r ts-node/register ./**/unnest.test.ts", "testStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts", "testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/properties.test.ts", - "testGraphs": "mocha --timeout 9999999 -r ts-node/register ./**/graphs.test.ts", "testMigrationStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/migration-check.test.ts", "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts", "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts", --- a/tests/src/nesting/graphs.test.ts +++ b/tests/src/nesting/graphs.test.ts @@ -32,10 +32,10 @@ return collectionId; } -describe.skip('Graphs', () => { +describe('Graphs', () => { it('Ouroboros can\'t be created in a complex graph', async () => { await usingApi(async api => { - const alice = privateKey('//alice'); + const alice = privateKey('//Alice'); const collection = await buildComplexObjectGraph(api, alice); // to self @@ -55,197 +55,3 @@ }); }); }); - -import type { EventRecord } from '@polkadot/types/interfaces'; -import type { GenericEventData } from '@polkadot/types'; -import type { Option, Bytes } from '@polkadot/types-codec'; -import type { - RmrkTypesCollectionInfo as Collection, - RmrkTypesNftInfo as Nft, - RmrkTypesResourceInfo as Resource, - RmrkTypesBaseInfo as Base, - RmrkTypesPartType as PartType, - RmrkTypesNftChild as NftChild, - RmrkTypesTheme as Theme, - RmrkTypesPropertyInfo as Property, -} from '@polkadot/types/lookup'; - -interface TxResult { - success: boolean; - successData: T | null; -} - -export function extractTxResult( - events: EventRecord[], - expectSection: string, - expectMethod: string, - extractAction: (data: GenericEventData) => T -): TxResult { - let success = false; - let successData = null; - events.forEach(({event: {data, method, section}}) => { - //console.log(expectSection + " "+ " " + section + " " + expectMethod + " " + method) - if (method == 'ExtrinsicSuccess') { - success = true; - } else if ((expectSection == section) && (expectMethod == method)) { - successData = extractAction(data); - } - }); - const result: TxResult = { - success, - successData, - }; - return result; -} - -export function extractRmrkCoreTxResult( - events: EventRecord[], - expectMethod: string, - extractAction: (data: GenericEventData) => T -): TxResult { - return extractTxResult(events, 'rmrkCore', expectMethod, extractAction); -} - -export async function expectTxFailure(expectedError: RegExp, promise: Promise) { - await expect(promise).to.be.rejectedWith(expectedError); -} - -export async function getCollectionsCount(api: ApiPromise): Promise { - return (await api.rpc.rmrk.lastCollectionIdx()).toNumber(); -} - -export async function getCollection(api: ApiPromise, id: number): Promise> { - return api.rpc.rmrk.collectionById(id); -} - -export async function createCollection( - api: ApiPromise, - issuerUri: string, - metadata: string, - max: number | null, - symbol: string -): Promise { - let collectionId = 0; - - const oldCollectionCount = await getCollectionsCount(api); - const maxOptional = max ? max.toString() : null; - console.log(maxOptional) - console.log('right above me') - - const issuer = privateKey(issuerUri); - const tx = api.tx.rmrkCore.createCollection(metadata, maxOptional, symbol); - const events = await executeTransaction(api, issuer, tx); - - const collectionResult = extractRmrkCoreTxResult( - events, 'CollectionCreated', (data) => { - return parseInt(data[1].toString(), 10) - } - ); - expect(collectionResult.success, 'Error: unable to create a collection').to.be.true; - const newCollectionCount = await getCollectionsCount(api); - expect(newCollectionCount).to.be.equal(oldCollectionCount + 1, 'Error: NFT collection count should increase'); - - collectionId = collectionResult.successData ?? 0; - - console.log(collectionId); - - const collectionOption = await getCollection(api, collectionId); - - expect(collectionOption.isSome, 'Error: unable to fetch created NFT collection').to.be.true; - - const collection = collectionOption.unwrap(); - - expect(collection.metadata.toUtf8()).to.be.equal(metadata, "Error: Invalid NFT collection metadata"); - console.log(collection.max, max) - expect(collection.max.isSome).to.be.equal(max !== null, "Error: Invalid NFT collection max"); - - if (collection.max.isSome) { - expect(collection.max.unwrap().toNumber()).to.be.equal(max, "Error: Invalid NFT collection max"); - } - expect(collection.symbol.toUtf8()).to.be.equal(symbol, "Error: Invalid NFT collection's symbol"); - expect(collection.nftsCount.toNumber()).to.be.equal(0, "Error: NFT collection shoudn't have any tokens"); - expect(collection.issuer.toString()).to.be.equal(issuer.address, "Error: Invalid NFT collection issuer"); - - return collectionId; -} - -export async function deleteCollection( - api: ApiPromise, - issuerUri: string, - collectionId: string -): Promise { - const issuer = privateKey(issuerUri); - const tx = api.tx.rmrkCore.destroyCollection(collectionId); - const events = await executeTransaction(api, issuer, tx); - - const collectionTxResult = extractRmrkCoreTxResult( - events, - "CollectionDestroy", - (data) => { - return parseInt(data[1].toString(), 10); - } - ); - expect(collectionTxResult.success, 'Error: Unable to delete NFT collection').to.be.true; - - const collection = await getCollection( - api, - parseInt(collectionId, 10) - ); - expect(collection.isEmpty, 'Error: NFT collection should be deleted').to.be.true; - - return 0; -} - -describe('Something', () => { - const alice = '//Alice'; - const bob = "//Bob"; - - it('create NFT collection', async () => { - await usingApi(async api => { - await createCollection(api, alice, 'test-metadata', 42, 'test-symbol'); - //console.log((await api.rpc.rmrk.base(3)).toHuman()); - }); - }); - - it('create NFT collection without token limit', async () => { - await usingApi(async api => { - await createCollection(api, alice, 'no-limit-metadata', null, 'no-limit-symbol'); - }); - }); - - it("Delete NFT collection", async () => { - await usingApi(async api => { - await createCollection( - api, - alice, - "test-metadata", - null, - "test-symbol" - ).then(async (collectionId) => { - await deleteCollection(api, alice, collectionId.toString()); - }); - }); - }); - - it("[Negative] delete non-existing NFT collection", async () => { - await usingApi(async api => { - const tx = deleteCollection(api, alice, "99999"); - await expectTxFailure(/rmrkCore.CollectionUnknown/, tx); - }); - }); - - it("[Negative] delete not an owner NFT collection", async () => { - await usingApi(async api => { - await createCollection( - api, - alice, - "test-metadata", - null, - "test-symbol" - ).then(async (collectionId) => { - const tx = deleteCollection(api, bob, collectionId.toString()); - await expectTxFailure(/uniques.NoPermission/, tx); - }); - }); - }); -}); \ No newline at end of file -- gitstuff