Search in sources :

Example 6 with ReceiveResponse

use of com.quorum.tessera.transaction.ReceiveResponse in project tessera by ConsenSys.

the class BesuTransactionResourceTest method receiveWithRecipient.

@Test
public void receiveWithRecipient() {
    String key = Base64.getEncoder().encodeToString("KEY".getBytes());
    ReceiveRequest receiveRequest = new ReceiveRequest();
    receiveRequest.setKey(key);
    receiveRequest.setTo(Base64.getEncoder().encodeToString("Reno Raynes".getBytes()));
    ReceiveResponse receiveResponse = mock(ReceiveResponse.class);
    when(receiveResponse.getPrivacyMode()).thenReturn(PrivacyMode.STANDARD_PRIVATE);
    when(transactionManager.receive(any())).thenReturn(receiveResponse);
    when(receiveResponse.getUnencryptedTransactionData()).thenReturn("Result".getBytes());
    when(receiveResponse.sender()).thenReturn(PublicKey.from("sender".getBytes()));
    when(receiveResponse.getPrivacyGroupId()).thenReturn(Optional.of(PrivacyGroup.Id.fromBytes("group".getBytes())));
    BesuTransactionResource resource = new BesuTransactionResource(transactionManager, privacyGroupManager);
    final Response result = resource.receive(receiveRequest);
    assertThat(result.getStatus()).isEqualTo(200);
    BesuReceiveResponse resultResponse = (BesuReceiveResponse) result.getEntity();
    assertThat(resultResponse.getPayload()).isEqualTo("Result".getBytes());
    assertThat(resultResponse.getSenderKey()).isEqualTo(PublicKey.from("sender".getBytes()).encodeToBase64());
    assertThat(resultResponse.getPrivacyGroupId()).isEqualTo(PublicKey.from("group".getBytes()).encodeToBase64());
    verify(transactionManager).receive(any(com.quorum.tessera.transaction.ReceiveRequest.class));
}
Also used : SendResponse(com.quorum.tessera.api.SendResponse) BesuReceiveResponse(com.quorum.tessera.api.BesuReceiveResponse) ReceiveResponse(com.quorum.tessera.transaction.ReceiveResponse) Response(jakarta.ws.rs.core.Response) BesuReceiveResponse(com.quorum.tessera.api.BesuReceiveResponse) ReceiveResponse(com.quorum.tessera.transaction.ReceiveResponse) BesuReceiveResponse(com.quorum.tessera.api.BesuReceiveResponse) ReceiveRequest(com.quorum.tessera.api.ReceiveRequest) Test(org.junit.Test)

Example 7 with ReceiveResponse

use of com.quorum.tessera.transaction.ReceiveResponse in project tessera by ConsenSys.

the class EncodedPayloadResourceTest method decryptPayload.

