difftreelog
Tests: normalizeEvents to ethPlaygrounds
in: master
3 files changed
tests/src/eth/collectionSponsoring.test.tsdiffbeforeafterboth1import {usingPlaygrounds} from './../util/playgrounds/index';2import {IKeyringPair} from '@polkadot/types/types';1import {IKeyringPair} from '@polkadot/types/types';3import {normalizeEvents} from './util/helpers';2import {usingPlaygrounds} from './../util/playgrounds/index';4import {itEth, expect} from '../eth/util/playgrounds';3import {itEth, expect} from '../eth/util/playgrounds';546describe('evm collection sponsoring', () => {5describe('evm collection sponsoring', () => {37 const nextTokenId = await contract.methods.nextTokenId().call();36 const nextTokenId = await contract.methods.nextTokenId().call();38 expect(nextTokenId).to.equal('1');37 expect(nextTokenId).to.equal('1');39 const result = await contract.methods.mint(minter, nextTokenId).send();38 const result = await contract.methods.mint(minter, nextTokenId).send();40 const events = normalizeEvents(result.events);39 const events = helper.eth.normalizeEvents(result.events);41 expect(events).to.be.deep.equal([40 expect(events).to.be.deep.equal([42 {41 {43 address: collectionAddress,42 address: collectionAddress,142 nextTokenId,141 nextTokenId,143 'Test URI',142 'Test URI',144 ).send({from: user});143 ).send({from: user});145 const events = normalizeEvents(result.events);144 const events = helper.eth.normalizeEvents(result.events);146145147 expect(events).to.be.deep.equal([146 expect(events).to.be.deep.equal([148 {147 {257 'Test URI',256 'Test URI',258 ).send();257 ).send();259258260 const events = normalizeEvents(result.events);259 const events = helper.eth.normalizeEvents(result.events);261 const address = helper.ethAddress.fromCollectionId(collectionId);260 const address = helper.ethAddress.fromCollectionId(collectionId);262261263 expect(events).to.be.deep.equal([262 expect(events).to.be.deep.equal([tests/src/eth/util/playgrounds/types.tsdiffbeforeafterboth8 object: string;8 object: string;9}9}1011export type NormalizedEvent = {12 address: string,13 event: string,14 args: { [key: string]: string }15};16tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth181819import {DevUniqueHelper} from '../../../util/playgrounds/unique.dev';19import {DevUniqueHelper} from '../../../util/playgrounds/unique.dev';202021import {ContractImports, CompiledContract} from './types';21import {ContractImports, CompiledContract, NormalizedEvent} from './types';222223// Native contracts ABI23// Native contracts ABI24import collectionHelpersAbi from '../../collectionHelpersAbi.json';24import collectionHelpersAbi from '../../collectionHelpersAbi.json';253 return before - after;253 return before - after;254 }254 }255256 normalizeEvents(events: any): NormalizedEvent[] {257 const output = [];258 for (const key of Object.keys(events)) {259 if (key.match(/^[0-9]+$/)) {260 output.push(events[key]);261 } else if (Array.isArray(events[key])) {262 output.push(...events[key]);263 } else {264 output.push(events[key]);265 }266 }267 output.sort((a, b) => a.logIndex - b.logIndex);268 return output.map(({address, event, returnValues}) => {269 const args: { [key: string]: string } = {};270 for (const key of Object.keys(returnValues)) {271 if (!key.match(/^[0-9]+$/)) {272 args[key] = returnValues[key];273 }274 }275 return {276 address,277 event,278 args,279 };280 });281 }255} 282} 256283257class EthAddressGroup extends EthGroupBase {284class EthAddressGroup extends EthGroupBase {