--- a/tests/src/eth/destroyCollection.test.ts +++ b/tests/src/eth/destroyCollection.test.ts @@ -15,62 +15,48 @@ // along with Unique Network. If not, see . import {IKeyringPair} from '@polkadot/types/types'; -import {Pallets, requirePalletsOrSkip} from '../util'; +import {Pallets} from '../util'; import {expect, itEth, usingEthPlaygrounds} from './util'; - -describe('Destroy Collection from EVM', () => { +describe('Destroy Collection from EVM', function() { let donor: IKeyringPair; + const testCases = [ + {method: 'createRFTCollection' as const, params: ['Limits', 'absolutely anything', 'OLF'], requiredPallets: [Pallets.ReFungible]}, + {method: 'createNFTCollection' as const, params: ['Limits', 'absolutely anything', 'OLF'], requiredPallets: [Pallets.NFT]}, + {method: 'createFTCollection' as const, params: ['Limits', 'absolutely anything', 'OLF', 18], requiredPallets: [Pallets.Fungible]}, + ]; before(async function() { - await usingEthPlaygrounds(async (helper, privateKey) => { - requirePalletsOrSkip(this, helper, [Pallets.ReFungible, Pallets.NFT]); + await usingEthPlaygrounds(async (_, privateKey) => { donor = await privateKey({filename: __filename}); }); }); - - itEth('(!negative test!) RFT', async ({helper}) => { - const owner = await helper.eth.createAccountWithBalance(donor); - const signer = await helper.eth.createAccountWithBalance(donor); - - const unexistedCollection = helper.ethAddress.fromCollectionId(1000000); - - const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'OLF'); - const collectionHelper = helper.ethNativeContract.collectionHelpers(signer); - - await expect(collectionHelper.methods - .destroyCollection(collectionAddress) - .send({from: signer})).to.be.rejected; - - await expect(collectionHelper.methods - .destroyCollection(unexistedCollection) - .send({from: signer})).to.be.rejected; - - expect(await collectionHelper.methods - .isCollectionExist(unexistedCollection) - .call()).to.be.false; - }); - - itEth('(!negative test!) NFT', async ({helper}) => { - const owner = await helper.eth.createAccountWithBalance(donor); - const signer = await helper.eth.createAccountWithBalance(donor); - - const unexistedCollection = helper.ethAddress.fromCollectionId(1000000); - - const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Limits', 'absolutely anything', 'OLF'); - const collectionHelper = helper.ethNativeContract.collectionHelpers(signer); - - await expect(collectionHelper.methods - .destroyCollection(collectionAddress) - .send({from: signer})).to.be.rejected; - - await expect(collectionHelper.methods - .destroyCollection(unexistedCollection) - .send({from: signer})).to.be.rejected; - - expect(await collectionHelper.methods - .isCollectionExist(unexistedCollection) - .call()).to.be.false; - }); + testCases.map((testCase) => + itEth.ifWithPallets(`(!negative test!) ${testCase.method}`, testCase.requiredPallets, async ({helper}) => { + const owner = await helper.eth.createAccountWithBalance(donor); + const signer = await helper.eth.createAccountWithBalance(donor); + + const unexistedCollection = helper.ethAddress.fromCollectionId(1000000); + + const collectionHelpers = helper.ethNativeContract.collectionHelpers(signer); + const {collectionAddress} = await helper.eth.createCollecion(testCase.method, owner, ...testCase.params as [string, string, string, number?]); + + // cannot burn collec + await expect(collectionHelpers.methods + .destroyCollection(collectionAddress) + .send({from: signer})).to.be.rejected; + + await expect(collectionHelpers.methods + .destroyCollection(unexistedCollection) + .send({from: signer})).to.be.rejected; + + expect(await collectionHelpers.methods + .isCollectionExist(unexistedCollection) + .call()).to.be.false; + + expect(await collectionHelpers.methods + .isCollectionExist(collectionAddress) + .call()).to.be.true; + })); }); --- a/tests/src/eth/util/playgrounds/unique.dev.ts +++ b/tests/src/eth/util/playgrounds/unique.dev.ts @@ -186,11 +186,12 @@ return await this.helper.callRpc('api.rpc.eth.call', [{from: signer, to: contractAddress, data: abi}]); } - async createCollecion(functionName: string, signer: string, name: string, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> { + async createCollecion(functionName: 'createNFTCollection' | 'createRFTCollection' | 'createFTCollection', signer: string, name: string, description: string, tokenPrefix: string, decimals?: number): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> { const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice(); const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer); - const result = await collectionHelper.methods[functionName](name, description, tokenPrefix).send({value: Number(collectionCreationPrice)}); + const functionParams = functionName === 'createFTCollection' ? [name, decimals, description, tokenPrefix] : [name, description, tokenPrefix]; + const result = await collectionHelper.methods[functionName](...functionParams).send({value: Number(collectionCreationPrice)}); const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId); const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress); @@ -217,17 +218,8 @@ return this.createCollecion('createRFTCollection', signer, name, description, tokenPrefix); } - async createFungibleCollection(signer: string, name: string, decimals: number, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> { - const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice(); - const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer); - - const result = await collectionHelper.methods.createFTCollection(name, decimals, description, tokenPrefix).send({value: Number(collectionCreationPrice)}); - const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId); - const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress); - - const events = this.helper.eth.normalizeEvents(result.events); - - return {collectionId, collectionAddress, events}; + createFungibleCollection(signer: string, name: string, decimals: number, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> { + return this.createCollecion('createFTCollection', signer, name, description, tokenPrefix, decimals); } async createERC721MetadataCompatibleRFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {