Skip to content

Commit

Permalink
GraphQL serializes BlobVersionedHashes (hyperledger#6769)
Browse files Browse the repository at this point in the history
Fix error where GraphQL fails to serialize the versioned hash of a
blob transaction.

Signed-off-by: Danno Ferrin (shemnon) <[email protected]>
  • Loading branch information
shemnon authored Mar 21, 2024
1 parent 010f947 commit da4be73
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -256,6 +257,8 @@ Bytes32 convertImpl(final Object input) {
return null;
}
}
} else if (input instanceof VersionedHash versionedHash) {
return versionedHash.toBytes();
} else {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 =
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit da4be73

Please sign in to comment.