difftreelog
Add destroyCollection tests
in: master
2 files changed
tests/src/eth/destroyCollection.test.tsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {Pallets, requirePalletsOrSkip} from '../util';18import {Pallets} from '../util';19import {expect, itEth, usingEthPlaygrounds} from './util';19import {expect, itEth, usingEthPlaygrounds} from './util';20212022describe('Destroy Collection from EVM', () => {21describe('Destroy Collection from EVM', function() {23 let donor: IKeyringPair;22 let donor: IKeyringPair;23 const testCases = [24 {method: 'createRFTCollection' as const, params: ['Limits', 'absolutely anything', 'OLF'], requiredPallets: [Pallets.ReFungible]},25 {method: 'createNFTCollection' as const, params: ['Limits', 'absolutely anything', 'OLF'], requiredPallets: [Pallets.NFT]},26 {method: 'createFTCollection' as const, params: ['Limits', 'absolutely anything', 'OLF', 18], requiredPallets: [Pallets.Fungible]},27 ];242825 before(async function() {29 before(async function() {26 await usingEthPlaygrounds(async (helper, privateKey) => {30 await usingEthPlaygrounds(async (_, privateKey) => {27 requirePalletsOrSkip(this, helper, [Pallets.ReFungible, Pallets.NFT]);28 donor = await privateKey({filename: __filename});31 donor = await privateKey({filename: __filename});29 });32 });30 });33 });313432 35 testCases.map((testCase) => 33 itEth('(!negative test!) RFT', async ({helper}) => {36 itEth.ifWithPallets(`(!negative test!) ${testCase.method}`, testCase.requiredPallets, async ({helper}) => {34 const owner = await helper.eth.createAccountWithBalance(donor);37 const owner = await helper.eth.createAccountWithBalance(donor);35 const signer = await helper.eth.createAccountWithBalance(donor);38 const signer = await helper.eth.createAccountWithBalance(donor);36 39 37 const unexistedCollection = helper.ethAddress.fromCollectionId(1000000);40 const unexistedCollection = helper.ethAddress.fromCollectionId(1000000);38 41 39 const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');42 const collectionHelpers = helper.ethNativeContract.collectionHelpers(signer);40 const collectionHelper = helper.ethNativeContract.collectionHelpers(signer);43 const {collectionAddress} = await helper.eth.createCollecion(testCase.method, owner, ...testCase.params as [string, string, string, number?]);41 4445 // cannot burn collec42 await expect(collectionHelper.methods46 await expect(collectionHelpers.methods43 .destroyCollection(collectionAddress)47 .destroyCollection(collectionAddress)44 .send({from: signer})).to.be.rejected;48 .send({from: signer})).to.be.rejected;45 49 46 await expect(collectionHelper.methods50 await expect(collectionHelpers.methods47 .destroyCollection(unexistedCollection)51 .destroyCollection(unexistedCollection)48 .send({from: signer})).to.be.rejected;52 .send({from: signer})).to.be.rejected;49 53 50 expect(await collectionHelper.methods54 expect(await collectionHelpers.methods51 .isCollectionExist(unexistedCollection)55 .isCollectionExist(unexistedCollection)52 .call()).to.be.false;56 .call()).to.be.false;57 58 expect(await collectionHelpers.methods59 .isCollectionExist(collectionAddress)60 .call()).to.be.true;53 });61 }));54 55 itEth('(!negative test!) NFT', async ({helper}) => {56 const owner = await helper.eth.createAccountWithBalance(donor);57 const signer = await helper.eth.createAccountWithBalance(donor);58 59 const unexistedCollection = helper.ethAddress.fromCollectionId(1000000);60 61 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');62 const collectionHelper = helper.ethNativeContract.collectionHelpers(signer);63 64 await expect(collectionHelper.methods65 .destroyCollection(collectionAddress)66 .send({from: signer})).to.be.rejected;67 68 await expect(collectionHelper.methods69 .destroyCollection(unexistedCollection)70 .send({from: signer})).to.be.rejected;71 72 expect(await collectionHelper.methods73 .isCollectionExist(unexistedCollection)74 .call()).to.be.false;75 });76});62});7763tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth186 return await this.helper.callRpc('api.rpc.eth.call', [{from: signer, to: contractAddress, data: abi}]);186 return await this.helper.callRpc('api.rpc.eth.call', [{from: signer, to: contractAddress, data: abi}]);187 }187 }188188189 async createCollecion(functionName: string, signer: string, name: string, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {189 async createCollecion(functionName: 'createNFTCollection' | 'createRFTCollection' | 'createFTCollection', signer: string, name: string, description: string, tokenPrefix: string, decimals?: number): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {190 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();190 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();191 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);191 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);192192193 const functionParams = functionName === 'createFTCollection' ? [name, decimals, description, tokenPrefix] : [name, description, tokenPrefix];193 const result = await collectionHelper.methods[functionName](name, description, tokenPrefix).send({value: Number(collectionCreationPrice)});194 const result = await collectionHelper.methods[functionName](...functionParams).send({value: Number(collectionCreationPrice)});194195195 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);196 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);196 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);197 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);217 return this.createCollecion('createRFTCollection', signer, name, description, tokenPrefix);218 return this.createCollecion('createRFTCollection', signer, name, description, tokenPrefix);218 }219 }219220220 async createFungibleCollection(signer: string, name: string, decimals: number, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> {221 createFungibleCollection(signer: string, name: string, decimals: number, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> {221 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();222 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);223224 const result = await collectionHelper.methods.createFTCollection(name, decimals, description, tokenPrefix).send({value: Number(collectionCreationPrice)});222 return this.createCollecion('createFTCollection', signer, name, description, tokenPrefix, decimals);225 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);226 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);227228 const events = this.helper.eth.normalizeEvents(result.events);229230 return {collectionId, collectionAddress, events};231 }223 }232224233 async createERC721MetadataCompatibleRFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {225 async createERC721MetadataCompatibleRFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {