use of com.quorum.tessera.data.MessageHash 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.MessageHash 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.MessageHash 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.data.MessageHash in project tessera by ConsenSys.
the class RecoveryImplTest method testSyncSuccess.
@Test
public void testSyncSuccess() {
StagingTransaction version1 = mock(StagingTransaction.class);
StagingTransaction version2 = mock(StagingTransaction.class);
when(version1.getHash()).thenReturn("TXN1");
when(version2.getHash()).thenReturn("TXN1");
EncodedPayload firstPayload = mock(EncodedPayload.class);
EncodedPayload secondPayload = mock(EncodedPayload.class);
when(version1.getEncodedPayload()).thenReturn(firstPayload);
when(version2.getEncodedPayload()).thenReturn(secondPayload);
when(stagingEntityDAO.retrieveTransactionBatchOrderByStageAndHash(anyInt(), anyInt())).thenReturn(List.of(version1, version2));
when(stagingEntityDAO.countAll()).thenReturn(2L);
when(transactionManager.storePayload(any())).thenReturn(new MessageHash("hash".getBytes()));
RecoveryResult result = recovery.sync();
assertThat(result).isEqualTo(RecoveryResult.SUCCESS);
verify(stagingEntityDAO).retrieveTransactionBatchOrderByStageAndHash(anyInt(), anyInt());
verify(stagingEntityDAO, times(2)).countAll();
verify(transactionManager).storePayload(firstPayload);
verify(transactionManager).storePayload(secondPayload);
}
use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.
the class RawTransactionResourceTest method storeUsingDefaultKeyVersion21.
@Test
public void storeUsingDefaultKeyVersion21() {
com.quorum.tessera.transaction.StoreRawResponse response = mock(com.quorum.tessera.transaction.StoreRawResponse.class);
MessageHash transactionHash = mock(MessageHash.class);
when(transactionHash.getHashBytes()).thenReturn("TXN".getBytes());
when(response.getHash()).thenReturn(transactionHash);
when(transactionManager.store(any())).thenReturn(response);
when(transactionManager.defaultPublicKey()).thenReturn(PublicKey.from("SENDER".getBytes()));
final StoreRawRequest storeRawRequest = new StoreRawRequest();
storeRawRequest.setPayload("PAYLOAD".getBytes());
final Response result = transactionResource.storeVersion21(storeRawRequest);
assertThat(result.getStatus()).isEqualTo(200);
verify(transactionManager).store(any());
verify(transactionManager).defaultPublicKey();
}
Aggregations