rpc: change getStorageAt param type to HexDataStr

if using HexQuantityStr, it will fail when given hex string with leading zeros
This commit is contained in:
jangko 2022-06-27 16:49:51 +07:00
parent 3f99ece6c5
commit 4a50b00c37
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
6 changed files with 15 additions and 7 deletions

View File

@ -99,6 +99,9 @@ proc pickNextPayloadProducer(cl: CLMocker): bool =
let lastBlockNumber = nRes.get
if cl.latestHeadNumber != lastBlockNumber:
error "CLMocker: unexpected lastBlockNumber",
get = lastBlockNumber,
expect = cl.latestHeadNumber
return false
var header: common.BlockHeader

View File

@ -1215,9 +1215,11 @@ proc reorgBack(t: TestEnv): TestStatus =
# It is only expected that the client does not produce an error and the CL Mocker is able to progress after the re-org
let r = client.forkchoiceUpdatedV1(forkchoiceUpdatedBack)
r.isOk
if r.isErr:
error "failed to reorg back", msg = r.error
return false
return true
))
testCond r2
# Verify that the client is pointing to the latest payload sent

View File

@ -101,6 +101,9 @@ proc getCanonicalHead*(self: BaseChainDB): BlockHeader =
raise newException(CanonicalHeadNotFound,
"No canonical head set for this chain")
proc getCanonicalHeaderHash*(self: BaseChainDB): Hash256 =
discard self.getHash(canonicalHeadHashKey(), result)
proc populateProgress*(self: BaseChainDB) =
try:
self.startingBlock = self.getCanonicalHead().blockNumber

View File

@ -108,17 +108,17 @@ proc setupEthRpc*(node: EthereumNode, ctx: EthContext, chain: BaseChainDB, txPoo
balance = accDB.getBalance(address)
result = encodeQuantity(balance)
server.rpc("eth_getStorageAt") do(data: EthAddressStr, quantity: HexQuantityStr, quantityTag: string) -> HexDataStr:
server.rpc("eth_getStorageAt") do(data: EthAddressStr, slot: HexDataStr, quantityTag: string) -> HexDataStr:
## Returns the value from a storage position at a given address.
##
## data: address of the storage.
## quantity: integer of the position in the storage.
## slot: integer of the position in the storage.
## quantityTag: integer block number, or the string "latest", "earliest" or "pending", see the default block parameter.
## Returns: the value at this storage position.
let
accDB = stateDBFromTag(quantityTag)
address = data.toAddress
key = fromHex(UInt256, quantity.string)
key = fromHex(UInt256, slot.string)
value = accDB.getStorage(address, key)[0]
result = hexDataStr(value)

View File

@ -27,7 +27,7 @@ proc eth_gasPrice(): HexQuantityStr
proc eth_accounts(): seq[EthAddressStr]
proc eth_blockNumber(): HexQuantityStr
proc eth_getBalance(data: EthAddressStr, quantityTag: string): HexQuantityStr
proc eth_getStorageAt(data: EthAddressStr, quantity: HexQuantityStr, quantityTag: string): HexDataStr
proc eth_getStorageAt(data: EthAddressStr, slot: HexDataStr, quantityTag: string): HexDataStr
proc eth_getTransactionCount(data: EthAddressStr, quantityTag: string): HexQuantityStr
proc eth_getBlockTransactionCountByHash(data: Hash256): HexQuantityStr
proc eth_getBlockTransactionCountByNumber(quantityTag: string): HexQuantityStr

View File

@ -257,7 +257,7 @@ proc rpcMain*() =
check c.string == "0x3635c9adc5dea00000"
test "eth_getStorageAt":
let res = await client.eth_getStorageAt(ethAddressStr("0xfff33a3bd36abdbd412707b8e310d6011454a7ae"), hexQuantityStr "0x0", "0x0")
let res = await client.eth_getStorageAt(ethAddressStr("0xfff33a3bd36abdbd412707b8e310d6011454a7ae"), hexDataStr "0x00", "0x0")
check hexDataStr(0.u256).string == res.string
test "eth_getTransactionCount":