From ded93b1587f567e9f82fb8ceb003112a28ad392d Mon Sep 17 00:00:00 2001 From: Ivaylo Kirilov Date: Tue, 30 Jul 2019 10:02:39 +0100 Subject: [PATCH] [PAN-2959] return the ethereum address of the privacy precompile from priv_getPrivacyPrecompileAddress (#1766) (#1786) --- .../methods/privacy/EeaGetPrivacyPrecompileAddress.java | 4 +++- .../privacy/EeaGetPrivacyPrecompileAddressTest.java | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaGetPrivacyPrecompileAddress.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaGetPrivacyPrecompileAddress.java index e798f6d817..2ee1520dab 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaGetPrivacyPrecompileAddress.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaGetPrivacyPrecompileAddress.java @@ -12,6 +12,7 @@ */ package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.privacy; +import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.jsonrpc.RpcMethod; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest; @@ -40,7 +41,8 @@ public String getName() { public JsonRpcResponse response(final JsonRpcRequest request) { if (privacyEnabled) { - return new JsonRpcSuccessResponse(request.getId(), privacyAddress); + return new JsonRpcSuccessResponse( + request.getId(), Address.privacyPrecompiled(privacyAddress).toString()); } else { return new JsonRpcErrorResponse(request.getId(), JsonRpcError.PRIVACY_NOT_ENABLED); } diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaGetPrivacyPrecompileAddressTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaGetPrivacyPrecompileAddressTest.java index bbec69c5b5..62eb882f1d 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaGetPrivacyPrecompileAddressTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaGetPrivacyPrecompileAddressTest.java @@ -16,6 +16,7 @@ import static org.mockito.Mockito.mock; 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.jsonrpc.internal.JsonRpcRequest; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError; @@ -28,12 +29,13 @@ public class EeaGetPrivacyPrecompileAddressTest { - 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); @Test public void verifyPrivacyPrecompileAddress() { - when(privacyParameters.getPrivacyAddress()).thenReturn(privacyAddress); + when(privacyParameters.getPrivacyAddress()).thenReturn(rawPrivacyAddress); when(privacyParameters.isEnabled()).thenReturn(true); final EeaGetPrivacyPrecompileAddress eeaGetPrivacyPrecompileAddress = @@ -50,7 +52,7 @@ public void verifyPrivacyPrecompileAddress() { @Test public void verifyErrorPrivacyDisabled() { - when(privacyParameters.getPrivacyAddress()).thenReturn(privacyAddress); + when(privacyParameters.getPrivacyAddress()).thenReturn(rawPrivacyAddress); when(privacyParameters.isEnabled()).thenReturn(false); final EeaGetPrivacyPrecompileAddress eeaGetPrivacyPrecompileAddress =