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
1import {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';
54
6describe('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);
146145
147 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();
259258
260 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);
262261
263 expect(events).to.be.deep.equal([262 expect(events).to.be.deep.equal([
modifiedtests/src/eth/util/playgrounds/types.tsdiffbeforeafterboth
8 object: string;8 object: string;
9}9}
10
11export type NormalizedEvent = {
12 address: string,
13 event: string,
14 args: { [key: string]: string }
15};
16
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 {