use of com.quorum.tessera.data.EncryptedTransaction in project tessera by ConsenSys.
the class LegacyResendManagerImplTest method performResendAll.
@Test
public void performResendAll() {
final PublicKey targetResendKey = PublicKey.from("target".getBytes());
final ResendRequest request = ResendRequest.Builder.create().withType(ResendRequest.ResendRequestType.ALL).withRecipient(targetResendKey).build();
// Not bothered about going through the process, just make sure they are all loaded from the
// database
// We are not testing the workflow itself, only that the workflow gets the right amount of
// transactions
when(dao.transactionCount()).thenReturn(2L);
when(dao.retrieveTransactions(0, 1)).thenReturn(List.of(new EncryptedTransaction()));
when(dao.retrieveTransactions(1, 1)).thenReturn(List.of(new EncryptedTransaction()));
final ResendResponse response = resendManager.resend(request);
assertThat(response).isNotNull();
assertThat(response.getPayload()).isNull();
verify(enclave, times(2)).status();
verify(dao).transactionCount();
verify(dao).retrieveTransactions(0, 1);
verify(dao).retrieveTransactions(1, 1);
}
use of com.quorum.tessera.data.EncryptedTransaction in project tessera by ConsenSys.
the class LegacyResendManagerImplTest method individualNonStandardPrivateTxFails.
@Test
public void individualNonStandardPrivateTxFails() {
final EncodedPayload nonSPPayload = EncodedPayload.Builder.create().withPrivacyMode(PrivacyMode.PARTY_PROTECTION).build();
final EncryptedTransaction databaseTx = new EncryptedTransaction();
databaseTx.setPayload(nonSPPayload);
when(dao.retrieveByHash(any(MessageHash.class))).thenReturn(Optional.of(databaseTx));
final MessageHash txHash = new MessageHash("sample-hash".getBytes());
final PublicKey targetResendKey = PublicKey.from("target".getBytes());
final ResendRequest request = ResendRequest.Builder.create().withType(ResendRequest.ResendRequestType.INDIVIDUAL).withHash(txHash).withRecipient(targetResendKey).build();
final Throwable throwable = catchThrowable(() -> resendManager.resend(request));
assertThat(throwable).isInstanceOf(EnhancedPrivacyNotSupportedException.class).hasMessage("Cannot resend enhanced privacy transaction in legacy resend");
verify(dao).retrieveByHash(txHash);
}
use of com.quorum.tessera.data.EncryptedTransaction in project tessera by ConsenSys.
the class LegacyResendManagerImplTest method targetKeyIsNotSenderOfTransaction.
@Test
public void targetKeyIsNotSenderOfTransaction() {
final MessageHash txHash = new MessageHash("sample-hash".getBytes());
final PublicKey targetResendKey = PublicKey.from("target".getBytes());
final EncodedPayload nonSPPayload = EncodedPayload.Builder.create().withPrivacyMode(PrivacyMode.STANDARD_PRIVATE).build();
final EncryptedTransaction databaseTx = new EncryptedTransaction();
databaseTx.setPayload(nonSPPayload);
final ResendRequest request = ResendRequest.Builder.create().withType(ResendRequest.ResendRequestType.INDIVIDUAL).withHash(txHash).withRecipient(targetResendKey).build();
when(dao.retrieveByHash(any(MessageHash.class))).thenReturn(Optional.of(databaseTx));
final ResendResponse response;
try (var mockStatic = mockStatic(EncodedPayload.Builder.class)) {
EncodedPayload.Builder builder = mock(EncodedPayload.Builder.class);
mockStatic.when(() -> EncodedPayload.Builder.forRecipient(nonSPPayload, targetResendKey)).thenReturn(builder);
when(builder.build()).thenReturn(nonSPPayload);
response = resendManager.resend(request);
mockStatic.verify(() -> EncodedPayload.Builder.forRecipient(nonSPPayload, targetResendKey));
}
assertThat(response).isNotNull();
assertThat(response.getPayload()).isEqualTo(nonSPPayload);
verify(dao).retrieveByHash(txHash);
}
use of com.quorum.tessera.data.EncryptedTransaction in project tessera by ConsenSys.
the class LegacyResendWorkflowFactoryTest method successForAllStagesReturnsTrue.
@Test
public void successForAllStagesReturnsTrue() {
final PublicKey targetResendKey = PublicKey.from("target".getBytes());
final PublicKey localRecipient = PublicKey.from("local-recipient".getBytes());
final EncodedPayload payload = EncodedPayload.Builder.create().withSenderKey(targetResendKey).withRecipientBox("testbox".getBytes()).build();
final NodeInfo nodeInfo = mock(NodeInfo.class);
when(nodeInfo.getRecipients()).thenReturn(Set.of(Recipient.of(targetResendKey, "url")));
when(discovery.getCurrent()).thenReturn(nodeInfo);
final EncryptedTransaction encryptedTx = mock(EncryptedTransaction.class);
when(enclave.getPublicKeys()).thenReturn(Set.of(localRecipient));
when(enclave.unencryptTransaction(any(EncodedPayload.class), eq(localRecipient))).thenReturn(new byte[0]);
final BatchWorkflow batchWorkflow = wfFactory.create();
final BatchWorkflowContext context = new BatchWorkflowContext();
context.setEncryptedTransaction(encryptedTx);
context.setEncodedPayload(payload);
context.setRecipientKey(targetResendKey);
context.setBatchSize(1);
final boolean success = batchWorkflow.execute(context);
assertThat(success).isTrue();
verify(discovery).getCurrent();
verify(payloadPublisher).publishPayload(any(EncodedPayload.class), eq(targetResendKey));
verify(enclave).status();
verify(enclave, times(2)).getPublicKeys();
verify(enclave).unencryptTransaction(any(EncodedPayload.class), eq(localRecipient));
}
use of com.quorum.tessera.data.EncryptedTransaction 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);
}
Aggregations