Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

rename eea_getTransactionCount to priv_getEeaTransactionCount #110

Merged
merged 4 commits into from
Oct 28, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermRemoveAccountsFromWhitelist;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermRemoveNodesFromWhitelist;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.eea.EeaGetTransactionCount;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.eea.EeaPrivateNonceProvider;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.eea.EeaSendRawTransaction;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivCreatePrivacyGroup;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivDeletePrivacyGroup;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivDistributeRawTransaction;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivFindPrivacyGroup;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetEeaTransactionCount;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetPrivacyPrecompileAddress;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetPrivateTransaction;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetTransactionCount;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetTransactionReceipt;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivateEeaNonceProvider;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockReplay;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTracer;
Expand Down Expand Up @@ -367,8 +367,8 @@ blockchainQueries, new TransactionTracer(blockReplay), parameter),
addMethods(
enabledMethods,
new EeaSendRawTransaction(privateTransactionHandler, transactionPool, parameter),
new EeaGetTransactionCount(
parameter, new EeaPrivateNonceProvider(enclave, privateTransactionHandler)));
new PrivGetEeaTransactionCount(
parameter, new PrivateEeaNonceProvider(enclave, privateTransactionHandler)));
}
if (priv) {
addMethods(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public enum RpcMethod {
PRIV_DELETE_PRIVACY_GROUP("priv_deletePrivacyGroup"),
PRIV_FIND_PRIVACY_GROUP("priv_findPrivacyGroup"),
PRIV_DISTRIBUTE_RAW_TRANSACTION("priv_distributeRawTransaction"),
PRIV_GET_EEA_TRANSACTION_COUNT("priv_getEeaTransactionCount"),
EEA_SEND_RAW_TRANSACTION("eea_sendRawTransaction"),
EEA_GET_TRANSACTION_COUNT("eea_getTransactionCount"),
ETH_ACCOUNTS("eth_accounts"),
ETH_BLOCK_NUMBER("eth_blockNumber"),
ETH_CALL("eth_call"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.eea;
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv;

import static org.apache.logging.log4j.LogManager.getLogger;

Expand All @@ -29,22 +29,22 @@

import org.apache.logging.log4j.Logger;

public class EeaGetTransactionCount implements JsonRpcMethod {
public class PrivGetEeaTransactionCount implements JsonRpcMethod {

private static final Logger LOG = getLogger();

private final JsonRpcParameter parameters;
private final EeaPrivateNonceProvider nonceProvider;
private final PrivateEeaNonceProvider nonceProvider;

public EeaGetTransactionCount(
final JsonRpcParameter parameters, final EeaPrivateNonceProvider nonceProvider) {
public PrivGetEeaTransactionCount(
final JsonRpcParameter parameters, final PrivateEeaNonceProvider nonceProvider) {
this.parameters = parameters;
this.nonceProvider = nonceProvider;
}

@Override
public String getName() {
return RpcMethod.EEA_GET_TRANSACTION_COUNT.getMethodName();
return RpcMethod.PRIV_GET_EEA_TRANSACTION_COUNT.getMethodName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.eea;
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv;

import org.hyperledger.besu.enclave.Enclave;
import org.hyperledger.besu.enclave.types.FindPrivacyGroupRequest;
Expand All @@ -27,12 +27,12 @@
import com.google.common.collect.Lists;
import org.bouncycastle.util.Arrays;

public class EeaPrivateNonceProvider {
public class PrivateEeaNonceProvider {

private final Enclave enclave;
private final PrivateTransactionHandler privateTransactionHandler;

public EeaPrivateNonceProvider(
public PrivateEeaNonceProvider(
final Enclave enclave, final PrivateTransactionHandler privateTransactionHandler) {
this.enclave = enclave;
this.privateTransactionHandler = privateTransactionHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.eea.EeaGetTransactionCount;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.eea.EeaPrivateNonceProvider;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetEeaTransactionCount;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivateEeaNonceProvider;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
Expand All @@ -31,9 +31,9 @@
import org.junit.Before;
import org.junit.Test;

public class EeaGetTransactionCountTest {
public class PrivGetEeaTransactionCountTest {

private EeaPrivateNonceProvider nonceProvider = mock(EeaPrivateNonceProvider.class);
private final PrivateEeaNonceProvider nonceProvider = mock(PrivateEeaNonceProvider.class);
private JsonRpcRequest request;

private final String privateFrom = "thePrivateFromKey";
Expand All @@ -43,29 +43,29 @@ public class EeaGetTransactionCountTest {
@Before
public void setup() {
final Object[] jsonBody = new Object[] {address.toString(), privateFrom, privateFor};
request = new JsonRpcRequest("2.0", "eea_getTransactionCount", jsonBody);
request = new JsonRpcRequest("2.0", "priv_getEeaTransactionCount", jsonBody);
}

@Test
public void validRequestProducesExpectedNonce() {
final long reportedNonce = 8L;
final EeaGetTransactionCount method =
new EeaGetTransactionCount(new JsonRpcParameter(), nonceProvider);
final PrivGetEeaTransactionCount method =
new PrivGetEeaTransactionCount(new JsonRpcParameter(), nonceProvider);

when(nonceProvider.determineNonce(privateFrom, privateFor, address)).thenReturn(reportedNonce);

final JsonRpcResponse response = method.response(request);
assertThat(response).isInstanceOf(JsonRpcSuccessResponse.class);

final JsonRpcSuccessResponse successResponse = (JsonRpcSuccessResponse) response;
int returnedValue = Integer.decode((String) successResponse.getResult());
final int returnedValue = Integer.decode((String) successResponse.getResult());
assertThat(returnedValue).isEqualTo(reportedNonce);
}

@Test
public void nonceProviderThrowsRuntimeExceptionProducesErrorResponse() {
final EeaGetTransactionCount method =
new EeaGetTransactionCount(new JsonRpcParameter(), nonceProvider);
final PrivGetEeaTransactionCount method =
new PrivGetEeaTransactionCount(new JsonRpcParameter(), nonceProvider);

when(nonceProvider.determineNonce(privateFrom, privateFor, address))
.thenThrow(RuntimeException.class);
Expand All @@ -80,8 +80,8 @@ public void nonceProviderThrowsRuntimeExceptionProducesErrorResponse() {

@Test
public void nonceProviderThrowsAnExceptionProducesErrorResponse() {
final EeaGetTransactionCount method =
new EeaGetTransactionCount(new JsonRpcParameter(), nonceProvider);
final PrivGetEeaTransactionCount method =
new PrivGetEeaTransactionCount(new JsonRpcParameter(), nonceProvider);

when(nonceProvider.determineNonce(privateFrom, privateFor, address))
.thenThrow(RuntimeException.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@
import org.hyperledger.besu.enclave.types.FindPrivacyGroupRequest;
import org.hyperledger.besu.enclave.types.PrivacyGroup;
import org.hyperledger.besu.enclave.types.PrivacyGroup.Type;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.eea.EeaPrivateNonceProvider;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivateEeaNonceProvider;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.privacy.PrivateTransactionHandler;

import com.google.common.collect.Lists;
import org.junit.Test;
import org.mockito.ArgumentCaptor;

public class EeaPrivateNonceProviderTest {
public class PrivateEeaNonceProviderTest {

private final Address address = Address.fromHexString("55");
private Enclave enclave = mock(Enclave.class);
private PrivateTransactionHandler privateTransactionHandler =
private final Enclave enclave = mock(Enclave.class);
private final PrivateTransactionHandler privateTransactionHandler =
mock(PrivateTransactionHandler.class);

private final EeaPrivateNonceProvider nonceProvider =
new EeaPrivateNonceProvider(enclave, privateTransactionHandler);
private final PrivateEeaNonceProvider nonceProvider =
new PrivateEeaNonceProvider(enclave, privateTransactionHandler);

@Test
public void validRequestProducesExpectedNonce() {
final long reportedNonce = 8L;
PrivacyGroup[] returnedGroups =
final PrivacyGroup[] returnedGroups =
new PrivacyGroup[] {
new PrivacyGroup("Group1", Type.LEGACY, "Group1_Name", "Group1_Desc", new String[0]),
};
Expand All @@ -68,7 +68,7 @@ public void validRequestProducesExpectedNonce() {
@Test
public void noMatchingLegacyGroupsProducesExpectedNonce() {
final long reportedNonce = 0L;
PrivacyGroup[] returnedGroups = new PrivacyGroup[0];
final PrivacyGroup[] returnedGroups = new PrivacyGroup[0];

final ArgumentCaptor<FindPrivacyGroupRequest> groupMembersCaptor =
ArgumentCaptor.forClass(FindPrivacyGroupRequest.class);
Expand All @@ -86,7 +86,7 @@ public void noMatchingLegacyGroupsProducesExpectedNonce() {

@Test
public void moreThanOneMatchingLegacyGroupThrowsException() {
PrivacyGroup[] returnedGroups =
final PrivacyGroup[] returnedGroups =
new PrivacyGroup[] {
new PrivacyGroup("Group1", Type.LEGACY, "Group1_Name", "Group1_Desc", new String[0]),
new PrivacyGroup("Group2", Type.LEGACY, "Group2_Name", "Group2_Desc", new String[0]),
Expand Down