Skip to content

Commit

Permalink
Make graffiti append able to add codes to 28 bytes graffiti (without …
Browse files Browse the repository at this point in the history
…space) (#8276)
  • Loading branch information
zilm13 authored May 1, 2024
1 parent 7463355 commit dbc5827
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,23 @@ public Bytes32 buildGraffiti(final Optional<Bytes32> userGraffiti) {
return switch (clientGraffitiAppendFormat) {
case AUTO -> {
final int clientInfoLength = Bytes32.SIZE - 1 - userGraffitiLength;
// Could drop SPACE's `-1` in a corner case
if (clientInfoLength == 3) {
yield joinNonEmpty(
"", extractGraffiti(userGraffiti, userGraffitiLength), formatClientsInfo(4));
}
yield joinNonEmpty(
SPACE,
extractGraffiti(userGraffiti, userGraffitiLength),
formatClientsInfo(clientInfoLength));
}
case CLIENT_CODES -> {
final int clientInfoLength = Integer.min(Bytes32.SIZE - 1 - userGraffitiLength, 4);
// Could drop SPACE's `-1` in a corner case
if (clientInfoLength == 3) {
yield joinNonEmpty(
"", extractGraffiti(userGraffiti, userGraffitiLength), formatClientsInfo(4));
}
yield joinNonEmpty(
SPACE,
extractGraffiti(userGraffiti, userGraffitiLength),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class GraffitiBuilderTest {

private final String asciiGraffiti0 = "";
private static final String ASCII_GRAFFITI_20 = "I've proposed ablock";
private static final String ASCII_GRAFFITI_27 = "27 bytes of user's graffiti";
private static final String ASCII_GRAFFITI_28 = "28 bytes of user's graffiti!";
private final String asciiGraffiti32 = "I've proposed a good Teku block!";

private static final String UTF_8_GRAFFITI_4 = "\uD83D\uDE80";
Expand Down Expand Up @@ -541,6 +543,14 @@ private static Stream<Arguments> getBuildGraffitiFixtures() {
+ TEKU_CLIENT_VERSION.commit().toUnprefixedHexString().substring(0, 2)
+ BESU_CLIENT_VERSION.code()
+ BESU_CLIENT_VERSION.commit().toUnprefixedHexString().substring(0, 2)),
Arguments.of(
AUTO,
Optional.of(ASCII_GRAFFITI_27),
ASCII_GRAFFITI_27 + " " + TEKU_CLIENT_VERSION.code() + BESU_CLIENT_VERSION.code()),
Arguments.of(
AUTO,
Optional.of(ASCII_GRAFFITI_28),
ASCII_GRAFFITI_28 + TEKU_CLIENT_VERSION.code() + BESU_CLIENT_VERSION.code()),
Arguments.of(
CLIENT_CODES,
Optional.empty(),
Expand All @@ -557,6 +567,14 @@ private static Stream<Arguments> getBuildGraffitiFixtures() {
CLIENT_CODES,
Optional.of(ASCII_GRAFFITI_20),
ASCII_GRAFFITI_20 + " " + TEKU_CLIENT_VERSION.code() + BESU_CLIENT_VERSION.code()),
Arguments.of(
CLIENT_CODES,
Optional.of(ASCII_GRAFFITI_27),
ASCII_GRAFFITI_27 + " " + TEKU_CLIENT_VERSION.code() + BESU_CLIENT_VERSION.code()),
Arguments.of(
CLIENT_CODES,
Optional.of(ASCII_GRAFFITI_28),
ASCII_GRAFFITI_28 + TEKU_CLIENT_VERSION.code() + BESU_CLIENT_VERSION.code()),
Arguments.of(DISABLED, Optional.empty(), ""),
Arguments.of(DISABLED, Optional.of("small"), "small"),
Arguments.of(DISABLED, Optional.of(UTF_8_GRAFFITI_4), UTF_8_GRAFFITI_4),
Expand Down Expand Up @@ -589,6 +607,12 @@ private static Stream<Arguments> getBuildGraffitiFixturesElInfoNa() {
+ " "
+ TEKU_CLIENT_VERSION.code()
+ TEKU_CLIENT_VERSION.commit().toUnprefixedHexString().substring(0, 2)),
Arguments.of(
AUTO,
Optional.of(ASCII_GRAFFITI_27),
ASCII_GRAFFITI_27 + " " + TEKU_CLIENT_VERSION.code()),
Arguments.of(
AUTO, Optional.of(ASCII_GRAFFITI_28), ASCII_GRAFFITI_28 + TEKU_CLIENT_VERSION.code()),
Arguments.of(CLIENT_CODES, Optional.empty(), TEKU_CLIENT_VERSION.code()),
Arguments.of(CLIENT_CODES, Optional.of("small"), "small " + TEKU_CLIENT_VERSION.code()),
Arguments.of(
Expand All @@ -599,6 +623,14 @@ private static Stream<Arguments> getBuildGraffitiFixturesElInfoNa() {
CLIENT_CODES,
Optional.of(ASCII_GRAFFITI_20),
ASCII_GRAFFITI_20 + " " + TEKU_CLIENT_VERSION.code()),
Arguments.of(
CLIENT_CODES,
Optional.of(ASCII_GRAFFITI_27),
ASCII_GRAFFITI_27 + " " + TEKU_CLIENT_VERSION.code()),
Arguments.of(
CLIENT_CODES,
Optional.of(ASCII_GRAFFITI_28),
ASCII_GRAFFITI_28 + TEKU_CLIENT_VERSION.code()),
Arguments.of(DISABLED, Optional.empty(), ""),
Arguments.of(DISABLED, Optional.of("small"), "small"),
Arguments.of(DISABLED, Optional.of(UTF_8_GRAFFITI_4), UTF_8_GRAFFITI_4),
Expand Down

0 comments on commit dbc5827

Please sign in to comment.