From fcb62e95543299caf35c8e045daecd18fa176b92 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Tue, 13 Oct 2020 07:49:04 +1000 Subject: [PATCH] Enclave key rename (#1442) * rename transactionEnclaveKey -> privateTransactionLookupId Signed-off-by: Sally MacFarlane --- .../MultiTenancyAcceptanceTest.java | 46 +++++++++++-------- .../methods/eea/EeaSendRawTransaction.java | 22 +++++---- .../eea/EeaSendRawTransactionTest.java | 6 --- .../privacy/DefaultPrivacyController.java | 8 ++-- .../MultiTenancyPrivacyController.java | 8 ++-- .../ethereum/privacy/PrivacyController.java | 4 +- ...igningPrivateMarkerTransactionFactory.java | 4 +- .../PrivateMarkerTransactionFactory.java | 14 +++--- ...igningPrivateMarkerTransactionFactory.java | 4 +- ...OnChainPrivacyPrecompiledContractTest.java | 22 +++++---- .../PrivacyPrecompiledContractTest.java | 26 ++++++----- .../privacy/DefaultPrivacyControllerTest.java | 16 +++---- .../PrivateTransactionLocatorTest.java | 8 ++-- 13 files changed, 98 insertions(+), 90 deletions(-) diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/privacy/multitenancy/MultiTenancyAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/privacy/multitenancy/MultiTenancyAcceptanceTest.java index ece9cd0630..cbae10dd99 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/privacy/multitenancy/MultiTenancyAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/privacy/multitenancy/MultiTenancyAcceptanceTest.java @@ -63,10 +63,14 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase { new BigInteger( "853d7f0010fd86d0d7811c1f9d968ea89a24484a8127b4a483ddf5d2cfec766d", 16))); private static final String PRIVACY_GROUP_ID = "B1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo="; - private static final String ENCLAVE_KEY = "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo="; - private static final String KEY1 = "sgFkVOyFndZe/5SAZJO5UYbrl7pezHetveriBBWWnE8="; - private static final String KEY2 = "R1kW75NQC9XX3kwNpyPjCBFflM29+XvnKKS9VLrUkzo="; - private static final String KEY3 = "QzHuACXpfhoGAgrQriWJcDJ6MrUwcCvutKMoAn9KplQ="; + private static final String PARTICIPANT_ENCLAVE_KEY0 = + "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo="; + private static final String PARTICIPANT_ENCLAVE_KEY1 = + "sgFkVOyFndZe/5SAZJO5UYbrl7pezHetveriBBWWnE8="; + private static final String PARTICIPANT_ENCLAVE_KEY2 = + "R1kW75NQC9XX3kwNpyPjCBFflM29+XvnKKS9VLrUkzo="; + private static final String PARTICIPANT_ENCLAVE_KEY3 = + "QzHuACXpfhoGAgrQriWJcDJ6MrUwcCvutKMoAn9KplQ="; private final Address senderAddress = Address.wrap(Bytes.fromHexString(accounts.getPrimaryBenefactor().getAddress())); @@ -108,7 +112,7 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase { receiveEnclaveStub(validSignedPrivateTransaction); retrievePrivacyGroupEnclaveStub(); - sendEnclaveStub(KEY1); + sendEnclaveStub(PARTICIPANT_ENCLAVE_KEY1); final Hash transactionHash = node.execute( @@ -124,7 +128,10 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase { node.verify( priv.createPrivacyGroup( - List.of(KEY1, KEY2, KEY3), "GroupName", "Group description.", PRIVACY_GROUP_ID)); + List.of(PARTICIPANT_ENCLAVE_KEY1, PARTICIPANT_ENCLAVE_KEY2, PARTICIPANT_ENCLAVE_KEY3), + "GroupName", + "Group description.", + PRIVACY_GROUP_ID)); } @Test @@ -140,13 +147,13 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase { throws JsonProcessingException { final List groupMembership = List.of( - testPrivacyGroup(singletonList(ENCLAVE_KEY), PrivacyGroup.Type.PANTHEON), - testPrivacyGroup(singletonList(ENCLAVE_KEY), PrivacyGroup.Type.PANTHEON), - testPrivacyGroup(singletonList(ENCLAVE_KEY), PrivacyGroup.Type.PANTHEON)); + testPrivacyGroup(singletonList(PARTICIPANT_ENCLAVE_KEY0), PrivacyGroup.Type.PANTHEON), + testPrivacyGroup(singletonList(PARTICIPANT_ENCLAVE_KEY0), PrivacyGroup.Type.PANTHEON), + testPrivacyGroup(singletonList(PARTICIPANT_ENCLAVE_KEY0), PrivacyGroup.Type.PANTHEON)); findPrivacyGroupEnclaveStub(groupMembership); - node.verify(priv.findPrivacyGroup(groupMembership.size(), ENCLAVE_KEY)); + node.verify(priv.findPrivacyGroup(groupMembership.size(), PARTICIPANT_ENCLAVE_KEY0)); } @Test @@ -156,7 +163,7 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase { getValidSignedPrivateTransaction(senderAddress); retrievePrivacyGroupEnclaveStub(); - sendEnclaveStub(KEY1); + sendEnclaveStub(PARTICIPANT_ENCLAVE_KEY1); receiveEnclaveStub(validSignedPrivateTransaction); node.verify( @@ -173,7 +180,7 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase { final BytesValueRLPOutput rlpOutput = getRLPOutput(validSignedPrivateTransaction); retrievePrivacyGroupEnclaveStub(); - sendEnclaveStub(KEY1); + sendEnclaveStub(PARTICIPANT_ENCLAVE_KEY1); receiveEnclaveStub(validSignedPrivateTransaction); node.verify(priv.getTransactionCount(accountAddress, PRIVACY_GROUP_ID, 0)); @@ -187,10 +194,11 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase { @Test public void privDistributeRawTransactionSuccessShouldReturnEnclaveKey() throws JsonProcessingException { - final String enclaveResponseKeyBytes = Bytes.wrap(Bytes.fromBase64String(KEY1)).toString(); + final String enclaveResponseKeyBytes = + Bytes.wrap(Bytes.fromBase64String(PARTICIPANT_ENCLAVE_KEY1)).toString(); retrievePrivacyGroupEnclaveStub(); - sendEnclaveStub(KEY1); + sendEnclaveStub(PARTICIPANT_ENCLAVE_KEY1); node.verify( priv.distributeRawTransaction( @@ -206,7 +214,7 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase { final BytesValueRLPOutput rlpOutput = getRLPOutput(validSignedPrivateTransaction); retrievePrivacyGroupEnclaveStub(); - sendEnclaveStub(KEY1); + sendEnclaveStub(PARTICIPANT_ENCLAVE_KEY1); receiveEnclaveStub(validSignedPrivateTransaction); final Hash transactionReceipt = @@ -227,7 +235,7 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase { List.of(testPrivacyGroup(emptyList(), PrivacyGroup.Type.LEGACY)); retrievePrivacyGroupEnclaveStub(); - sendEnclaveStub(KEY1); + sendEnclaveStub(PARTICIPANT_ENCLAVE_KEY1); receiveEnclaveStub(validSignedPrivateTransaction); findPrivacyGroupEnclaveStub(groupMembership); @@ -237,7 +245,7 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase { node.verify(priv.getSuccessfulTransactionReceipt(transactionHash)); - final String privateFrom = ENCLAVE_KEY; + final String privateFrom = PARTICIPANT_ENCLAVE_KEY0; final String[] privateFor = {senderAddressBase64}; node.verify(priv.getEeaTransactionCount(accountAddress, privateFrom, privateFor, 1)); } @@ -262,7 +270,7 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase { private void retrievePrivacyGroupEnclaveStub() throws JsonProcessingException { final String retrieveGroupResponse = mapper.writeValueAsString( - testPrivacyGroup(List.of(ENCLAVE_KEY), PrivacyGroup.Type.PANTHEON)); + testPrivacyGroup(List.of(PARTICIPANT_ENCLAVE_KEY0), PrivacyGroup.Type.PANTHEON)); stubFor(post("/retrievePrivacyGroup").willReturn(ok(retrieveGroupResponse))); } @@ -309,7 +317,7 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase { .payload(Bytes.wrap(new byte[] {})) .sender(senderAddress) .chainId(BigInteger.valueOf(2018)) - .privateFrom(Bytes.fromBase64String(ENCLAVE_KEY)) + .privateFrom(Bytes.fromBase64String(PARTICIPANT_ENCLAVE_KEY0)) .restriction(Restriction.RESTRICTED) .privacyGroupId(Bytes.fromBase64String(PRIVACY_GROUP_ID)) .signAndBuild(TEST_KEY); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransaction.java index ea5cadde70..ed3ee9da24 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransaction.java @@ -115,7 +115,7 @@ public class EeaSendRawTransaction implements JsonRpcMethod { id, convertTransactionInvalidReason(validationResult.getInvalidReason())); } - final String enclaveKey = + final String privateTransactionLookupId = privacyController.sendTransaction( privateTransaction, enclavePublicKey, maybePrivacyGroup); @@ -125,7 +125,7 @@ public class EeaSendRawTransaction implements JsonRpcMethod { () -> new RuntimeException( JsonRpcError.OFFCHAIN_PRIVACY_GROUP_DOES_NOT_EXIST.getMessage())); - final Optional addPayloadEnclaveKey = + final Optional addPayloadPrivateTransactionLookupId = privacyController.buildAndSendAddPayload( privateTransaction, Bytes32.wrap(privacyGroupId), @@ -133,10 +133,11 @@ public class EeaSendRawTransaction implements JsonRpcMethod { return createPMTAndAddToTxPool( id, privateTransaction, - buildCompoundKey(enclaveKey, addPayloadEnclaveKey), + buildCompoundLookupId(privateTransactionLookupId, addPayloadPrivateTransactionLookupId), Address.ONCHAIN_PRIVACY); } else { // legacy or pantheon transaction - return createPMTAndAddToTxPool(id, privateTransaction, enclaveKey, Address.DEFAULT_PRIVACY); + return createPMTAndAddToTxPool( + id, privateTransaction, privateTransactionLookupId, Address.DEFAULT_PRIVACY); } } catch (final IllegalArgumentException | RLPException e) { return new JsonRpcErrorResponse(id, DECODE_ERROR); @@ -170,13 +171,14 @@ public class EeaSendRawTransaction implements JsonRpcMethod { return new JsonRpcErrorResponse(id, convertTransactionInvalidReason(errorReason)); } - private String buildCompoundKey( - final String enclaveKey, final Optional addPayloadEnclaveKey) { - return addPayloadEnclaveKey.isPresent() + private String buildCompoundLookupId( + final String privateTransactionLookupId, + final Optional maybePrivateTransactionLookupId) { + return maybePrivateTransactionLookupId.isPresent() ? Bytes.concatenate( - Bytes.fromBase64String(enclaveKey), - Bytes.fromBase64String(addPayloadEnclaveKey.get())) + Bytes.fromBase64String(privateTransactionLookupId), + Bytes.fromBase64String(maybePrivateTransactionLookupId.get())) .toBase64String() - : enclaveKey; + : privateTransactionLookupId; } } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransactionTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransactionTest.java index a5d221c9a1..40b41391cc 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransactionTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransactionTest.java @@ -37,7 +37,6 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorR 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.core.Address; -import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.Wei; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; @@ -58,7 +57,6 @@ import io.vertx.core.json.JsonObject; import io.vertx.ext.auth.User; import io.vertx.ext.auth.jwt.impl.JWTUser; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -108,7 +106,6 @@ public class EeaSendRawTransactionTest { @Mock private TransactionPool transactionPool; @Mock private EeaSendRawTransaction method; @Mock private PrivacyController privacyController; - @Mock private PrivacyParameters privacyParameters; @Before public void before() { @@ -255,9 +252,6 @@ public class EeaSendRawTransactionTest { "", PrivacyGroup.Type.ONCHAIN, "", "", Arrays.asList(ENCLAVE_PUBLIC_KEY))); when(privacyController.retrieveOnChainPrivacyGroupWithToBeAddedMembers(any(), any(), any())) .thenReturn(optionalPrivacyGroup); - when(privacyController.buildAndSendAddPayload( - any(PrivateTransaction.class), any(Bytes32.class), any(String.class))) - .thenReturn(Optional.of(ENCLAVE_PUBLIC_KEY)); when(privacyController.createPrivacyMarkerTransaction( any(String.class), any(PrivateTransaction.class), any(Address.class))) .thenReturn(PUBLIC_TRANSACTION); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/DefaultPrivacyController.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/DefaultPrivacyController.java index ebbccd7008..5317efcf9b 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/DefaultPrivacyController.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/DefaultPrivacyController.java @@ -164,17 +164,17 @@ public class DefaultPrivacyController implements PrivacyController { @Override public Transaction createPrivacyMarkerTransaction( - final String transactionEnclaveKey, final PrivateTransaction privateTransaction) { - return privateMarkerTransactionFactory.create(transactionEnclaveKey, privateTransaction); + final String privateTransactionLookupId, final PrivateTransaction privateTransaction) { + return privateMarkerTransactionFactory.create(privateTransactionLookupId, privateTransaction); } @Override public Transaction createPrivacyMarkerTransaction( - final String transactionEnclaveKey, + final String privateTransactionLookupId, final PrivateTransaction privateTransaction, final Address privacyPrecompileAddress) { return privateMarkerTransactionFactory.create( - transactionEnclaveKey, privateTransaction, privacyPrecompileAddress); + privateTransactionLookupId, privateTransaction, privacyPrecompileAddress); } @Override diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/MultiTenancyPrivacyController.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/MultiTenancyPrivacyController.java index 8e3d8fcde6..bb94622ad5 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/MultiTenancyPrivacyController.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/MultiTenancyPrivacyController.java @@ -129,18 +129,18 @@ public class MultiTenancyPrivacyController implements PrivacyController { @Override public Transaction createPrivacyMarkerTransaction( - final String transactionEnclaveKey, final PrivateTransaction privateTransaction) { + final String privateTransactionLookupId, final PrivateTransaction privateTransaction) { return privacyController.createPrivacyMarkerTransaction( - transactionEnclaveKey, privateTransaction); + privateTransactionLookupId, privateTransaction); } @Override public Transaction createPrivacyMarkerTransaction( - final String transactionEnclaveKey, + final String privateTransactionLookupId, final PrivateTransaction privateTransaction, final Address privacyPrecompileAddress) { return privacyController.createPrivacyMarkerTransaction( - transactionEnclaveKey, privateTransaction, privacyPrecompileAddress); + privateTransactionLookupId, privateTransaction, privacyPrecompileAddress); } @Override diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivacyController.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivacyController.java index 9c42fb087d..cc1aa2b142 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivacyController.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivacyController.java @@ -49,10 +49,10 @@ public interface PrivacyController { PrivacyGroup[] findPrivacyGroup(List addresses, String enclavePublicKey); Transaction createPrivacyMarkerTransaction( - String transactionEnclaveKey, PrivateTransaction privateTransaction); + String privateTransactionLookupId, PrivateTransaction privateTransaction); Transaction createPrivacyMarkerTransaction( - String transactionEnclaveKey, + String privateTransactionLookupId, PrivateTransaction privateTransaction, Address privacyPrecompileAddress); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/markertransaction/FixedKeySigningPrivateMarkerTransactionFactory.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/markertransaction/FixedKeySigningPrivateMarkerTransactionFactory.java index 7f1ef993a4..7063bdedc4 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/markertransaction/FixedKeySigningPrivateMarkerTransactionFactory.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/markertransaction/FixedKeySigningPrivateMarkerTransactionFactory.java @@ -40,11 +40,11 @@ public class FixedKeySigningPrivateMarkerTransactionFactory @Override public Transaction create( - final String transactionEnclaveKey, + final String privateTransactionLookupId, final PrivateTransaction privateTransaction, final Address precompileAddress) { return create( - transactionEnclaveKey, + privateTransactionLookupId, privateTransaction, nonceProvider.getNonce(sender), signingKey, diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/markertransaction/PrivateMarkerTransactionFactory.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/markertransaction/PrivateMarkerTransactionFactory.java index acb5a82677..667055b6c1 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/markertransaction/PrivateMarkerTransactionFactory.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/markertransaction/PrivateMarkerTransactionFactory.java @@ -34,17 +34,17 @@ public abstract class PrivateMarkerTransactionFactory { } public Transaction create( - final String transactionEnclaveKey, final PrivateTransaction privateTransaction) { - return create(transactionEnclaveKey, privateTransaction, privacyPrecompileAddress); + final String privateTransactionLookupId, final PrivateTransaction privateTransaction) { + return create(privateTransactionLookupId, privateTransaction, privacyPrecompileAddress); } public abstract Transaction create( - final String transactionEnclaveKey, + final String privateTransactionLookupId, final PrivateTransaction privateTransaction, final Address precompileAddress); protected Transaction create( - final String transactionEnclaveKey, + final String privateTransactionLookupId, final PrivateTransaction privateTransaction, final long nonce, final KeyPair signingKey) { @@ -54,12 +54,12 @@ public abstract class PrivateMarkerTransactionFactory { .gasLimit(privateTransaction.getGasLimit()) .to(getPrivacyPrecompileAddress()) .value(privateTransaction.getValue()) - .payload(Bytes.fromBase64String(transactionEnclaveKey)) + .payload(Bytes.fromBase64String(privateTransactionLookupId)) .signAndBuild(signingKey); } protected Transaction create( - final String transactionEnclaveKey, + final String privateTransactionLookupId, final PrivateTransaction privateTransaction, final long nonce, final KeyPair signingKey, @@ -70,7 +70,7 @@ public abstract class PrivateMarkerTransactionFactory { .gasLimit(privateTransaction.getGasLimit()) .to(precompileAddress) .value(privateTransaction.getValue()) - .payload(Bytes.fromBase64String(transactionEnclaveKey)) + .payload(Bytes.fromBase64String(privateTransactionLookupId)) .signAndBuild(signingKey); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/markertransaction/RandomSigningPrivateMarkerTransactionFactory.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/markertransaction/RandomSigningPrivateMarkerTransactionFactory.java index b164920ba8..e6f95de011 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/markertransaction/RandomSigningPrivateMarkerTransactionFactory.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/markertransaction/RandomSigningPrivateMarkerTransactionFactory.java @@ -27,10 +27,10 @@ public class RandomSigningPrivateMarkerTransactionFactory extends PrivateMarkerT @Override public Transaction create( - final String transactionEnclaveKey, + final String privateTransactionLookupId, final PrivateTransaction privateTransaction, final Address precompileAddress) { final KeyPair signingKey = KeyPair.generate(); - return create(transactionEnclaveKey, privateTransaction, 0, signingKey, precompileAddress); + return create(privateTransactionLookupId, privateTransaction, 0, signingKey, precompileAddress); } } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/OnChainPrivacyPrecompiledContractTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/OnChainPrivacyPrecompiledContractTest.java index f0cadfa5c6..23df2380de 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/OnChainPrivacyPrecompiledContractTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/OnChainPrivacyPrecompiledContractTest.java @@ -71,7 +71,7 @@ public class OnChainPrivacyPrecompiledContractTest { @Rule public final TemporaryFolder temp = new TemporaryFolder(); - private final Bytes txEnclaveKey = Bytes.random(32); + private final Bytes privateTransactionLookupId = Bytes.random(32); private MessageFrame messageFrame; private Blockchain blockchain; private final String DEFAULT_OUTPUT = "0x01"; @@ -166,7 +166,7 @@ public class OnChainPrivacyPrecompiledContractTest { .when(contractSpy) .canExecute(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()); - final Bytes actual = contractSpy.compute(txEnclaveKey, messageFrame); + final Bytes actual = contractSpy.compute(privateTransactionLookupId, messageFrame); assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT)); } @@ -178,7 +178,7 @@ public class OnChainPrivacyPrecompiledContractTest { when(enclave.receive(any(String.class))).thenThrow(EnclaveClientException.class); - final Bytes expected = contract.compute(txEnclaveKey, messageFrame); + final Bytes expected = contract.compute(privateTransactionLookupId, messageFrame); assertThat(expected).isEqualTo(Bytes.EMPTY); } @@ -189,7 +189,7 @@ public class OnChainPrivacyPrecompiledContractTest { when(enclave.receive(any(String.class))).thenThrow(new RuntimeException()); - contract.compute(txEnclaveKey, messageFrame); + contract.compute(privateTransactionLookupId, messageFrame); } @Test @@ -202,9 +202,10 @@ public class OnChainPrivacyPrecompiledContractTest { final ReceiveResponse responseWithoutSenderKey = new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, null); - when(enclave.receive(eq(txEnclaveKey.toBase64String()))).thenReturn(responseWithoutSenderKey); + when(enclave.receive(eq(privateTransactionLookupId.toBase64String()))) + .thenReturn(responseWithoutSenderKey); - assertThatThrownBy(() -> contract.compute(txEnclaveKey, messageFrame)) + assertThatThrownBy(() -> contract.compute(privateTransactionLookupId, messageFrame)) .isInstanceOf(EnclaveConfigurationException.class) .hasMessage("Incompatible Orion version. Orion version must be 1.6.0 or greater."); } @@ -220,9 +221,10 @@ public class OnChainPrivacyPrecompiledContractTest { final String wrongSenderKey = Bytes.random(32).toBase64String(); final ReceiveResponse responseWithWrongSenderKey = new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, wrongSenderKey); - when(enclave.receive(eq(txEnclaveKey.toBase64String()))).thenReturn(responseWithWrongSenderKey); + when(enclave.receive(eq(privateTransactionLookupId.toBase64String()))) + .thenReturn(responseWithWrongSenderKey); - final Bytes expected = contract.compute(txEnclaveKey, messageFrame); + final Bytes expected = contract.compute(privateTransactionLookupId, messageFrame); assertThat(expected).isEqualTo(Bytes.EMPTY); } @@ -256,7 +258,7 @@ public class OnChainPrivacyPrecompiledContractTest { new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, privateFrom); when(enclave.receive(any(String.class))).thenReturn(response); - final Bytes actual = contractSpy.compute(txEnclaveKey, messageFrame); + final Bytes actual = contractSpy.compute(privateTransactionLookupId, messageFrame); assertThat(actual).isEqualTo(Bytes.EMPTY); } @@ -294,7 +296,7 @@ public class OnChainPrivacyPrecompiledContractTest { when(enclave.receive(any(String.class))).thenReturn(response); - final Bytes actual = contractSpy.compute(txEnclaveKey, messageFrame); + final Bytes actual = contractSpy.compute(privateTransactionLookupId, messageFrame); assertThat(actual).isEqualTo(Bytes.EMPTY); } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContractTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContractTest.java index 9b11fba59f..47bc286f6b 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContractTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContractTest.java @@ -73,7 +73,7 @@ public class PrivacyPrecompiledContractTest { @Rule public final TemporaryFolder temp = new TemporaryFolder(); private final String actual = "Test String"; - private final Bytes txEnclaveKey = Bytes.wrap(actual.getBytes(UTF_8)); + private final Bytes privateTransactionLookupId = Bytes.wrap(actual.getBytes(UTF_8)); private MessageFrame messageFrame; private Blockchain blockchain; private final String DEFAULT_OUTPUT = "0x01"; @@ -160,7 +160,7 @@ public class PrivacyPrecompiledContractTest { new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, privateFrom); when(enclave.receive(any(String.class))).thenReturn(response); - final Bytes actual = contract.compute(txEnclaveKey, messageFrame); + final Bytes actual = contract.compute(privateTransactionLookupId, messageFrame); assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT)); } @@ -172,7 +172,7 @@ public class PrivacyPrecompiledContractTest { when(enclave.receive(any(String.class))).thenThrow(EnclaveClientException.class); - final Bytes expected = contract.compute(txEnclaveKey, messageFrame); + final Bytes expected = contract.compute(privateTransactionLookupId, messageFrame); assertThat(expected).isEqualTo(Bytes.EMPTY); } @@ -183,7 +183,7 @@ public class PrivacyPrecompiledContractTest { when(enclave.receive(any(String.class))).thenThrow(new RuntimeException()); - contract.compute(txEnclaveKey, messageFrame); + contract.compute(privateTransactionLookupId, messageFrame); } @Test @@ -195,9 +195,10 @@ public class PrivacyPrecompiledContractTest { final ReceiveResponse responseWithoutSenderKey = new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, null); - when(enclave.receive(eq(txEnclaveKey.toBase64String()))).thenReturn(responseWithoutSenderKey); + when(enclave.receive(eq(privateTransactionLookupId.toBase64String()))) + .thenReturn(responseWithoutSenderKey); - assertThatThrownBy(() -> contract.compute(txEnclaveKey, messageFrame)) + assertThatThrownBy(() -> contract.compute(privateTransactionLookupId, messageFrame)) .isInstanceOf(EnclaveConfigurationException.class) .hasMessage("Incompatible Orion version. Orion version must be 1.6.0 or greater."); } @@ -213,9 +214,9 @@ public class PrivacyPrecompiledContractTest { final String senderKey = privateTransaction.getPrivateFrom().toBase64String(); final ReceiveResponse response = new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, senderKey); - when(enclave.receive(eq(txEnclaveKey.toBase64String()))).thenReturn(response); + when(enclave.receive(eq(privateTransactionLookupId.toBase64String()))).thenReturn(response); - final Bytes expected = contract.compute(txEnclaveKey, messageFrame); + final Bytes expected = contract.compute(privateTransactionLookupId, messageFrame); assertThat(expected).isEqualTo(Bytes.EMPTY); } @@ -229,9 +230,10 @@ public class PrivacyPrecompiledContractTest { final String wrongSenderKey = Bytes.random(32).toBase64String(); final ReceiveResponse responseWithWrongSenderKey = new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, wrongSenderKey); - when(enclave.receive(eq(txEnclaveKey.toBase64String()))).thenReturn(responseWithWrongSenderKey); + when(enclave.receive(eq(privateTransactionLookupId.toBase64String()))) + .thenReturn(responseWithWrongSenderKey); - final Bytes expected = contract.compute(txEnclaveKey, messageFrame); + final Bytes expected = contract.compute(privateTransactionLookupId, messageFrame); assertThat(expected).isEqualTo(Bytes.EMPTY); } @@ -260,7 +262,7 @@ public class PrivacyPrecompiledContractTest { new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, privateFrom); when(enclave.receive(any(String.class))).thenReturn(response); - final Bytes actual = contract.compute(txEnclaveKey, messageFrame); + final Bytes actual = contract.compute(privateTransactionLookupId, messageFrame); assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT)); } @@ -298,7 +300,7 @@ public class PrivacyPrecompiledContractTest { when(enclave.receive(any(String.class))).thenReturn(response); - final Bytes actual = contract.compute(txEnclaveKey, messageFrame); + final Bytes actual = contract.compute(privateTransactionLookupId, messageFrame); assertThat(actual).isEqualTo(Bytes.EMPTY); } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/DefaultPrivacyControllerTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/DefaultPrivacyControllerTest.java index cda70cdd30..53998d6e5b 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/DefaultPrivacyControllerTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/DefaultPrivacyControllerTest.java @@ -89,7 +89,7 @@ public class DefaultPrivacyControllerTest { "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002"; private static final PrivacyGroup PANTHEON_PRIVACY_GROUP = new PrivacyGroup("", PrivacyGroup.Type.PANTHEON, "", "", emptyList()); - private static final PrivacyGroup ON_CHAIN_PRIVACY_GROUP = + private static final PrivacyGroup ONCHAIN_PRIVACY_GROUP = new PrivacyGroup("", PrivacyGroup.Type.ONCHAIN, "", "", Arrays.asList(ENCLAVE_PUBLIC_KEY)); private PrivacyController privacyController; @@ -185,14 +185,14 @@ public class DefaultPrivacyControllerTest { public void sendsValidLegacyTransaction() { final PrivateTransaction transaction = buildLegacyPrivateTransaction(1); - final String enclaveKey = + final String privateTransactionLookupId = privacyController.sendTransaction(transaction, ENCLAVE_PUBLIC_KEY, Optional.empty()); final ValidationResult validationResult = privacyController.validatePrivateTransaction(transaction, ENCLAVE_PUBLIC_KEY); final Transaction markerTransaction = - privacyController.createPrivacyMarkerTransaction(enclaveKey, transaction); + privacyController.createPrivacyMarkerTransaction(privateTransactionLookupId, transaction); assertThat(validationResult).isEqualTo(ValidationResult.valid()); assertThat(markerTransaction.contractAddress()).isEqualTo(PUBLIC_TRANSACTION.contractAddress()); @@ -208,7 +208,7 @@ public class DefaultPrivacyControllerTest { public void sendValidBesuTransaction() { final PrivateTransaction transaction = buildBesuPrivateTransaction(1); - final String enclaveKey = + final String privateTransactionLookupId = privacyController.sendTransaction( transaction, ENCLAVE_PUBLIC_KEY, Optional.of(PANTHEON_PRIVACY_GROUP)); @@ -216,7 +216,7 @@ public class DefaultPrivacyControllerTest { privacyController.validatePrivateTransaction(transaction, ENCLAVE_PUBLIC_KEY); final Transaction markerTransaction = - privacyController.createPrivacyMarkerTransaction(enclaveKey, transaction); + privacyController.createPrivacyMarkerTransaction(privateTransactionLookupId, transaction); assertThat(validationResult).isEqualTo(ValidationResult.valid()); assertThat(markerTransaction.contractAddress()).isEqualTo(PUBLIC_TRANSACTION.contractAddress()); @@ -449,13 +449,13 @@ public class DefaultPrivacyControllerTest { public void canCreatePrivacyMarkerTransactionForOnChainPrivacy() { final PrivateTransaction transaction = buildBesuPrivateTransaction(0); - final String enclaveKey = + final String privateTransactionLookupId = privacyController.sendTransaction( - transaction, ENCLAVE_PUBLIC_KEY, Optional.of(ON_CHAIN_PRIVACY_GROUP)); + transaction, ENCLAVE_PUBLIC_KEY, Optional.of(ONCHAIN_PRIVACY_GROUP)); final Transaction onChainPrivacyMarkerTransaction = privacyController.createPrivacyMarkerTransaction( - enclaveKey, transaction, Address.ONCHAIN_PRIVACY); + privateTransactionLookupId, transaction, Address.ONCHAIN_PRIVACY); assertThat(onChainPrivacyMarkerTransaction.contractAddress()) .isEqualTo(PUBLIC_TRANSACTION.contractAddress()); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/PrivateTransactionLocatorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/PrivateTransactionLocatorTest.java index 645781db87..295c699df4 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/PrivateTransactionLocatorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/PrivateTransactionLocatorTest.java @@ -243,12 +243,12 @@ public class PrivateTransactionLocatorTest { final Transaction pmt, final PrivateTransaction privateTransaction, final Optional version) { - final String privateTxEnclaveKey = pmt.getData().orElseThrow().toBase64String(); + final String privateTransactionLookupId = pmt.getData().orElseThrow().toBase64String(); final byte[] encodePrivateTransaction = encodePrivateTransaction(privateTransaction, version) .toBase64String() .getBytes(StandardCharsets.UTF_8); - when(enclave.receive(eq(privateTxEnclaveKey), eq(participantKey))) + when(enclave.receive(eq(privateTransactionLookupId), eq(participantKey))) .thenReturn(new ReceiveResponse(encodePrivateTransaction, privacyGroupId, participantKey)); } @@ -263,10 +263,10 @@ public class PrivateTransactionLocatorTest { } private void mockEnclaveForNonExistingPayload(final Transaction pmt) { - final String privateTxEnclaveKey = pmt.getData().orElseThrow().toBase64String(); + final String privateTransactionLookupId = pmt.getData().orElseThrow().toBase64String(); final EnclaveClientException payloadNotFoundException = new EnclaveClientException(404, "Payload not found"); - when(enclave.receive(eq(privateTxEnclaveKey), eq(participantKey))) + when(enclave.receive(eq(privateTransactionLookupId), eq(participantKey))) .thenThrow(payloadNotFoundException); }