Skip to content

Commit

Permalink
fix: removed RESOURCE_NOT_FOUND error in eth_getStorageAt when resp…
Browse files Browse the repository at this point in the history
…onse is null (#2492)

fix: removed RESOURCE_NOT_FOUND error in eth_getStorageAt when response is null

Signed-off-by: Logan Nguyen <[email protected]>
  • Loading branch information
quiet-node committed May 20, 2024
1 parent de412ad commit bd9ab17
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
7 changes: 1 addition & 6 deletions packages/relay/src/lib/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,12 +831,7 @@ export class EthImpl implements Eth {
await this.mirrorNodeClient
.getContractStateByAddressAndSlot(address, slot, blockEndTimestamp, requestIdPrefix)
.then((response) => {
if (response === null) {
throw predefined.RESOURCE_NOT_FOUND(
`Cannot find current state for contract address ${address} at slot=${slot}`,
);
}
if (response.state.length > 0) {
if (response !== null && response.state.length > 0) {
result = response.state[0].value;
}
})
Expand Down
16 changes: 7 additions & 9 deletions packages/relay/tests/lib/eth/eth_getStorageAt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import path from 'path';
import dotenv from 'dotenv';
import { expect, use } from 'chai';
import { ethers } from 'ethers';
import sinon from 'sinon';
import chaiAsPromised from 'chai-as-promised';

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

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

const args = [CONTRACT_ADDRESS_1, defaultDetailedContractResults.state_changes[0].slot, numberTo0x(BLOCK_NUMBER)];

await RelayAssertions.assertRejection(
predefined.RESOURCE_NOT_FOUND(),
ethImpl.getStorageAt,
false,
ethImpl,
args,
const result = await ethImpl.getStorageAt(
CONTRACT_ADDRESS_1,
DEFAULT_OLDER_CONTRACT_STATE.state[0].slot,
numberTo0x(OLDER_BLOCK.number),
);
expect(result).to.equal(ethers.ZeroHash);
});
});
});
13 changes: 13 additions & 0 deletions packages/server/tests/acceptance/rpc_batch2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,19 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
);
expect(storageVal).to.eq(EXPECTED_STORAGE_VAL);
});

it('should execute "eth_getStorageAt" request against an inactive address (contains no data) and receive a 32-byte-zero-hex string ', async function () {
const hexString = ethers.ZeroHash;
const inactiveAddress = ethers.Wallet.createRandom();

const storageVal = await relay.call(
RelayCalls.ETH_ENDPOINTS.ETH_GET_STORAGE_AT,
[inactiveAddress.address, '0x0', 'latest'],
requestId,
);

expect(storageVal).to.eq(hexString);
});
});

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

0 comments on commit bd9ab17

Please sign in to comment.