difftreelog
Tests: normalizeEvents to ethPlaygrounds
in: master
3 files changed
tests/src/eth/collectionSponsoring.test.tsdiffbeforeafterboth--- 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([
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.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 {