Skip to content

Commit

Permalink
eth_getStorageAt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shunjizhan committed Oct 8, 2024
1 parent c9db8a6 commit 56b9f42
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 97 deletions.
1 change: 0 additions & 1 deletion packages/eth-providers/src/__tests__/parseBlock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ describe.concurrent('getAllReceiptsAtBlock', () => {
});

afterAll(async () => {
await sleep(10_000);
await apiK.disconnect();
await apiA.disconnect();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ describe('finalized/safe/pending blocktag', () => {
expect(Number(res)).to.equal(Number(resP) - 1); // pending should have +1 nonce

await token.deployed(); // wait for deployment in case it affects next tests

const resL = (await eth_getTransactionCount([wallet.address, 'latest'])).data.result;
expect(resL).to.equal(resP);
});

it('eth_getBalance', async () => {
Expand Down
95 changes: 0 additions & 95 deletions packages/eth-rpc-adapter/src/__tests__/endpoint-tests/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,101 +609,6 @@ describe('endpoint', () => {
});
});


describe('eth_getBlockByNumber', () => {
if (process.env.SKIP_PUBLIC) {
console.log('public karura tests are skipped ❗');
return;
}

it('when there are 0 EVM transactions', async () => {
const resFull = (await eth_getBlockByNumber_karura([1818188, true])).data.result;
const res = (await eth_getBlockByNumber_karura([1818188, false])).data.result;

expect(resFull).toMatchSnapshot();
expect(res).toMatchSnapshot();
});

it('when there are 1 EVM transactions', async () => {
const resFull = (await eth_getBlockByNumber_karura([1818518, true])).data.result;
const res = (await eth_getBlockByNumber_karura([1818518, false])).data.result;

expect(resFull).toMatchSnapshot();
expect(res).toMatchSnapshot();
});

it('when there are >= 2 EVM transactions', async () => {
const resFull = (await eth_getBlockByNumber_karura([2449983, true])).data.result;
const res = (await eth_getBlockByNumber_karura([2449983, false])).data.result;

expect(resFull).toMatchSnapshot();
expect(res).toMatchSnapshot();
});

it('for very old runtime', async () => {
const resFull = (await eth_getBlockByNumber_karura([372268, true])).data.result;
const res = (await eth_getBlockByNumber_karura([372268, false])).data.result;

expect(resFull).toMatchSnapshot();
expect(res).toMatchSnapshot();
});
});

describe('eth_getBalance', () => {
it('get correct balance', async () => {
const block8Balance = 8999995192165097994000000n; // edit me for different mandala version
expect(BigInt((await eth_getBalance([ADDRESS_ALICE, 8])).data.result)).to.equal(block8Balance);
expect(BigInt((await eth_getBalance([ADDRESS_ALICE, '0x8'])).data.result)).to.equal(block8Balance);
expect(BigInt((await eth_getBalance([ADDRESS_ALICE, { blockNumber: 8 }])).data.result)).to.equal(block8Balance);

const curBlock = (await eth_blockNumber([])).data.result;
expect(Number((await eth_getBalance([ADDRESS_ALICE, { blockNumber: curBlock }])).data.result)).to.equal(
Number((await eth_getBalance([ADDRESS_ALICE, 'latest'])).data.result)
);
});
});

describe('eth_getTransactionCount', () => {
it('get correct transaction', async () => {
expect(Number((await eth_getTransactionCount([ADDRESS_ALICE, 1])).data.result)).to.equal(0);
expect(Number((await eth_getTransactionCount([ADDRESS_ALICE, '0x5'])).data.result)).to.equal(1);
expect(Number((await eth_getTransactionCount([ADDRESS_ALICE, { blockNumber: 8 }])).data.result)).to.equal(4);

const curBlock = (await eth_blockNumber([])).data.result;
expect(Number((await eth_getTransactionCount([ADDRESS_ALICE, { blockNumber: curBlock }])).data.result)).to.equal(
Number((await eth_getTransactionCount([ADDRESS_ALICE, 'latest'])).data.result)
);
});
});

describe('eth_getStorageAt', () => {
if (process.env.SKIP_PUBLIC) {
console.log('public karura tests are skipped ❗');
return;
}

it('get correct storage from public karura', async () => {
const contractAddr = '0x1f3a10587a20114ea25ba1b388ee2dd4a337ce27';
expect(
(
await eth_getStorageAt_karura([
contractAddr,
'0x0000000000000000000000000000000000000000000000000000000000000000',
2000000,
])
).data.result
).to.equal('0x55534420436f696e000000000000000000000000000000000000000000000010');

expect((await eth_getStorageAt_karura([contractAddr, '0x0', 2000000])).data.result).to.equal(
'0x55534420436f696e000000000000000000000000000000000000000000000010'
);

expect((await eth_getStorageAt_karura([contractAddr, '0x3', 2000000])).data.result).to.equal(
'0x000000000000000000000000000000000000000000000000000000070d785f88'
);
});
});

describe('eth_newBlockFilter', () => {
const provider = new EvmRpcProvider(NODE_RPC_URL);
const aca = new Contract(ADDRESS.ACA, TokenABI.abi, wallet1.connect(provider));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, expect, it } from 'vitest';

import { deployErc20, eth_getStorageAt, testSetup } from '../utils';
import { hexZeroPad, parseEther } from 'ethers/lib/utils';

const { wallet } = testSetup;

describe('eth_getStorageAt', () => {
it('get correct storage', async () => {
const token = await deployErc20(wallet);

const _getStorageAtForToken = async (slot: string) => {
return (await eth_getStorageAt([token.address, slot, 'latest'])).data.result;
};

const totalSupplyStorage = hexZeroPad(parseEther('1000000000').toHexString(), 32);

expect((await _getStorageAtForToken('0x0000000000000000000000000000000000000000000000000000000000000000'))).to.equal(totalSupplyStorage);
expect((await _getStorageAtForToken('0x0'))).to.equal(totalSupplyStorage);

expect((await _getStorageAtForToken('0x1'))).to.equal(
'0x0000000000000000000000000000000000000000000000000000000000000000'
);

expect((await _getStorageAtForToken('0x2'))).to.equal(
'0x0000000000000000000000000000000000000000000000000000000000000000'
);

expect((await _getStorageAtForToken('0x3'))).to.equal(
'0x54657374546f6b656e0000000000000000000000000000000000000000000012'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ export const eth_blockNumber_karura = rpcGet('eth_blockNumber', KARURA_ETH_RPC_U
export const eth_getTransactionReceipt_karura = rpcGet('eth_getTransactionReceipt', KARURA_ETH_RPC_URL);
export const eth_getTransactionByHash_karura = rpcGet('eth_getTransactionByHash', KARURA_ETH_RPC_URL);
export const eth_getBlockByNumber_karura = rpcGet('eth_getBlockByNumber', KARURA_ETH_RPC_URL);
export const eth_getStorageAt_karura = rpcGet('eth_getStorageAt', KARURA_ETH_RPC_URL);
export const eth_getStorageAt = rpcGet('eth_getStorageAt', ETH_RPC_URL);

0 comments on commit 56b9f42

Please sign in to comment.