2019-01-06 19:19:48 +00:00
|
|
|
# Nimbus
|
2024-01-09 02:05:52 +00:00
|
|
|
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
2019-01-06 19:19:48 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2018-07-26 21:48:01 +00:00
|
|
|
import
|
2024-11-02 09:30:45 +00:00
|
|
|
chronicles,
|
2024-01-09 02:05:52 +00:00
|
|
|
std/[json, os, typetraits, times, sequtils],
|
2023-12-08 09:35:50 +00:00
|
|
|
asynctest, web3/eth_api,
|
2024-01-09 02:05:52 +00:00
|
|
|
stew/byteutils,
|
2022-12-02 04:39:12 +00:00
|
|
|
json_rpc/[rpcserver, rpcclient],
|
2024-11-02 09:30:45 +00:00
|
|
|
eth/[rlp, trie/hexary_proof_verification],
|
|
|
|
eth/common/[transaction_utils, addresses],
|
|
|
|
../hive_integration/nodocker/engine/engine_client,
|
2024-06-17 07:56:39 +00:00
|
|
|
../nimbus/[constants, transaction, config, evm/state, evm/types, version],
|
2023-12-12 19:12:56 +00:00
|
|
|
../nimbus/db/[ledger, storage_types],
|
2022-05-13 16:30:10 +00:00
|
|
|
../nimbus/sync/protocol,
|
2022-12-02 04:39:12 +00:00
|
|
|
../nimbus/core/[tx_pool, chain, executor, executor/executor_helpers, pow/difficulty],
|
|
|
|
../nimbus/utils/utils,
|
|
|
|
../nimbus/common,
|
|
|
|
../nimbus/rpc,
|
2023-12-08 09:35:50 +00:00
|
|
|
../nimbus/rpc/rpc_types,
|
|
|
|
../nimbus/beacon/web3_eth_conv,
|
|
|
|
./test_helpers,
|
|
|
|
./macro_assembler,
|
|
|
|
./test_block_fixture
|
2018-07-26 21:48:01 +00:00
|
|
|
|
2020-07-30 07:21:11 +00:00
|
|
|
type
|
2024-10-16 01:34:12 +00:00
|
|
|
Hash32 = common.Hash32
|
|
|
|
Header = common.Header
|
2023-12-08 09:35:50 +00:00
|
|
|
|
2020-07-30 07:21:11 +00:00
|
|
|
TestEnv = object
|
2024-10-16 01:34:12 +00:00
|
|
|
txHash: Hash32
|
|
|
|
blockHash: Hash32
|
2020-07-30 07:21:11 +00:00
|
|
|
|
2024-12-18 04:04:23 +00:00
|
|
|
const
|
|
|
|
zeroHash = hash32"0x0000000000000000000000000000000000000000000000000000000000000000"
|
|
|
|
emptyCodeHash = hash32"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
|
|
|
|
emptyStorageHash = hash32"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
|
2023-12-08 09:35:50 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
proc verifyAccountProof(trustedStateRoot: Hash32, res: ProofResponse): MptProofVerificationResult =
|
2024-01-09 02:05:52 +00:00
|
|
|
let
|
2024-11-02 09:30:45 +00:00
|
|
|
key = toSeq(keccak256(res.address.data).data)
|
2024-01-09 02:05:52 +00:00
|
|
|
value = rlp.encode(Account(
|
|
|
|
nonce: res.nonce.uint64,
|
|
|
|
balance: res.balance,
|
2024-10-16 01:34:12 +00:00
|
|
|
storageRoot: res.storageHash,
|
|
|
|
codeHash: res.codeHash))
|
2024-01-09 02:05:52 +00:00
|
|
|
|
|
|
|
verifyMptProof(
|
|
|
|
seq[seq[byte]](res.accountProof),
|
2024-10-16 01:34:12 +00:00
|
|
|
trustedStateRoot,
|
2024-01-09 02:05:52 +00:00
|
|
|
key,
|
|
|
|
value)
|
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
proc verifySlotProof(trustedStorageRoot: Hash32, slot: StorageProof): MptProofVerificationResult =
|
2024-01-09 02:05:52 +00:00
|
|
|
let
|
2024-10-16 01:34:12 +00:00
|
|
|
key = toSeq(keccak256(toBytesBE(slot.key)).data)
|
2024-01-09 02:05:52 +00:00
|
|
|
value = rlp.encode(slot.value)
|
|
|
|
|
|
|
|
verifyMptProof(
|
|
|
|
seq[seq[byte]](slot.proof),
|
2024-10-16 01:34:12 +00:00
|
|
|
trustedStorageRoot,
|
2024-01-09 02:05:52 +00:00
|
|
|
key,
|
|
|
|
value)
|
|
|
|
|
2023-08-04 11:10:09 +00:00
|
|
|
proc persistFixtureBlock(chainDB: CoreDbRef) =
|
2022-06-29 15:44:08 +00:00
|
|
|
let header = getBlockHeader4514995()
|
|
|
|
# Manually inserting header to avoid any parent checks
|
2024-07-10 12:19:35 +00:00
|
|
|
discard chainDB.ctx.getKvt.put(genericHashKey(header.blockHash).toOpenArray, rlp.encode(header))
|
2024-11-02 09:30:45 +00:00
|
|
|
chainDB.addBlockNumberToHashLookup(header.number, header.blockHash)
|
2024-06-29 05:43:17 +00:00
|
|
|
chainDB.persistTransactions(header.number, header.txRoot, getBlockBody4514995().transactions)
|
|
|
|
chainDB.persistReceipts(header.receiptsRoot, getReceipts4514995())
|
2022-06-29 15:44:08 +00:00
|
|
|
|
2024-11-02 09:30:45 +00:00
|
|
|
proc setupClient(port: Port): RpcHttpClient =
|
|
|
|
let client = newRpcHttpClient()
|
|
|
|
waitFor client.connect("127.0.0.1", port, false)
|
|
|
|
return client
|
|
|
|
|
|
|
|
proc close(client: RpcHttpClient, server: RpcHttpServer) =
|
|
|
|
waitFor client.close()
|
|
|
|
waitFor server.closeWait()
|
|
|
|
|
|
|
|
|
|
|
|
# NOTE : The setup of the environment should have been done through the
|
|
|
|
# `ForkedChainRef`, however the `ForkedChainRef` is does not persist blocks to the db
|
|
|
|
# unless the base distance is reached. This is not the case for the tests, so we
|
|
|
|
# have to manually persist the blocks to the db.
|
|
|
|
# Main goal of the tests to check the RPC calls, can serve data persisted in the db
|
2024-11-03 00:11:24 +00:00
|
|
|
# as data from memory blocks are easily tested via kurtosis or other tests
|
2024-11-02 09:30:45 +00:00
|
|
|
proc setupEnv(signer, ks2: Address, ctx: EthContext, com: CommonRef): TestEnv =
|
2020-07-28 16:48:45 +00:00
|
|
|
var
|
2021-09-07 12:30:12 +00:00
|
|
|
acc = ctx.am.getAccount(signer).tryGet()
|
2024-11-02 09:30:45 +00:00
|
|
|
blockNumber = 1'u64
|
2024-11-07 01:24:21 +00:00
|
|
|
parent = com.db.getCanonicalHead().expect("canonicalHead exists")
|
2020-07-28 16:48:45 +00:00
|
|
|
parentHash = parent.blockHash
|
|
|
|
|
2024-11-02 09:30:45 +00:00
|
|
|
let code = evmByteCode:
|
2022-04-08 04:54:11 +00:00
|
|
|
Push4 "0xDEADBEEF" # PUSH
|
|
|
|
Push1 "0x00" # MSTORE AT 0x00
|
|
|
|
Mstore
|
|
|
|
Push1 "0x04" # RETURN LEN
|
|
|
|
Push1 "0x1C" # RETURN OFFSET at 28
|
|
|
|
Return
|
2020-07-28 16:48:45 +00:00
|
|
|
|
2022-01-18 16:19:32 +00:00
|
|
|
let
|
2024-10-16 01:34:12 +00:00
|
|
|
vmHeader = Header(parentHash: parentHash, gasLimit: 5_000_000)
|
2024-11-02 09:30:45 +00:00
|
|
|
vmState = BaseVMState()
|
|
|
|
vmState.init(parent, vmHeader, com)
|
2022-01-18 16:19:32 +00:00
|
|
|
|
|
|
|
vmState.stateDB.setCode(ks2, code)
|
2024-05-28 06:36:38 +00:00
|
|
|
vmState.stateDB.addBalance(
|
|
|
|
signer, 1.u256 * 1_000_000_000.u256 * 1_000_000_000.u256) # 1 ETH
|
2024-01-09 02:05:52 +00:00
|
|
|
|
|
|
|
# Test data created for eth_getProof tests
|
2024-12-18 04:04:23 +00:00
|
|
|
let regularAcc = address"0x0000000000000000000000000000000000000001"
|
2024-01-09 02:05:52 +00:00
|
|
|
vmState.stateDB.addBalance(regularAcc, 2_000_000_000.u256)
|
|
|
|
vmState.stateDB.setNonce(regularAcc, 1.uint64)
|
|
|
|
|
2024-12-18 04:04:23 +00:00
|
|
|
let contractAccWithStorage = address"0x0000000000000000000000000000000000000002"
|
2024-01-09 02:05:52 +00:00
|
|
|
vmState.stateDB.addBalance(contractAccWithStorage, 1_000_000_000.u256)
|
|
|
|
vmState.stateDB.setNonce(contractAccWithStorage, 2.uint64)
|
|
|
|
vmState.stateDB.setCode(contractAccWithStorage, code)
|
|
|
|
vmState.stateDB.setStorage(contractAccWithStorage, u256(0), u256(1234))
|
|
|
|
vmState.stateDB.setStorage(contractAccWithStorage, u256(1), u256(2345))
|
|
|
|
|
2024-12-18 04:04:23 +00:00
|
|
|
let contractAccNoStorage = address"0x0000000000000000000000000000000000000003"
|
2024-01-09 02:05:52 +00:00
|
|
|
vmState.stateDB.setCode(contractAccNoStorage, code)
|
|
|
|
|
|
|
|
|
2020-07-28 16:48:45 +00:00
|
|
|
let
|
2021-06-27 04:19:43 +00:00
|
|
|
unsignedTx1 = Transaction(
|
|
|
|
txType : TxLegacy,
|
2020-07-28 16:48:45 +00:00
|
|
|
nonce : 0,
|
2024-11-02 09:30:45 +00:00
|
|
|
gasPrice: uint64(30_000_000_000),
|
2020-07-28 16:48:45 +00:00
|
|
|
gasLimit: 70_000,
|
|
|
|
value : 1.u256,
|
2024-11-02 09:30:45 +00:00
|
|
|
to : Opt.some(zeroAddress),
|
2024-10-04 14:34:31 +00:00
|
|
|
chainId : com.chainId,
|
2020-07-28 16:48:45 +00:00
|
|
|
)
|
2021-06-27 04:19:43 +00:00
|
|
|
unsignedTx2 = Transaction(
|
|
|
|
txType : TxLegacy,
|
2023-04-11 08:28:45 +00:00
|
|
|
nonce : 1,
|
2024-11-02 09:30:45 +00:00
|
|
|
gasPrice: uint64(30_000_000_100),
|
2020-07-28 16:48:45 +00:00
|
|
|
gasLimit: 70_000,
|
|
|
|
value : 2.u256,
|
2024-11-02 09:30:45 +00:00
|
|
|
to : Opt.some(zeroAddress),
|
2024-10-04 14:34:31 +00:00
|
|
|
chainId : com.chainId,
|
2020-07-28 16:48:45 +00:00
|
|
|
)
|
2022-12-02 04:39:12 +00:00
|
|
|
eip155 = com.isEIP155(com.syncCurrent)
|
2024-10-04 14:34:31 +00:00
|
|
|
signedTx1 = signTransaction(unsignedTx1, acc.privateKey, eip155)
|
|
|
|
signedTx2 = signTransaction(unsignedTx2, acc.privateKey, eip155)
|
2020-07-28 16:48:45 +00:00
|
|
|
txs = [signedTx1, signedTx2]
|
2024-06-14 05:10:00 +00:00
|
|
|
|
2024-06-29 05:43:17 +00:00
|
|
|
let txRoot = calcTxRoot(txs)
|
|
|
|
com.db.persistTransactions(blockNumber, txRoot, txs)
|
2020-07-28 16:48:45 +00:00
|
|
|
|
|
|
|
vmState.receipts = newSeq[Receipt](txs.len)
|
|
|
|
vmState.cumulativeGasUsed = 0
|
|
|
|
for txIndex, tx in txs:
|
2024-10-04 14:34:31 +00:00
|
|
|
let sender = tx.recoverSender().expect("valid signature")
|
2023-04-11 08:28:45 +00:00
|
|
|
let rc = vmState.processTransaction(tx, sender, vmHeader)
|
2024-05-28 06:36:38 +00:00
|
|
|
doAssert(rc.isOk, "Invalid transaction: " & rc.error)
|
2021-07-06 13:14:45 +00:00
|
|
|
vmState.receipts[txIndex] = makeReceipt(vmState, tx.txType)
|
2020-07-28 16:48:45 +00:00
|
|
|
|
|
|
|
let
|
2024-07-10 12:19:35 +00:00
|
|
|
# TODO: `getColumn(CtReceipts)` does not exists anymore. There s only the
|
|
|
|
# generic `MPT` left that can be retrieved with `getGeneric()`,
|
|
|
|
# optionally with argument `clearData=true`
|
2023-06-12 04:29:03 +00:00
|
|
|
date = dateTime(2017, mMar, 30)
|
2023-10-18 02:16:11 +00:00
|
|
|
timeStamp = date.toTime.toUnix.EthTime
|
2022-12-02 04:39:12 +00:00
|
|
|
difficulty = com.calcDifficulty(timeStamp, parent)
|
2020-07-28 16:48:45 +00:00
|
|
|
|
2024-10-27 18:56:28 +00:00
|
|
|
# call persist() before we get the stateRoot
|
2021-10-26 15:18:08 +00:00
|
|
|
vmState.stateDB.persist()
|
2022-01-23 11:39:43 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
var header = Header(
|
2024-12-18 04:04:23 +00:00
|
|
|
parentHash : parentHash,
|
|
|
|
stateRoot : vmState.stateDB.getStateRoot,
|
|
|
|
transactionsRoot: txRoot,
|
|
|
|
receiptsRoot : calcReceiptsRoot(vmState.receipts),
|
2024-11-02 09:30:45 +00:00
|
|
|
logsBloom : createBloom(vmState.receipts),
|
2024-12-18 04:04:23 +00:00
|
|
|
difficulty : difficulty,
|
|
|
|
number : blockNumber,
|
|
|
|
gasLimit : vmState.cumulativeGasUsed + 1_000_000,
|
|
|
|
gasUsed : vmState.cumulativeGasUsed,
|
|
|
|
timestamp : timeStamp
|
2020-07-28 16:48:45 +00:00
|
|
|
)
|
|
|
|
|
2024-12-18 04:04:23 +00:00
|
|
|
com.db.persistHeaderAndSetHead(header,
|
|
|
|
com.startOfHistory).expect("persistHeader not error")
|
|
|
|
|
2020-07-30 07:21:11 +00:00
|
|
|
let uncles = [header]
|
2022-12-02 04:39:12 +00:00
|
|
|
header.ommersHash = com.db.persistUncles(uncles)
|
2020-07-30 07:21:11 +00:00
|
|
|
|
2024-12-18 04:04:23 +00:00
|
|
|
com.db.persistHeaderAndSetHead(header,
|
|
|
|
com.startOfHistory).expect("persistHeader not error")
|
2024-11-03 00:11:24 +00:00
|
|
|
|
2022-12-02 04:39:12 +00:00
|
|
|
com.db.persistFixtureBlock()
|
2024-11-02 09:30:45 +00:00
|
|
|
|
|
|
|
com.db.persistent(header.number).isOkOr:
|
|
|
|
echo "Failed to save state: ", $error
|
|
|
|
quit(QuitFailure)
|
|
|
|
|
2020-07-30 07:21:11 +00:00
|
|
|
result = TestEnv(
|
|
|
|
txHash: signedTx1.rlpHash,
|
2024-11-02 09:30:45 +00:00
|
|
|
blockHash: header.blockHash
|
2020-07-30 07:21:11 +00:00
|
|
|
)
|
2024-11-03 00:11:24 +00:00
|
|
|
|
2020-07-30 07:21:11 +00:00
|
|
|
|
2021-06-22 01:32:32 +00:00
|
|
|
proc rpcMain*() =
|
|
|
|
suite "Remote Procedure Calls":
|
|
|
|
# TODO: Include other transports such as Http
|
|
|
|
let
|
2024-11-02 09:30:45 +00:00
|
|
|
conf = makeConfig(@[])
|
2021-09-07 13:45:01 +00:00
|
|
|
ctx = newEthContext()
|
|
|
|
ethNode = setupEthNode(conf, ctx, eth)
|
2022-12-02 04:39:12 +00:00
|
|
|
com = CommonRef.new(
|
2024-12-13 04:53:41 +00:00
|
|
|
newCoreDbRef DefaultDbMemory, nil,
|
2021-09-16 15:59:46 +00:00
|
|
|
conf.networkId,
|
|
|
|
conf.networkParams
|
2021-09-11 14:58:01 +00:00
|
|
|
)
|
2024-12-18 04:04:23 +00:00
|
|
|
signer = address"0x0e69cde81b1aa07a45c32c6cd85d67229d36bb1b"
|
|
|
|
ks2 = address"0xa3b2222afa5c987da6ef773fde8d01b9f23d481f"
|
|
|
|
ks3 = address"0x597176e9a64aad0845d83afdaf698fbeff77703b"
|
2022-11-12 04:12:17 +00:00
|
|
|
|
2021-09-11 14:58:01 +00:00
|
|
|
let keyStore = "tests" / "keystore"
|
|
|
|
let res = ctx.am.loadKeystores(keyStore)
|
2021-06-22 01:32:32 +00:00
|
|
|
if res.isErr:
|
|
|
|
debugEcho res.error
|
|
|
|
doAssert(res.isOk)
|
|
|
|
|
2021-09-07 12:30:12 +00:00
|
|
|
let acc1 = ctx.am.getAccount(signer).tryGet()
|
|
|
|
let unlock = ctx.am.unlockAccount(signer, acc1.keystore["password"].getStr())
|
2021-06-22 01:32:32 +00:00
|
|
|
if unlock.isErr:
|
|
|
|
debugEcho unlock.error
|
|
|
|
doAssert(unlock.isOk)
|
|
|
|
|
2024-11-03 00:11:24 +00:00
|
|
|
let
|
2024-11-02 09:30:45 +00:00
|
|
|
env = setupEnv(signer, ks2, ctx, com)
|
|
|
|
chain = ForkedChainRef.init(com)
|
2024-12-13 06:21:20 +00:00
|
|
|
txPool = TxPoolRef.new(chain)
|
2024-11-02 09:30:45 +00:00
|
|
|
|
|
|
|
# txPool must be informed of active head
|
|
|
|
# so it can know the latest account state
|
2024-12-13 06:21:20 +00:00
|
|
|
doAssert txPool.smartHead(chain.latestHeader)
|
2021-06-22 01:32:32 +00:00
|
|
|
|
2024-11-02 09:30:45 +00:00
|
|
|
let
|
|
|
|
server = newRpcHttpServerWithParams("127.0.0.1:0").valueOr:
|
|
|
|
quit(QuitFailure)
|
|
|
|
serverApi = newServerAPI(chain, txPool)
|
|
|
|
|
|
|
|
setupServerAPI(serverApi, server, ctx)
|
|
|
|
setupCommonRpc(ethNode, conf, server)
|
2022-01-23 11:39:43 +00:00
|
|
|
|
2024-11-02 09:30:45 +00:00
|
|
|
server.start()
|
|
|
|
let client = setupClient(server.localAddress[0].port)
|
|
|
|
|
|
|
|
# disable POS/post Merge feature
|
|
|
|
com.setTTD Opt.none(DifficultyInt)
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
test "web3_clientVersion":
|
|
|
|
let res = await client.web3_clientVersion()
|
2024-11-01 14:29:38 +00:00
|
|
|
check res == ClientId
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "web3_sha3":
|
2023-12-08 09:35:50 +00:00
|
|
|
let data = @(NimbusName.toOpenArrayByte(0, NimbusName.len-1))
|
|
|
|
let res = await client.web3_sha3(data)
|
2024-10-16 01:34:12 +00:00
|
|
|
let hash = keccak256(data)
|
|
|
|
check hash == res
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "net_version":
|
|
|
|
let res = await client.net_version()
|
2021-09-16 15:59:46 +00:00
|
|
|
check res == $conf.networkId
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "net_listening":
|
|
|
|
let res = await client.net_listening()
|
2021-09-11 14:58:01 +00:00
|
|
|
let listening = ethNode.peerPool.connectedNodes.len < conf.maxPeers
|
2021-06-22 01:32:32 +00:00
|
|
|
check res == listening
|
|
|
|
|
|
|
|
test "net_peerCount":
|
|
|
|
let res = await client.net_peerCount()
|
|
|
|
let peerCount = ethNode.peerPool.connectedNodes.len
|
2023-12-08 09:35:50 +00:00
|
|
|
check res == w3Qty(peerCount)
|
2021-06-22 01:32:32 +00:00
|
|
|
|
2022-09-10 13:05:32 +00:00
|
|
|
test "eth_chainId":
|
|
|
|
let res = await client.eth_chainId()
|
2023-12-08 09:35:50 +00:00
|
|
|
check res == w3Qty(distinctBase(com.chainId))
|
2022-09-10 13:05:32 +00:00
|
|
|
|
2021-06-22 01:32:32 +00:00
|
|
|
test "eth_syncing":
|
|
|
|
let res = await client.eth_syncing()
|
2024-01-13 01:41:57 +00:00
|
|
|
if res.syncing == false:
|
2021-06-22 01:32:32 +00:00
|
|
|
let syncing = ethNode.peerPool.connectedNodes.len > 0
|
2024-01-13 01:41:57 +00:00
|
|
|
check syncing == false
|
2021-06-22 01:32:32 +00:00
|
|
|
else:
|
2024-11-02 09:30:45 +00:00
|
|
|
check com.syncStart == res.syncObject.startingBlock.uint64
|
|
|
|
check com.syncCurrent == res.syncObject.currentBlock.uint64
|
|
|
|
check com.syncHighest == res.syncObject.highestBlock.uint64
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_gasPrice":
|
|
|
|
let res = await client.eth_gasPrice()
|
2024-05-28 06:36:38 +00:00
|
|
|
check res == w3Qty(30_000_000_050) # Avg of `unsignedTx1` / `unsignedTx2`
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_accounts":
|
|
|
|
let res = await client.eth_accounts()
|
2024-10-16 01:34:12 +00:00
|
|
|
check signer in res
|
|
|
|
check ks2 in res
|
|
|
|
check ks3 in res
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_blockNumber":
|
|
|
|
let res = await client.eth_blockNumber()
|
2023-12-08 09:35:50 +00:00
|
|
|
check res == w3Qty(0x1'u64)
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_getBalance":
|
2024-12-18 04:04:23 +00:00
|
|
|
let a = await client.eth_getBalance(address"0xfff33a3bd36abdbd412707b8e310d6011454a7ae", blockId(1'u64))
|
2023-12-08 09:35:50 +00:00
|
|
|
check a == UInt256.fromHex("0x1b1ae4d6e2ef5000000")
|
2024-12-18 04:04:23 +00:00
|
|
|
let b = await client.eth_getBalance(address"0xfff4bad596633479a2a29f9a8b3f78eefd07e6ee", blockId(1'u64))
|
2023-12-08 09:35:50 +00:00
|
|
|
check b == UInt256.fromHex("0x56bc75e2d63100000")
|
2024-12-18 04:04:23 +00:00
|
|
|
let c = await client.eth_getBalance(address"0xfff7ac99c8e4feb60c9750054bdc14ce1857f181", blockId(1'u64))
|
2023-12-08 09:35:50 +00:00
|
|
|
check c == UInt256.fromHex("0x3635c9adc5dea00000")
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_getStorageAt":
|
2024-12-18 04:04:23 +00:00
|
|
|
let res = await client.eth_getStorageAt(address"0xfff33a3bd36abdbd412707b8e310d6011454a7ae", 0.u256, blockId(1'u64))
|
2024-11-02 09:30:45 +00:00
|
|
|
check FixedBytes[32](zeroHash32.data) == res
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_getTransactionCount":
|
2024-12-18 04:04:23 +00:00
|
|
|
let res = await client.eth_getTransactionCount(address"0xfff7ac99c8e4feb60c9750054bdc14ce1857f181", blockId(1'u64))
|
2023-12-08 09:35:50 +00:00
|
|
|
check res == w3Qty(0'u64)
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_getBlockTransactionCountByHash":
|
2024-11-07 01:24:21 +00:00
|
|
|
let hash = com.db.getBlockHash(0'u64).expect("block hash exists")
|
2024-10-16 01:34:12 +00:00
|
|
|
let res = await client.eth_getBlockTransactionCountByHash(hash)
|
2023-12-08 09:35:50 +00:00
|
|
|
check res == w3Qty(0'u64)
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_getBlockTransactionCountByNumber":
|
2023-12-08 09:35:50 +00:00
|
|
|
let res = await client.eth_getBlockTransactionCountByNumber(blockId(0'u64))
|
|
|
|
check res == w3Qty(0'u64)
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_getUncleCountByBlockHash":
|
2024-11-07 01:24:21 +00:00
|
|
|
let hash = com.db.getBlockHash(0'u64).expect("block hash exists")
|
2024-10-16 01:34:12 +00:00
|
|
|
let res = await client.eth_getUncleCountByBlockHash(hash)
|
2023-12-08 09:35:50 +00:00
|
|
|
check res == w3Qty(0'u64)
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_getUncleCountByBlockNumber":
|
2023-12-08 09:35:50 +00:00
|
|
|
let res = await client.eth_getUncleCountByBlockNumber(blockId(0'u64))
|
|
|
|
check res == w3Qty(0'u64)
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_getCode":
|
2024-12-18 04:04:23 +00:00
|
|
|
let res = await client.eth_getCode(address"0xfff7ac99c8e4feb60c9750054bdc14ce1857f181", blockId(1'u64))
|
2023-12-08 09:35:50 +00:00
|
|
|
check res.len == 0
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_sign":
|
|
|
|
let msg = "hello world"
|
2023-12-08 09:35:50 +00:00
|
|
|
let msgBytes = @(msg.toOpenArrayByte(0, msg.len-1))
|
2021-06-22 01:32:32 +00:00
|
|
|
|
2024-01-13 01:41:57 +00:00
|
|
|
expect JsonRpcError:
|
2024-10-16 01:34:12 +00:00
|
|
|
discard await client.eth_sign(ks2, msgBytes)
|
2021-06-22 01:32:32 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
let res = await client.eth_sign(signer, msgBytes)
|
2023-12-08 09:35:50 +00:00
|
|
|
let sig = Signature.fromRaw(res).tryGet()
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
# now let us try to verify signature
|
|
|
|
let msgData = "\x19Ethereum Signed Message:\n" & $msg.len & msg
|
2023-12-08 09:35:50 +00:00
|
|
|
let msgDataBytes = @(msgData.toOpenArrayByte(0, msgData.len-1))
|
|
|
|
let msgHash = await client.web3_sha3(msgDataBytes)
|
2024-11-03 00:11:24 +00:00
|
|
|
let pubkey = recover(sig, SkMessage(msgHash.data)).tryGet()
|
2021-06-22 01:32:32 +00:00
|
|
|
let recoveredAddr = pubkey.toCanonicalAddress()
|
|
|
|
check recoveredAddr == signer # verified
|
|
|
|
|
|
|
|
test "eth_signTransaction, eth_sendTransaction, eth_sendRawTransaction":
|
2024-03-21 01:05:22 +00:00
|
|
|
var unsignedTx = TransactionArgs(
|
2024-11-02 09:30:45 +00:00
|
|
|
`from`: Opt.some(signer),
|
|
|
|
to: Opt.some(ks2),
|
|
|
|
gas: Opt.some(w3Qty(100000'u)),
|
|
|
|
gasPrice: Opt.none(Quantity),
|
|
|
|
value: Opt.some(100.u256),
|
|
|
|
nonce: Opt.none(Quantity)
|
2021-06-22 01:32:32 +00:00
|
|
|
)
|
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
let signedTxBytes = await client.eth_signTransaction(unsignedTx)
|
|
|
|
let signedTx = rlp.decode(signedTxBytes, Transaction)
|
2024-10-04 14:34:31 +00:00
|
|
|
check signer == signedTx.recoverSender().expect("valid signature") # verified
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
let hashAhex = await client.eth_sendTransaction(unsignedTx)
|
2023-12-08 09:35:50 +00:00
|
|
|
let hashBhex = await client.eth_sendRawTransaction(signedTxBytes)
|
|
|
|
check hashAhex == hashBhex
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_call":
|
2024-03-21 01:05:22 +00:00
|
|
|
var ec = TransactionArgs(
|
2024-11-02 09:30:45 +00:00
|
|
|
`from`: Opt.some(signer),
|
|
|
|
to: Opt.some(ks2),
|
|
|
|
gas: Opt.some(w3Qty(100000'u)),
|
|
|
|
gasPrice: Opt.none(Quantity),
|
|
|
|
value: Opt.some(100.u256)
|
2021-06-22 01:32:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
let res = await client.eth_call(ec, "latest")
|
2023-12-08 09:35:50 +00:00
|
|
|
check res == hexToSeqByte("deadbeef")
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_estimateGas":
|
2024-03-21 01:05:22 +00:00
|
|
|
var ec = TransactionArgs(
|
2024-11-02 09:30:45 +00:00
|
|
|
`from`: Opt.some(signer),
|
|
|
|
to: Opt.some(ks3),
|
|
|
|
gas: Opt.some(w3Qty(42000'u)),
|
|
|
|
gasPrice: Opt.some(w3Qty(100'u)),
|
|
|
|
value: Opt.some(100.u256)
|
2021-06-22 01:32:32 +00:00
|
|
|
)
|
|
|
|
|
2024-01-13 01:41:57 +00:00
|
|
|
let res = await client.eth_estimateGas(ec)
|
2023-12-08 09:35:50 +00:00
|
|
|
check res == w3Qty(21000'u64)
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_getBlockByHash":
|
2024-10-16 01:34:12 +00:00
|
|
|
let res = await client.eth_getBlockByHash(env.blockHash, true)
|
2023-12-08 09:35:50 +00:00
|
|
|
check res.isNil.not
|
2024-10-16 01:34:12 +00:00
|
|
|
check res.hash == env.blockHash
|
|
|
|
let res2 = await client.eth_getBlockByHash(env.txHash, true)
|
2023-12-08 09:35:50 +00:00
|
|
|
check res2.isNil
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_getBlockByNumber":
|
|
|
|
let res = await client.eth_getBlockByNumber("latest", true)
|
2023-12-08 09:35:50 +00:00
|
|
|
check res.isNil.not
|
2024-10-16 01:34:12 +00:00
|
|
|
check res.hash == env.blockHash
|
2021-06-22 01:32:32 +00:00
|
|
|
let res2 = await client.eth_getBlockByNumber($1, true)
|
2023-12-08 09:35:50 +00:00
|
|
|
check res2.isNil
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_getTransactionByHash":
|
2024-10-16 01:34:12 +00:00
|
|
|
let res = await client.eth_getTransactionByHash(env.txHash)
|
2023-12-08 09:35:50 +00:00
|
|
|
check res.isNil.not
|
2024-11-07 03:43:25 +00:00
|
|
|
check res.blockNumber.get() == w3Qty(1'u64)
|
2024-10-16 01:34:12 +00:00
|
|
|
let res2 = await client.eth_getTransactionByHash(env.blockHash)
|
2023-12-08 09:35:50 +00:00
|
|
|
check res2.isNil
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_getTransactionByBlockHashAndIndex":
|
2024-10-16 01:34:12 +00:00
|
|
|
let res = await client.eth_getTransactionByBlockHashAndIndex(env.blockHash, w3Qty(0'u64))
|
2023-12-08 09:35:50 +00:00
|
|
|
check res.isNil.not
|
2024-11-07 03:43:25 +00:00
|
|
|
check res.blockNumber.get() == w3Qty(1'u64)
|
2021-06-22 01:32:32 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
let res2 = await client.eth_getTransactionByBlockHashAndIndex(env.blockHash, w3Qty(3'u64))
|
2023-12-08 09:35:50 +00:00
|
|
|
check res2.isNil
|
2021-06-22 01:32:32 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
let res3 = await client.eth_getTransactionByBlockHashAndIndex(env.txHash, w3Qty(3'u64))
|
2023-12-08 09:35:50 +00:00
|
|
|
check res3.isNil
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_getTransactionByBlockNumberAndIndex":
|
2023-12-08 09:35:50 +00:00
|
|
|
let res = await client.eth_getTransactionByBlockNumberAndIndex("latest", w3Qty(1'u64))
|
|
|
|
check res.isNil.not
|
2024-11-07 03:43:25 +00:00
|
|
|
check res.blockNumber.get() == w3Qty(1'u64)
|
2021-06-22 01:32:32 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
let res2 = await client.eth_getTransactionByBlockNumberAndIndex("latest", w3Qty(3'u64))
|
|
|
|
check res2.isNil
|
2021-06-22 01:32:32 +00:00
|
|
|
|
2024-11-02 09:30:45 +00:00
|
|
|
# TODO: Solved with Issue #2700
|
2021-06-22 01:32:32 +00:00
|
|
|
|
2024-11-02 09:30:45 +00:00
|
|
|
# test "eth_getBlockReceipts":
|
|
|
|
# let recs = await client.eth_getBlockReceipts(blockId(1'u64))
|
|
|
|
# check recs.isSome
|
|
|
|
# if recs.isSome:
|
|
|
|
# let receipts = recs.get
|
|
|
|
# check receipts.len == 2
|
|
|
|
# check receipts[0].transactionIndex == 0.Quantity
|
|
|
|
# check receipts[1].transactionIndex == 1.Quantity
|
|
|
|
|
|
|
|
# test "eth_getTransactionReceipt":
|
|
|
|
# let res = await client.eth_getTransactionReceipt(env.txHash)
|
|
|
|
# check res.isNil.not
|
2024-11-07 03:43:25 +00:00
|
|
|
# check res.blockNumber == w3Qty(1'u64)
|
2024-11-02 09:30:45 +00:00
|
|
|
|
|
|
|
# let res2 = await client.eth_getTransactionReceipt(env.blockHash)
|
|
|
|
# check res2.isNil
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_getUncleByBlockHashAndIndex":
|
2024-10-16 01:34:12 +00:00
|
|
|
let res = await client.eth_getUncleByBlockHashAndIndex(env.blockHash, w3Qty(0'u64))
|
2023-12-08 09:35:50 +00:00
|
|
|
check res.isNil.not
|
2024-11-07 03:43:25 +00:00
|
|
|
check res.number == w3Qty(1'u64)
|
2021-06-22 01:32:32 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
let res2 = await client.eth_getUncleByBlockHashAndIndex(env.blockHash, w3Qty(1'u64))
|
2023-12-08 09:35:50 +00:00
|
|
|
check res2.isNil
|
2021-06-22 01:32:32 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
let res3 = await client.eth_getUncleByBlockHashAndIndex(env.txHash, w3Qty(0'u64))
|
2023-12-08 09:35:50 +00:00
|
|
|
check res3.isNil
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
test "eth_getUncleByBlockNumberAndIndex":
|
2023-12-08 09:35:50 +00:00
|
|
|
let res = await client.eth_getUncleByBlockNumberAndIndex("latest", w3Qty(0'u64))
|
|
|
|
check res.isNil.not
|
2024-11-07 03:43:25 +00:00
|
|
|
check res.number == w3Qty(1'u64)
|
2021-06-22 01:32:32 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
let res2 = await client.eth_getUncleByBlockNumberAndIndex("latest", w3Qty(1'u64))
|
|
|
|
check res2.isNil
|
2021-06-22 01:32:32 +00:00
|
|
|
|
2022-06-29 15:44:08 +00:00
|
|
|
test "eth_getLogs by blockhash, no filters":
|
|
|
|
let testHeader = getBlockHeader4514995()
|
|
|
|
let testHash = testHeader.blockHash
|
|
|
|
let filterOptions = FilterOptions(
|
2024-11-02 09:30:45 +00:00
|
|
|
blockHash: Opt.some(testHash),
|
2022-06-29 15:44:08 +00:00
|
|
|
topics: @[]
|
|
|
|
)
|
|
|
|
let logs = await client.eth_getLogs(filterOptions)
|
|
|
|
|
|
|
|
check:
|
|
|
|
len(logs) == 54
|
|
|
|
|
|
|
|
var i = 0
|
|
|
|
for l in logs:
|
|
|
|
check:
|
|
|
|
l.blockHash.isSome()
|
2024-11-02 09:30:45 +00:00
|
|
|
l.blockHash.get() == testHash
|
|
|
|
l.logIndex.get() == w3Qty(i.uint64)
|
2022-06-29 15:44:08 +00:00
|
|
|
inc i
|
|
|
|
|
2024-01-13 01:41:57 +00:00
|
|
|
test "eth_getLogs by blockhash, filter logs at specific positions":
|
2022-06-29 15:44:08 +00:00
|
|
|
let testHeader = getBlockHeader4514995()
|
|
|
|
let testHash = testHeader.blockHash
|
|
|
|
|
2024-12-18 04:04:23 +00:00
|
|
|
let topic = bytes32"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
|
|
|
|
let topic1 = bytes32"0x000000000000000000000000fdc183d01a793613736cd40a5a578f49add1772b"
|
2022-06-29 15:44:08 +00:00
|
|
|
|
|
|
|
let filterOptions = FilterOptions(
|
2024-11-02 09:30:45 +00:00
|
|
|
blockHash: Opt.some(testHash),
|
2024-01-13 01:41:57 +00:00
|
|
|
topics: @[
|
|
|
|
TopicOrList(kind: slkList, list: @[topic]),
|
|
|
|
TopicOrList(kind: slkNull),
|
|
|
|
TopicOrList(kind: slkList, list: @[topic1])
|
|
|
|
]
|
2022-06-29 15:44:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
let logs = await client.eth_getLogs(filterOptions)
|
|
|
|
|
|
|
|
check:
|
|
|
|
len(logs) == 1
|
|
|
|
|
|
|
|
|
|
|
|
test "eth_getLogs by blockhash, filter logs at specific postions with or options":
|
|
|
|
let testHeader = getBlockHeader4514995()
|
|
|
|
let testHash = testHeader.blockHash
|
|
|
|
|
2024-12-18 04:04:23 +00:00
|
|
|
let topic = bytes32"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
|
|
|
|
let topic1 = bytes32"0xa64da754fccf55aa65a1f0128a648633fade3884b236e879ee9f64c78df5d5d7"
|
2022-06-29 15:44:08 +00:00
|
|
|
|
2024-12-18 04:04:23 +00:00
|
|
|
let topic2 = bytes32"0x000000000000000000000000e16c02eac87920033ac72fc55ee1df3151c75786"
|
|
|
|
let topic3 = bytes32"0x000000000000000000000000b626a5facc4de1c813f5293ec3be31979f1d1c78"
|
2022-06-29 15:44:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let filterOptions = FilterOptions(
|
2024-11-02 09:30:45 +00:00
|
|
|
blockHash: Opt.some(testHash),
|
2022-06-29 15:44:08 +00:00
|
|
|
topics: @[
|
2024-01-13 01:41:57 +00:00
|
|
|
TopicOrList(kind: slkList, list: @[topic, topic1]),
|
|
|
|
TopicOrList(kind: slkList, list: @[topic2, topic3])
|
2022-06-29 15:44:08 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
let logs = await client.eth_getLogs(filterOptions)
|
|
|
|
|
|
|
|
check:
|
|
|
|
len(logs) == 2
|
|
|
|
|
2024-01-09 02:05:52 +00:00
|
|
|
test "eth_getProof - Non existent account and storage slots":
|
|
|
|
let blockData = await client.eth_getBlockByNumber("latest", true)
|
|
|
|
|
|
|
|
block:
|
|
|
|
# account doesn't exist
|
|
|
|
let
|
2024-12-18 04:04:23 +00:00
|
|
|
address = address"0x0000000000000000000000000000000000000004"
|
2024-01-09 02:05:52 +00:00
|
|
|
proofResponse = await client.eth_getProof(address, @[], blockId(1'u64))
|
|
|
|
storageProof = proofResponse.storageProof
|
|
|
|
|
|
|
|
check:
|
|
|
|
proofResponse.address == address
|
|
|
|
verifyAccountProof(blockData.stateRoot, proofResponse).isMissing()
|
|
|
|
proofResponse.balance == 0.u256
|
2024-12-18 04:04:23 +00:00
|
|
|
proofResponse.codeHash == zeroHash
|
2024-01-09 02:05:52 +00:00
|
|
|
proofResponse.nonce == w3Qty(0.uint64)
|
2024-12-18 04:04:23 +00:00
|
|
|
proofResponse.storageHash == zeroHash
|
2024-01-09 02:05:52 +00:00
|
|
|
storageProof.len() == 0
|
|
|
|
|
|
|
|
block:
|
|
|
|
# account exists but requested slots don't exist
|
|
|
|
let
|
2024-12-18 04:04:23 +00:00
|
|
|
address = address"0x0000000000000000000000000000000000000001"
|
2024-01-09 02:05:52 +00:00
|
|
|
slot1Key = 0.u256
|
|
|
|
slot2Key = 1.u256
|
|
|
|
proofResponse = await client.eth_getProof(address, @[slot1Key, slot2Key], blockId(1'u64))
|
|
|
|
storageProof = proofResponse.storageProof
|
|
|
|
|
|
|
|
check:
|
|
|
|
proofResponse.address == address
|
|
|
|
verifyAccountProof(blockData.stateRoot, proofResponse).isValid()
|
|
|
|
proofResponse.balance == 2_000_000_000.u256
|
2024-12-18 04:04:23 +00:00
|
|
|
proofResponse.codeHash == emptyCodeHash
|
2024-01-09 02:05:52 +00:00
|
|
|
proofResponse.nonce == w3Qty(1.uint64)
|
2024-12-18 04:04:23 +00:00
|
|
|
proofResponse.storageHash == emptyStorageHash
|
2024-01-09 02:05:52 +00:00
|
|
|
storageProof.len() == 2
|
|
|
|
storageProof[0].key == slot1Key
|
|
|
|
storageProof[0].proof.len() == 0
|
|
|
|
storageProof[0].value == 0.u256
|
|
|
|
storageProof[1].key == slot2Key
|
|
|
|
storageProof[1].proof.len() == 0
|
|
|
|
storageProof[1].value == 0.u256
|
|
|
|
|
|
|
|
block:
|
|
|
|
# contract account with no storage slots
|
|
|
|
let
|
2024-12-18 04:04:23 +00:00
|
|
|
address = address"0x0000000000000000000000000000000000000003"
|
2024-01-09 02:05:52 +00:00
|
|
|
slot1Key = 0.u256 # Doesn't exist
|
|
|
|
proofResponse = await client.eth_getProof(address, @[slot1Key], blockId(1'u64))
|
|
|
|
storageProof = proofResponse.storageProof
|
|
|
|
|
|
|
|
check:
|
|
|
|
proofResponse.address == address
|
|
|
|
verifyAccountProof(blockData.stateRoot, proofResponse).isValid()
|
|
|
|
proofResponse.balance == 0.u256
|
2024-12-18 04:04:23 +00:00
|
|
|
proofResponse.codeHash == hash32"0x09044b55d7aba83cb8ac3d2c9c8d8bcadbfc33f06f1be65e8cc1e4ddab5f3074"
|
2024-01-09 02:05:52 +00:00
|
|
|
proofResponse.nonce == w3Qty(0.uint64)
|
2024-12-18 04:04:23 +00:00
|
|
|
proofResponse.storageHash == emptyStorageHash
|
2024-01-09 02:05:52 +00:00
|
|
|
storageProof.len() == 1
|
|
|
|
storageProof[0].key == slot1Key
|
|
|
|
storageProof[0].proof.len() == 0
|
|
|
|
storageProof[0].value == 0.u256
|
|
|
|
|
|
|
|
test "eth_getProof - Existing accounts and storage slots":
|
|
|
|
let blockData = await client.eth_getBlockByNumber("latest", true)
|
|
|
|
|
|
|
|
block:
|
|
|
|
# contract account with storage slots
|
|
|
|
let
|
2024-12-18 04:04:23 +00:00
|
|
|
address = address"0x0000000000000000000000000000000000000002"
|
2024-01-09 02:05:52 +00:00
|
|
|
slot1Key = 0.u256
|
|
|
|
slot2Key = 1.u256
|
|
|
|
slot3Key = 2.u256 # Doesn't exist
|
|
|
|
proofResponse = await client.eth_getProof(address, @[slot1Key, slot2Key, slot3Key], blockId(1'u64))
|
|
|
|
storageProof = proofResponse.storageProof
|
|
|
|
|
|
|
|
check:
|
|
|
|
proofResponse.address == address
|
|
|
|
verifyAccountProof(blockData.stateRoot, proofResponse).isValid()
|
|
|
|
proofResponse.balance == 1_000_000_000.u256
|
2024-12-18 04:04:23 +00:00
|
|
|
proofResponse.codeHash == hash32"0x09044b55d7aba83cb8ac3d2c9c8d8bcadbfc33f06f1be65e8cc1e4ddab5f3074"
|
2024-01-09 02:05:52 +00:00
|
|
|
proofResponse.nonce == w3Qty(2.uint64)
|
2024-12-18 04:04:23 +00:00
|
|
|
proofResponse.storageHash == hash32"0x2ed06ec37dad4cd8c8fc1a1172d633a8973987fa6995b14a7c0a50c0e8d1a9c3"
|
2024-01-09 02:05:52 +00:00
|
|
|
storageProof.len() == 3
|
|
|
|
storageProof[0].key == slot1Key
|
|
|
|
storageProof[0].proof.len() > 0
|
|
|
|
storageProof[0].value == 1234.u256
|
|
|
|
storageProof[1].key == slot2Key
|
|
|
|
storageProof[1].proof.len() > 0
|
|
|
|
storageProof[1].value == 2345.u256
|
|
|
|
storageProof[2].key == slot3Key
|
|
|
|
storageProof[2].proof.len() > 0
|
|
|
|
storageProof[2].value == 0.u256
|
|
|
|
verifySlotProof(proofResponse.storageHash, storageProof[0]).isValid()
|
|
|
|
verifySlotProof(proofResponse.storageHash, storageProof[1]).isValid()
|
|
|
|
verifySlotProof(proofResponse.storageHash, storageProof[2]).isMissing()
|
|
|
|
|
|
|
|
block:
|
|
|
|
# externally owned account
|
|
|
|
let
|
2024-12-18 04:04:23 +00:00
|
|
|
address = address"0x0000000000000000000000000000000000000001"
|
2024-01-09 02:05:52 +00:00
|
|
|
proofResponse = await client.eth_getProof(address, @[], blockId(1'u64))
|
|
|
|
storageProof = proofResponse.storageProof
|
|
|
|
|
|
|
|
check:
|
|
|
|
proofResponse.address == address
|
|
|
|
verifyAccountProof(blockData.stateRoot, proofResponse).isValid()
|
|
|
|
proofResponse.balance == 2_000_000_000.u256
|
2024-12-18 04:04:23 +00:00
|
|
|
proofResponse.codeHash == emptyCodeHash
|
2024-01-09 02:05:52 +00:00
|
|
|
proofResponse.nonce == w3Qty(1.uint64)
|
2024-12-18 04:04:23 +00:00
|
|
|
proofResponse.storageHash == emptyStorageHash
|
2024-01-09 02:05:52 +00:00
|
|
|
storageProof.len() == 0
|
|
|
|
|
|
|
|
test "eth_getProof - Multiple blocks":
|
|
|
|
let blockData = await client.eth_getBlockByNumber("latest", true)
|
|
|
|
|
|
|
|
block:
|
|
|
|
# block 1 - account has balance, code and storage
|
|
|
|
let
|
2024-12-18 04:04:23 +00:00
|
|
|
address = address"0x0000000000000000000000000000000000000002"
|
2024-01-09 02:05:52 +00:00
|
|
|
slot2Key = 1.u256
|
|
|
|
proofResponse = await client.eth_getProof(address, @[slot2Key], blockId(1'u64))
|
|
|
|
storageProof = proofResponse.storageProof
|
|
|
|
|
|
|
|
check:
|
|
|
|
proofResponse.address == address
|
|
|
|
verifyAccountProof(blockData.stateRoot, proofResponse).isValid()
|
|
|
|
proofResponse.balance == 1_000_000_000.u256
|
2024-12-18 04:04:23 +00:00
|
|
|
proofResponse.codeHash == hash32"0x09044b55d7aba83cb8ac3d2c9c8d8bcadbfc33f06f1be65e8cc1e4ddab5f3074"
|
2024-01-09 02:05:52 +00:00
|
|
|
proofResponse.nonce == w3Qty(2.uint64)
|
2024-12-18 04:04:23 +00:00
|
|
|
proofResponse.storageHash == hash32"0x2ed06ec37dad4cd8c8fc1a1172d633a8973987fa6995b14a7c0a50c0e8d1a9c3"
|
2024-01-09 02:05:52 +00:00
|
|
|
storageProof.len() == 1
|
|
|
|
verifySlotProof(proofResponse.storageHash, storageProof[0]).isValid()
|
|
|
|
|
2024-11-02 09:30:45 +00:00
|
|
|
close(client, server)
|
2024-01-24 11:04:59 +00:00
|
|
|
|
2024-11-02 09:30:45 +00:00
|
|
|
proc setErrorLevel* =
|
|
|
|
discard
|
|
|
|
when defined(chronicles_runtime_filtering) and loggingEnabled:
|
|
|
|
setLogLevel(LogLevel.ERROR)
|
2021-06-22 01:32:32 +00:00
|
|
|
|
|
|
|
when isMainModule:
|
2024-11-02 09:30:45 +00:00
|
|
|
setErrorLevel()
|
2021-06-22 01:32:32 +00:00
|
|
|
rpcMain()
|