Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration;
import org.hyperledger.besu.plugin.services.BesuConfiguration;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;
import org.hyperledger.besu.util.BesuVersionUtils;

import java.nio.file.Path;
import java.util.Optional;
Expand Down Expand Up @@ -135,6 +136,16 @@ public Wei getMinGasPrice() {
return new DataStoreConfigurationImpl(dataStorageConfiguration);
}

@Override
public String getBesuVersion() {
return BesuVersionUtils.shortVersion();
}

@Override
public String getBesuCommitHash() {
return BesuVersionUtils.commit();
}

/**
* A concrete implementation of DataStorageConfiguration which is used in Besu plugin framework.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.services;

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

import org.junit.jupiter.api.Test;

class BesuConfigurationImplTest {

@Test
void getBesuVersion_returnsNonEmptyString() {
BesuConfigurationImpl config = new BesuConfigurationImpl();
String version = config.getBesuVersion();
assertThat(version).isNotNull();
assertThat(version).isNotEmpty();
}

@Test
void getBesuCommitHash_returnsNonEmptyString() {
BesuConfigurationImpl config = new BesuConfigurationImpl();
String commit = config.getBesuCommitHash();
assertThat(commit).isNotNull();
assertThat(commit).isNotEmpty();
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests only assert non-null/non-empty, so they won’t catch regressions where the methods stop delegating correctly (e.g., returning a constant placeholder) or violate the documented format. Consider asserting equality with BesuVersionUtils.shortVersion() / BesuVersionUtils.commit() and (optionally) validating basic format expectations (e.g., SemVer-like version, hex-ish commit hash) to better pin down the intended contract.

Suggested change
import org.junit.jupiter.api.Test;
class BesuConfigurationImplTest {
@Test
void getBesuVersion_returnsNonEmptyString() {
BesuConfigurationImpl config = new BesuConfigurationImpl();
String version = config.getBesuVersion();
assertThat(version).isNotNull();
assertThat(version).isNotEmpty();
}
@Test
void getBesuCommitHash_returnsNonEmptyString() {
BesuConfigurationImpl config = new BesuConfigurationImpl();
String commit = config.getBesuCommitHash();
assertThat(commit).isNotNull();
assertThat(commit).isNotEmpty();
import org.hyperledger.besu.util.BesuVersionUtils;
import org.junit.jupiter.api.Test;
class BesuConfigurationImplTest {
@Test
void getBesuVersion_returnsShortVersion() {
BesuConfigurationImpl config = new BesuConfigurationImpl();
String version = config.getBesuVersion();
assertThat(version)
.isEqualTo(BesuVersionUtils.shortVersion())
.matches("\\d+\\.\\d+\\.\\d+(?:[-+].+)?");
}
@Test
void getBesuCommitHash_returnsCommitHash() {
BesuConfigurationImpl config = new BesuConfigurationImpl();
String commit = config.getBesuCommitHash();
assertThat(commit)
.isEqualTo(BesuVersionUtils.commit())
.matches("[0-9a-fA-F]+");

Copilot uses AI. Check for mistakes.
}
Comment on lines +25 to +35
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests only assert non-null/non-empty, which doesn’t verify the intended contract that BesuConfigurationImpl delegates to BesuVersionUtils. To better protect against regressions (e.g., accidental hard-coding or wiring to the wrong source), assert equality with BesuVersionUtils.shortVersion() / BesuVersionUtils.commit() and consider using isNotBlank() if whitespace-only values would be undesirable.

Copilot uses AI. Check for mistakes.
}
2 changes: 1 addition & 1 deletion plugin-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Calculated : ${currentHash}
tasks.register('checkAPIChanges', FileStateChecker) {
description = "Checks that the API for the Plugin-API project does not change without deliberate thought"
files = sourceSets.main.allJava.files
knownHash = 'fDkUshUOXLQDBHsugUujwwJkJtYVYnqipuScb8CIof0='
knownHash = '/z6HqXUJiqnSTy6/KHXGXYbf9/Ww4Q3fpN3H2KF3FFw='
}
check.dependsOn('checkAPIChanges')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,24 @@ public interface BesuConfiguration extends BesuService {
*/
@Unstable
DataStorageConfiguration getDataStorageConfiguration();

