From da4be733e38e48d8ed381e7dbabdc1a1727c9534 Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Thu, 21 Mar 2024 05:57:22 -0700 Subject: [PATCH] GraphQL serializes BlobVersionedHashes (#6769) Fix error where GraphQL fails to serialize the versioned hash of a blob transaction. Signed-off-by: Danno Ferrin (shemnon) --- .../besu/ethereum/api/graphql/internal/Scalars.java | 3 +++ .../ethereum/api/graphql/scalar/Bytes32ScalarTest.java | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/Scalars.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/Scalars.java index bab7a278f15..5b69b0708e7 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/Scalars.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/Scalars.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.ethereum.api.graphql.internal; import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.VersionedHash; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; import java.math.BigInteger; @@ -256,6 +257,8 @@ Bytes32 convertImpl(final Object input) { return null; } } + } else if (input instanceof VersionedHash versionedHash) { + return versionedHash.toBytes(); } else { return null; } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/scalar/Bytes32ScalarTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/scalar/Bytes32ScalarTest.java index 165a8afc422..fd7d4a61b5a 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/scalar/Bytes32ScalarTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/scalar/Bytes32ScalarTest.java @@ -17,6 +17,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.datatypes.VersionedHash; import org.hyperledger.besu.ethereum.api.graphql.internal.Scalars; import java.util.Locale; @@ -42,6 +44,8 @@ public class Bytes32ScalarTest { private final StringValue strValue = StringValue.newStringValue(str).build(); private final StringValue invalidStrValue = StringValue.newStringValue("0xgh").build(); + private final VersionedHash versionedHash = new VersionedHash((byte)1, Hash.hash(value)); + @Test public void pareValueTest() { final var result = @@ -121,6 +125,12 @@ public void parseLiteralErrorTest2() { .isInstanceOf(CoercingParseLiteralException.class); } + @Test + public void parseVersionedHash() { + assertThat(scalar.getCoercing().serialize(versionedHash, GraphQLContext.newContext().build(), Locale.ENGLISH)) + .isEqualTo(versionedHash.toString()); + } + @BeforeEach public void before() { scalar = Scalars.bytes32Scalar();