@Test
public void decryptPayload() {
    final PrivacyMode privacyMode = PrivacyMode.PRIVATE_STATE_VALIDATION;
    final Base64.Decoder decoder = Base64.getDecoder();
    final PayloadDecryptRequest request = new PayloadDecryptRequest();
    request.setSenderKey(decoder.decode("BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo="));
    request.setCipherText(decoder.decode("h7av/vhPlaPFECB1K30hNWugv/Bu"));
    request.setCipherTextNonce(decoder.decode("8MVXAESCQuRHWxrQ6b5MXuYApjia+2h0"));
    request.setRecipientBoxes(List.of(decoder.decode("FNirZRc2ayMaYopCBaWQ/1I7VWFiCM0lNw533Hckzxb+qpvngdWVVzJlsE05dbxl")));
    request.setRecipientNonce(decoder.decode("p9gYDJlEoBvLdUQ+ZoONl2Jl9AirV1en"));
    request.setRecipientKeys(List.of(decoder.decode("BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=")));
    request.setPrivacyMode(privacyMode.getPrivacyFlag());
    request.setAffectedContractTransactions(Map.of("dHgx", "dHgxdmFs", "dHgy", "dHgydmFs"));
    request.setExecHash("execHash".getBytes());
    final ReceiveResponse response = mock(ReceiveResponse.class);
    when(response.getPrivacyMode()).thenReturn(privacyMode);
    when(response.getUnencryptedTransactionData()).thenReturn("decryptedData".getBytes());
    when(response.getExecHash()).thenReturn("I Love sparrows".getBytes());
    MessageHash messageHash = mock(MessageHash.class);
    when(messageHash.getHashBytes()).thenReturn("SomeMessageHashBytes".getBytes());
    when(response.getAffectedTransactions()).thenReturn(Set.of(messageHash));
    when(encodedPayloadManager.decrypt(any(), eq(null))).thenReturn(response);
    final Response result = encodedPayloadResource.decryptEncodedPayload(request);
    assertThat(result.getStatus()).isEqualTo(200);
    final com.quorum.tessera.api.ReceiveResponse payloadEncryptResponse = com.quorum.tessera.api.ReceiveResponse.class.cast(result.getEntity());
    assertThat(payloadEncryptResponse.getPayload()).isEqualTo("decryptedData".getBytes());
    assertThat(payloadEncryptResponse.getPrivacyFlag()).isEqualTo(privacyMode.getPrivacyFlag());
    assertThat(payloadEncryptResponse.getAffectedContractTransactions()).contains(Base64.getEncoder().encodeToString("SomeMessageHashBytes".getBytes()));
    assertThat(payloadEncryptResponse.getExecHash()).isEqualTo("I Love sparrows");
    verify(encodedPayloadManager).decrypt(any(), eq(null));
}
Also used : PayloadDecryptRequest(com.quorum.tessera.api.PayloadDecryptRequest) PayloadEncryptResponse(com.quorum.tessera.api.PayloadEncryptResponse) ReceiveResponse(com.quorum.tessera.transaction.ReceiveResponse) Response(jakarta.ws.rs.core.Response) Base64(java.util.Base64) ReceiveResponse(com.quorum.tessera.transaction.ReceiveResponse) MessageHash(com.quorum.tessera.data.MessageHash) Test(org.junit.Test)

Example 8 with ReceiveResponse

use of com.quorum.tessera.transaction.ReceiveResponse in project tessera by ConsenSys.

the class TransactionResource3Test method receiveWithRecipient.

@Test
public void receiveWithRecipient() {
    String key = Base64.getEncoder().encodeToString("KEY".getBytes());
    String recipientKeyBase64 = Base64.getEncoder().encodeToString("recipient".getBytes());
    final PublicKey senderPublicKey = PublicKey.from("sender".getBytes());
    final ReceiveResponse receiveResponse = ReceiveResponse.Builder.create().withPrivacyMode(PrivacyMode.STANDARD_PRIVATE).withUnencryptedTransactionData("Result".getBytes()).withManagedParties(Set.of(senderPublicKey)).withSender(senderPublicKey).build();
    when(transactionManager.receive(any())).thenReturn(receiveResponse);
    final Response result = transactionResource.receive(key, recipientKeyBase64, Boolean.FALSE.toString());
    assertThat(result.getStatus()).isEqualTo(200);
    com.quorum.tessera.api.ReceiveResponse resultResponse = com.quorum.tessera.api.ReceiveResponse.class.cast(result.getEntity());
    assertThat(resultResponse.getPrivacyFlag()).isEqualTo(PrivacyMode.STANDARD_PRIVATE.getPrivacyFlag());
    assertThat(resultResponse.getPayload()).isEqualTo("Result".getBytes());
    assertThat(resultResponse.getManagedParties()).containsExactlyInAnyOrder(senderPublicKey.encodeToBase64());
    assertThat(resultResponse.getSenderKey()).isEqualTo(senderPublicKey.encodeToBase64());
    verify(transactionManager).receive(any(com.quorum.tessera.transaction.ReceiveRequest.class));
}
Also used : SendResponse(com.quorum.tessera.api.SendResponse) ReceiveResponse(com.quorum.tessera.transaction.ReceiveResponse) Response(jakarta.ws.rs.core.Response) PublicKey(com.quorum.tessera.encryption.PublicKey) ReceiveResponse(com.quorum.tessera.transaction.ReceiveResponse) Test(org.junit.Test)

