Search in sources :

Example 21 with EncodedPayload

use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.

the class RestPayloadPublisherTest method handleConnectionError.

@Test
public void handleConnectionError() {
    final String targetUri = "http://jimmywhite.com";
    final PublicKey recipientKey = mock(PublicKey.class);
    Recipient recipient = mock(Recipient.class);
    when(recipient.getKey()).thenReturn(recipientKey);
    when(recipient.getUrl()).thenReturn(targetUri);
    NodeInfo nodeInfo = mock(NodeInfo.class);
    when(nodeInfo.getRecipients()).thenReturn(Set.of(recipient));
    when(nodeInfo.getUrl()).thenReturn(targetUri);
    when(discovery.getRemoteNodeInfo(recipientKey)).thenReturn(nodeInfo);
    Client client = mock(Client.class);
    when(client.target(targetUri)).thenThrow(ProcessingException.class);
    final EncodedPayload payload = mock(EncodedPayload.class);
    when(payload.getPrivacyMode()).thenReturn(PrivacyMode.STANDARD_PRIVATE);
    when(payloadEncoder.encode(payload)).thenReturn("SomeData".getBytes());
    RestPayloadPublisher restPayloadPublisher = new RestPayloadPublisher(client, discovery);
    try {
        restPayloadPublisher.publishPayload(payload, recipientKey);
        failBecauseExceptionWasNotThrown(NodeOfflineException.class);
    } catch (NodeOfflineException ex) {
        assertThat(ex).hasMessageContaining(targetUri);
        verify(client).target(targetUri);
        verify(discovery).getRemoteNodeInfo(eq(recipientKey));
        verify(payloadEncoder).encode(payload);
        verify(discovery).getRemoteNodeInfo(eq(recipientKey));
        payloadEncoderFactoryFunction.verify(() -> PayloadEncoder.create(any(EncodedPayloadCodec.class)));
    }
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Client(jakarta.ws.rs.client.Client) NodeOfflineException(com.quorum.tessera.transaction.publish.NodeOfflineException) EncodedPayloadCodec(com.quorum.tessera.enclave.EncodedPayloadCodec) Test(org.junit.Test)

Example 22 with EncodedPayload

use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.

the class EncryptedTransactionListener method onUpdate.

@PreUpdate
public void onUpdate(EncryptedTransaction encryptedTransaction) {
    LOGGER.debug("onUpdate {}", encryptedTransaction);
    final EncodedPayload encodedPayload = encryptedTransaction.getPayload();
    final EncodedPayloadCodec encodedPayloadCodec = encryptedTransaction.getEncodedPayloadCodec();
    final PayloadEncoder payloadEncoder = PayloadEncoder.create(encodedPayloadCodec);
    final byte[] encodedPayloadData = payloadEncoder.encode(encodedPayload);
    encryptedTransaction.setEncodedPayload(encodedPayloadData);
}
Also used : PayloadEncoder(com.quorum.tessera.enclave.PayloadEncoder) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) EncodedPayloadCodec(com.quorum.tessera.enclave.EncodedPayloadCodec) PreUpdate(jakarta.persistence.PreUpdate)

Example 23 with EncodedPayload

use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.

the class LegacyResendWorkflowFactoryTest method failureAtStepReturnsFalse.

@Test
public void failureAtStepReturnsFalse() {
    final PublicKey targetResendKey = PublicKey.from("target".getBytes());
    final EncodedPayload testPayload = mock(EncodedPayload.class);
    // causes a failure
    when(testPayload.getPrivacyMode()).thenReturn(PrivacyMode.PARTY_PROTECTION);
    when(testPayload.getSenderKey()).thenReturn(targetResendKey);
    final EncryptedTransaction encryptedTx = new EncryptedTransaction();
    final BatchWorkflow batchWorkflow = wfFactory.create();
    final BatchWorkflowContext context = new BatchWorkflowContext();
    context.setEncryptedTransaction(encryptedTx);
    context.setRecipientKey(targetResendKey);
    context.setBatchSize(1);
    final boolean success = batchWorkflow.execute(context);
    assertThat(success).isFalse();
    verify(enclave).status();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) Test(org.junit.Test)

Example 24 with EncodedPayload

use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.

the class PreparePayloadForRecipientTest method targetKeyIsRecipientOfTransaction.

