From c722547c8cbac95cba7495561c853600a2328ee0 Mon Sep 17 00:00:00 2001 From: jangko Date: Mon, 25 Mar 2024 16:37:58 +0700 Subject: [PATCH] Fix execution types conversion functions --- tests/test_execution_types.nim | 25 +++++++++++++++++++++---- web3/execution_types.nim | 14 +++++++------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/tests/test_execution_types.nim b/tests/test_execution_types.nim index bef897e..a02ee76 100644 --- a/tests/test_execution_types.nim +++ b/tests/test_execution_types.nim @@ -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) @@ -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 diff --git a/web3/execution_types.nim b/web3/execution_types.nim index 539533a..abd224b 100644 --- a/web3/execution_types.nim +++ b/web3/execution_types.nim @@ -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)) @@ -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 @@ -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 @@ -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 = @@ -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 =