2023-11-01 03:32:09 +00:00
|
|
|
# Nimbus
|
2024-02-21 16:04:59 +00:00
|
|
|
# Copyright (c) 2022-2024 Status Research & Development GmbH
|
2023-11-01 03:32:09 +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.
|
|
|
|
|
2022-03-30 04:50:35 +00:00
|
|
|
import
|
2024-10-22 02:07:43 +00:00
|
|
|
std/[tables, math],
|
2024-10-16 01:34:12 +00:00
|
|
|
eth/common/keys,
|
2024-10-22 02:07:43 +00:00
|
|
|
results,
|
|
|
|
unittest2,
|
|
|
|
../hive_integration/nodocker/engine/tx_sender,
|
2024-05-30 10:11:41 +00:00
|
|
|
../nimbus/db/ledger,
|
2022-12-02 04:39:12 +00:00
|
|
|
../nimbus/core/chain,
|
2024-10-22 02:07:43 +00:00
|
|
|
../nimbus/core/eip4844,
|
2022-12-02 04:39:12 +00:00
|
|
|
../nimbus/[config, transaction, constants],
|
|
|
|
../nimbus/core/tx_pool,
|
2024-08-08 23:05:18 +00:00
|
|
|
../nimbus/core/tx_pool/tx_desc,
|
2022-12-06 05:55:40 +00:00
|
|
|
../nimbus/core/casper,
|
2022-12-02 04:39:12 +00:00
|
|
|
../nimbus/common/common,
|
2023-10-04 03:47:18 +00:00
|
|
|
../nimbus/utils/utils,
|
2024-08-08 23:05:18 +00:00
|
|
|
../nimbus/evm/types,
|
2022-03-30 04:50:35 +00:00
|
|
|
./test_txpool/helpers,
|
|
|
|
./macro_assembler
|
|
|
|
|
|
|
|
const
|
2022-04-04 08:34:59 +00:00
|
|
|
baseDir = [".", "tests"]
|
|
|
|
repoDir = [".", "customgenesis"]
|
|
|
|
genesisFile = "merge.json"
|
2022-03-30 04:50:35 +00:00
|
|
|
|
2024-10-22 02:07:43 +00:00
|
|
|
type TestEnv = object
|
|
|
|
nonce: uint64
|
|
|
|
chainId: ChainId
|
|
|
|
vaultKey: PrivateKey
|
|
|
|
conf: NimbusConf
|
|
|
|
com: CommonRef
|
|
|
|
chain: ForkedChainRef
|
|
|
|
xp: TxPoolRef
|
2022-03-30 04:50:35 +00:00
|
|
|
|
|
|
|
const
|
2024-08-08 23:05:18 +00:00
|
|
|
# signerKeyHex = "9c647b8b7c4e7c3490668fb6c11473619db80c93704c70893d3813af4090c39c"
|
2022-03-30 04:50:35 +00:00
|
|
|
vaultKeyHex = "63b508a03c3b5937ceb903af8b1b0c191012ef6eb7e9c3fb7afa94e5d214d376"
|
2024-09-29 12:37:09 +00:00
|
|
|
recipient = address"0000000000000000000000000000000000000318"
|
|
|
|
feeRecipient = address"0000000000000000000000000000000000000212"
|
2022-03-30 04:50:35 +00:00
|
|
|
contractCode = evmByteCode:
|
2024-10-22 02:07:43 +00:00
|
|
|
PrevRandao # VAL
|
|
|
|
Push1 "0x11" # KEY
|
|
|
|
Sstore # OP
|
2022-03-30 04:50:35 +00:00
|
|
|
Stop
|
|
|
|
|
|
|
|
proc privKey(keyHex: string): PrivateKey =
|
|
|
|
let kRes = PrivateKey.fromHex(keyHex)
|
|
|
|
if kRes.isErr:
|
|
|
|
echo kRes.error
|
|
|
|
quit(QuitFailure)
|
|
|
|
|
|
|
|
kRes.get()
|
|
|
|
|
2024-05-30 20:30:40 +00:00
|
|
|
func makeTx(
|
2024-10-22 02:07:43 +00:00
|
|
|
t: var TestEnv, recipient: Address, amount: UInt256, payload: openArray[byte] = []
|
|
|
|
): Transaction =
|
2022-03-30 04:50:35 +00:00
|
|
|
const
|
|
|
|
gasLimit = 75000.GasInt
|
|
|
|
gasPrice = 30.gwei
|
|
|
|
|
|
|
|
let tx = Transaction(
|
2024-10-22 02:07:43 +00:00
|
|
|
txType: TxLegacy,
|
|
|
|
chainId: t.chainId,
|
|
|
|
nonce: AccountNonce(t.nonce),
|
2022-03-30 04:50:35 +00:00
|
|
|
gasPrice: gasPrice,
|
|
|
|
gasLimit: gasLimit,
|
2024-10-22 02:07:43 +00:00
|
|
|
to: Opt.some(recipient),
|
|
|
|
value: amount,
|
|
|
|
payload: @payload,
|
2022-03-30 04:50:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
inc t.nonce
|
2024-10-04 14:34:31 +00:00
|
|
|
signTransaction(tx, t.vaultKey, eip155 = true)
|
2022-03-30 04:50:35 +00:00
|
|
|
|
2024-10-22 02:07:43 +00:00
|
|
|
proc createPooledTransactionWithBlob(
|
|
|
|
t: var TestEnv, recipient: Address, amount: UInt256
|
|
|
|
): PooledTransaction =
|
|
|
|
# Create the transaction
|
|
|
|
let
|
|
|
|
tc = BlobTx(
|
|
|
|
recipient: Opt.some(recipient),
|
|
|
|
gasLimit: 100000.GasInt,
|
|
|
|
gasTip: GasInt(10 ^ 9),
|
|
|
|
gasFee: GasInt(10 ^ 9),
|
|
|
|
blobGasFee: u256(1),
|
|
|
|
blobCount: 1,
|
|
|
|
blobID: 1,
|
|
|
|
)
|
|
|
|
params = MakeTxParams(chainId: t.chainId, key: t.vaultKey, nonce: t.nonce)
|
|
|
|
|
|
|
|
inc t.nonce
|
|
|
|
params.makeTx(tc)
|
|
|
|
|
|
|
|
func signTxWithNonce(t: TestEnv, tx: Transaction, nonce: AccountNonce): Transaction =
|
2023-08-04 03:59:12 +00:00
|
|
|
var tx = tx
|
|
|
|
tx.nonce = nonce
|
2024-10-04 14:34:31 +00:00
|
|
|
signTransaction(tx, t.vaultKey, eip155 = true)
|
2023-08-04 03:59:12 +00:00
|
|
|
|
2023-07-25 05:28:17 +00:00
|
|
|
proc initEnv(envFork: HardFork): TestEnv =
|
2024-10-22 02:07:43 +00:00
|
|
|
var conf = makeConfig(
|
|
|
|
@["--custom-network:" & genesisFile.findFilePath(baseDir, repoDir).value]
|
2022-03-30 04:50:35 +00:00
|
|
|
)
|
|
|
|
|
2024-10-22 02:07:43 +00:00
|
|
|
conf.networkParams.genesis.alloc[recipient] = GenesisAccount(code: contractCode)
|
|
|
|
|
2023-07-25 05:28:17 +00:00
|
|
|
if envFork >= MergeFork:
|
2024-12-17 11:42:13 +00:00
|
|
|
conf.networkParams.config.mergeNetsplitBlock = Opt.some(0'u64)
|
2024-06-14 07:31:08 +00:00
|
|
|
conf.networkParams.config.terminalTotalDifficulty = Opt.some(100.u256)
|
2023-07-25 05:28:17 +00:00
|
|
|
|
|
|
|
if envFork >= Shanghai:
|
2024-06-14 07:31:08 +00:00
|
|
|
conf.networkParams.config.shanghaiTime = Opt.some(0.EthTime)
|
2023-07-25 05:28:17 +00:00
|
|
|
|
|
|
|
if envFork >= Cancun:
|
2024-06-14 07:31:08 +00:00
|
|
|
conf.networkParams.config.cancunTime = Opt.some(0.EthTime)
|
2022-03-30 04:50:35 +00:00
|
|
|
|
|
|
|
let
|
2024-10-22 02:07:43 +00:00
|
|
|
com =
|
2024-12-13 04:53:41 +00:00
|
|
|
CommonRef.new(newCoreDbRef DefaultDbMemory, nil, conf.networkId, conf.networkParams)
|
2024-09-04 09:54:54 +00:00
|
|
|
chain = newForkedChain(com, com.genesisHeader)
|
2022-03-30 04:50:35 +00:00
|
|
|
|
|
|
|
result = TestEnv(
|
|
|
|
conf: conf,
|
2022-12-02 04:39:12 +00:00
|
|
|
com: com,
|
2022-03-30 04:50:35 +00:00
|
|
|
chain: chain,
|
2024-12-13 06:21:20 +00:00
|
|
|
xp: TxPoolRef.new(chain),
|
2022-03-30 04:50:35 +00:00
|
|
|
vaultKey: privKey(vaultKeyHex),
|
|
|
|
chainId: conf.networkParams.config.chainId,
|
2024-10-22 02:07:43 +00:00
|
|
|
nonce: 0'u64,
|
2022-03-30 04:50:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const
|
|
|
|
amount = 1000.u256
|
|
|
|
slot = 0x11.u256
|
2024-10-03 11:42:24 +00:00
|
|
|
prevRandao = Bytes32 EMPTY_UNCLE_HASH # it can be any valid hash
|
2022-03-30 04:50:35 +00:00
|
|
|
|
2024-05-30 10:11:41 +00:00
|
|
|
proc runTxPoolPosTest() =
|
2024-10-22 02:07:43 +00:00
|
|
|
var env = initEnv(MergeFork)
|
2022-03-30 04:50:35 +00:00
|
|
|
|
|
|
|
var
|
|
|
|
tx = env.makeTx(recipient, amount)
|
|
|
|
xp = env.xp
|
2022-12-02 04:39:12 +00:00
|
|
|
com = env.com
|
2022-03-30 04:50:35 +00:00
|
|
|
chain = env.chain
|
|
|
|
body: BlockBody
|
|
|
|
blk: EthBlock
|
|
|
|
|
|
|
|
suite "Test TxPool with PoS block":
|
2024-07-25 15:36:08 +00:00
|
|
|
test "TxPool add":
|
|
|
|
xp.add(PooledTransaction(tx: tx))
|
2022-03-30 04:50:35 +00:00
|
|
|
|
|
|
|
test "TxPool jobCommit":
|
|
|
|
check xp.nItems.total == 1
|
|
|
|
|
|
|
|
test "TxPool ethBlock":
|
2022-12-06 05:55:40 +00:00
|
|
|
com.pos.prevRandao = prevRandao
|
|
|
|
com.pos.feeRecipient = feeRecipient
|
2023-10-18 02:16:11 +00:00
|
|
|
com.pos.timestamp = EthTime.now()
|
2022-12-06 05:55:40 +00:00
|
|
|
|
2023-11-01 02:24:32 +00:00
|
|
|
let r = xp.assembleBlock()
|
|
|
|
if r.isErr:
|
|
|
|
debugEcho r.error
|
|
|
|
check false
|
|
|
|
return
|
2022-03-30 04:50:35 +00:00
|
|
|
|
2024-05-15 03:07:59 +00:00
|
|
|
blk = r.get.blk
|
2024-10-22 02:07:43 +00:00
|
|
|
body = BlockBody(transactions: blk.txs, uncles: blk.uncles)
|
2022-03-30 04:50:35 +00:00
|
|
|
check blk.txs.len == 1
|
2022-12-06 05:55:40 +00:00
|
|
|
|
2022-03-30 04:50:35 +00:00
|
|
|
test "PoS persistBlocks":
|
2024-09-04 09:54:54 +00:00
|
|
|
let rr = chain.importBlock(EthBlock.init(blk.header, body))
|
2024-05-31 07:13:56 +00:00
|
|
|
check rr.isOk()
|
2022-03-30 04:50:35 +00:00
|
|
|
|
|
|
|
test "validate TxPool prevRandao setter":
|
2024-10-27 18:56:28 +00:00
|
|
|
var sdb = LedgerRef.init(com.db)
|
2024-05-30 10:11:41 +00:00
|
|
|
let val = sdb.getStorage(recipient, slot)
|
2024-10-03 11:42:24 +00:00
|
|
|
let randao = Bytes32(val.toBytesBE)
|
2022-03-30 04:50:35 +00:00
|
|
|
check randao == prevRandao
|
|
|
|
|
2022-04-04 02:01:39 +00:00
|
|
|
test "feeRecipient rewarded":
|
|
|
|
check blk.header.coinbase == feeRecipient
|
2024-10-27 18:56:28 +00:00
|
|
|
var sdb = LedgerRef.init(com.db)
|
2022-04-04 02:01:39 +00:00
|
|
|
let bal = sdb.getBalance(feeRecipient)
|
|
|
|
check not bal.isZero
|
|
|
|
|
2024-05-30 10:11:41 +00:00
|
|
|
proc runTxPoolBlobhashTest() =
|
2024-10-22 02:07:43 +00:00
|
|
|
var env = initEnv(Cancun)
|
2023-07-25 05:28:17 +00:00
|
|
|
|
|
|
|
var
|
2024-10-22 02:07:43 +00:00
|
|
|
tx1 = env.createPooledTransactionWithBlob(recipient, amount)
|
|
|
|
tx2 = env.createPooledTransactionWithBlob(recipient, amount)
|
2023-07-25 05:28:17 +00:00
|
|
|
xp = env.xp
|
|
|
|
com = env.com
|
|
|
|
chain = env.chain
|
|
|
|
body: BlockBody
|
|
|
|
blk: EthBlock
|
|
|
|
|
|
|
|
suite "Test TxPool with blobhash block":
|
|
|
|
test "TxPool jobCommit":
|
2024-10-22 02:07:43 +00:00
|
|
|
xp.add(tx1)
|
|
|
|
xp.add(tx2)
|
2023-08-04 03:59:12 +00:00
|
|
|
check xp.nItems.total == 2
|
2023-07-25 05:28:17 +00:00
|
|
|
|
|
|
|
test "TxPool ethBlock":
|
|
|
|
com.pos.prevRandao = prevRandao
|
|
|
|
com.pos.feeRecipient = feeRecipient
|
2023-10-18 02:16:11 +00:00
|
|
|
com.pos.timestamp = EthTime.now()
|
2023-07-25 05:28:17 +00:00
|
|
|
|
2023-11-01 02:24:32 +00:00
|
|
|
let r = xp.assembleBlock()
|
|
|
|
if r.isErr:
|
|
|
|
debugEcho r.error
|
|
|
|
check false
|
|
|
|
return
|
2023-07-25 05:28:17 +00:00
|
|
|
|
2024-08-08 23:05:18 +00:00
|
|
|
let bundle = r.get
|
|
|
|
blk = bundle.blk
|
2023-07-25 05:28:17 +00:00
|
|
|
body = BlockBody(
|
|
|
|
transactions: blk.txs,
|
|
|
|
uncles: blk.uncles,
|
2024-10-22 02:07:43 +00:00
|
|
|
withdrawals: Opt.some(newSeq[Withdrawal]()),
|
2023-07-25 05:28:17 +00:00
|
|
|
)
|
2023-08-04 03:59:12 +00:00
|
|
|
check blk.txs.len == 2
|
2023-07-25 05:28:17 +00:00
|
|
|
|
2024-08-08 23:05:18 +00:00
|
|
|
let
|
|
|
|
gasUsed1 = xp.vmState.receipts[0].cumulativeGasUsed
|
|
|
|
gasUsed2 = xp.vmState.receipts[1].cumulativeGasUsed - gasUsed1
|
2024-10-22 02:07:43 +00:00
|
|
|
totalBlobGasUsed = tx1.tx.getTotalBlobGas + tx2.tx.getTotalBlobGas
|
|
|
|
blockValue =
|
|
|
|
gasUsed1.u256 * tx1.tx.effectiveGasTip(blk.header.baseFeePerGas).u256 +
|
|
|
|
gasUsed2.u256 * tx2.tx.effectiveGasTip(blk.header.baseFeePerGas).u256
|
2024-08-08 23:05:18 +00:00
|
|
|
|
|
|
|
check blockValue == bundle.blockValue
|
2024-10-22 02:07:43 +00:00
|
|
|
check totalBlobGasUsed == blk.header.blobGasUsed.get()
|
2024-08-08 23:05:18 +00:00
|
|
|
|
2023-07-25 05:28:17 +00:00
|
|
|
test "Blobhash persistBlocks":
|
2024-09-04 09:54:54 +00:00
|
|
|
let rr = chain.importBlock(EthBlock.init(blk.header, body))
|
2024-05-31 07:13:56 +00:00
|
|
|
check rr.isOk()
|
2023-07-25 05:28:17 +00:00
|
|
|
|
|
|
|
test "validate TxPool prevRandao setter":
|
2024-10-27 18:56:28 +00:00
|
|
|
var sdb = LedgerRef.init(com.db)
|
2024-05-30 10:11:41 +00:00
|
|
|
let val = sdb.getStorage(recipient, slot)
|
2024-10-03 11:42:24 +00:00
|
|
|
let randao = Bytes32(val.toBytesBE)
|
2023-07-25 05:28:17 +00:00
|
|
|
check randao == prevRandao
|
|
|
|
|
|
|
|
test "feeRecipient rewarded":
|
|
|
|
check blk.header.coinbase == feeRecipient
|
2024-10-27 18:56:28 +00:00
|
|
|
var sdb = LedgerRef.init(com.db)
|
2023-07-25 05:28:17 +00:00
|
|
|
let bal = sdb.getBalance(feeRecipient)
|
|
|
|
check not bal.isZero
|
|
|
|
|
2023-08-04 03:59:12 +00:00
|
|
|
test "add tx with nonce too low":
|
|
|
|
let
|
|
|
|
tx3 = env.makeTx(recipient, amount)
|
2024-10-22 02:07:43 +00:00
|
|
|
tx4 = env.signTxWithNonce(tx3, AccountNonce(env.nonce - 2))
|
2023-08-04 03:59:12 +00:00
|
|
|
xp = env.xp
|
|
|
|
|
2024-12-13 06:21:20 +00:00
|
|
|
check xp.smartHead(blk.header)
|
2024-07-25 15:36:08 +00:00
|
|
|
xp.add(PooledTransaction(tx: tx4))
|
2023-08-04 03:59:12 +00:00
|
|
|
|
|
|
|
check inPoolAndOk(xp, rlpHash(tx4)) == false
|
|
|
|
|
2024-05-30 10:11:41 +00:00
|
|
|
proc runTxHeadDelta(noisy = true) =
|
2022-04-04 08:34:59 +00:00
|
|
|
## see github.com/status-im/nimbus-eth1/issues/1031
|
|
|
|
|
2022-04-04 15:56:21 +00:00
|
|
|
suite "TxPool: Synthesising blocks (covers issue #1031)":
|
|
|
|
test "Packing and adding multiple blocks to chain":
|
2022-04-04 08:34:59 +00:00
|
|
|
var
|
2023-07-25 05:28:17 +00:00
|
|
|
env = initEnv(MergeFork)
|
2022-04-04 08:34:59 +00:00
|
|
|
xp = env.xp
|
2022-12-02 04:39:12 +00:00
|
|
|
com = env.com
|
2022-04-04 08:34:59 +00:00
|
|
|
chain = env.chain
|
2024-12-18 04:04:23 +00:00
|
|
|
head = chain.latestHeader
|
2022-04-04 08:34:59 +00:00
|
|
|
timestamp = head.timestamp
|
|
|
|
|
|
|
|
const
|
|
|
|
txPerblock = 20
|
|
|
|
numBlocks = 10
|
|
|
|
|
|
|
|
# setTraceLevel()
|
|
|
|
|
2022-04-08 14:05:30 +00:00
|
|
|
block:
|
2024-10-22 02:07:43 +00:00
|
|
|
for n in 0 ..< numBlocks:
|
|
|
|
for tn in 0 ..< txPerblock:
|
2022-04-04 08:34:59 +00:00
|
|
|
let tx = env.makeTx(recipient, amount)
|
2024-05-15 03:07:59 +00:00
|
|
|
xp.add(PooledTransaction(tx: tx))
|
2022-04-04 08:34:59 +00:00
|
|
|
|
2024-10-22 02:07:43 +00:00
|
|
|
noisy.say "***",
|
|
|
|
"txDB",
|
2022-04-04 08:34:59 +00:00
|
|
|
&" n={n}",
|
2022-04-04 15:56:21 +00:00
|
|
|
# pending/staged/packed : total/disposed
|
|
|
|
&" stats={xp.nItems.pp}"
|
2022-04-04 08:34:59 +00:00
|
|
|
|
2023-10-18 02:16:11 +00:00
|
|
|
timestamp = timestamp + 1
|
2022-12-06 05:55:40 +00:00
|
|
|
com.pos.prevRandao = prevRandao
|
2024-10-22 02:07:43 +00:00
|
|
|
com.pos.timestamp = timestamp
|
2022-12-06 05:55:40 +00:00
|
|
|
com.pos.feeRecipient = feeRecipient
|
|
|
|
|
2023-11-01 02:24:32 +00:00
|
|
|
let r = xp.assembleBlock()
|
|
|
|
if r.isErr:
|
|
|
|
debugEcho r.error
|
|
|
|
check false
|
|
|
|
return
|
|
|
|
|
2024-05-15 03:07:59 +00:00
|
|
|
let blk = r.get.blk
|
2024-10-22 02:07:43 +00:00
|
|
|
let body = BlockBody(transactions: blk.txs, uncles: blk.uncles)
|
2022-04-04 08:34:59 +00:00
|
|
|
|
2022-04-04 15:56:21 +00:00
|
|
|
# Commit to block chain
|
2024-09-04 09:54:54 +00:00
|
|
|
check chain.importBlock(EthBlock.init(blk.header, body)).isOk
|
2022-04-04 08:34:59 +00:00
|
|
|
|
2022-04-04 15:56:21 +00:00
|
|
|
# Synchronise TxPool against new chain head, register txs differences.
|
|
|
|
# In this particular case, these differences will simply flush the
|
|
|
|
# packer bucket.
|
2024-12-13 06:21:20 +00:00
|
|
|
check xp.smartHead(blk.header)
|
2022-04-04 15:56:21 +00:00
|
|
|
|
|
|
|
# Move TxPool chain head to new chain head and apply delta jobs
|
|
|
|
check xp.nItems.staged == 0
|
|
|
|
check xp.nItems.packed == 0
|
|
|
|
|
|
|
|
setErrorLevel() # in case we set trace level
|
2022-04-04 08:34:59 +00:00
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
check com.syncCurrent == 10.BlockNumber
|
2024-12-18 04:04:23 +00:00
|
|
|
head = chain.headerByNumber(com.syncCurrent).expect("block header exists")
|
2022-04-04 08:34:59 +00:00
|
|
|
let
|
2024-10-27 18:56:28 +00:00
|
|
|
sdb = LedgerRef.init(com.db)
|
2022-04-04 08:34:59 +00:00
|
|
|
expected = u256(txPerblock * numBlocks) * amount
|
|
|
|
balance = sdb.getBalance(recipient)
|
|
|
|
check balance == expected
|
|
|
|
|
2024-06-29 05:43:17 +00:00
|
|
|
proc runGetBlockBodyTest() =
|
|
|
|
var
|
|
|
|
env = initEnv(Cancun)
|
|
|
|
blockTime = EthTime.now()
|
2024-10-08 02:37:36 +00:00
|
|
|
parentHeader: Header
|
|
|
|
currentHeader: Header
|
2024-06-29 05:43:17 +00:00
|
|
|
|
|
|
|
suite "Test get parent transactions after persistBlock":
|
|
|
|
test "TxPool create first block":
|
|
|
|
let
|
|
|
|
tx1 = env.makeTx(recipient, 1.u256)
|
|
|
|
tx2 = env.makeTx(recipient, 2.u256)
|
|
|
|
|
2024-07-25 15:36:08 +00:00
|
|
|
env.xp.add(PooledTransaction(tx: tx1))
|
|
|
|
env.xp.add(PooledTransaction(tx: tx2))
|
2024-06-29 05:43:17 +00:00
|
|
|
|
|
|
|
env.com.pos.prevRandao = prevRandao
|
|
|
|
env.com.pos.feeRecipient = feeRecipient
|
|
|
|
env.com.pos.timestamp = blockTime
|
|
|
|
|
|
|
|
let r = env.xp.assembleBlock()
|
|
|
|
if r.isErr:
|
|
|
|
check false
|
|
|
|
return
|
|
|
|
|
|
|
|
let blk = r.get.blk
|
2024-09-04 09:54:54 +00:00
|
|
|
check env.chain.importBlock(blk).isOk
|
2024-06-29 05:43:17 +00:00
|
|
|
parentHeader = blk.header
|
2024-12-13 06:21:20 +00:00
|
|
|
check env.xp.smartHead(parentHeader)
|
2024-06-29 05:43:17 +00:00
|
|
|
check blk.transactions.len == 2
|
|
|
|
|
|
|
|
test "TxPool create second block":
|
|
|
|
let
|
|
|
|
tx1 = env.makeTx(recipient, 3.u256)
|
|
|
|
tx2 = env.makeTx(recipient, 4.u256)
|
|
|
|
tx3 = env.makeTx(recipient, 5.u256)
|
|
|
|
|
2024-07-25 15:36:08 +00:00
|
|
|
env.xp.add(PooledTransaction(tx: tx1))
|
|
|
|
env.xp.add(PooledTransaction(tx: tx2))
|
|
|
|
env.xp.add(PooledTransaction(tx: tx3))
|
2024-06-29 05:43:17 +00:00
|
|
|
|
|
|
|
env.com.pos.prevRandao = prevRandao
|
|
|
|
env.com.pos.feeRecipient = feeRecipient
|
|
|
|
env.com.pos.timestamp = blockTime + 1
|
|
|
|
|
|
|
|
let r = env.xp.assembleBlock()
|
|
|
|
if r.isErr:
|
|
|
|
check false
|
|
|
|
return
|
|
|
|
|
|
|
|
let blk = r.get.blk
|
2024-09-04 09:54:54 +00:00
|
|
|
check env.chain.importBlock(blk).isOk
|
2024-06-29 05:43:17 +00:00
|
|
|
currentHeader = blk.header
|
2024-12-13 06:21:20 +00:00
|
|
|
check env.xp.smartHead(currentHeader)
|
2024-06-29 05:43:17 +00:00
|
|
|
check blk.transactions.len == 3
|
2024-09-04 09:54:54 +00:00
|
|
|
let currHash = currentHeader.blockHash
|
|
|
|
check env.chain.forkChoice(currHash, currHash).isOk
|
2024-06-29 05:43:17 +00:00
|
|
|
|
2024-05-30 10:11:41 +00:00
|
|
|
proc txPool2Main*() =
|
2024-10-22 02:07:43 +00:00
|
|
|
const noisy = defined(debug)
|
|
|
|
|
2024-10-22 06:42:16 +00:00
|
|
|
loadKzgTrustedSetup().expect("Failed to load KZG trusted setup")
|
2022-04-04 08:34:59 +00:00
|
|
|
|
|
|
|
setErrorLevel() # mute logger
|
|
|
|
|
2023-07-25 05:28:17 +00:00
|
|
|
runTxPoolPosTest()
|
|
|
|
runTxPoolBlobhashTest()
|
2024-05-30 10:11:41 +00:00
|
|
|
noisy.runTxHeadDelta
|
2024-06-29 05:43:17 +00:00
|
|
|
runGetBlockBodyTest()
|
2024-05-30 10:11:41 +00:00
|
|
|
|
|
|
|
when isMainModule:
|
|
|
|
txPool2Main()
|
2022-04-04 08:34:59 +00:00
|
|
|
|
2022-04-08 14:05:30 +00:00
|
|
|
# End
|