Search in sources :

Example 36 with MessageHash

use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.

the class PrivacyHelperTest method findAffectedContractTransactionsFromSendRequestFound.

@Test
public void findAffectedContractTransactionsFromSendRequestFound() {
    final MessageHash hash1 = mock(MessageHash.class);
    final MessageHash hash2 = mock(MessageHash.class);
    EncryptedTransaction et1 = mock(EncryptedTransaction.class);
    when(et1.getEncodedPayload()).thenReturn("payload1".getBytes());
    when(et1.getHash()).thenReturn(hash1);
    when(et1.getPayload()).thenReturn(mock(EncodedPayload.class));
    EncryptedTransaction et2 = mock(EncryptedTransaction.class);
    when(et2.getEncodedPayload()).thenReturn("payload2".getBytes());
    when(et2.getHash()).thenReturn(hash2);
    when(et2.getPayload()).thenReturn(mock(EncodedPayload.class));
    when(encryptedTransactionDAO.findByHashes(anyCollection())).thenReturn(List.of(et1, et2));
    List<AffectedTransaction> affectedTransactions = privacyHelper.findAffectedContractTransactionsFromSendRequest(Set.of(hash1, hash2));
    assertThat(affectedTransactions).isNotNull();
    assertThat(affectedTransactions.size()).isEqualTo(2);
    verify(encryptedTransactionDAO).findByHashes(any());
}
Also used : MessageHash(com.quorum.tessera.data.MessageHash) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) Test(org.junit.Test)

Example 37 with MessageHash

use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.

the class ReceiveRequestTest method buildWithTransactionHashAndRecipient.

@Test
public void buildWithTransactionHashAndRecipient() {
    MessageHash messageHash = mock(MessageHash.class);
    PublicKey recipient = mock(PublicKey.class);
    ReceiveRequest result = ReceiveRequest.Builder.create().withTransactionHash(messageHash).withRecipient(recipient).build();
    assertThat(result).isNotNull();
    assertThat(result.getTransactionHash()).isNotNull().isSameAs(messageHash);
    assertThat(result.getRecipient()).containsSame(recipient);
    assertThat(result.isRaw()).isFalse();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) MessageHash(com.quorum.tessera.data.MessageHash) Test(org.junit.Test)

Example 38 with MessageHash

use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.

the class ReceiveResponseTest method buildWithEverything.

@Test
public void buildWithEverything() {
    ReceiveResponse result = ReceiveResponse.Builder.create().withUnencryptedTransactionData("data".getBytes()).withSender(PublicKey.from("sender".getBytes())).withPrivacyMode(PrivacyMode.PRIVATE_STATE_VALIDATION).withAffectedTransactions(Set.of(new MessageHash("hash".getBytes()))).withExecHash("execHash".getBytes()).withManagedParties(Set.of(PublicKey.from("ownKey".getBytes()))).withPrivacyGroupId(PrivacyGroup.Id.fromBytes("group".getBytes())).build();
    assertThat(result.getPrivacyGroupId()).isPresent();
    assertThat(result.getPrivacyMode()).isEqualTo(PrivacyMode.PRIVATE_STATE_VALIDATION);
    assertThat(result.getAffectedTransactions()).containsExactly(new MessageHash("hash".getBytes()));
    assertThat(result.getExecHash()).isEqualTo("execHash".getBytes());
    assertThat(result.getPrivacyGroupId().get()).isEqualTo(PrivacyGroup.Id.fromBytes("group".getBytes()));
    assertThat(result.sender()).isEqualTo(PublicKey.from("sender".getBytes()));
    assertThat(result.getManagedParties()).containsExactly(PublicKey.from("ownKey".getBytes()));
}
Also used : MessageHash(com.quorum.tessera.data.MessageHash) Test(org.junit.Test)

Example 39 with MessageHash

use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.

the class SendRequestTest method buildWithMandatoryRecipients.

