Search in sources :

Example 1 with BesuReceiveResponse

use of com.quorum.tessera.api.BesuReceiveResponse in project tessera by ConsenSys.

the class BesuTransactionResourceTest method receive.

@Test
public void receive() {
    String key = Base64.getEncoder().encodeToString("KEY".getBytes());
    ReceiveRequest receiveRequest = new ReceiveRequest();
    receiveRequest.setKey(key);
    String recipient = Base64.getEncoder().encodeToString("Bobby Sixkiller".getBytes());
    receiveRequest.setTo(recipient);
    ReceiveResponse receiveResponse = mock(ReceiveResponse.class);
    when(receiveResponse.getAffectedTransactions()).thenReturn(Set.of());
    when(receiveResponse.getUnencryptedTransactionData()).thenReturn("Result".getBytes());
    when(receiveResponse.getPrivacyMode()).thenReturn(PrivacyMode.STANDARD_PRIVATE);
    when(receiveResponse.sender()).thenReturn(PublicKey.from("sender".getBytes()));
    when(receiveResponse.getPrivacyGroupId()).thenReturn(Optional.of(PrivacyGroup.Id.fromBytes("group".getBytes())));
    when(transactionManager.receive(any(com.quorum.tessera.transaction.ReceiveRequest.class))).thenReturn(receiveResponse);
    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 2 with BesuReceiveResponse

use of com.quorum.tessera.api.BesuReceiveResponse 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)

Aggregations

BesuReceiveResponse (com.quorum.tessera.api.BesuReceiveResponse)2 ReceiveRequest (com.quorum.tessera.api.ReceiveRequest)2 SendResponse (com.quorum.tessera.api.SendResponse)2 ReceiveResponse (com.quorum.tessera.transaction.ReceiveResponse)2 Response (jakarta.ws.rs.core.Response)2 Test (org.junit.Test)2