From aa8bcd1e4a39f2056d1c4829fd8fa2c76d9c4ed8 Mon Sep 17 00:00:00 2001 From: Maksandre Date: Wed, 05 Oct 2022 10:43:00 +0000 Subject: [PATCH] Tests: normalizeEvents to ethPlaygrounds --- --- a/tests/src/eth/collectionSponsoring.test.ts +++ b/tests/src/eth/collectionSponsoring.test.ts @@ -1,6 +1,5 @@ -import {usingPlaygrounds} from './../util/playgrounds/index'; import {IKeyringPair} from '@polkadot/types/types'; -import {normalizeEvents} from './util/helpers'; +import {usingPlaygrounds} from './../util/playgrounds/index'; import {itEth, expect} from '../eth/util/playgrounds'; describe('evm collection sponsoring', () => { @@ -37,7 +36,7 @@ const nextTokenId = await contract.methods.nextTokenId().call(); expect(nextTokenId).to.equal('1'); const result = await contract.methods.mint(minter, nextTokenId).send(); - const events = normalizeEvents(result.events); + const events = helper.eth.normalizeEvents(result.events); expect(events).to.be.deep.equal([ { address: collectionAddress, @@ -142,7 +141,7 @@ nextTokenId, 'Test URI', ).send({from: user}); - const events = normalizeEvents(result.events); + const events = helper.eth.normalizeEvents(result.events); expect(events).to.be.deep.equal([ { @@ -257,7 +256,7 @@ 'Test URI', ).send(); - const events = normalizeEvents(result.events); + const events = helper.eth.normalizeEvents(result.events); const address = helper.ethAddress.fromCollectionId(collectionId); expect(events).to.be.deep.equal([ --- a/tests/src/eth/util/playgrounds/types.ts +++ b/tests/src/eth/util/playgrounds/types.ts @@ -6,4 +6,10 @@ export interface CompiledContract { abi: any; object: string; -} \ No newline at end of file +} + +export type NormalizedEvent = { + address: string, + event: string, + args: { [key: string]: string } +}; --- a/tests/src/eth/util/playgrounds/unique.dev.ts +++ b/tests/src/eth/util/playgrounds/unique.dev.ts @@ -18,7 +18,7 @@ import {DevUniqueHelper} from '../../../util/playgrounds/unique.dev'; -import {ContractImports, CompiledContract} from './types'; +import {ContractImports, CompiledContract, NormalizedEvent} from './types'; // Native contracts ABI import collectionHelpersAbi from '../../collectionHelpersAbi.json'; @@ -252,6 +252,33 @@ return before - after; } + + normalizeEvents(events: any): NormalizedEvent[] { + const output = []; + for (const key of Object.keys(events)) { + if (key.match(/^[0-9]+$/)) { + output.push(events[key]); + } else if (Array.isArray(events[key])) { + output.push(...events[key]); + } else { + output.push(events[key]); + } + } + output.sort((a, b) => a.logIndex - b.logIndex); + return output.map(({address, event, returnValues}) => { + const args: { [key: string]: string } = {}; + for (const key of Object.keys(returnValues)) { + if (!key.match(/^[0-9]+$/)) { + args[key] = returnValues[key]; + } + } + return { + address, + event, + args, + }; + }); + } } class EthAddressGroup extends EthGroupBase { -- gitstuff