Skip to content

Commit 97ae22a

Browse files
authored
Use evm_address from mirror node query of recently deployed contracts to populate the transaction receipt result (#686)
* Get the contract's evm_address Signed-off-by: nikolay <[email protected]> * Add test with evm address Signed-off-by: nikolay <[email protected]> Signed-off-by: nikolay <[email protected]>
1 parent f642c83 commit 97ae22a

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

packages/relay/src/lib/eth.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,11 +1006,12 @@ export class EthImpl implements Eth {
10061006
receiptResponse.max_fee_per_gas === undefined || receiptResponse.max_fee_per_gas == '0x'
10071007
? receiptResponse.gas_price
10081008
: receiptResponse.max_fee_per_gas;
1009-
const createdContract =
1010-
receiptResponse.created_contract_ids.length > 0
1011-
? EthImpl.prepend0x(ContractId.fromString(receiptResponse.created_contract_ids[0]).toSolidityAddress())
1012-
: undefined;
10131009

1010+
let createdContract;
1011+
if (receiptResponse.created_contract_ids.length) {
1012+
const contract = await this.mirrorNodeClient.getContract(receiptResponse.created_contract_ids[0]);
1013+
createdContract = contract?.evm_address ?? EthImpl.prepend0x(ContractId.fromString(receiptResponse.created_contract_ids[0]).toSolidityAddress());
1014+
}
10141015

10151016
// support stricter go-eth client which requires the transaction hash property on logs
10161017
const logs = receiptResponse.logs.map(log => {

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,6 +2136,7 @@ describe('Eth', async function () {
21362136
ethImpl = new EthImpl(null, mirrorNodeInstance, logger);
21372137
});
21382138

2139+
const contractEvmAddress = '0xd8db0b1dbf8ba6721ef5256ad5fe07d72d1d04b9';
21392140
const defaultTxHash = '0x4a563af33c4871b51a8b108aa2fe1dd5280a30dfb7236170ae5e5e7957eb6392';
21402141
const defaultTransaction = {
21412142
"accessList": undefined,
@@ -2353,6 +2354,7 @@ describe('Eth', async function () {
23532354
it('valid receipt on match', async function () {
23542355
// mirror node request mocks
23552356
mock.onGet(`contracts/results/${defaultTxHash}`).reply(200, defaultDetailedContractResultByHash);
2357+
mock.onGet(`contracts/${defaultDetailedContractResultByHash.created_contract_ids[0]}`).reply(404);
23562358
const receipt = await ethImpl.getTransactionReceipt(defaultTxHash);
23572359

23582360
// Assert the data format
@@ -2390,6 +2392,24 @@ describe('Eth', async function () {
23902392
expect(receipt.effectiveGasPrice).to.eq(defaultReceipt.effectiveGasPrice);
23912393
});
23922394

2395+
it('valid receipt with evm address on match', async function() {
2396+
// mirror node request mocks
2397+
mock.onGet(`contracts/results/${defaultTxHash}`).reply(200, defaultDetailedContractResultByHash);
2398+
mock.onGet(`contracts/${defaultDetailedContractResultByHash.created_contract_ids[0]}`).reply(200, {
2399+
evm_address: contractEvmAddress
2400+
});
2401+
const receipt = await ethImpl.getTransactionReceipt(defaultTxHash);
2402+
2403+
expect(receipt).to.exist;
2404+
if (receipt == null) return;
2405+
2406+
expect(validateHash(receipt.from, 40)).to.eq(true);
2407+
if (receipt.contractAddress) {
2408+
expect(validateHash(receipt.contractAddress, 40)).to.eq(true);
2409+
}
2410+
expect(receipt.contractAddress).to.eq(contractEvmAddress);
2411+
});
2412+
23932413
it("Handles null effectiveGasPrice", async function() {
23942414
const contractResult = {
23952415
...defaultDetailedContractResultByHash,
@@ -2398,6 +2418,7 @@ describe('Eth', async function () {
23982418
};
23992419

24002420
mock.onGet(`contracts/results/${defaultTxHash}`).reply(200, contractResult);
2421+
mock.onGet(`contracts/${defaultDetailedContractResultByHash.created_contract_ids[0]}`).reply(404);
24012422
const receipt = await ethImpl.getTransactionReceipt(defaultTxHash);
24022423

24032424
expect(receipt).to.exist;
@@ -2412,6 +2433,7 @@ describe('Eth', async function () {
24122433
bloom: '0x'
24132434
};
24142435
mock.onGet(`contracts/results/${defaultTxHash}`).reply(200, receiptWith0xBloom);
2436+
mock.onGet(`contracts/${defaultDetailedContractResultByHash.created_contract_ids[0]}`).reply(404);
24152437
const receipt = await ethImpl.getTransactionReceipt(defaultTxHash);
24162438

24172439
expect(receipt).to.exist;
@@ -2426,6 +2448,7 @@ describe('Eth', async function () {
24262448
};
24272449

24282450
mock.onGet(`contracts/results/${defaultTxHash}`).reply(200, receiptWithErrorMessage);
2451+
mock.onGet(`contracts/${defaultDetailedContractResultByHash.created_contract_ids[0]}`).reply(404);
24292452
const receipt = await ethImpl.getTransactionReceipt(defaultTxHash);
24302453

24312454
expect(receipt).to.exist;
@@ -2438,6 +2461,7 @@ describe('Eth', async function () {
24382461
gas_used: null
24392462
};
24402463
mock.onGet(`contracts/results/${defaultTxHash}`).reply(200, receiptWithNullGasUsed);
2464+
mock.onGet(`contracts/${defaultDetailedContractResultByHash.created_contract_ids[0]}`).reply(404);
24412465
const receipt = await ethImpl.getTransactionReceipt(defaultTxHash);
24422466

24432467
expect(receipt).to.exist;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ describe("Open RPC Specification", function () {
327327
});
328328

329329
it('should execute "eth_getTransactionReceipt"', async function () {
330+
mock.onGet(`contracts/${defaultDetailedContractResultByHash.created_contract_ids[0]}`).reply(404);
330331
const response = await ethImpl.getTransactionReceipt(defaultTxHash);
331332

332333
validateResponseSchema(methodsResponseSchema.eth_getTransactionReceipt, response);

0 commit comments

Comments
 (0)