/**
* Returns the version of the running Besu node.
*
* <p>The format follows semantic versioning: {@code "MAJOR.MINOR.PATCH"} for release builds
* (e.g., {@code "25.3.0"}) or {@code "MAJOR.MINOR.PATCH-qualifier"} for development builds
* (e.g., {@code "25.3.1-dev-ac23d311"}).
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Javadoc currently guarantees a specific version string shape (including an example that embeds what looks like a commit hash in the version). Unless BesuVersionUtils.shortVersion() is explicitly specified to always follow this exact format, this is easy to get out of sync with actual behavior. Consider loosening the contract to: (a) state it’s the output of BesuVersionUtils.shortVersion(), and/or (b) describe it as a human-readable version string that is typically SemVer for releases, without guaranteeing qualifier structure.

Suggested change
* <p>The format follows semantic versioning: {@code "MAJOR.MINOR.PATCH"} for release builds
* (e.g., {@code "25.3.0"}) or {@code "MAJOR.MINOR.PATCH-qualifier"} for development builds
* (e.g., {@code "25.3.1-dev-ac23d311"}).
* <p>This is a human-readable Besu version string. For release builds, it is typically a
* semantic version such as {@code "25.3.0"}.

Copilot uses AI. Check for mistakes.
*
* <p>Available during all plugin lifecycle phases ({@code register} through {@code stop}).
*
* @return the Besu node version string, never null
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Javadoc promises semantic-version formatting and a non-null return, but it doesn’t document what happens when build metadata is unavailable (e.g., missing/stripped manifest properties). Please document the exact fallback value(s) (such as \"UNKNOWN\") and whether the value is guaranteed to match the documented SemVer patterns in all build variants.

Suggested change
* <p>The format follows semantic versioning: {@code "MAJOR.MINOR.PATCH"} for release builds
* (e.g., {@code "25.3.0"}) or {@code "MAJOR.MINOR.PATCH-qualifier"} for development builds
* (e.g., {@code "25.3.1-dev-ac23d311"}).
*
* <p>Available during all plugin lifecycle phases ({@code register} through {@code stop}).
*
* @return the Besu node version string, never null
* <p>When build metadata is available, the returned value follows semantic versioning:
* {@code "MAJOR.MINOR.PATCH"} for release builds (e.g., {@code "25.3.0"}) or
* {@code "MAJOR.MINOR.PATCH-qualifier"} for development builds (e.g.,
* {@code "25.3.1-dev-ac23d311"}).
*
* <p>If the version metadata is unavailable (for example, if manifest properties are missing
* or stripped), this method returns the literal string {@code "UNKNOWN"}. That fallback value
* is never null, but it is not guaranteed to match the semantic-version patterns described
* above.
*
* <p>Available during all plugin lifecycle phases ({@code register} through {@code stop}).
*
* @return the Besu node version string; never null, and {@code "UNKNOWN"} if version metadata
* is unavailable

Copilot uses AI. Check for mistakes.
*/
String getBesuVersion();

/**
* Returns the git commit hash of the running Besu build.
*
* @return the short git commit hash, never null
*/
String getBesuCommitHash();
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding abstract methods to a public plugin API interface is source-breaking for any downstream code that implements BesuConfiguration (common in plugin unit tests via fakes/stubs). To reduce upgrade friction, consider making these default methods (with a documented fallback like \"UNKNOWN\") or introducing a new extended interface (e.g., BesuConfigurationV2) / dedicated service for version info so older implementers aren’t forced to update immediately.

Suggested change
* @return the Besu node version string, never null
*/
String getBesuVersion();
/**
* Returns the git commit hash of the running Besu build.
*
* @return the short git commit hash, never null
*/
String getBesuCommitHash();
* <p>The default implementation returns {@code "UNKNOWN"} to preserve source compatibility
* for existing downstream implementations of this public plugin API.
*
* @return the Besu node version string, never null
*/
default String getBesuVersion() {
return "UNKNOWN";
}
/**
* Returns the git commit hash of the running Besu build.
*
* <p>The default implementation returns {@code "UNKNOWN"} to preserve source compatibility
* for existing downstream implementations of this public plugin API.
*
* @return the short git commit hash, never null
*/
default String getBesuCommitHash() {
return "UNKNOWN";
}

Copilot uses AI. Check for mistakes.
}