mirror of https://github.com/hyperledger/besu
add engine_getClientVersionV1 (#7512)
* add engine_getClientVersionV1 Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>pull/7530/head
parent
b57310ffac
commit
e0aa4f6d4a
@ -0,0 +1,57 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger 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.methods.engine; |
||||||
|
|
||||||
|
import org.hyperledger.besu.ethereum.ProtocolContext; |
||||||
|
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; |
||||||
|
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; |
||||||
|
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod; |
||||||
|
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; |
||||||
|
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; |
||||||
|
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EngineGetClientVersionResultV1; |
||||||
|
|
||||||
|
import io.vertx.core.Vertx; |
||||||
|
|
||||||
|
public class EngineGetClientVersionV1 extends ExecutionEngineJsonRpcMethod { |
||||||
|
private static final String ENGINE_CLIENT_CODE = "BU"; |
||||||
|
private static final String ENGINE_CLIENT_NAME = "Besu"; |
||||||
|
|
||||||
|
private final String clientVersion; |
||||||
|
private final String commit; |
||||||
|
|
||||||
|
public EngineGetClientVersionV1( |
||||||
|
final Vertx vertx, |
||||||
|
final ProtocolContext protocolContext, |
||||||
|
final EngineCallListener engineCallListener, |
||||||
|
final String clientVersion, |
||||||
|
final String commit) { |
||||||
|
super(vertx, protocolContext, engineCallListener); |
||||||
|
this.clientVersion = clientVersion; |
||||||
|
this.commit = commit; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getName() { |
||||||
|
return RpcMethod.ENGINE_GET_CLIENT_VERSION_V1.getMethodName(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public JsonRpcResponse syncResponse(final JsonRpcRequestContext request) { |
||||||
|
return new JsonRpcSuccessResponse( |
||||||
|
request.getRequest().getId(), |
||||||
|
new EngineGetClientVersionResultV1( |
||||||
|
ENGINE_CLIENT_CODE, ENGINE_CLIENT_NAME, clientVersion, commit)); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,52 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger 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 com.fasterxml.jackson.annotation.JsonGetter; |
||||||
|
|
||||||
|
public class EngineGetClientVersionResultV1 { |
||||||
|
private final String code; |
||||||
|
private final String name; |
||||||
|
private final String version; |
||||||
|
private final String commit; |
||||||
|
|
||||||
|
public EngineGetClientVersionResultV1( |
||||||
|
final String code, final String name, final String version, final String commit) { |
||||||
|
this.code = code; |
||||||
|
this.name = name; |
||||||
|
this.version = version; |
||||||
|
this.commit = commit; |
||||||
|
} |
||||||
|
|
||||||
|
@JsonGetter(value = "code") |
||||||
|
public String getCode() { |
||||||
|
return code; |
||||||
|
} |
||||||
|
|
||||||
|
@JsonGetter(value = "name") |
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
@JsonGetter(value = "version") |
||||||
|
public String getVersion() { |
||||||
|
return version; |
||||||
|
} |
||||||
|
|
||||||
|
@JsonGetter(value = "commit") |
||||||
|
public String getCommit() { |
||||||
|
return commit; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,72 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger 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.methods.engine; |
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat; |
||||||
|
|
||||||
|
import org.hyperledger.besu.ethereum.ProtocolContext; |
||||||
|
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; |
||||||
|
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; |
||||||
|
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; |
||||||
|
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; |
||||||
|
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EngineGetClientVersionResultV1; |
||||||
|
|
||||||
|
import io.vertx.core.Vertx; |
||||||
|
import org.junit.jupiter.api.BeforeEach; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
import org.mockito.Mockito; |
||||||
|
|
||||||
|
class EngineGetClientVersionV1Test { |
||||||
|
|
||||||
|
private static final String ENGINE_CLIENT_CODE = "BU"; |
||||||
|
private static final String ENGINE_CLIENT_NAME = "Besu"; |
||||||
|
|
||||||
|
private static final String CLIENT_VERSION = "v25.6.7-dev-abcdef12"; |
||||||
|
private static final String COMMIT = "abcdef12"; |
||||||
|
|
||||||
|
private EngineGetClientVersionV1 getClientVersion; |
||||||
|
|
||||||
|
@BeforeEach |
||||||
|
void before() { |
||||||
|
getClientVersion = |
||||||
|
new EngineGetClientVersionV1( |
||||||
|
Mockito.mock(Vertx.class), |
||||||
|
Mockito.mock(ProtocolContext.class), |
||||||
|
Mockito.mock(EngineCallListener.class), |
||||||
|
CLIENT_VERSION, |
||||||
|
COMMIT); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void testGetName() { |
||||||
|
assertThat(getClientVersion.getName()).isEqualTo("engine_getClientVersionV1"); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void testSyncResponse() { |
||||||
|
JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("v", "m", null)); |
||||||
|
JsonRpcResponse actualResult = getClientVersion.syncResponse(request); |
||||||
|
|
||||||
|
assertThat(actualResult).isInstanceOf(JsonRpcSuccessResponse.class); |
||||||
|
JsonRpcSuccessResponse successResponse = (JsonRpcSuccessResponse) actualResult; |
||||||
|
assertThat(successResponse.getResult()).isInstanceOf(EngineGetClientVersionResultV1.class); |
||||||
|
EngineGetClientVersionResultV1 actualEngineGetClientVersionResultV1 = |
||||||
|
(EngineGetClientVersionResultV1) successResponse.getResult(); |
||||||
|
assertThat(actualEngineGetClientVersionResultV1.getName()).isEqualTo(ENGINE_CLIENT_NAME); |
||||||
|
assertThat(actualEngineGetClientVersionResultV1.getCode()).isEqualTo(ENGINE_CLIENT_CODE); |
||||||
|
assertThat(actualEngineGetClientVersionResultV1.getVersion()).isEqualTo(CLIENT_VERSION); |
||||||
|
assertThat(actualEngineGetClientVersionResultV1.getCommit()).isEqualTo(COMMIT); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue