Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix execution types conversion functions #139

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions tests/test_execution_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,21 @@ suite "Execution types tests":
v2.excessBlobGas = none(Quantity)
var v1 = v2
v1.withdrawals = none(seq[WithdrawalV1])
check badv31.version == Version.V2
check badv32.version == Version.V2
check badv31.version == Version.V3
check badv32.version == Version.V3
check v2.version == Version.V2
check v1.version == Version.V1
check payload.version == Version.V3

let v31 = badv31.V3
check v31.excessBlobGas == payload.excessBlobGas.get
check v31.blobGasUsed == 0.Quantity

let v32 = badv32.V3
check v32.excessBlobGas == 0.Quantity
check v32.blobGasUsed == payload.blobGasUsed.get


test "attr version":
var v2 = attr
v2.parentBeaconBlockRoot = none(Hash256)
Expand All @@ -99,12 +108,20 @@ suite "Execution types tests":
v2.shouldOverrideBuilder = none(bool)
var v1 = v2
v1.blockValue = none(UInt256)
check badv31.version == Version.V2
check badv32.version == Version.V2
check badv31.version == Version.V3
check badv32.version == Version.V3
check v2.version == Version.V2
check v1.version == Version.V1
check response.version == Version.V3

let v31 = badv31.V3
check v31.blobsBundle == BlobsBundleV1()
check v31.shouldOverrideBuilder == response.shouldOverrideBuilder.get

let v32 = badv32.V3
check v32.blobsBundle == response.blobsBundle.get
check v32.shouldOverrideBuilder == false

test "ExecutionPayload roundtrip":
let v3 = payload.V3
check v3 == v3.executionPayload.V3
Expand Down
14 changes: 7 additions & 7 deletions web3/execution_types.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# nim-web3
# Copyright (c) 2023 Status Research & Development GmbH
# Copyright (c) 2023-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
Expand Down Expand Up @@ -61,7 +61,7 @@ type
{.push raises: [].}

func version*(payload: ExecutionPayload): Version =
if payload.blobGasUsed.isSome and payload.excessBlobGas.isSome:
if payload.blobGasUsed.isSome or payload.excessBlobGas.isSome:
Version.V3
elif payload.withdrawals.isSome:
Version.V2
Expand All @@ -77,7 +77,7 @@ func version*(attr: PayloadAttributes): Version =
Version.V1

func version*(res: GetPayloadResponse): Version =
if res.blobsBundle.isSome and res.shouldOverrideBuilder.isSome:
if res.blobsBundle.isSome or res.shouldOverrideBuilder.isSome:
Version.V3
elif res.blockValue.isSome:
Version.V2
Expand Down Expand Up @@ -240,8 +240,8 @@ func V3*(p: ExecutionPayload): ExecutionPayloadV3 =
blockHash: p.blockHash,
transactions: p.transactions,
withdrawals: p.withdrawals.get,
blobGasUsed: p.blobGasUsed.get,
excessBlobGas: p.excessBlobGas.get
blobGasUsed: p.blobGasUsed.get(0.Quantity),
excessBlobGas: p.excessBlobGas.get(0.Quantity)
)

func V1*(p: ExecutionPayloadV1OrV2): ExecutionPayloadV1 =
Expand Down Expand Up @@ -371,8 +371,8 @@ func V3*(res: GetPayloadResponse): GetPayloadV3Response =
GetPayloadV3Response(
executionPayload: res.executionPayload.V3,
blockValue: res.blockValue.get,
blobsBundle: res.blobsBundle.get,
shouldOverrideBuilder: res.shouldOverrideBuilder.get
blobsBundle: res.blobsBundle.get(BlobsBundleV1()),
shouldOverrideBuilder: res.shouldOverrideBuilder.get(false)
)

func getPayloadResponse*(x: ExecutionPayloadV1): GetPayloadResponse =
Expand Down