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)));
}
}
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);
}
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();
}
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);
}
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()));
}
Aggregations