Skip to content

Commit 6d40673

Browse files
fix: adds acceptance test toAddress is null and to field is missing (#4455)
Signed-off-by: Konstantina Blazhukova <konstantina.blajukova@gmail.com> Signed-off-by: Logan Nguyen <logan.nguyen@swirldslabs.com> Co-authored-by: Logan Nguyen <logan.nguyen@swirldslabs.com>
1 parent b08791d commit 6d40673

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,7 @@ describe('@ethGetTransactionByHash eth_getTransactionByHash tests', async functi
242242
.onGet(`contracts/results/${uniqueTxHash}`)
243243
.reply(200, JSON.stringify(detailedResultsWithNullNullableValues));
244244
const result = await ethImpl.getTransactionByHash(uniqueTxHash, requestDetails);
245-
expect(result).to.not.be.null;
246-
247-
expect(result).to.exist;
248-
if (result) expect(result.gas).to.eq('0x0');
245+
expect(result!.gas).to.eq('0x0');
249246
});
250247

251248
it('handles transactions with null amount', async function () {
@@ -259,10 +256,7 @@ describe('@ethGetTransactionByHash eth_getTransactionByHash tests', async functi
259256
.onGet(`contracts/results/${uniqueTxHash}`)
260257
.reply(200, JSON.stringify(detailedResultsWithNullNullableValues));
261258
const result = await ethImpl.getTransactionByHash(uniqueTxHash, requestDetails);
262-
expect(result).to.not.be.null;
263-
264-
expect(result).to.exist;
265-
if (result) expect(result.value).to.eq('0x0');
259+
expect(result!.value).to.eq('0x0');
266260
});
267261

268262
it('handles transactions with v as null', async function () {
@@ -277,10 +271,7 @@ describe('@ethGetTransactionByHash eth_getTransactionByHash tests', async functi
277271
.onGet(`contracts/results/${uniqueTxHash}`)
278272
.reply(200, JSON.stringify(detailedResultsWithNullNullableValues));
279273
const result = await ethImpl.getTransactionByHash(uniqueTxHash, requestDetails);
280-
expect(result).to.not.be.null;
281-
282-
expect(result).to.exist;
283-
if (result) expect(result.v).to.eq('0x0');
274+
expect(result!.v).to.eq('0x0');
284275
});
285276

286277
it('should throw an error if transaction_index is falsy', async function () {
@@ -298,7 +289,6 @@ describe('@ethGetTransactionByHash eth_getTransactionByHash tests', async functi
298289
await ethImpl.getTransactionByHash(uniqueTxHash, requestDetails);
299290
expect.fail('should have thrown an error');
300291
} catch (error) {
301-
expect(error).to.exist;
302292
expect(error).to.eq(predefined.DEPENDENT_SERVICE_IMMATURE_RECORDS);
303293
}
304294
});
@@ -317,7 +307,6 @@ describe('@ethGetTransactionByHash eth_getTransactionByHash tests', async functi
317307
await ethImpl.getTransactionByHash(uniqueTxHash, requestDetails);
318308
expect.fail('should have thrown an error');
319309
} catch (error) {
320-
expect(error).to.exist;
321310
expect(error).to.eq(predefined.DEPENDENT_SERVICE_IMMATURE_RECORDS);
322311
}
323312
});
@@ -338,7 +327,6 @@ describe('@ethGetTransactionByHash eth_getTransactionByHash tests', async functi
338327
await ethImpl.getTransactionByHash(uniqueTxHash, requestDetails);
339328
expect.fail('should have thrown an error');
340329
} catch (error) {
341-
expect(error).to.exist;
342330
expect(error).to.eq(predefined.DEPENDENT_SERVICE_IMMATURE_RECORDS);
343331
}
344332
});
@@ -355,4 +343,17 @@ describe('@ethGetTransactionByHash eth_getTransactionByHash tests', async functi
355343
maxPriorityFeePerGas: '0x43',
356344
});
357345
});
346+
347+
it('returns to field for transaction with contract revert on contract creation', async function () {
348+
const detailedResultsWithNullTo = {
349+
...defaultDetailedContractResultByHash,
350+
to: null,
351+
};
352+
353+
const uniqueTxHash = '0x15aad7b827375d12d73af57b6a3e84353645fd31305ea58ff52dda53ec640533';
354+
355+
restMock.onGet(`contracts/results/${uniqueTxHash}`).reply(200, JSON.stringify(detailedResultsWithNullTo));
356+
const result = await ethImpl.getTransactionByHash(uniqueTxHash, requestDetails);
357+
expect(result?.to).to.eq(null);
358+
});
358359
});

packages/server/tests/acceptance/rpc_batch1.spec.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
733733
expect(res).to.be.null;
734734
});
735735

736-
it('should execute "eth_getBlockReceipts" for a block that contains synthetic transaction', async function() {
736+
it('should execute "eth_getBlockReceipts" for a block that contains synthetic transaction', async function () {
737737
const tokenId = await servicesNode.createToken(1000);
738738
await accounts[2].client.associateToken(tokenId);
739739
const transaction = new TransferTransaction()
@@ -754,7 +754,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
754754

755755
const receipts = await relay.call(RelayCalls.ETH_ENDPOINTS.ETH_GET_BLOCK_RECEIPTS, [formattedBlockNumber]);
756756
expect(receipts).to.not.be.empty;
757-
expect(receipts.filter(receipt => receipt.transactionHash === transactionHash)).to.not.be.empty;
757+
expect(receipts.filter((receipt) => receipt.transactionHash === transactionHash)).to.not.be.empty;
758758
});
759759
});
760760

@@ -2019,6 +2019,27 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
20192019
]);
20202020
expect(res).to.be.null;
20212021
});
2022+
2023+
it('@release getTransactionByHash should return null for to for reverted contract creation', async function () {
2024+
// the data below is actually disassembled opcodes
2025+
// containing revert as well
2026+
const dataToRevert = '0x600160015560006000fd';
2027+
const gasPrice = await relay.gasPrice();
2028+
const transaction = {
2029+
...defaultLondonTransactionData,
2030+
to: null,
2031+
data: dataToRevert,
2032+
nonce: await relay.getAccountNonce(accounts[2].address),
2033+
maxPriorityFeePerGas: gasPrice,
2034+
maxFeePerGas: gasPrice,
2035+
};
2036+
const signedTx = await accounts[2].wallet.signTransaction(transaction);
2037+
const transactionHash = await relay.sendRawTransaction(signedTx);
2038+
2039+
const res = await relay.call(RelayCalls.ETH_ENDPOINTS.ETH_GET_TRANSACTION_BY_HASH, [transactionHash]);
2040+
2041+
expect(res.to).to.be.null;
2042+
});
20222043
});
20232044
});
20242045
});

0 commit comments

Comments
 (0)