Skip to content

Commit

Permalink
fix: fix potential bug in transaction formatter (#1035)
Browse files Browse the repository at this point in the history
* fix: fix potential bug in transaction formatter

* fix: fix fixture tests
  • Loading branch information
fabiorigam authored Jul 11, 2024
1 parent d0fc33a commit cba77da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,11 @@ function formatTransactionReceiptToRPCStandard(
transactionHash,
chainId
);
const n = receipt.outputs.length > 0 ? receipt.outputs[0].events.length : 0;
const filledLogIndexes = new Array<number>(n)
.fill(logIndexOffset)
.map((_, i) => i + logIndexOffset);

const logIndexes: string[] = filledLogIndexes.map((i) => Quantity.of(i));

const logs: TransactionReceiptLogsRPC[] = [];
let logIndex = logIndexOffset;
receipt.outputs.forEach((output) => {
output.events.forEach((event, index) => {
output.events.forEach((event) => {
logs.push({
blockHash: receipt.meta.blockID,
blockNumber: Quantity.of(receipt.meta.blockNumber),
Expand All @@ -165,8 +160,9 @@ function formatTransactionReceiptToRPCStandard(
data: event.data,
removed: false,
transactionIndex: Quantity.of(transactionIndex),
logIndex: logIndexes[index]
logIndex: Quantity.of(logIndex)
});
logIndex++;
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const getReceiptCorrectCasesTestNetwork = [
'0x0114b4a1182a9103113a4052b2d08e7785ea74901c6974f16661d352202d7bf6',
blockNumber: '0x114b4a1',
data: '0x0000000000000000000000000000000000000000000000024808a928fe542eed',
logIndex: '0x1',
logIndex: '0x2',
removed: false,
topics: [
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
Expand All @@ -168,7 +168,7 @@ const getReceiptCorrectCasesTestNetwork = [
'0x0114b4a1182a9103113a4052b2d08e7785ea74901c6974f16661d352202d7bf6',
blockNumber: '0x114b4a1',
data: '0x0000000000000000000000000000000000000000000000043c47d85f5fdafe3d000000000000000000000000000000000000000000000006845081885e2f2d2a',
logIndex: undefined,
logIndex: '0x3',
removed: false,
topics: [
'0xdec2bacdd2f05b59de34da9b523dff8be42e5e38e818c82fdb0bae774387a724',
Expand All @@ -184,7 +184,7 @@ const getReceiptCorrectCasesTestNetwork = [
'0x0114b4a1182a9103113a4052b2d08e7785ea74901c6974f16661d352202d7bf6',
blockNumber: '0x114b4a1',
data: '0x0000000000000000000000000000000000000000000000024808a928fe542eed',
logIndex: undefined,
logIndex: '0x4',
removed: false,
topics: [
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
Expand Down

1 comment on commit cba77da

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Coverage

Summary

Lines Statements Branches Functions
Coverage: 100%
100% (3469/3469) 100% (812/812) 100% (716/716)
Title Tests Skipped Failures Errors Time
core 494 0 💤 0 ❌ 0 🔥 1m 4s ⏱️
network 669 0 💤 0 ❌ 0 🔥 3m 48s ⏱️
errors 48 0 💤 0 ❌ 0 🔥 10.819s ⏱️

Please sign in to comment.