Search in sources :

Example 1 with SendRequest

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

the class EncodedPayloadManagerImplTest method createCallsEnclaveCorrectly.

@Test
public void createCallsEnclaveCorrectly() {
    final byte[] payload = "test payload".getBytes();
    final String senderKeyBase64 = "BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=";
    final PublicKey sender = PublicKey.from(Base64.getDecoder().decode(senderKeyBase64));
    final String singleRecipientBase64 = "QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc=";
    final PublicKey singleRecipient = PublicKey.from(Base64.getDecoder().decode(singleRecipientBase64));
    final List<PublicKey> recipients = List.of(singleRecipient);
    final SendRequest request = mock(SendRequest.class);
    when(request.getSender()).thenReturn(sender);
    when(request.getRecipients()).thenReturn(recipients);
    when(request.getPayload()).thenReturn(payload);
    when(request.getPrivacyMode()).thenReturn(PrivacyMode.STANDARD_PRIVATE);
    when(request.getAffectedContractTransactions()).thenReturn(emptySet());
    when(request.getExecHash()).thenReturn(new byte[0]);
    final EncodedPayload sampleReturnPayload = mock(EncodedPayload.class);
    when(enclave.encryptPayload(any(), eq(sender), eq(List.of(singleRecipient, sender)), any())).thenReturn(sampleReturnPayload);
    final EncodedPayload encodedPayload = encodedPayloadManager.create(request);
    assertThat(encodedPayload).isEqualTo(sampleReturnPayload);
    verify(privacyHelper).findAffectedContractTransactionsFromSendRequest(emptySet());
    verify(privacyHelper).validateSendRequest(PrivacyMode.STANDARD_PRIVATE, List.of(singleRecipient, sender), emptyList(), emptySet());
    verify(enclave).encryptPayload(eq(request.getPayload()), eq(sender), eq(List.of(singleRecipient, sender)), any());
    verify(enclave).getForwardingKeys();
}
Also used : SendRequest(com.quorum.tessera.transaction.SendRequest) PublicKey(com.quorum.tessera.encryption.PublicKey) Test(org.junit.Test)

Example 2 with SendRequest

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

the class EncodedPayloadManagerImplTest method createDeduplicatesRecipients.

@Test
public void createDeduplicatesRecipients() {
    final byte[] testPayload = "test payload".getBytes();
    final String senderKeyBase64 = "BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=";
    final PublicKey sender = PublicKey.from(Base64.getDecoder().decode(senderKeyBase64));
    final String singleRecipientBase64 = "QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc=";
    final PublicKey singleRecipient = PublicKey.from(Base64.getDecoder().decode(singleRecipientBase64));
    final List<PublicKey> recipients = // list the keys multiple times
    List.of(singleRecipient, sender, singleRecipient);
    final SendRequest request = mock(SendRequest.class);
    when(request.getSender()).thenReturn(sender);
    when(request.getRecipients()).thenReturn(recipients);
    when(request.getPayload()).thenReturn(testPayload);
    when(request.getPrivacyMode()).thenReturn(PrivacyMode.STANDARD_PRIVATE);
    when(request.getAffectedContractTransactions()).thenReturn(emptySet());
    when(request.getExecHash()).thenReturn(new byte[0]);
    final EncodedPayload sampleReturnPayload = mock(EncodedPayload.class);
    when(enclave.encryptPayload(eq(testPayload), eq(sender), eq(List.of(singleRecipient, sender)), any())).thenReturn(sampleReturnPayload);
    final EncodedPayload encodedPayload = encodedPayloadManager.create(request);
    assertThat(encodedPayload).isEqualTo(sampleReturnPayload);
    verify(privacyHelper).findAffectedContractTransactionsFromSendRequest(emptySet());
    verify(privacyHelper).validateSendRequest(PrivacyMode.STANDARD_PRIVATE, List.of(singleRecipient, sender), emptyList(), emptySet());
    verify(enclave).encryptPayload(eq(request.getPayload()), eq(sender), eq(List.of(singleRecipient, sender)), any());
    verify(enclave).getForwardingKeys();
}
Also used : SendRequest(com.quorum.tessera.transaction.SendRequest) PublicKey(com.quorum.tessera.encryption.PublicKey) Test(org.junit.Test)

Aggregations

PublicKey (com.quorum.tessera.encryption.PublicKey)2 SendRequest (com.quorum.tessera.transaction.SendRequest)2 Test (org.junit.Test)2