2023-11-01 03:32:09 +00:00
|
|
|
# Nimbus
|
2024-02-15 02:57:05 +00:00
|
|
|
# Copyright (c) 2023-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.
|
|
|
|
|
2023-08-08 03:44:29 +00:00
|
|
|
import
|
2023-10-18 02:16:11 +00:00
|
|
|
std/[options],
|
|
|
|
eth/common/eth_types,
|
2023-08-08 03:44:29 +00:00
|
|
|
./test_env,
|
|
|
|
./types,
|
|
|
|
chronicles,
|
2024-02-15 02:57:05 +00:00
|
|
|
../../../nimbus/common/hardforks
|
2023-08-08 03:44:29 +00:00
|
|
|
|
2024-02-15 02:57:05 +00:00
|
|
|
import ../../../tools/common/helpers except LogLevel
|
2023-10-18 02:16:11 +00:00
|
|
|
|
2023-08-08 03:44:29 +00:00
|
|
|
type
|
2023-08-21 02:08:54 +00:00
|
|
|
ECSpec* = ref object of BaseSpec
|
2023-09-06 09:18:26 +00:00
|
|
|
exec*: proc(env: TestEnv): bool
|
2023-08-08 03:44:29 +00:00
|
|
|
conf*: ChainConfig
|
|
|
|
|
|
|
|
const
|
|
|
|
ShanghaiCapabilities = [
|
|
|
|
"engine_newPayloadV1",
|
|
|
|
"engine_newPayloadV2",
|
|
|
|
"engine_forkchoiceUpdatedV1",
|
|
|
|
"engine_forkchoiceUpdatedV2",
|
|
|
|
"engine_getPayloadV1",
|
|
|
|
"engine_getPayloadV2",
|
|
|
|
]
|
|
|
|
CancunCapabilities = [
|
|
|
|
"engine_newPayloadV1",
|
|
|
|
"engine_newPayloadV2",
|
|
|
|
"engine_newPayloadV3",
|
|
|
|
"engine_forkchoiceUpdatedV1",
|
|
|
|
"engine_forkchoiceUpdatedV2",
|
|
|
|
"engine_getPayloadV1",
|
|
|
|
"engine_getPayloadV2",
|
|
|
|
"engine_getPayloadV3",
|
|
|
|
]
|
|
|
|
|
2023-09-06 09:18:26 +00:00
|
|
|
proc ecImpl(env: TestEnv, minExpectedCaps: openArray[string]): bool =
|
|
|
|
let res = env.client.exchangeCapabilities(@minExpectedCaps)
|
2023-08-08 03:44:29 +00:00
|
|
|
testCond res.isOk:
|
|
|
|
error "Unable request capabilities", msg=res.error
|
|
|
|
|
|
|
|
let returnedCaps = res.get
|
|
|
|
for x in minExpectedCaps:
|
|
|
|
testCond x in returnedCaps:
|
|
|
|
error "Expected capability not found", cap=x
|
2023-08-21 02:08:54 +00:00
|
|
|
return true
|
2023-08-08 03:44:29 +00:00
|
|
|
|
2023-08-21 02:08:54 +00:00
|
|
|
proc ecShanghai(env: TestEnv): bool =
|
2023-08-08 03:44:29 +00:00
|
|
|
ecImpl(env, ShanghaiCapabilities)
|
|
|
|
|
2023-08-21 02:08:54 +00:00
|
|
|
proc ecCancun(env: TestEnv): bool =
|
2023-08-08 03:44:29 +00:00
|
|
|
ecImpl(env, CancunCapabilities)
|
|
|
|
|
|
|
|
proc getCCShanghai(timestamp: int): ChainConfig =
|
|
|
|
result = getChainConfig("Shanghai")
|
2024-06-14 07:31:08 +00:00
|
|
|
result.shanghaiTime = Opt.some(EthTime(timestamp))
|
2023-08-08 03:44:29 +00:00
|
|
|
|
|
|
|
proc getCCCancun(timestamp: int): ChainConfig =
|
|
|
|
result = getChainConfig("Cancun")
|
2024-06-14 07:31:08 +00:00
|
|
|
result.cancunTime = Opt.some(EthTime(timestamp))
|
2023-08-08 03:44:29 +00:00
|
|
|
|
2023-08-21 02:08:54 +00:00
|
|
|
proc specExecute(ws: BaseSpec): bool =
|
|
|
|
let ws = ECSpec(ws)
|
2023-09-06 09:18:26 +00:00
|
|
|
let env = TestEnv.new(ws.conf)
|
2023-08-21 02:08:54 +00:00
|
|
|
result = ws.exec(env)
|
2023-09-06 09:18:26 +00:00
|
|
|
env.close()
|
2023-08-21 02:08:54 +00:00
|
|
|
|
2023-08-08 03:44:29 +00:00
|
|
|
# const doesn't work with ref object
|
2023-08-21 02:08:54 +00:00
|
|
|
let ecTestList* = [
|
|
|
|
TestDesc(
|
2023-08-08 03:44:29 +00:00
|
|
|
name: "Exchange Capabilities - Shanghai",
|
2023-08-21 02:08:54 +00:00
|
|
|
run: specExecute,
|
|
|
|
spec: ECSpec(
|
|
|
|
exec: ecShanghai,
|
|
|
|
conf: getCCShanghai(0)
|
|
|
|
)
|
2023-08-08 03:44:29 +00:00
|
|
|
),
|
2023-08-21 02:08:54 +00:00
|
|
|
TestDesc(
|
2023-08-08 03:44:29 +00:00
|
|
|
name: "Exchange Capabilities - Shanghai (Not active)",
|
2023-08-21 02:08:54 +00:00
|
|
|
run: specExecute,
|
|
|
|
spec: ECSpec(
|
|
|
|
exec: ecShanghai,
|
|
|
|
conf: getCCShanghai(1000)
|
|
|
|
)
|
2023-08-08 03:44:29 +00:00
|
|
|
),
|
2023-08-21 02:08:54 +00:00
|
|
|
TestDesc(
|
2023-08-08 03:44:29 +00:00
|
|
|
name: "Exchange Capabilities - Cancun",
|
2023-08-21 02:08:54 +00:00
|
|
|
run: specExecute,
|
|
|
|
spec: ECSpec(
|
|
|
|
exec: ecCancun,
|
|
|
|
conf: getCCCancun(0)
|
|
|
|
)
|
2023-08-08 03:44:29 +00:00
|
|
|
),
|
2023-08-21 02:08:54 +00:00
|
|
|
TestDesc(
|
2023-08-08 03:44:29 +00:00
|
|
|
name: "Exchange Capabilities - Cancun (Not active)",
|
2023-08-21 02:08:54 +00:00
|
|
|
run: specExecute,
|
|
|
|
spec: ECSpec(
|
|
|
|
exec: ecCancun,
|
|
|
|
conf: getCCCancun(1000)
|
|
|
|
)
|
2023-08-08 03:44:29 +00:00
|
|
|
)
|
|
|
|
]
|