Search in sources :

Example 96 with PublicKey

use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.

the class SendRequestTest method buildWithInvalidExecHash.

@Test(expected = RuntimeException.class)
public void buildWithInvalidExecHash() {
    byte[] payload = "Payload".getBytes();
    PublicKey sender = mock(PublicKey.class);
    SendRequest.Builder.create().withPayload(payload).withSender(sender).withRecipients(Collections.emptyList()).withAffectedContractTransactions(Collections.emptySet()).withPrivacyMode(PrivacyMode.PRIVATE_STATE_VALIDATION).withExecHash(new byte[0]).build();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) Test(org.junit.Test)

Example 97 with PublicKey

use of com.quorum.tessera.encryption.PublicKey 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 98 with PublicKey

use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.

the class SendRequestTest method buildWithNoMandatoryRecipientsData.

@Test(expected = RuntimeException.class)
public void buildWithNoMandatoryRecipientsData() {
    byte[] payload = "Payload".getBytes();
    PublicKey sender = mock(PublicKey.class);
    List<PublicKey> recipients = List.of(mock(PublicKey.class));
    SendRequest.Builder.create().withPayload(payload).withSender(sender).withRecipients(recipients).withPrivacyMode(PrivacyMode.MANDATORY_RECIPIENTS).build();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) Test(org.junit.Test)

Example 99 with PublicKey

use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.

the class SendRequestTest method buildWithMandatoryRecipientsInvalid.

@Test(expected = RuntimeException.class)
public void buildWithMandatoryRecipientsInvalid() {
    byte[] payload = "Payload".getBytes();
    PublicKey sender = mock(PublicKey.class);
    List<PublicKey> recipients = List.of(mock(PublicKey.class));
    SendRequest.Builder.create().withPayload(payload).withSender(sender).withRecipients(recipients).withPrivacyMode(PrivacyMode.PARTY_PROTECTION).withMandatoryRecipients(Set.of(PublicKey.from("key".getBytes()))).build();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) Test(org.junit.Test)

Example 100 with PublicKey

use of com.quorum.tessera.encryption.PublicKey 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

PublicKey (com.quorum.tessera.encryption.PublicKey)281 Test (org.junit.Test)213 Response (jakarta.ws.rs.core.Response)59 MessageHash (com.quorum.tessera.data.MessageHash)57 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)48 Collectors (java.util.stream.Collectors)32 PrivacyGroup (com.quorum.tessera.enclave.PrivacyGroup)28 NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)25 java.util (java.util)23 SendResponse (com.quorum.tessera.api.SendResponse)21 Nonce (com.quorum.tessera.encryption.Nonce)20 Recipient (com.quorum.tessera.partyinfo.node.Recipient)20 Operation (io.swagger.v3.oas.annotations.Operation)20 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)20 Stream (java.util.stream.Stream)19 ReceiveResponse (com.quorum.tessera.transaction.ReceiveResponse)18 EncryptedTransaction (com.quorum.tessera.data.EncryptedTransaction)17 PrivacyMode (com.quorum.tessera.enclave.PrivacyMode)17 URI (java.net.URI)17 SendRequest (com.quorum.tessera.api.SendRequest)15