Skip to content

Commit f540496

Browse files
authored
chore: reverted "fix: added null check for nullable values in formatContractResult() (#3210)" (#3216)
This reverts commit ca044f1. Signed-off-by: Logan Nguyen <[email protected]>
1 parent 74a93bc commit f540496

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

packages/relay/src/formatters.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ const formatContractResult = (cr: any) => {
166166
const commonFields = {
167167
blockHash: toHash32(cr.block_hash),
168168
blockNumber: nullableNumberTo0x(cr.block_number),
169-
from: cr.from?.substring(0, 42) || null,
169+
from: cr.from.substring(0, 42),
170170
gas: nanOrNumberTo0x(cr.gas_used),
171171
gasPrice,
172-
hash: cr.hash?.substring(0, 66) || null,
172+
hash: cr.hash.substring(0, 66),
173173
input: cr.function_parameters,
174174
nonce: nanOrNumberTo0x(cr.nonce),
175175
r: cr.r === null ? '0x0' : stripLeadingZeroForSignatures(cr.r.substring(0, 66)),
176176
s: cr.s === null ? '0x0' : stripLeadingZeroForSignatures(cr.s.substring(0, 66)),
177-
to: cr.to?.substring(0, 42) || null,
177+
to: cr.to?.substring(0, 42),
178178
transactionIndex: nullableNumberTo0x(cr.transaction_index),
179179
type: cr.type === null ? '0x0' : nanOrNumberTo0x(cr.type),
180180
v: cr.v === null ? '0x0' : nanOrNumberTo0x(cr.v),

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ describe('@ethGetTransactionByBlockHashAndIndex using MirrorNode', async functio
120120
verifyAggregatedInfo(result);
121121
});
122122

123-
it('eth_getTransactionByBlockHashAndIndex should NOT throw for internal error if `from` field is null', async function () {
123+
it('eth_getTransactionByBlockHashAndIndex should throw for internal error', async function () {
124124
const randomBlock = {
125125
hash: '0x5f827a801c579c84eca738827b65612b28ed425b7578bfdd10177e24fc3db8d4b1a7f3d56d83c39b950cc5e4d175dd64',
126126
count: 9,
@@ -131,9 +131,16 @@ describe('@ethGetTransactionByBlockHashAndIndex using MirrorNode', async functio
131131
.onGet(contractResultsByHashByIndexURL(randomBlock.hash, randomBlock.count))
132132
.reply(200, defaultContractResultsWithNullableFrom);
133133

134-
const result = await ethImpl.getTransactionByBlockHashAndIndex(randomBlock.hash, randomBlock.count, requestDetails);
135-
expect(result).to.not.be.null;
136-
expect(result.from).to.be.null;
134+
const args = [randomBlock.hash, numberTo0x(randomBlock.count), requestDetails];
135+
const errMessage = "Cannot read properties of null (reading 'substring')";
136+
137+
await RelayAssertions.assertRejection(
138+
predefined.INTERNAL_ERROR(errMessage),
139+
ethImpl.getTransactionByBlockHashAndIndex,
140+
true,
141+
ethImpl,
142+
args,
143+
);
137144
});
138145

139146
it('eth_getTransactionByBlockHashAndIndex with no contract result match', async function () {

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ describe('@ethGetTransactionByBlockNumberAndIndex using MirrorNode', async funct
159159
expect(result).to.equal(null);
160160
});
161161

162-
it('eth_getTransactionByBlockNumberAndIndex should NOT throw for internal error if `from` field is null', async function () {
162+
it('eth_getTransactionByBlockNumberAndIndex should throw for internal error', async function () {
163163
const defaultContractResultsWithNullableFrom = _.cloneDeep(defaultContractResults);
164164
defaultContractResultsWithNullableFrom.results[0].from = null;
165165
const randomBlock = {
@@ -170,14 +170,16 @@ describe('@ethGetTransactionByBlockNumberAndIndex using MirrorNode', async funct
170170
.onGet(contractResultsByNumberByIndexURL(randomBlock.number, randomBlock.count))
171171
.reply(200, defaultContractResultsWithNullableFrom);
172172

173-
const result = await ethImpl.getTransactionByBlockNumberAndIndex(
174-
numberTo0x(randomBlock.number),
175-
numberTo0x(randomBlock.count),
176-
requestDetails,
177-
);
173+
const args = [numberTo0x(randomBlock.number), numberTo0x(randomBlock.count), requestDetails];
174+
const errMessage = "Cannot read properties of null (reading 'substring')";
178175

179-
expect(result).to.not.be.null;
180-
expect(result.from).to.be.null;
176+
await RelayAssertions.assertRejection(
177+
predefined.INTERNAL_ERROR(errMessage),
178+
ethImpl.getTransactionByBlockNumberAndIndex,
179+
true,
180+
ethImpl,
181+
args,
182+
);
181183
});
182184

183185
it('eth_getTransactionByBlockNumberAndIndex with no contract results', async function () {

packages/relay/tests/lib/formatters.spec.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,6 @@ describe('Formatters', () => {
340340
const formattedResult = formatContractResult({ ...contractResult, type: undefined });
341341
expect(formattedResult).to.be.null;
342342
});
343-
344-
it('Should return formatted result even when `from` and `hash` fields are null', () => {
345-
const formattedResult: any = formatContractResult({ ...contractResult, from: null, hash: null, to: null });
346-
347-
expect(formattedResult).to.not.be.undefined;
348-
expect(formattedResult.from).to.be.null;
349-
expect(formattedResult.hash).to.be.null;
350-
expect(formattedResult.to).to.be.null;
351-
});
352343
});
353344

354345
describe('prepend0x', () => {

0 commit comments

Comments
 (0)