diff --git a/rskj-core/src/main/java/org/ethereum/rpc/Web3Impl.java b/rskj-core/src/main/java/org/ethereum/rpc/Web3Impl.java index e91d9d1eca9..8b8a5464036 100644 --- a/rskj-core/src/main/java/org/ethereum/rpc/Web3Impl.java +++ b/rskj-core/src/main/java/org/ethereum/rpc/Web3Impl.java @@ -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; @@ -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()) { diff --git a/rskj-core/src/main/java/org/ethereum/util/Utils.java b/rskj-core/src/main/java/org/ethereum/util/Utils.java index a2d23853a51..0738853cc32 100644 --- a/rskj-core/src/main/java/org/ethereum/util/Utils.java +++ b/rskj-core/src/main/java/org/ethereum/util/Utils.java @@ -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.", ""); + return String.format("Java%s", javaMajorVersion); + } } diff --git a/rskj-core/src/test/java/org/ethereum/rpc/Web3ImplTest.java b/rskj-core/src/test/java/org/ethereum/rpc/Web3ImplTest.java index f23da51c182..dc651c0d29d 100644 --- a/rskj-core/src/test/java/org/ethereum/rpc/Web3ImplTest.java +++ b/rskj-core/src/test/java/org/ethereum/rpc/Web3ImplTest.java @@ -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(); @@ -3097,14 +3119,12 @@ private void assertInvalidInput(Function 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;