git.delta.rocks / unique-network / refs/commits / aa8bcd1e4a39

difftreelog

Tests: normalizeEvents to ethPlaygrounds

Maksandre2022-10-05parent: #19616c6.patch.diff
in: master

3 files changed

modifiedtests/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([
modifiedtests/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 }
+};
modifiedtests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth
1818
19import {DevUniqueHelper} from '../../../util/playgrounds/unique.dev';19import {DevUniqueHelper} from '../../../util/playgrounds/unique.dev';
2020
21import {ContractImports, CompiledContract} from './types';21import {ContractImports, CompiledContract, NormalizedEvent} from './types';
2222
23// Native contracts ABI23// Native contracts ABI
24import collectionHelpersAbi from '../../collectionHelpersAbi.json';24import collectionHelpersAbi from '../../collectionHelpersAbi.json';
253 return before - after;253 return before - after;
254 }254 }
255
256 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}
256283
257class EthAddressGroup extends EthGroupBase {284class EthAddressGroup extends EthGroupBase {