Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import org.awaitility.Awaitility;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
Expand Down Expand Up @@ -210,11 +209,4 @@ protected void waitForFile(final Path path) {
}
});
}

@Test
public void dryRunDetector() {
assertThat(true)
.withFailMessage("This test is here so gradle --dry-run executes this class")
.isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down Expand Up @@ -148,11 +147,4 @@ public static Stream<Arguments> testCasesFromPath(final String testCasesPath)

return Arrays.stream(testCasesList).sorted().map(File::toURI).map(Arguments::of);
}

@Test
void dryRunDetector() {
assertThat(true)
.withFailMessage("This test is here so gradle --dry-run executes this class")
.isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@

import com.google.common.collect.Streams;
import org.apache.tuweni.bytes.Bytes;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down Expand Up @@ -207,11 +206,4 @@ public Stream<Long> streamMilestoneBlocks() {
MilestoneStreamingProtocolSchedule::streamMilestoneBlocks);
}
}

@Test
void dryRunDetector() {
assertThat(true)
.withFailMessage("This test is here so gradle --dry-run executes this class")
.isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
import dagger.Component;
import dagger.Module;
import dagger.Provides;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand Down Expand Up @@ -348,13 +347,6 @@ public void importChain_specialFields(final String consensusEngine) throws IOExc
.hasMessage(
"Some fields (coinbase, extraData) are no longer supported for block import since PoW consensus has been removed");
}

@Test
void dryRunDetector() {
assertThat(true)
.withFailMessage("This test is here so gradle --dry-run executes this class")
.isTrue();
}
}

protected Block getBlockAt(final Blockchain blockchain, final long blockNumber) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import org.hyperledger.besu.config.NetworkDefinition;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

Expand All @@ -42,11 +41,4 @@ void shouldThrowErrorForNonDeprecatedNetworks(final NetworkDefinition network) {
assertThatThrownBy(() -> NetworkDeprecationMessage.generate(network))
.isInstanceOf(AssertionError.class);
}

