Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Refactor Java version output in web3_clientVersion #2679

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion rskj-core/src/main/java/org/ethereum/rpc/Web3Impl.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.ethereum.rpc.exception.RskJsonRpcRequestException;
import org.ethereum.rpc.parameters.*;
import org.ethereum.util.BuildInfo;
import org.ethereum.util.Utils;
import org.ethereum.vm.DataWord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -195,8 +196,10 @@ public void stop() {

@Override
public String web3_clientVersion() {
String javaVersion = Utils.getFormattedJavaVersion();

String clientVersion = CLIENT_VERSION_PREFIX + "/" + config.projectVersion() + "/" +
System.getProperty("os.name") + "/Java1.8/" +
System.getProperty("os.name") + "/" + javaVersion + "/" +
config.projectVersionModifier() + "-" + buildInfo.getBuildHash();

if (logger.isDebugEnabled()) {
Expand Down
6 changes: 6 additions & 0 deletions rskj-core/src/main/java/org/ethereum/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,10 @@ public static int significantBitCount(int number) {
}
return result;
}

public static String getFormattedJavaVersion(){
String javaVersion = System.getProperty("java.specification.version");
String javaMajorVersion = javaVersion.replace("1.", "");
Copy link
Contributor

Choose a reason for hiding this comment

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

if you want we could add a check that the provided result has the format 1.x, but it is a minor thing.

return String.format("Java%s", javaMajorVersion);
}
}
24 changes: 22 additions & 2 deletions rskj-core/src/test/java/org/ethereum/rpc/Web3ImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,28 @@ void web3_clientVersion() {
assertTrue(clientVersion.toLowerCase().contains("rsk"), "client version is not including rsk!");
}

@Test
void web3_clientVersion_ShouldIncludeJava8() {
System.setProperty("java.specification.version", "1.8");

Web3 web3 = createWeb3();

String clientVersion = web3.web3_clientVersion();

assertTrue(clientVersion.contains("Java8"), "Java version is not Java8");
}

@Test
void web3_clientVersion_ShouldIncludeJava17() {
System.setProperty("java.specification.version", "17");

Web3 web3 = createWeb3();

String clientVersion = web3.web3_clientVersion();

assertTrue(clientVersion.contains("Java17"), "Java version is not Java17");
}

@Test
void net_version() {
Web3Impl web3 = createWeb3();
Expand Down Expand Up @@ -3097,14 +3119,12 @@ private void assertInvalidInput(Function<Map, String> toInvoke) {

//Chain Param Object creations
private class ChainParams {
private final World world;
private final Web3Impl web3;
private final String accountAddress;
private final Block block;
private CallArguments argsForCall; // for call tests could be null

private ChainParams(World world, String accountAddress, Block block) {
this.world = world;
this.web3 = createWeb3(world);
this.accountAddress = accountAddress;
this.block = block;
Expand Down
Loading