[PAN-2959] return the ethereum address of the privacy precompile from priv_getPrivacyPrecompileAddress (#1766)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Ivaylo Kirilov 5 years ago committed by MadelineMurray
parent f590c71e93
commit e219052c74
  1. 4
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/priv/PrivGetPrivacyPrecompileAddress.java
  2. 8
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/priv/PrivGetPrivacyPrecompileAddressTest.java

@ -12,6 +12,7 @@
*/ */
package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.privacy.priv; package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.privacy.priv;
import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcMethod; import tech.pegasys.pantheon.ethereum.jsonrpc.RpcMethod;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
@ -40,7 +41,8 @@ public class PrivGetPrivacyPrecompileAddress implements JsonRpcMethod {
public JsonRpcResponse response(final JsonRpcRequest request) { public JsonRpcResponse response(final JsonRpcRequest request) {
if (privacyEnabled) { if (privacyEnabled) {
return new JsonRpcSuccessResponse(request.getId(), privacyAddress); return new JsonRpcSuccessResponse(
request.getId(), Address.privacyPrecompiled(privacyAddress).toString());
} else { } else {
return new JsonRpcErrorResponse(request.getId(), JsonRpcError.PRIVACY_NOT_ENABLED); return new JsonRpcErrorResponse(request.getId(), JsonRpcError.PRIVACY_NOT_ENABLED);
} }

@ -16,6 +16,7 @@ import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError;
@ -28,12 +29,13 @@ import org.junit.Test;
public class PrivGetPrivacyPrecompileAddressTest { public class PrivGetPrivacyPrecompileAddressTest {
private final Integer privacyAddress = 127; private final int rawPrivacyAddress = Address.PRIVACY;
private final String privacyAddress = Address.privacyPrecompiled(rawPrivacyAddress).toString();
private final PrivacyParameters privacyParameters = mock(PrivacyParameters.class); private final PrivacyParameters privacyParameters = mock(PrivacyParameters.class);
@Test @Test
public void verifyPrivacyPrecompileAddress() { public void verifyPrivacyPrecompileAddress() {
when(privacyParameters.getPrivacyAddress()).thenReturn(privacyAddress); when(privacyParameters.getPrivacyAddress()).thenReturn(rawPrivacyAddress);
when(privacyParameters.isEnabled()).thenReturn(true); when(privacyParameters.isEnabled()).thenReturn(true);
final PrivGetPrivacyPrecompileAddress privGetPrivacyPrecompileAddress = final PrivGetPrivacyPrecompileAddress privGetPrivacyPrecompileAddress =
@ -50,7 +52,7 @@ public class PrivGetPrivacyPrecompileAddressTest {
@Test @Test
public void verifyErrorPrivacyDisabled() { public void verifyErrorPrivacyDisabled() {
when(privacyParameters.getPrivacyAddress()).thenReturn(privacyAddress); when(privacyParameters.getPrivacyAddress()).thenReturn(rawPrivacyAddress);
when(privacyParameters.isEnabled()).thenReturn(false); when(privacyParameters.isEnabled()).thenReturn(false);
final PrivGetPrivacyPrecompileAddress privGetPrivacyPrecompileAddress = final PrivGetPrivacyPrecompileAddress privGetPrivacyPrecompileAddress =

Loading…
Cancel
Save