Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix transaction getter being removed when cloning object #202

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- Getting transaction receipts when accessing via a log handler
- transaction missing from log (#202)

## [3.3.0] - 2023-11-06
### Added
Expand Down
27 changes: 27 additions & 0 deletions packages/node/src/ethereum/api.ethereum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ describe('Api.ethereum', () => {
it('should have the ability to get receipts via transactions from all types', () => {
expect(typeof blockData.transactions[0].receipt).toEqual('function');
expect(typeof blockData.logs[0].transaction.receipt).toEqual('function');
expect(typeof blockData.logs[0].transaction.from).toEqual('string');
expect(typeof blockData.transactions[81].logs[0].transaction.from).toEqual(
'string',
);
expect(
typeof blockData.transactions[81].logs[0].transaction.receipt,
).toEqual('function');
Expand All @@ -89,6 +93,17 @@ describe('Api.ethereum', () => {
expect(parsedTx.logs[0].args).toBeTruthy();
});

it('Should decode transaction data and not clone object', async () => {
const tx = blockData.transactions.find(
(e) =>
e.hash ===
'0x8e419d0e36d7f9c099a001fded516bd168edd9d27b4aec2bcd56ba3b3b955ccc',
);
const parsedTx = await ethApi.parseTransaction(tx, ds);

expect(parsedTx).toBe(tx);
});

it('Should return raw logs, if decode fails', async () => {
// not Erc721
const tx = blockData.transactions.find(
Expand All @@ -101,6 +116,18 @@ describe('Api.ethereum', () => {
expect(parsedLog).toBeTruthy();
});

// This test is here to ensure getters aren't removed
it('Should not clone logs when parsing args', async () => {
const log = blockData.transactions.find(
(e) =>
e.hash ===
'0x8e419d0e36d7f9c099a001fded516bd168edd9d27b4aec2bcd56ba3b3b955ccc',
).logs[1];

const parsedLog = await ethApi.parseLog(log, ds);
expect(parsedLog).toBe(log);
});

it('Null filter support', async () => {
const beamEndpoint = 'https://rpc.api.moonbeam.network';
ethApi = new EthereumApi(beamEndpoint, BLOCK_CONFIRMATIONS, eventEmitter);
Expand Down
16 changes: 8 additions & 8 deletions packages/node/src/ethereum/api.ethereum.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import assert from 'assert';
import fs from 'fs';
import http from 'http';
import https from 'https';
Expand Down Expand Up @@ -382,10 +383,10 @@ export class EthereumApi implements ApiWrapper {
return log;
}
const iface = this.buildInterface(ds.options.abi, await loadAssets(ds));
return {
...log,
args: iface?.parseLog(log).args as T,
};

log.args = iface?.parseLog(log).args as T;

return log;
} catch (e) {
logger.warn(`Failed to parse log data: ${e.message}`);
return log;
Expand All @@ -412,10 +413,9 @@ export class EthereumApi implements ApiWrapper {
transaction.logs.map(async (log) => this.parseLog(log, ds)),
)) as Array<EthereumLog | EthereumLog<T>>);

return {
...transaction,
args,
};
transaction.args = args;

return transaction;
} catch (e) {
logger.warn(`Failed to parse transaction data: ${e.message}`);
return transaction;
Expand Down