Example 9 with ReceiveResponse

use of com.quorum.tessera.transaction.ReceiveResponse in project tessera by ConsenSys.

the class TransactionResource3Test method receivePrivateStateValidation.

@Test
public void receivePrivateStateValidation() {
    final PublicKey senderPublicKey = PublicKey.from("sender".getBytes());
    ReceiveResponse response = ReceiveResponse.Builder.create().withPrivacyMode(PrivacyMode.PRIVATE_STATE_VALIDATION).withAffectedTransactions(Set.of()).withUnencryptedTransactionData("Success".getBytes()).withExecHash("execHash".getBytes()).withManagedParties(Set.of(senderPublicKey)).withSender(senderPublicKey).withPrivacyGroupId(PrivacyGroup.Id.fromBytes("group".getBytes())).build();
    when(transactionManager.receive(any(com.quorum.tessera.transaction.ReceiveRequest.class))).thenReturn(response);
    String transactionHash = Base64.getEncoder().encodeToString("transactionHash".getBytes());
    Response result = transactionResource.receive(transactionHash, null, Boolean.FALSE.toString());
    assertThat(result.getStatus()).isEqualTo(200);
    com.quorum.tessera.api.ReceiveResponse resultResponse = com.quorum.tessera.api.ReceiveResponse.class.cast(result.getEntity());
    assertThat(resultResponse.getExecHash()).isEqualTo("execHash");
    assertThat(resultResponse.getPrivacyFlag()).isEqualTo(PrivacyMode.PRIVATE_STATE_VALIDATION.getPrivacyFlag());
    assertThat(resultResponse.getAffectedContractTransactions()).isNullOrEmpty();
    assertThat(resultResponse.getPayload()).isEqualTo("Success".getBytes());
    assertThat(resultResponse.getManagedParties()).containsExactlyInAnyOrder(senderPublicKey.encodeToBase64());
    assertThat(resultResponse.getSenderKey()).isEqualTo(senderPublicKey.encodeToBase64());
    assertThat(resultResponse.getPrivacyGroupId()).isEqualTo(PublicKey.from("group".getBytes()).encodeToBase64());
    verify(transactionManager).receive(any(com.quorum.tessera.transaction.ReceiveRequest.class));
}
Also used : SendResponse(com.quorum.tessera.api.SendResponse) ReceiveResponse(com.quorum.tessera.transaction.ReceiveResponse) Response(jakarta.ws.rs.core.Response) PublicKey(com.quorum.tessera.encryption.PublicKey) ReceiveResponse(com.quorum.tessera.transaction.ReceiveResponse) Test(org.junit.Test)

Aggregations

ReceiveResponse (com.quorum.tessera.transaction.ReceiveResponse)9 Test (org.junit.Test)8 Response (jakarta.ws.rs.core.Response)7 SendResponse (com.quorum.tessera.api.SendResponse)5 PublicKey (com.quorum.tessera.encryption.PublicKey)5 MessageHash (com.quorum.tessera.data.MessageHash)3 BesuReceiveResponse (com.quorum.tessera.api.BesuReceiveResponse)2 PayloadDecryptRequest (com.quorum.tessera.api.PayloadDecryptRequest)2 PayloadEncryptResponse (com.quorum.tessera.api.PayloadEncryptResponse)2 ReceiveRequest (com.quorum.tessera.api.ReceiveRequest)2 Base64 (java.util.Base64)2 RecipientKeyNotFoundException (com.quorum.tessera.transaction.exception.RecipientKeyNotFoundException)1