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.tsdiffbeforeafterboth--- 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 }
+};
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- 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 {