nimbus-eth1/hive_integration/nodocker/engine/exchange_cap_tests.nim

102 lines
2.3 KiB
Nim
Raw Normal View History

import
std/[options],
eth/common/eth_types,
./test_env,
./types,
chronicles,
../../nimbus/common/hardforks
import ../../tools/common/helpers except LogLevel
type
2023-08-21 02:08:54 +00:00
ECSpec* = ref object of BaseSpec
exec*: proc(env: TestEnv): bool
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",
]
proc ecImpl(env: TestEnv, minExpectedCaps: openArray[string]): bool =
let res = env.client.exchangeCapabilities(@minExpectedCaps)
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-21 02:08:54 +00:00
proc ecShanghai(env: TestEnv): bool =
ecImpl(env, ShanghaiCapabilities)
2023-08-21 02:08:54 +00:00
proc ecCancun(env: TestEnv): bool =
ecImpl(env, CancunCapabilities)
proc getCCShanghai(timestamp: int): ChainConfig =
result = getChainConfig("Shanghai")
result.shanghaiTime = some(EthTime(timestamp))
proc getCCCancun(timestamp: int): ChainConfig =
result = getChainConfig("Cancun")
result.cancunTime = some(EthTime(timestamp))
2023-08-21 02:08:54 +00:00
proc specExecute(ws: BaseSpec): bool =
let ws = ECSpec(ws)
let env = TestEnv.new(ws.conf)
2023-08-21 02:08:54 +00:00
result = ws.exec(env)
env.close()
2023-08-21 02:08:54 +00:00
# const doesn't work with ref object
2023-08-21 02:08:54 +00:00
let ecTestList* = [
TestDesc(
name: "Exchange Capabilities - Shanghai",
2023-08-21 02:08:54 +00:00
run: specExecute,
spec: ECSpec(
exec: ecShanghai,
conf: getCCShanghai(0)
)
),
2023-08-21 02:08:54 +00:00
TestDesc(
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-21 02:08:54 +00:00
TestDesc(
name: "Exchange Capabilities - Cancun",
2023-08-21 02:08:54 +00:00
run: specExecute,
spec: ECSpec(
exec: ecCancun,
conf: getCCCancun(0)
)
),
2023-08-21 02:08:54 +00:00
TestDesc(
name: "Exchange Capabilities - Cancun (Not active)",
2023-08-21 02:08:54 +00:00
run: specExecute,
spec: ECSpec(
exec: ecCancun,
conf: getCCCancun(1000)
)
)
]