mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 05:14:14 +00:00
Simplify pyspec simulator
This commit is contained in:
parent
369a54d62a
commit
5754a9079b
@ -7,7 +7,8 @@ import
|
|||||||
../../../tests/rpcclient/eth_api,
|
../../../tests/rpcclient/eth_api,
|
||||||
../../../premix/parser,
|
../../../premix/parser,
|
||||||
../../../nimbus/rpc/hexstrings,
|
../../../nimbus/rpc/hexstrings,
|
||||||
../../../nimbus/beacon/execution_types
|
../../../nimbus/beacon/execution_types,
|
||||||
|
../../../nimbus/beacon/web3_eth_conv
|
||||||
|
|
||||||
import web3/engine_api as web3_engine_api
|
import web3/engine_api as web3_engine_api
|
||||||
|
|
||||||
@ -142,14 +143,32 @@ proc newPayloadV3*(client: RpcClient,
|
|||||||
wrapTrySimpleRes:
|
wrapTrySimpleRes:
|
||||||
client.engine_newPayloadV3(payload, versionedHashes, parentBeaconBlockRoot)
|
client.engine_newPayloadV3(payload, versionedHashes, parentBeaconBlockRoot)
|
||||||
|
|
||||||
|
#proc newPayload*(client: RpcClient,
|
||||||
|
# payload: ExecutionPayload,
|
||||||
|
# version: Version):
|
||||||
|
# Result[PayloadStatusV1, string] =
|
||||||
|
# if version == Version.V1:
|
||||||
|
# client.newPayloadV1(payload.V1)
|
||||||
|
# else:
|
||||||
|
# client.newPayloadV2(payload.V2)
|
||||||
|
|
||||||
|
proc collectBlobHashes(list: openArray[Web3Tx]): seq[Web3Hash] =
|
||||||
|
for w3tx in list:
|
||||||
|
let tx = ethTx(w3Tx)
|
||||||
|
for h in tx.versionedHashes:
|
||||||
|
result.add w3Hash(h)
|
||||||
|
|
||||||
proc newPayload*(client: RpcClient,
|
proc newPayload*(client: RpcClient,
|
||||||
payload: ExecutionPayload,
|
payload: ExecutionPayload,
|
||||||
version: Version):
|
beaconRoot = none(common.Hash256)): Result[PayloadStatusV1, string] =
|
||||||
Result[PayloadStatusV1, string] =
|
case payload.version
|
||||||
if version == Version.V1:
|
of Version.V1: return client.newPayloadV1(payload.V1)
|
||||||
client.newPayloadV1(payload.V1)
|
of Version.V2: return client.newPayloadV2(payload.V2)
|
||||||
else:
|
of Version.V3:
|
||||||
client.newPayloadV2(payload.V2)
|
let versionedHashes = collectBlobHashes(payload.transactions)
|
||||||
|
return client.newPayloadV3(payload.V3,
|
||||||
|
versionedHashes,
|
||||||
|
w3Hash beaconRoot.get)
|
||||||
|
|
||||||
proc exchangeCapabilities*(client: RpcClient,
|
proc exchangeCapabilities*(client: RpcClient,
|
||||||
methods: seq[string]):
|
methods: seq[string]):
|
||||||
|
@ -193,7 +193,7 @@ proc execute*(ws: ReorgSpec, env: TestEnv): bool =
|
|||||||
# This block is part of both chains, simply forward it to the secondary client
|
# This block is part of both chains, simply forward it to the secondary client
|
||||||
payload = env.clMock.latestPayloadBuilt
|
payload = env.clMock.latestPayloadBuilt
|
||||||
|
|
||||||
let r = sec.client.newPayload(payload, payload.version)
|
let r = sec.client.newPayload(payload)
|
||||||
r.expectStatus(valid)
|
r.expectStatus(valid)
|
||||||
|
|
||||||
let fcState = ForkchoiceStateV1(
|
let fcState = ForkchoiceStateV1(
|
||||||
@ -304,7 +304,7 @@ proc execute*(ws: ReorgSpec, env: TestEnv): bool =
|
|||||||
hash=payload.blockHash.short,
|
hash=payload.blockHash.short,
|
||||||
parentHash=payload.parentHash.short
|
parentHash=payload.parentHash.short
|
||||||
|
|
||||||
let r = env.client.newPayload(payload, version)
|
let r = env.client.newPayload(payload)
|
||||||
r.expectStatusEither(valid, accepted)
|
r.expectStatusEither(valid, accepted)
|
||||||
|
|
||||||
let fcState = ForkchoiceStateV1(headBlockHash: payload.blockHash)
|
let fcState = ForkchoiceStateV1(headBlockHash: payload.blockHash)
|
||||||
|
@ -109,32 +109,6 @@ proc validatePostState(node: JsonNode, t: TestEnv): bool =
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
proc collectBlobHashes(list: openArray[Web3Tx]): seq[Web3Hash] =
|
|
||||||
for w3tx in list:
|
|
||||||
let tx = ethTx(w3Tx)
|
|
||||||
for h in tx.versionedHashes:
|
|
||||||
result.add w3Hash(h)
|
|
||||||
|
|
||||||
proc newPayload(client: RpcClient,
|
|
||||||
payload: ExecutionPayload,
|
|
||||||
beaconRoot: Option[common.Hash256]): Result[PayloadStatusV1, string] =
|
|
||||||
case payload.version
|
|
||||||
of Version.V1: return client.newPayloadV1(payload.V1)
|
|
||||||
of Version.V2: return client.newPayloadV2(payload.V2)
|
|
||||||
of Version.V3:
|
|
||||||
let versionedHashes = collectBlobHashes(payload.transactions)
|
|
||||||
return client.newPayloadV3(payload.V3,
|
|
||||||
versionedHashes,
|
|
||||||
w3Hash beaconRoot.get)
|
|
||||||
|
|
||||||
proc forkchoiceUpdated(client: RpcClient, version: Version,
|
|
||||||
update: ForkchoiceStateV1):
|
|
||||||
Result[ForkchoiceUpdatedResponse, string] =
|
|
||||||
case version
|
|
||||||
of Version.V1: client.forkchoiceUpdatedV1(update)
|
|
||||||
of Version.V2: client.forkchoiceUpdatedV2(update)
|
|
||||||
of Version.V3: client.forkchoiceUpdatedV3(update)
|
|
||||||
|
|
||||||
proc runTest(node: JsonNode, network: string): TestStatus =
|
proc runTest(node: JsonNode, network: string): TestStatus =
|
||||||
let conf = getChainConfig(network)
|
let conf = getChainConfig(network)
|
||||||
var t = TestEnv(conf: makeTestConfig())
|
var t = TestEnv(conf: makeTestConfig())
|
||||||
|
@ -9,7 +9,6 @@ import
|
|||||||
constants,
|
constants,
|
||||||
transaction,
|
transaction,
|
||||||
db/accounts_cache,
|
db/accounts_cache,
|
||||||
core/sealer,
|
|
||||||
core/chain,
|
core/chain,
|
||||||
core/tx_pool,
|
core/tx_pool,
|
||||||
rpc,
|
rpc,
|
||||||
@ -28,7 +27,6 @@ type
|
|||||||
com: CommonRef
|
com: CommonRef
|
||||||
chainRef: ChainRef
|
chainRef: ChainRef
|
||||||
rpcServer: RpcHttpServer
|
rpcServer: RpcHttpServer
|
||||||
sealingEngine: SealingEngineRef
|
|
||||||
rpcClient*: RpcHttpClient
|
rpcClient*: RpcHttpClient
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -63,10 +61,6 @@ proc setupELClient*(t: TestEnv, conf: ChainConfig, node: JsonNode) =
|
|||||||
|
|
||||||
let txPool = TxPoolRef.new(t.com, engineSigner)
|
let txPool = TxPoolRef.new(t.com, engineSigner)
|
||||||
t.rpcServer = newRpcHttpServer(["127.0.0.1:8545"])
|
t.rpcServer = newRpcHttpServer(["127.0.0.1:8545"])
|
||||||
t.sealingEngine = SealingEngineRef.new(
|
|
||||||
t.chainRef, t.ctx, engineSigner,
|
|
||||||
txPool, EngineStopped
|
|
||||||
)
|
|
||||||
|
|
||||||
let beaconEngine = BeaconEngineRef.new(txPool, t.chainRef)
|
let beaconEngine = BeaconEngineRef.new(txPool, t.chainRef)
|
||||||
setupEthRpc(t.ethNode, t.ctx, t.com, txPool, t.rpcServer)
|
setupEthRpc(t.ethNode, t.ctx, t.com, txPool, t.rpcServer)
|
||||||
@ -79,5 +73,4 @@ proc setupELClient*(t: TestEnv, conf: ChainConfig, node: JsonNode) =
|
|||||||
|
|
||||||
proc stopELClient*(t: TestEnv) =
|
proc stopELClient*(t: TestEnv) =
|
||||||
waitFor t.rpcClient.close()
|
waitFor t.rpcClient.close()
|
||||||
waitFor t.sealingEngine.stop()
|
|
||||||
waitFor t.rpcServer.closeWait()
|
waitFor t.rpcServer.closeWait()
|
||||||
|
@ -38,14 +38,14 @@ proc `$`*(stat: SimStat): string =
|
|||||||
for c in stat.failingCases:
|
for c in stat.failingCases:
|
||||||
result.add " - $1 \n" % [c]
|
result.add " - $1 \n" % [c]
|
||||||
|
|
||||||
result.add "ok: $1, skipped: $2, failed: $3" % [$stat.ok, $stat.skipped, $stat.failed]
|
result.add " - ok: $1, skipped: $2, failed: $3" % [$stat.ok, $stat.skipped, $stat.failed]
|
||||||
|
|
||||||
proc print*(stat: SimStat, dur: Duration, name: string) =
|
proc print*(stat: SimStat, dur: Duration, name: string) =
|
||||||
var f = open(name & ".md", fmWrite)
|
var f = open(name & ".md", fmWrite)
|
||||||
f.write("* " & name)
|
f.write("* " & name)
|
||||||
f.write("\n")
|
f.write("\n")
|
||||||
f.write(" - " & $stat)
|
f.write($stat)
|
||||||
f.write("\n")
|
f.write("\n")
|
||||||
f.write(" - " & dur.short)
|
f.write(" - Elapsed: " & dur.short)
|
||||||
f.write("\n")
|
f.write("\n")
|
||||||
f.close()
|
f.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user