use of com.quorum.tessera.data.EncryptedTransaction in project tessera by ConsenSys.
the class MigrationTest method generateEncryptedTransaction.
static EncryptedTransaction generateEncryptedTransaction() {
EncryptedTransaction encryptedTransaction = new EncryptedTransaction();
encryptedTransaction.setHash(new MessageHash(UUID.randomUUID().toString().getBytes()));
encryptedTransaction.setPayload(generateEncodedPayload());
encryptedTransaction.setEncodedPayloadCodec(EncodedPayloadCodec.LEGACY);
return encryptedTransaction;
}
use of com.quorum.tessera.data.EncryptedTransaction in project tessera by ConsenSys.
the class ResendManagerImplTest method storePayloadAsSenderWhenTxIsPresentAndRecipientExisted.
@Test
public void storePayloadAsSenderWhenTxIsPresentAndRecipientExisted() {
final EncodedPayload encodedPayload = mock(EncodedPayload.class);
when(encodedPayload.getSenderKey()).thenReturn(senderKey);
when(encodedPayload.getCipherText()).thenReturn(cipherText);
when(encodedPayload.getRecipientKeys()).thenReturn(List.of(recipientKey1));
when(encodedPayload.getRecipientBoxes()).thenReturn(List.of(recipientBox1));
when(enclave.getPublicKeys()).thenReturn(singleton(senderKey));
final EncryptedTransaction et = mock(EncryptedTransaction.class);
when(et.getPayload()).thenReturn(encodedPayload);
when(encryptedTransactionDAO.retrieveByHash(any(MessageHash.class))).thenReturn(Optional.of(et));
resendManager.acceptOwnMessage(encodedPayload);
assertThat(encodedPayload.getRecipientKeys()).containsExactly(recipientKey1);
assertThat(encodedPayload.getRecipientBoxes()).containsExactly(recipientBox1);
verify(encryptedTransactionDAO).retrieveByHash(any(MessageHash.class));
verify(enclave).getPublicKeys();
verify(enclave).unencryptTransaction(encodedPayload, senderKey);
}
use of com.quorum.tessera.data.EncryptedTransaction in project tessera by ConsenSys.
the class ResendManagerImplTest method storePayloadAsSenderWhenTxIsPresentAndRecipientAlreadyExists.
@Test
public void storePayloadAsSenderWhenTxIsPresentAndRecipientAlreadyExists() {
final EncodedPayload encodedPayload = mock(EncodedPayload.class);
when(encodedPayload.getCipherText()).thenReturn("CIPHERTEXT".getBytes());
when(encodedPayload.getSenderKey()).thenReturn(senderKey);
when(encodedPayload.getRecipientKeys()).thenReturn(List.of(recipientKey2));
when(encodedPayload.getRecipientBoxes()).thenReturn(List.of(recipientBox2));
final EncodedPayload existingEncodedPayload = mock(EncodedPayload.class);
when(existingEncodedPayload.getCipherText()).thenReturn("CIPHERTEXT".getBytes());
when(existingEncodedPayload.getSenderKey()).thenReturn(senderKey);
when(existingEncodedPayload.getRecipientKeys()).thenReturn(List.of(recipientKey1, recipientKey2));
when(existingEncodedPayload.getRecipientBoxes()).thenReturn(List.of(recipientBox1, recipientBox2));
final EncryptedTransaction et = mock(EncryptedTransaction.class);
when(et.getPayload()).thenReturn(existingEncodedPayload);
when(enclave.getPublicKeys()).thenReturn(Set.of(senderKey));
when(encryptedTransactionDAO.retrieveByHash(any(MessageHash.class))).thenReturn(Optional.of(et));
resendManager.acceptOwnMessage(encodedPayload);
assertThat(encodedPayload.getRecipientKeys()).containsExactly(recipientKey2);
assertThat(encodedPayload.getRecipientBoxes()).containsExactly(recipientBox2);
verify(encryptedTransactionDAO).retrieveByHash(any(MessageHash.class));
verify(enclave).getPublicKeys();
verify(enclave).unencryptTransaction(encodedPayload, senderKey);
}
use of com.quorum.tessera.data.EncryptedTransaction in project tessera by ConsenSys.
the class ResendManagerImplTest method invalidPayloadFromMaliciousRecipient.
@Test
public void invalidPayloadFromMaliciousRecipient() {
final EncodedPayload encodedPayload = mock(EncodedPayload.class);
when(encodedPayload.getSenderKey()).thenReturn(senderKey);
when(encodedPayload.getCipherText()).thenReturn(cipherText);
when(encodedPayload.getRecipientKeys()).thenReturn(List.of(recipientKey1));
when(encodedPayload.getRecipientBoxes()).thenReturn(List.of(recipientBox1));
final EncodedPayload existingEncodedPayload = mock(EncodedPayload.class);
when(existingEncodedPayload.getCipherText()).thenReturn("CIPHERTEXT".getBytes());
when(existingEncodedPayload.getSenderKey()).thenReturn(senderKey);
when(existingEncodedPayload.getRecipientKeys()).thenReturn(List.of());
when(existingEncodedPayload.getRecipientBoxes()).thenReturn(List.of());
final EncryptedTransaction et = mock(EncryptedTransaction.class);
when(et.getPayload()).thenReturn(existingEncodedPayload);
when(enclave.getPublicKeys()).thenReturn(singleton(senderKey));
when(encryptedTransactionDAO.retrieveByHash(any(MessageHash.class))).thenReturn(Optional.of(et));
when(enclave.unencryptTransaction(existingEncodedPayload, senderKey)).thenReturn("payload1".getBytes());
final Throwable throwable = catchThrowable(() -> resendManager.acceptOwnMessage(encodedPayload));
assertThat(throwable).isInstanceOf(IllegalArgumentException.class).hasMessage("Invalid payload provided");
verify(encryptedTransactionDAO).retrieveByHash(any(MessageHash.class));
verify(enclave).getPublicKeys();
verify(enclave).unencryptTransaction(encodedPayload, senderKey);
verify(enclave).unencryptTransaction(existingEncodedPayload, senderKey);
}
use of com.quorum.tessera.data.EncryptedTransaction in project tessera by ConsenSys.
the class PrivacyHelperTest method findAffectedContractTransactionsFromSendRequestFound.
@Test
public void findAffectedContractTransactionsFromSendRequestFound() {
final MessageHash hash1 = mock(MessageHash.class);
final MessageHash hash2 = mock(MessageHash.class);
EncryptedTransaction et1 = mock(EncryptedTransaction.class);
when(et1.getEncodedPayload()).thenReturn("payload1".getBytes());
when(et1.getHash()).thenReturn(hash1);
when(et1.getPayload()).thenReturn(mock(EncodedPayload.class));
EncryptedTransaction et2 = mock(EncryptedTransaction.class);
when(et2.getEncodedPayload()).thenReturn("payload2".getBytes());
when(et2.getHash()).thenReturn(hash2);
when(et2.getPayload()).thenReturn(mock(EncodedPayload.class));
when(encryptedTransactionDAO.findByHashes(anyCollection())).thenReturn(List.of(et1, et2));
List<AffectedTransaction> affectedTransactions = privacyHelper.findAffectedContractTransactionsFromSendRequest(Set.of(hash1, hash2));
assertThat(affectedTransactions).isNotNull();
assertThat(affectedTransactions.size()).isEqualTo(2);
verify(encryptedTransactionDAO).findByHashes(any());
}
Aggregations