Skip to content

Commit e3188c1

Browse files
authored
chore: cherry picked 2492 (#2513)
fix: removed `RESOURCE_NOT_FOUND` error in eth_getStorageAt when response is null (#2492) fix: removed RESOURCE_NOT_FOUND error in eth_getStorageAt when response is null Signed-off-by: Logan Nguyen <[email protected]>
1 parent de412ad commit e3188c1

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

packages/relay/src/lib/eth.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -831,12 +831,7 @@ export class EthImpl implements Eth {
831831
await this.mirrorNodeClient
832832
.getContractStateByAddressAndSlot(address, slot, blockEndTimestamp, requestIdPrefix)
833833
.then((response) => {
834-
if (response === null) {
835-
throw predefined.RESOURCE_NOT_FOUND(
836-
`Cannot find current state for contract address ${address} at slot=${slot}`,
837-
);
838-
}
839-
if (response.state.length > 0) {
834+
if (response !== null && response.state.length > 0) {
840835
result = response.state[0].value;
841836
}
842837
})

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import path from 'path';
2121
import dotenv from 'dotenv';
2222
import { expect, use } from 'chai';
23+
import { ethers } from 'ethers';
2324
import sinon from 'sinon';
2425
import chaiAsPromised from 'chai-as-promised';
2526

@@ -267,23 +268,20 @@ describe('@ethGetStorageAt eth_getStorageAt spec', async function () {
267268
expect(result).to.equal(DEFAULT_OLDER_CONTRACT_STATE.state[0].value);
268269
});
269270

270-
it('eth_getStorageAt should throw error when contract not found', async function () {
271+
it('eth_getStorageAt should return Zero Hash when address is not found', async function () {
271272
// mirror node request mocks
272273
restMock
273274
.onGet(
274275
`contracts/${CONTRACT_ADDRESS_1}/state?timestamp=${DEFAULT_BLOCK.timestamp.to}&slot=${DEFAULT_OLDER_CONTRACT_STATE.state[0].slot}&limit=100&order=desc`,
275276
)
276277
.reply(404, DETAILD_CONTRACT_RESULT_NOT_FOUND);
277278

278-
const args = [CONTRACT_ADDRESS_1, defaultDetailedContractResults.state_changes[0].slot, numberTo0x(BLOCK_NUMBER)];
279-
280-
await RelayAssertions.assertRejection(
281-
predefined.RESOURCE_NOT_FOUND(),
282-
ethImpl.getStorageAt,
283-
false,
284-
ethImpl,
285-
args,
279+
const result = await ethImpl.getStorageAt(
280+
CONTRACT_ADDRESS_1,
281+
DEFAULT_OLDER_CONTRACT_STATE.state[0].slot,
282+
numberTo0x(OLDER_BLOCK.number),
286283
);
284+
expect(result).to.equal(ethers.ZeroHash);
287285
});
288286
});
289287
});

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,19 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
10381038
);
10391039
expect(storageVal).to.eq(EXPECTED_STORAGE_VAL);
10401040
});
1041+
1042+
it('should execute "eth_getStorageAt" request against an inactive address (contains no data) and receive a 32-byte-zero-hex string ', async function () {
1043+
const hexString = ethers.ZeroHash;
1044+
const inactiveAddress = ethers.Wallet.createRandom();
1045+
1046+
const storageVal = await relay.call(
1047+
RelayCalls.ETH_ENDPOINTS.ETH_GET_STORAGE_AT,
1048+
[inactiveAddress.address, '0x0', 'latest'],
1049+
requestId,
1050+
);
1051+
1052+
expect(storageVal).to.eq(hexString);
1053+
});
10411054
});
10421055

10431056
// Only run the following tests against a local node since they only work with the genesis account

0 commit comments

Comments
 (0)