@Test
public void buildWithMandatoryRecipients() {
    byte[] payload = "Payload".getBytes();
    PublicKey sender = mock(PublicKey.class);
    PrivacyGroup.Id groupId = mock(PrivacyGroup.Id.class);
    List<PublicKey> recipients = List.of(mock(PublicKey.class));
    MessageHash affectedTransaction = mock(MessageHash.class);
    SendRequest sendRequest = SendRequest.Builder.create().withPayload(payload).withSender(sender).withRecipients(recipients).withPrivacyMode(PrivacyMode.MANDATORY_RECIPIENTS).withMandatoryRecipients(Set.of(PublicKey.from("key".getBytes()))).withAffectedContractTransactions(Set.of(affectedTransaction)).withPrivacyGroupId(groupId).build();
    assertThat(sendRequest).isNotNull();
    assertThat(sendRequest.getSender()).isSameAs(sender);
    assertThat(sendRequest.getPayload()).containsExactly(payload);
    assertThat(sendRequest.getRecipients()).containsAll(recipients);
    assertThat(sendRequest.getPrivacyMode()).isEqualTo(PrivacyMode.MANDATORY_RECIPIENTS);
    assertThat(sendRequest.getAffectedContractTransactions()).containsExactly(affectedTransaction);
    assertThat(sendRequest.getMandatoryRecipients()).containsExactly(PublicKey.from("key".getBytes()));
    assertThat(sendRequest.getPrivacyGroupId()).isPresent().get().isSameAs(groupId);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) MessageHash(com.quorum.tessera.data.MessageHash) PrivacyGroup(com.quorum.tessera.enclave.PrivacyGroup) Test(org.junit.Test)

Example 40 with MessageHash

use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.

the class SendRequestTest method buildWithEverything.

@Test
public void buildWithEverything() {
    byte[] payload = "Payload".getBytes();
    PublicKey sender = mock(PublicKey.class);
    PrivacyGroup.Id groupId = mock(PrivacyGroup.Id.class);
    List<PublicKey> recipients = List.of(mock(PublicKey.class));
    MessageHash affectedTransaction = mock(MessageHash.class);
    final byte[] execHash = "ExecHash".getBytes();
    SendRequest sendRequest = SendRequest.Builder.create().withPayload(payload).withSender(sender).withRecipients(recipients).withPrivacyMode(PrivacyMode.PRIVATE_STATE_VALIDATION).withExecHash(execHash).withAffectedContractTransactions(Set.of(affectedTransaction)).withPrivacyGroupId(groupId).build();
    assertThat(sendRequest).isNotNull();
    assertThat(sendRequest.getSender()).isSameAs(sender);
    assertThat(sendRequest.getPayload()).containsExactly(payload);
    assertThat(sendRequest.getRecipients()).containsAll(recipients);
    assertThat(sendRequest.getPrivacyMode()).isEqualTo(PrivacyMode.PRIVATE_STATE_VALIDATION);
    assertThat(sendRequest.getExecHash()).containsExactly(execHash);
    assertThat(sendRequest.getAffectedContractTransactions()).containsExactly(affectedTransaction);
    assertThat(sendRequest.getPrivacyGroupId()).isPresent().get().isSameAs(groupId);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) MessageHash(com.quorum.tessera.data.MessageHash) PrivacyGroup(com.quorum.tessera.enclave.PrivacyGroup) Test(org.junit.Test)

Aggregations

MessageHash (com.quorum.tessera.data.MessageHash)81 PublicKey (com.quorum.tessera.encryption.PublicKey)56 Test (org.junit.Test)51 Response (jakarta.ws.rs.core.Response)44 Operation (io.swagger.v3.oas.annotations.Operation)21 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)21 SendResponse (com.quorum.tessera.api.SendResponse)17 ReceiveResponse (com.quorum.tessera.transaction.ReceiveResponse)16 SendRequest (com.quorum.tessera.api.SendRequest)15 PrivacyGroup (com.quorum.tessera.enclave.PrivacyGroup)15 PrivacyMode (com.quorum.tessera.enclave.PrivacyMode)15 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)13 java.util (java.util)13 Collectors (java.util.stream.Collectors)13 Logger (org.slf4j.Logger)13 LoggerFactory (org.slf4j.LoggerFactory)13 EncryptedTransaction (com.quorum.tessera.data.EncryptedTransaction)12 TransactionManager (com.quorum.tessera.transaction.TransactionManager)12 Tag (io.swagger.v3.oas.annotations.tags.Tag)11 Valid (jakarta.validation.Valid)11