@Test
void dryRunDetector() {
assertThat(true)
.withFailMessage("This test is here so gradle --dry-run executes this class")
.isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import java.util.stream.Stream;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand Down Expand Up @@ -53,11 +52,4 @@ public void test(final long input, final boolean expectedResult) {

assertThat(uut.validate(header, null)).isEqualTo(expectedResult);
}

@Test
void dryRunDetector() {
assertThat(true)
.withFailMessage("This test is here so gradle --dry-run executes this class")
.isTrue();
}
}
2 changes: 2 additions & 0 deletions ethereum/api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ dependencies {
api 'org.slf4j:slf4j-api'
api 'org.apache.logging.log4j:log4j-api'

annotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess'

compileOnly 'org.jspecify:jspecify'

implementation project(':config')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Copyright contributors to Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results;

import java.util.Objects;
import java.util.concurrent.TimeUnit;

import org.apache.tuweni.units.bigints.UInt256;
import org.apache.tuweni.units.bigints.UInt256Value;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;

@State(Scope.Thread)
@Warmup(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS)
@OutputTimeUnit(value = TimeUnit.NANOSECONDS)
@BenchmarkMode(Mode.AverageTime)
public class QuantityLongToHexBenchmark {
private static final String HEX_PREFIX = "0x";
public static final String HEX_ZERO = "0x0";
private static final char[] HEX_DIGITS = "0123456789abcdef".toCharArray();

@Param({"0", "255", "65535", "1000000", "9007199254740991", "9223372036854775807"})
public long value;

@Benchmark
public void current(final Blackhole blackhole) {
blackhole.consume(uint256ToHex(UInt256.fromHexString(Long.toHexString(value))));
}

@Benchmark
public void simpleHexString(final Blackhole blackhole) {
blackhole.consume(simpleHexString(value));
}

@Benchmark
public void directCharArray(final Blackhole blackhole) {
blackhole.consume(directCharArray(value));
}

@Benchmark
public void unrolled(final Blackhole blackhole) {
blackhole.consume(unrolled(value));
}

private static String simpleHexString(final long value) {
return HEX_PREFIX + Long.toHexString(value);
}

private static String unrolled(final long value) {
if (value == 0L) {
return HEX_ZERO;
}
final int leadingZeroNibbles = Long.numberOfLeadingZeros(value) >>> 2;
final char[] buf = new char[18];
buf[2] = HEX_DIGITS[(int) ((value >>> 60) & 0xF)];
buf[3] = HEX_DIGITS[(int) ((value >>> 56) & 0xF)];
buf[4] = HEX_DIGITS[(int) ((value >>> 52) & 0xF)];
buf[5] = HEX_DIGITS[(int) ((value >>> 48) & 0xF)];
buf[6] = HEX_DIGITS[(int) ((value >>> 44) & 0xF)];
buf[7] = HEX_DIGITS[(int) ((value >>> 40) & 0xF)];
buf[8] = HEX_DIGITS[(int) ((value >>> 36) & 0xF)];
buf[9] = HEX_DIGITS[(int) ((value >>> 32) & 0xF)];
buf[10] = HEX_DIGITS[(int) ((value >>> 28) & 0xF)];
buf[11] = HEX_DIGITS[(int) ((value >>> 24) & 0xF)];
buf[12] = HEX_DIGITS[(int) ((value >>> 20) & 0xF)];
buf[13] = HEX_DIGITS[(int) ((value >>> 16) & 0xF)];
buf[14] = HEX_DIGITS[(int) ((value >>> 12) & 0xF)];
buf[15] = HEX_DIGITS[(int) ((value >>> 8) & 0xF)];
buf[16] = HEX_DIGITS[(int) ((value >>> 4) & 0xF)];
buf[17] = HEX_DIGITS[(int) (value & 0xF)];
buf[leadingZeroNibbles] = '0';
buf[leadingZeroNibbles + 1] = 'x';
return new String(buf, leadingZeroNibbles, 18 - leadingZeroNibbles);
}

private static String directCharArray(final long value) {
if (value == 0L) {
return HEX_ZERO;
}
int nibbles = 16;
while (nibbles > 1 && ((value >>> ((nibbles - 1) * 4)) & 0xFL) == 0L) {
nibbles--;
}
final char[] buf = new char[2 + nibbles];
buf[0] = '0';
buf[1] = 'x';
for (int i = 0; i < nibbles; i++) {
buf[2 + i] = HEX_DIGITS[(int) ((value >>> ((nibbles - 1 - i) * 4)) & 0xFL)];
}
return new String(buf);
}

private static String uint256ToHex(final UInt256Value<?> value) {
return value == null ? null : formatMinimalValue(value.toMinimalBytes().toShortHexString());
}

private static String formatMinimalValue(final String hexValue) {
final String prefixedHexString = prefixHexNotation(hexValue);
return Objects.equals(prefixedHexString, HEX_PREFIX) ? HEX_ZERO : prefixedHexString;
}

private static String prefixHexNotation(final String hexValue) {
return hexValue.startsWith(HEX_PREFIX) ? hexValue : HEX_PREFIX + hexValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,29 @@ public static String create(final UInt64Value<?> value) {
}

public static String create(final int value) {
return uint256ToHex(UInt256.valueOf(value));
return HEX_PREFIX + Integer.toHexString(value);
}

public static String create(final long value) {
return uint256ToHex(UInt256.fromHexString(Long.toHexString(value)));
return HEX_PREFIX + Long.toHexString(value);
}

public static String create(final byte value) {
return HEX_PREFIX + Integer.toHexString(value);
}

public static String create(final Bytes value) {
return create(value.toArrayUnsafe());
return uint256ToHex(UInt256.fromBytes(Bytes32.leftPad(value)));
}

public static String create(final byte[] value) {
return uint256ToHex(UInt256.fromBytes(Bytes32.leftPad(Bytes.wrap(value))));
return create(Bytes.wrap(value));
}

public static String create(final BigInteger value) {
return uint256ToHex(UInt256.valueOf(value));
}

public static String create(final byte value) {
return formatMinimalValue(Integer.toHexString(value));
}

/**
* Fixed-length bytes sequences and should be returned as hex strings zero-padded to the expected
* length.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package org.hyperledger.besu.ethereum.api.graphql;

import static com.google.common.base.Preconditions.checkState;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.net.URISyntaxException;
Expand All @@ -32,7 +31,6 @@
import okhttp3.RequestBody;
import okhttp3.Response;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down Expand Up @@ -86,11 +84,4 @@ private void graphQLCall(final String name) throws IOException {
Assertions.assertThat(resp.code()).isEqualTo(expectedStatusCode);
}
}

@Test
void dryRunDetector() {
assertThat(true)
.withFailMessage("This test is here so gradle --dry-run executes this class")
.isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import okhttp3.Response;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

Expand Down Expand Up @@ -61,11 +60,4 @@ public void invalidJsonShouldReturnParseError(final String requestJson) throws E
json, null, expectedError.getCode(), expectedError.getMessage());
}
}

@Test
void dryRunDetector() {
assertThat(true)
.withFailMessage("This test is here so gradle --dry-run executes this class")
.isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Arrays;
import java.util.Collection;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

Expand Down Expand Up @@ -80,11 +79,4 @@ public void expectedTransactionValidationToJsonRpcErrorConversion(
assertThat(JsonRpcErrorConverter.convertTransactionInvalidReason(txInvalidReason))
.isEqualTo(expectedJsonRpcError);
}

@Test
void dryRunDetector() {
assertThat(true)
.withFailMessage("This test is here so gradle --dry-run executes this class")
.isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.bonsai;

import static org.assertj.core.api.Assertions.assertThat;

import org.hyperledger.besu.ethereum.api.jsonrpc.AbstractJsonRpcHttpBySpecTest;
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;

import org.junit.jupiter.api.Test;

public class DebugGethTraceJsonRpcHttpBySpecTest extends AbstractJsonRpcHttpBySpecTest {
@Override
protected void doSetup() throws Exception {
Expand Down Expand Up @@ -49,11 +45,4 @@ public static Object[][] specs() {
"debug-geth/specs/4byte-tracer"
});
}

@Test
void dryRunDetector() {
assertThat(true)
.withFailMessage("This test is here so gradle --dry-run executes this class")
.isTrue();
}
}
Loading
Loading