1234567891011121314151617import {ApiPromise} from '@polkadot/api';18import {evmToAddress} from '@polkadot/util-crypto';19import {expect} from 'chai';20import {getCreatedCollectionCount, getDetailedCollectionInfo} from '../util/helpers';21import {collectionHelper, collectionIdFromAddress, createEthAccountWithBalance, itWeb3, normalizeAddress} from './util/helpers';2223async function getCollectionAddressFromResult(api: ApiPromise, result: any) {24 const collectionIdAddress = normalizeAddress(result.events[0].raw.topics[2]);25 const collectionId = collectionIdFromAddress(collectionIdAddress); 26 const collection = (await getDetailedCollectionInfo(api, collectionId))!;27 return {collectionIdAddress, collectionId, collection};28}2930describe('Create collection from EVM', () => {31 itWeb3('Create collection', async ({api, web3}) => {32 const owner = await createEthAccountWithBalance(api, web3);33 const helper = collectionHelper(web3, owner);34 const collectionName = 'CollectionEVM';35 const description = 'Some description';36 const tokenPrefix = 'token prefix';37 38 const collectionCountBefore = await getCreatedCollectionCount(api);39 const result = await helper.methods40 .create721Collection(collectionName, description, tokenPrefix)41 .send();42 const collectionCountAfter = await getCreatedCollectionCount(api);43 44 const {collectionId, collection} = await getCollectionAddressFromResult(api, result);45 expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);46 expect(collectionId).to.be.eq(collectionCountAfter);47 expect(collection.name.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(collectionName);48 expect(collection.description.map(v => String.fromCharCode(v.toNumber())).join('')).to.be.eq(description);49 expect(collection.tokenPrefix.toHuman()).to.be.eq(tokenPrefix);50 expect(collection.schemaVersion.type).to.be.eq('ImageURL');51 });52 53 itWeb3('Set sponsorship', async ({api, web3}) => {54 const owner = await createEthAccountWithBalance(api, web3);55 const helper = collectionHelper(web3, owner);56 let result = await helper.methods.create721Collection('Sponsor collection', '1', '1').send();57 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);58 const sponsor = await createEthAccountWithBalance(api, web3);59 result = await helper.methods.setSponsor(collectionIdAddress, sponsor).send();60 const collection = (await getDetailedCollectionInfo(api, collectionId))!;61 expect(collection.sponsorship.isUnconfirmed).to.be.true;62 expect(collection.sponsorship.asUnconfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));63 });646566});