Skip to content

Commit d83bc10

Browse files
authored
fix: cherry pick: add value in transaction object for synthetic transactions (#4202)
Signed-off-by: Luis Mastrangelo <[email protected]>
1 parent 8990265 commit d83bc10

File tree

4 files changed

+124
-35
lines changed

4 files changed

+124
-35
lines changed

packages/relay/src/lib/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ export default {
249249
EMPTY_HEX: '0x',
250250
ONE_HEX: '0x1',
251251
TWO_HEX: '0x2',
252-
ONE_TWO_THREE_FOUR_HEX: '0x1234',
253252
HTS_ADDRESS: '0x0000000000000000000000000000000000000167',
254253
DEFAULT_GAS_USED_RATIO: 0.5,
255254

packages/relay/src/lib/factories/transactionFactory.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { Log, Transaction, Transaction1559, Transaction2930 } from '../model';
66

77
// TransactionFactory is a factory class that creates a Transaction object based on the type of transaction.
88
export class TransactionFactory {
9+
public static createTransactionByType(type: 2, fields: any): Transaction1559;
10+
911
public static createTransactionByType(type: number, fields: any): Transaction | null {
1012
switch (type) {
1113
case 0:
@@ -40,7 +42,7 @@ export class TransactionFactory {
4042
* @param log The log entry containing transaction data
4143
* @returns {Transaction1559 | null} A Transaction1559 object or null if creation fails
4244
*/
43-
public static createTransactionFromLog(chainId: string, log: Log): Transaction1559 | null {
45+
public static createTransactionFromLog(chainId: string, log: Log): Transaction1559 {
4446
const transaction = TransactionFactory.createTransactionByType(2, {
4547
accessList: undefined, // we don't support access lists for now
4648
blockHash: log.blockHash,
@@ -60,7 +62,8 @@ export class TransactionFactory {
6062
transactionIndex: log.transactionIndex,
6163
type: constants.TWO_HEX, // 0x0 for legacy transactions, 0x1 for access list types, 0x2 for dynamic fees.
6264
v: constants.ZERO_HEX,
63-
}) as Transaction1559;
65+
value: constants.ZERO_HEX,
66+
});
6467

6568
return transaction;
6669
}

packages/relay/src/lib/services/ethService/blockService/BlockService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ export class BlockService implements IBlockService {
421421
transactionIndex: log.transactionIndex,
422422
type: constants.TWO_HEX, // 0x0 for legacy transactions, 0x1 for access list types, 0x2 for dynamic fees.
423423
v: constants.ZERO_HEX,
424-
value: constants.ONE_TWO_THREE_FOUR_HEX,
424+
value: constants.ZERO_HEX,
425425
});
426426

427427
if (transaction !== null) {

packages/relay/tests/lib/eth/eth_getTransactionByHash.spec.ts

Lines changed: 118 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { expect, use } from 'chai';
44
import chaiAsPromised from 'chai-as-promised';
55

6+
import { predefined } from '../../../src';
67
import { Transaction, Transaction1559, Transaction2930 } from '../../../src/lib/model';
78
import { RequestDetails } from '../../../src/lib/types';
89
import RelayAssertions from '../../assertions';
@@ -16,7 +17,6 @@ import {
1617
NO_TRANSACTIONS,
1718
} from './eth-config';
1819
import { generateEthTestEnv } from './eth-helpers';
19-
import { predefined } from '../../../src';
2020

2121
use(chaiAsPromised);
2222

@@ -62,46 +62,61 @@ describe('@ethGetTransactionByHash eth_getTransactionByHash tests', async functi
6262

6363
this.beforeEach(function () {
6464
restMock.reset();
65-
restMock.onGet(`accounts/${defaultFromLongZeroAddress}${NO_TRANSACTIONS}`).reply(200, JSON.stringify({
66-
evm_address: `${DEFAULT_TRANSACTION.from}`,
67-
}));
68-
restMock.onGet(`accounts/${from}?transactions=false`).reply(200, JSON.stringify({
69-
evm_address: evm_address,
70-
}));
65+
restMock.onGet(`accounts/${defaultFromLongZeroAddress}${NO_TRANSACTIONS}`).reply(
66+
200,
67+
JSON.stringify({
68+
evm_address: `${DEFAULT_TRANSACTION.from}`,
69+
}),
70+
);
71+
restMock.onGet(`accounts/${from}?transactions=false`).reply(
72+
200,
73+
JSON.stringify({
74+
evm_address: evm_address,
75+
}),
76+
);
7177
});
7278

7379
it('returns 155 transaction for type 0', async function () {
7480
const uniqueTxHash = '0x27cad7b827375d12d73af57b6a3e84353645fd31305ea58ff52dda53ec640533';
75-
restMock.onGet(`contracts/results/${uniqueTxHash}`).reply(200, JSON.stringify({
76-
...contractResultMock,
77-
type: 0,
78-
}));
81+
restMock.onGet(`contracts/results/${uniqueTxHash}`).reply(
82+
200,
83+
JSON.stringify({
84+
...contractResultMock,
85+
type: 0,
86+
}),
87+
);
7988

8089
const result = await ethImpl.getTransactionByHash(uniqueTxHash, requestDetails);
8190
expect(result).to.be.an.instanceOf(Transaction);
8291
});
8392

8493
it('returns 2930 transaction for type 1', async function () {
8594
const uniqueTxHash = '0x28cad7b827375d12d73af57b6a3e84353645fd31305ea58ff52dda53ec640533';
86-
restMock.onGet(`contracts/results/${uniqueTxHash}`).reply(200, JSON.stringify({
87-
...contractResultMock,
88-
type: 1,
89-
access_list: [],
90-
}));
95+
restMock.onGet(`contracts/results/${uniqueTxHash}`).reply(
96+
200,
97+
JSON.stringify({
98+
...contractResultMock,
99+
type: 1,
100+
access_list: [],
101+
}),
102+
);
91103

92104
const result = await ethImpl.getTransactionByHash(uniqueTxHash, requestDetails);
93105
expect(result).to.be.an.instanceOf(Transaction2930);
94106
});
95107

96108
it('returns 1559 transaction for type 2', async function () {
97109
const uniqueTxHash = '0x27cad7b827375d12d73af57b7a3e84353645fd31305ea58ff52dda53ec640533';
98-
restMock.onGet(`contracts/results/${uniqueTxHash}`).reply(200, JSON.stringify({
99-
...contractResultMock,
100-
type: 2,
101-
access_list: [],
102-
max_fee_per_gas: '0x47',
103-
max_priority_fee_per_gas: '0x47',
104-
}));
110+
restMock.onGet(`contracts/results/${uniqueTxHash}`).reply(
111+
200,
112+
JSON.stringify({
113+
...contractResultMock,
114+
type: 2,
115+
access_list: [],
116+
max_fee_per_gas: '0x47',
117+
max_priority_fee_per_gas: '0x47',
118+
}),
119+
);
105120

106121
const result = await ethImpl.getTransactionByHash(uniqueTxHash, requestDetails);
107122
expect(result).to.be.an.instanceOf(Transaction1559);
@@ -118,16 +133,76 @@ describe('@ethGetTransactionByHash eth_getTransactionByHash tests', async functi
118133
expect(result).to.equal(null);
119134
});
120135

136+
it('returns a valid transaction for synthetic transactions', async function () {
137+
const uniqueTxHash = '0x1b1aaac9ee7b1ad9f95651aeec8d3beb80bb0197d01234a85a643e2ea02a55a5';
138+
const logs = {
139+
logs: [
140+
{
141+
address: '0x00000000000000000000000000000000006390e6',
142+
bloom: '0x00',
143+
contract_id: '0.0.6525158',
144+
data: '0x000000000000000000000000000000000000000000000000000000000000000a',
145+
index: 0,
146+
topics: [
147+
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
148+
'0x000000000000000000000000b562f7740eb5b7a2177994765f76c7b964437e85',
149+
'0x00000000000000000000000025639d1a6b4d3ace699d541d15b898bd6a7fd5bb',
150+
],
151+
block_hash:
152+
'0x730c1d0263e78303b189d778a75451113162547b4b466cb8c1796deef3a8a5e486aef01c205e42af0f1abc3c1cb2378c',
153+
block_number: 23279896,
154+
root_contract_id: '0.0.6525158',
155+
timestamp: '1754605000.616067461',
156+
transaction_hash: '0x1b1aaac9ee7b1ad9f95651aeec8d3beb80bb0197d01234a85a643e2ea02a55a5',
157+
transaction_index: 7,
158+
},
159+
],
160+
links: { next: null },
161+
};
162+
restMock.onGet(`contracts/results/${uniqueTxHash}`).reply(404, JSON.stringify(DETAILD_CONTRACT_RESULT_NOT_FOUND));
163+
restMock
164+
.onGet(`contracts/results/logs?transaction.hash=${uniqueTxHash}&limit=100&order=asc`)
165+
.reply(200, JSON.stringify(logs));
166+
167+
const result = await ethImpl.getTransactionByHash(uniqueTxHash, requestDetails);
168+
expect(result).to.be.deep.equal({
169+
blockHash: '0x730c1d0263e78303b189d778a75451113162547b4b466cb8c1796deef3a8a5e4',
170+
blockNumber: '0x1633918',
171+
chainId: '0x12a',
172+
from: '0x00000000000000000000000000000000006390e6',
173+
gas: '0x61a80',
174+
gasPrice: '0xfe',
175+
hash: '0x1b1aaac9ee7b1ad9f95651aeec8d3beb80bb0197d01234a85a643e2ea02a55a5',
176+
input: '0x0000000000000000',
177+
nonce: '0x0',
178+
r: '0x',
179+
s: '0x',
180+
to: '0x00000000000000000000000000000000006390e6',
181+
transactionIndex: '0x7',
182+
type: '0x2',
183+
v: '0x0',
184+
yParity: '0x0',
185+
accessList: [],
186+
maxPriorityFeePerGas: '0x0',
187+
maxFeePerGas: '0x0',
188+
value: '0x0',
189+
});
190+
});
191+
121192
it('account should be cached', async function () {
122-
restMock.onGet(`contracts/results/${DEFAULT_TX_HASH}`).reply(200, JSON.stringify(defaultDetailedContractResultByHash));
193+
restMock
194+
.onGet(`contracts/results/${DEFAULT_TX_HASH}`)
195+
.reply(200, JSON.stringify(defaultDetailedContractResultByHash));
123196
const resBeforeCache = await ethImpl.getTransactionByHash(DEFAULT_TX_HASH, requestDetails);
124197
restMock.onGet(`accounts/${defaultFromLongZeroAddress}${NO_TRANSACTIONS}`).reply(404);
125198
const resAfterCache = await ethImpl.getTransactionByHash(DEFAULT_TX_HASH, requestDetails);
126199
expect(resBeforeCache).to.deep.equal(resAfterCache);
127200
});
128201

129202
it('returns correct transaction for existing hash', async function () {
130-
restMock.onGet(`contracts/results/${DEFAULT_TX_HASH}`).reply(200, JSON.stringify(defaultDetailedContractResultByHash));
203+
restMock
204+
.onGet(`contracts/results/${DEFAULT_TX_HASH}`)
205+
.reply(200, JSON.stringify(defaultDetailedContractResultByHash));
131206
const result = await ethImpl.getTransactionByHash(DEFAULT_TX_HASH, requestDetails);
132207
RelayAssertions.assertTransaction(result, {
133208
...DEFAULT_TRANSACTION,
@@ -163,7 +238,9 @@ describe('@ethGetTransactionByHash eth_getTransactionByHash tests', async functi
163238
};
164239
const uniqueTxHash = '0x14aad7b827375d12d73af57b6a3e84353645fd31305ea58ff52dda53ec640533';
165240

166-
restMock.onGet(`contracts/results/${uniqueTxHash}`).reply(200, JSON.stringify(detailedResultsWithNullNullableValues));
241+
restMock
242+
.onGet(`contracts/results/${uniqueTxHash}`)
243+
.reply(200, JSON.stringify(detailedResultsWithNullNullableValues));
167244
const result = await ethImpl.getTransactionByHash(uniqueTxHash, requestDetails);
168245
expect(result).to.not.be.null;
169246

@@ -178,7 +255,9 @@ describe('@ethGetTransactionByHash eth_getTransactionByHash tests', async functi
178255
};
179256
const uniqueTxHash = '0x0aaad7b827375d12d73af57b6a3e84353645fd31305ea58ff52dda53ec640533';
180257

181-
restMock.onGet(`contracts/results/${uniqueTxHash}`).reply(200, JSON.stringify(detailedResultsWithNullNullableValues));
258+
restMock
259+
.onGet(`contracts/results/${uniqueTxHash}`)
260+
.reply(200, JSON.stringify(detailedResultsWithNullNullableValues));
182261
const result = await ethImpl.getTransactionByHash(uniqueTxHash, requestDetails);
183262
expect(result).to.not.be.null;
184263

@@ -194,7 +273,9 @@ describe('@ethGetTransactionByHash eth_getTransactionByHash tests', async functi
194273
};
195274
const uniqueTxHash = '0xb4cad7b827375d12d73af57b6a3e84353645fd31305ea58ff52dda53ec640533';
196275

197-
restMock.onGet(`contracts/results/${uniqueTxHash}`).reply(200, JSON.stringify(detailedResultsWithNullNullableValues));
276+
restMock
277+
.onGet(`contracts/results/${uniqueTxHash}`)
278+
.reply(200, JSON.stringify(detailedResultsWithNullNullableValues));
198279
const result = await ethImpl.getTransactionByHash(uniqueTxHash, requestDetails);
199280
expect(result).to.not.be.null;
200281

@@ -209,7 +290,9 @@ describe('@ethGetTransactionByHash eth_getTransactionByHash tests', async functi
209290
};
210291
const uniqueTxHash = '0x14aad7b827375d12d73af57b6a3e84353645fd31305ea58ff52dda53ec640534';
211292

212-
restMock.onGet(`contracts/results/${uniqueTxHash}`).reply(200, JSON.stringify(detailedResultsWithNullNullableValues));
293+
restMock
294+
.onGet(`contracts/results/${uniqueTxHash}`)
295+
.reply(200, JSON.stringify(detailedResultsWithNullNullableValues));
213296

214297
try {
215298
await ethImpl.getTransactionByHash(uniqueTxHash, requestDetails);
@@ -227,7 +310,9 @@ describe('@ethGetTransactionByHash eth_getTransactionByHash tests', async functi
227310
};
228311
const uniqueTxHash = '0x14aad7b827375d12d73af57b6a3e84353645fd31305ea58ff52dda53ec640511';
229312

230-
restMock.onGet(`contracts/results/${uniqueTxHash}`).reply(200, JSON.stringify(detailedResultsWithNullNullableValues));
313+
restMock
314+
.onGet(`contracts/results/${uniqueTxHash}`)
315+
.reply(200, JSON.stringify(detailedResultsWithNullNullableValues));
231316
try {
232317
await ethImpl.getTransactionByHash(uniqueTxHash, requestDetails);
233318
expect.fail('should have thrown an error');
@@ -246,7 +331,9 @@ describe('@ethGetTransactionByHash eth_getTransactionByHash tests', async functi
246331

247332
const uniqueTxHash = '0x14aad7b827375d12d73af57b6a3e84353645fd31305ea58ff52d1a53ec640511';
248333

249-
restMock.onGet(`contracts/results/${uniqueTxHash}`).reply(200, JSON.stringify(detailedResultsWithNullNullableValues));
334+
restMock
335+
.onGet(`contracts/results/${uniqueTxHash}`)
336+
.reply(200, JSON.stringify(detailedResultsWithNullNullableValues));
250337
try {
251338
await ethImpl.getTransactionByHash(uniqueTxHash, requestDetails);
252339
expect.fail('should have thrown an error');

0 commit comments

Comments
 (0)