Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
add pending block check to eth_getStorageAt test
Browse files Browse the repository at this point in the history
  • Loading branch information
MicaiahReid committed Aug 25, 2022
1 parent 9f7f1b8 commit 16d9346
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions src/chains/ethereum/ethereum/tests/api/eth/getStorageAt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,27 @@ describe("api", () => {
describe("getStorageAt", () => {
let provider: EthereumProvider;
let contract: CompileOutput;
let contractAddress: string;
// we can preset the contract address because we have the wallet in
// deterministic mode. this allows us to get the storage at the contract
// address for the pending block before the contract is actually
// deployed
let contractAddress = "0xe78a0f7e598cc8b0bb87894b0f60dd2a88d6a8ab";
let contractMethods: any;
let pendingStorage0: string, pendingStorage1: string;

before(() => {
contract = compile(join(__dirname, "./contracts/GetStorageAt.sol"));
});

beforeEach(async () => {
provider = await getProvider({
miner: { defaultTransactionGasLimit: 6721975 }
miner: { defaultTransactionGasLimit: 6721975 },
wallet: { deterministic: true }
});
const accounts = await provider.send("eth_accounts");
const from = accounts[0];

await provider.send("miner_stop");
await provider.send("eth_subscribe", ["newHeads"]);

const transactionHash = await provider.send("eth_sendTransaction", [
Expand All @@ -32,14 +39,28 @@ describe("api", () => {
data: contract.code
}
]);

pendingStorage0 = await provider.send("eth_getStorageAt", [
contractAddress,
"0x0",
"pending"
]);
pendingStorage1 = await provider.send("eth_getStorageAt", [
contractAddress,
"0x1",
"pending"
]);
await provider.send("miner_start");
await provider.once("message");

const receipt = await provider.send("eth_getTransactionReceipt", [
transactionHash
]);

contractAddress = receipt.contractAddress;
assert.strictEqual(
contractAddress,
receipt.contractAddress,
"Deployed contract address is not the expected address."
);
contractMethods = contract.contract.evm.methodIdentifiers;
});

Expand All @@ -56,6 +77,19 @@ describe("api", () => {
assert.strictEqual(result2, "0x01");
});

it("returns the value at the hex position when 'pending' tag is passed, before the contract is deployed", async () => {
assert.strictEqual(
BigInt(pendingStorage0),
123n,
"Unexpected storage value for key 0 in pending block."
);
assert.strictEqual(
pendingStorage1,
"0x01",
"Unexpected storage value for key 1 in pending block."
);
});

it("returns the value at the 32-byte hex position", async () => {
const result = await provider.send("eth_getStorageAt", [
contractAddress,
Expand Down

0 comments on commit 16d9346

Please sign in to comment.