Add makeNextWithdrawals to engine api simulator

This commit is contained in:
jangko 2023-09-30 20:16:45 +07:00
parent 501d8a369a
commit 369a54d62a
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
3 changed files with 34 additions and 6 deletions

View File

@ -434,6 +434,36 @@ proc broadcastLatestForkchoice(cl: CLMocker): bool =
return true
func w3Address(x: int): Web3Address =
var res: array[20, byte]
res[^1] = x.byte
Web3Address(res)
proc makeNextWithdrawals(cl: CLMocker): seq[WithdrawalV1] =
var
withdrawalCount = 10
withdrawalIndex = 0'u64
if cl.latestPayloadBuilt.withdrawals.isSome:
let wds = cl.latestPayloadBuilt.withdrawals.get
for w in wds:
if w.index.uint64 > withdrawalIndex:
withdrawalIndex = w.index.uint64
var
withdrawals = newSeq[WithdrawalV1](withdrawalCount)
for i in 0..<withdrawalCount:
withdrawalIndex += 1
withdrawals[i] = WithdrawalV1(
index: w3Qty withdrawalIndex,
validatorIndex: w3Qty i,
address: w3Address i,
amount: w3Qty 100'u64,
)
return withdrawals
proc produceSingleBlock*(cl: CLMocker, cb: BlockProcessCallbacks): bool {.gcsafe.} =
doAssert(cl.ttdReached)
@ -444,7 +474,7 @@ proc produceSingleBlock*(cl: CLMocker, cb: BlockProcessCallbacks): bool {.gcsafe
# Check if next withdrawals necessary, test can override this value on
# `OnPayloadProducerSelected` callback
if cl.nextWithdrawals.isNone:
var nw: seq[WithdrawalV1]
let nw = cl.makeNextWithdrawals()
cl.setNextWithdrawals(some(nw))
if cb.onPayloadProducerSelected != nil:

View File

@ -175,6 +175,9 @@ func w3Qty*(x: Option[uint64]): Option[Web3Quantity] =
if x.isNone: none(Web3Quantity)
else: some(Web3Quantity x.get)
func w3Qty*(x: uint64): Web3Quantity =
Web3Quantity(x)
func w3ExtraData*(x: common.Blob): Web3ExtraData =
Web3ExtraData x

View File

@ -114,17 +114,12 @@ proc txFeesCovered(xp: TxPoolRef; item: TxItemRef): bool =
return false
true
import stew/byteutils
import ../../../utils/debug
proc txCostInBudget(xp: TxPoolRef; item: TxItemRef): bool =
## Check whether the worst case expense is covered by the price budget,
let
balance = xp.chain.getBalance(item.sender)
gasCost = item.tx.gasCost
if balance < gasCost:
debugEcho "nonce: ", item.tx.nonce, " ", balance, " ", gasCost, " ", item.sender.toHex
debugEcho debug(item.tx)
debug "invalid tx: not enough cash for gas",
available = balance,
require = gasCost