2023-10-23 13:59:57 +00:00
|
|
|
import
|
|
|
|
std/strutils,
|
|
|
|
chronicles,
|
|
|
|
./step_desc,
|
|
|
|
./customizer,
|
|
|
|
../test_env,
|
|
|
|
../types
|
|
|
|
|
2023-10-19 03:28:52 +00:00
|
|
|
# Send a modified version of the latest payload produced using NewPayloadV3
|
2023-10-23 13:59:57 +00:00
|
|
|
type
|
|
|
|
SendModifiedLatestPayload* = ref object of TestStep
|
|
|
|
clientID* : int
|
|
|
|
newPayloadCustomizer*: NewPayloadCustomizer
|
2023-10-19 03:28:52 +00:00
|
|
|
|
|
|
|
method execute*(step: SendModifiedLatestPayload, ctx: CancunTestContext): bool =
|
|
|
|
# Get the latest payload
|
2023-10-23 13:59:57 +00:00
|
|
|
doAssert(step.newPayloadCustomizer.isNil.not, "TEST-FAIL: no payload customizer available")
|
|
|
|
|
|
|
|
var
|
|
|
|
env = ctx.env
|
|
|
|
payload = env.clMock.latestExecutableData
|
|
|
|
expectedError = step.newPayloadCustomizer.getExpectedError()
|
|
|
|
expectedStatus = PayloadExecutionStatus.valid
|
|
|
|
|
|
|
|
doAssert(env.clMock.latestBlobsBundle.isSome, "TEST-FAIL: no blob bundle available")
|
2023-10-19 03:28:52 +00:00
|
|
|
|
|
|
|
# Send a custom new payload
|
2023-10-23 13:59:57 +00:00
|
|
|
step.newPayloadCustomizer.setEngineAPIVersionResolver(env.engine.com)
|
|
|
|
|
|
|
|
payload = step.newPayloadCustomizer.customizePayload(payload)
|
|
|
|
let version = step.newPayloadCustomizer.newPayloadVersion(payload.basePayload.timestamp.uint64)
|
|
|
|
|
|
|
|
if step.newPayloadCustomizer.getExpectInvalidStatus():
|
|
|
|
expectedStatus = PayloadExecutionStatus.invalid
|
2023-10-19 03:28:52 +00:00
|
|
|
|
|
|
|
# Send the payload
|
2023-10-23 13:59:57 +00:00
|
|
|
doAssert(step.clientID < env.numEngines(), "invalid client index " & $step.clientID)
|
|
|
|
|
|
|
|
let eng = env.engines(step.clientID)
|
|
|
|
let r = eng.client.newPayload(version, payload)
|
|
|
|
if expectedError != 0:
|
|
|
|
r.expectErrorCode(expectedError)
|
2023-10-19 03:28:52 +00:00
|
|
|
else:
|
2023-10-23 13:59:57 +00:00
|
|
|
r.expectNPStatus(expectedStatus)
|
|
|
|
|
|
|
|
return true
|
2023-10-19 03:28:52 +00:00
|
|
|
|
|
|
|
method description*(step: SendModifiedLatestPayload): string =
|
2023-10-23 13:59:57 +00:00
|
|
|
let desc = "SendModifiedLatestPayload: client $1, expected invalid=$2" % [
|
|
|
|
$step.clientID, $step.newPayloadCustomizer.getExpectInvalidStatus()]
|
|
|
|
#[
|
2023-10-19 03:28:52 +00:00
|
|
|
TODO: Figure out if we need this.
|
|
|
|
if step.VersionedHashes != nil {
|
|
|
|
desc += step.VersionedHashes.Description()
|
|
|
|
}
|
2023-10-23 13:59:57 +00:00
|
|
|
]#
|
2023-10-19 03:28:52 +00:00
|
|
|
return desc
|