@Test
public void targetKeyIsRecipientOfTransaction() {
    final PublicKey targetResendKey = PublicKey.from("target".getBytes());
    final EncodedPayload payload = mock(EncodedPayload.class);
    when(payload.getRecipientKeys()).thenReturn(List.of(targetResendKey));
    when(payload.getRecipientBoxes()).thenReturn(List.of(mock(RecipientBox.class)));
    final BatchWorkflowContext workflowEvent = new BatchWorkflowContext();
    workflowEvent.setEncodedPayload(payload);
    workflowEvent.setRecipientKey(targetResendKey);
    final EncodedPayload formattedPayload = mock(EncodedPayload.class);
    try (var mockStatic = mockStatic(EncodedPayload.Builder.class)) {
        EncodedPayload.Builder builder = mock(EncodedPayload.Builder.class);
        mockStatic.when(() -> EncodedPayload.Builder.forRecipient(payload, targetResendKey)).thenReturn(builder);
        when(builder.build()).thenReturn(formattedPayload);
        preparePayloadForRecipient.execute(workflowEvent);
        mockStatic.verify(() -> EncodedPayload.Builder.forRecipient(payload, targetResendKey));
    }
    final Set<EncodedPayload> payloadsToPublish = workflowEvent.getPayloadsToPublish();
    assertThat(payloadsToPublish).containsExactly(formattedPayload);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Test(org.junit.Test)

Example 25 with EncodedPayload

use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.

the class PreparePayloadForRecipientTest method targetKeyIsSenderOfTransactionWithNoRecipientsPresent.

@Test
public void targetKeyIsSenderOfTransactionWithNoRecipientsPresent() {
    final PublicKey targetResendKey = PublicKey.from("target".getBytes());
    final EncodedPayload payload = mock(EncodedPayload.class);
    when(payload.getSenderKey()).thenReturn(targetResendKey);
    when(payload.getRecipientBoxes()).thenReturn(List.of(RecipientBox.from("box1".getBytes()), RecipientBox.from("box2".getBytes())));
    final BatchWorkflowContext workflowEvent = new BatchWorkflowContext();
    workflowEvent.setEncodedPayload(payload);
    workflowEvent.setRecipientKey(targetResendKey);
    preparePayloadForRecipient.execute(workflowEvent);
    final Set<EncodedPayload> payloadsToPublish = workflowEvent.getPayloadsToPublish();
    assertThat(payloadsToPublish.size()).isEqualTo(2);
    assertThat(payloadsToPublish.stream().map(EncodedPayload::getSenderKey).filter(targetResendKey::equals).count()).isEqualTo(2);
    assertThat(payloadsToPublish.stream().map(EncodedPayload::getRecipientBoxes).flatMap(Collection::stream).collect(Collectors.toList())).containsExactlyInAnyOrder(RecipientBox.from("box1".getBytes()), RecipientBox.from("box2".getBytes()));
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Test(org.junit.Test)

Aggregations

EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)91 Test (org.junit.Test)60 PublicKey (com.quorum.tessera.encryption.PublicKey)50 PayloadEncoder (com.quorum.tessera.enclave.PayloadEncoder)23 Response (jakarta.ws.rs.core.Response)20 MessageHash (com.quorum.tessera.data.MessageHash)13 Collectors (java.util.stream.Collectors)12 EncryptedTransaction (com.quorum.tessera.data.EncryptedTransaction)11 PrivacyMode (com.quorum.tessera.enclave.PrivacyMode)11 EncodedPayloadCodec (com.quorum.tessera.enclave.EncodedPayloadCodec)9 NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)8 Recipient (com.quorum.tessera.partyinfo.node.Recipient)8 java.util (java.util)8 Invocation (jakarta.ws.rs.client.Invocation)6 WebTarget (jakarta.ws.rs.client.WebTarget)6 StagingTransaction (com.quorum.tessera.data.staging.StagingTransaction)5 PrivacyMetadata (com.quorum.tessera.enclave.PrivacyMetadata)5 RecipientBox (com.quorum.tessera.enclave.RecipientBox)5 TxHash (com.quorum.tessera.enclave.TxHash)5 ResendRequest (com.quorum.tessera.p2p.resend.ResendRequest)5