use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.
the class PreparePayloadForRecipientTest method psvTransactionOnlyUsesKeysWithBoxes.
@Test
public void psvTransactionOnlyUsesKeysWithBoxes() {
final PublicKey targetResendKey = PublicKey.from("target".getBytes());
final PublicKey recipient1 = PublicKey.from("recipient1".getBytes());
final PublicKey recipient2 = PublicKey.from("recipient2".getBytes());
final EncodedPayload payload = mock(EncodedPayload.class);
when(payload.getSenderKey()).thenReturn(targetResendKey);
when(payload.getPrivacyMode()).thenReturn(PrivacyMode.PRIVATE_STATE_VALIDATION);
when(payload.getRecipientKeys()).thenReturn(List.of(recipient1, recipient2));
when(payload.getRecipientBoxes()).thenReturn(List.of(RecipientBox.from("box1".getBytes())));
final BatchWorkflowContext workflowEvent = new BatchWorkflowContext();
workflowEvent.setEncodedPayload(payload);
workflowEvent.setRecipientKey(targetResendKey);
try (var mockStatic = mockStatic(EncodedPayload.Builder.class)) {
EncodedPayload.Builder builder1 = mock(EncodedPayload.Builder.class);
when(builder1.build()).thenReturn(mock(EncodedPayload.class));
EncodedPayload.Builder builder2 = mock(EncodedPayload.Builder.class);
when(builder2.build()).thenReturn(mock(EncodedPayload.class));
mockStatic.when(() -> EncodedPayload.Builder.forRecipient(payload, recipient1)).thenReturn(builder1);
mockStatic.when(() -> EncodedPayload.Builder.forRecipient(payload, recipient2)).thenReturn(builder2);
preparePayloadForRecipient.execute(workflowEvent);
mockStatic.verify(() -> EncodedPayload.Builder.forRecipient(payload, recipient1));
verify(builder1).build();
verifyNoMoreInteractions(builder1, builder2);
}
final Set<EncodedPayload> payloadsToPublish = workflowEvent.getPayloadsToPublish();
assertThat(payloadsToPublish).hasSize(1);
}
use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.
the class PreparePayloadForRecipientTest method targetKeyIsSenderOfTransactionWithRecipientsPresent.
@Test
public void targetKeyIsSenderOfTransactionWithRecipientsPresent() {
final PublicKey targetResendKey = PublicKey.from("target".getBytes());
final PublicKey recipient1 = PublicKey.from("recipient1".getBytes());
final PublicKey recipient2 = PublicKey.from("recipient2".getBytes());
final EncodedPayload payload = mock(EncodedPayload.class);
when(payload.getSenderKey()).thenReturn(targetResendKey);
when(payload.getRecipientKeys()).thenReturn(List.of(recipient1, recipient2));
when(payload.getRecipientBoxes()).thenReturn(List.of(mock(RecipientBox.class), mock(RecipientBox.class)));
final BatchWorkflowContext workflowEvent = new BatchWorkflowContext();
workflowEvent.setEncodedPayload(payload);
workflowEvent.setRecipientKey(targetResendKey);
try (var mockStatic = mockStatic(EncodedPayload.Builder.class)) {
EncodedPayload.Builder builder1 = mock(EncodedPayload.Builder.class);
when(builder1.build()).thenReturn(mock(EncodedPayload.class));
EncodedPayload.Builder builder2 = mock(EncodedPayload.Builder.class);
when(builder2.build()).thenReturn(mock(EncodedPayload.class));
mockStatic.when(() -> EncodedPayload.Builder.forRecipient(payload, recipient1)).thenReturn(builder1);
mockStatic.when(() -> EncodedPayload.Builder.forRecipient(payload, recipient2)).thenReturn(builder2);
preparePayloadForRecipient.execute(workflowEvent);
mockStatic.verify(() -> EncodedPayload.Builder.forRecipient(payload, recipient1));
mockStatic.verify(() -> EncodedPayload.Builder.forRecipient(payload, recipient2));
verify(builder1).build();
verify(builder2).build();
}
final Set<EncodedPayload> payloadsToPublish = workflowEvent.getPayloadsToPublish();
assertThat(payloadsToPublish).hasSize(2);
}
use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.
the class SearchRecipientKeyForPayloadTest method execute.
@Test
public void execute() {
final BatchWorkflowContext workflowEvent = new BatchWorkflowContext();
final EncryptedTransaction encryptedTransaction = new EncryptedTransaction();
encryptedTransaction.setHash(new MessageHash("sampleHash".getBytes()));
workflowEvent.setEncryptedTransaction(encryptedTransaction);
final EncodedPayload encodedPayloadForRecipient1 = EncodedPayload.Builder.create().withRecipientBox("sample-box-1".getBytes()).build();
final EncodedPayload encodedPayloadForRecipient2 = EncodedPayload.Builder.create().withRecipientBox("sample-box-2".getBytes()).build();
workflowEvent.setPayloadsToPublish(Set.of(encodedPayloadForRecipient1, encodedPayloadForRecipient2));
final PublicKey recipient1 = PublicKey.from("sample-public-key-1".getBytes());
final PublicKey recipient2 = PublicKey.from("sample-public-key-2".getBytes());
// Using this LinkedHashSet instead of Set.of(...) to provide a defined iteration order.
final LinkedHashSet<PublicKey> enclaveKeys = new LinkedHashSet<>();
enclaveKeys.add(recipient1);
enclaveKeys.add(recipient2);
when(enclave.getPublicKeys()).thenReturn(enclaveKeys);
when(enclave.unencryptTransaction(encodedPayloadForRecipient1, recipient1)).thenReturn(new byte[0]);
when(enclave.unencryptTransaction(encodedPayloadForRecipient2, recipient2)).thenReturn(new byte[0]);
when(enclave.unencryptTransaction(encodedPayloadForRecipient2, recipient1)).thenThrow(EncryptorException.class);
searchRecipientKeyForPayload.execute(workflowEvent);
final Set<EncodedPayload> updatedPayloads = workflowEvent.getPayloadsToPublish();
assertThat(updatedPayloads).containsExactlyInAnyOrder(EncodedPayload.Builder.from(encodedPayloadForRecipient1).withRecipientKey(recipient1).build(), EncodedPayload.Builder.from(encodedPayloadForRecipient2).withRecipientKey(recipient2).build());
verify(enclave).unencryptTransaction(encodedPayloadForRecipient1, recipient1);
verify(enclave).unencryptTransaction(encodedPayloadForRecipient2, recipient1);
verify(enclave).unencryptTransaction(encodedPayloadForRecipient2, recipient2);
verify(enclave, times(2)).getPublicKeys();
verifyNoMoreInteractions(enclave);
}
use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.
the class SingleEncodedPayloadPublisherTest method unsuccessfulPublishReturnsFalse.
@Test
public void unsuccessfulPublishReturnsFalse() {
final PublicKey sampleKey = PublicKey.from("testkey".getBytes());
final EncodedPayload samplePayload1 = EncodedPayload.Builder.create().withSenderKey(sampleKey).build();
final EncodedPayload samplePayload2 = EncodedPayload.Builder.create().build();
final BatchWorkflowContext context = new BatchWorkflowContext();
context.setRecipientKey(sampleKey);
context.setPayloadsToPublish(Set.of(samplePayload1, samplePayload2));
doThrow(PublishPayloadException.class).when(payloadPublisher).publishPayload(samplePayload1, sampleKey);
final boolean success = workflowPublisher.execute(context);
assertThat(success).isFalse();
verify(payloadPublisher).publishPayload(samplePayload1, sampleKey);
}
use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.
the class RecoveryImplTest method testSyncPartialSuccess.
@Test
public void testSyncPartialSuccess() {
StagingTransaction version1 = mock(StagingTransaction.class);
StagingTransaction version2 = mock(StagingTransaction.class);
when(version1.getHash()).thenReturn("TXN1");
when(version2.getHash()).thenReturn("TXN1");
when(stagingEntityDAO.retrieveTransactionBatchOrderByStageAndHash(anyInt(), anyInt())).thenReturn(List.of(version1, version2));
when(stagingEntityDAO.countAll()).thenReturn(2L);
EncodedPayload encodedPayload = mock(EncodedPayload.class);
EncodedPayload encodedPayload2 = mock(EncodedPayload.class);
when(version1.getEncodedPayload()).thenReturn(encodedPayload);
when(version2.getEncodedPayload()).thenReturn(encodedPayload2);
when(transactionManager.storePayload(encodedPayload)).thenThrow(PrivacyViolationException.class);
RecoveryResult result = recovery.sync();
assertThat(result).isEqualTo(RecoveryResult.PARTIAL_SUCCESS);
verify(stagingEntityDAO).retrieveTransactionBatchOrderByStageAndHash(anyInt(), anyInt());
verify(stagingEntityDAO, times(2)).countAll();
verify(transactionManager).storePayload(encodedPayload);
verify(transactionManager).storePayload(encodedPayload2);
}
Aggregations