Skip to content

Commit f642c83

Browse files
authored
Add acceptance test for getStorageAt (#664)
* Add getStorageAt test Signed-off-by: lukelee-sl <[email protected]> * fix test to call contract function Signed-off-by: lukelee-sl <[email protected]> * update name of test Signed-off-by: lukelee-sl <[email protected]> * fix getStorageAt test Signed-off-by: lukelee-sl <[email protected]> Signed-off-by: lukelee-sl <[email protected]>
1 parent b3864c1 commit f642c83

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ import TokenCreateJson from '../contracts/TokenCreateContract.json';
3030
// local resources
3131
import parentContractJson from '../contracts/Parent.json';
3232
import basicContractJson from '../contracts/Basic.json';
33+
import storageContractJson from '../contracts/Storage.json';
3334
import reverterContractJson from '../contracts/Reverter.json';
3435
import logsContractJson from '../contracts/Logs.json';
3536
import { predefined } from '../../../relay/src/lib/errors/JsonRpcError';
3637
import { EthImpl } from '@hashgraph/json-rpc-relay/src/lib/eth';
3738
import constants from '@hashgraph/json-rpc-relay/src/lib/constants';
39+
import { resourceLimits } from 'worker_threads';
3840

3941
describe('@api RPC Server Acceptance Tests', function () {
4042
this.timeout(240 * 1000); // 240 seconds
@@ -1162,6 +1164,52 @@ describe('@api RPC Server Acceptance Tests', function () {
11621164
});
11631165
});
11641166

1167+
// Test state changes with getStorageAt
1168+
describe('eth_getStorageAt', () => {
1169+
let storageContract, contractId, evmAddress;
1170+
const STORAGE_CONTRACT_UPDATE = "0x2de4e884";
1171+
1172+
before(async () => {
1173+
storageContract = await servicesNode.deployContract(storageContractJson);
1174+
// Wait for creation to propagate
1175+
await mirrorNode.get(`/contracts/${storageContract.contractId}`);
1176+
1177+
contractId = storageContract.contractId;
1178+
evmAddress = `0x${storageContract.contractId.toSolidityAddress()}`;
1179+
});
1180+
1181+
it('should execute "eth_getStorageAt" request to get state changes', async function () {
1182+
const BEGIN_EXPECTED_STORAGE_VAL = "0x000000000000000000000000000000000000000000000000000000000000000f";
1183+
const END_EXPECTED_STORAGE_VAL = "0x0000000000000000000000000000000000000000000000000000000000000008";
1184+
1185+
const beginStorageVal = await relay.call('eth_getStorageAt', [`${contractId}`, '0x', 'latest'] );
1186+
expect(beginStorageVal).to.eq(BEGIN_EXPECTED_STORAGE_VAL)
1187+
1188+
const gasPrice = await relay.gasPrice();
1189+
const transaction = {
1190+
value: 0,
1191+
gasLimit: 50000,
1192+
chainId: Number(CHAIN_ID),
1193+
to: evmAddress,
1194+
nonce: await relay.getAccountNonce(accounts[1].address),
1195+
gasPrice: gasPrice,
1196+
data: STORAGE_CONTRACT_UPDATE,
1197+
maxPriorityFeePerGas: gasPrice,
1198+
maxFeePerGas: gasPrice,
1199+
type: 2
1200+
};
1201+
1202+
const signedTx = await accounts[1].wallet.signTransaction(transaction);
1203+
await relay.call('eth_sendRawTransaction', [signedTx]);
1204+
1205+
// wait for the transaction to propogate to mirror node
1206+
await new Promise(r => setTimeout(r, 2000));
1207+
1208+
const storageVal = await relay.call('eth_getStorageAt', [`${contractId}`, '0x', 'latest'] );
1209+
expect(storageVal).to.eq(END_EXPECTED_STORAGE_VAL)
1210+
});
1211+
});
1212+
11651213
// Only run the following tests against a local node since they only work with the genesis account
11661214
if (process.env.LOCAL_NODE && process.env.LOCAL_NODE !== 'false') {
11671215
describe('Gas Price related RPC endpoints', () => {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"_format": "hh-sol-artifact-1",
3+
"contractName": "Storage",
4+
"sourceName": "contracts/Storage.sol",
5+
"abi": [
6+
{
7+
"inputs": [],
8+
"name": "updateStoredUInt",
9+
"outputs": [],
10+
"stateMutability": "nonpayable",
11+
"type": "function"
12+
}
13+
],
14+
"bytecode": "0x6080604052600f600055348015601457600080fd5b50606e8060226000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80632de4e88414602d575b600080fd5b60366008600055565b00fea26469706673582212204f4929609314772906604fbf3fa15708239abd76b6d2a022fa89ae0e0b888bb264736f6c63430008090033",
15+
"deployedBytecode": "0x6080604052348015600f57600080fd5b506004361060285760003560e01c80632de4e88414602d575b600080fd5b60366008600055565b00fea26469706673582212204f4929609314772906604fbf3fa15708239abd76b6d2a022fa89ae0e0b888bb264736f6c63430008090033",
16+
"linkReferences": {},
17+
"deployedLinkReferences": {}
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity >=0.5.0 <0.9.0;
3+
4+
contract Storage {
5+
uint storedUint = 15;
6+
7+
function updateStoredUInt() public {
8+
storedUint = 8;
9+
}
10+
}

0 commit comments

Comments
 (0)