use of com.quorum.tessera.data.MessageHash 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());
}
use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.
the class ReceiveRequestTest method buildWithTransactionHashAndRecipient.
@Test
public void buildWithTransactionHashAndRecipient() {
MessageHash messageHash = mock(MessageHash.class);
PublicKey recipient = mock(PublicKey.class);
ReceiveRequest result = ReceiveRequest.Builder.create().withTransactionHash(messageHash).withRecipient(recipient).build();
assertThat(result).isNotNull();
assertThat(result.getTransactionHash()).isNotNull().isSameAs(messageHash);
assertThat(result.getRecipient()).containsSame(recipient);
assertThat(result.isRaw()).isFalse();
}
use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.
the class ReceiveResponseTest method buildWithEverything.
@Test
public void buildWithEverything() {
ReceiveResponse result = ReceiveResponse.Builder.create().withUnencryptedTransactionData("data".getBytes()).withSender(PublicKey.from("sender".getBytes())).withPrivacyMode(PrivacyMode.PRIVATE_STATE_VALIDATION).withAffectedTransactions(Set.of(new MessageHash("hash".getBytes()))).withExecHash("execHash".getBytes()).withManagedParties(Set.of(PublicKey.from("ownKey".getBytes()))).withPrivacyGroupId(PrivacyGroup.Id.fromBytes("group".getBytes())).build();
assertThat(result.getPrivacyGroupId()).isPresent();
assertThat(result.getPrivacyMode()).isEqualTo(PrivacyMode.PRIVATE_STATE_VALIDATION);
assertThat(result.getAffectedTransactions()).containsExactly(new MessageHash("hash".getBytes()));
assertThat(result.getExecHash()).isEqualTo("execHash".getBytes());
assertThat(result.getPrivacyGroupId().get()).isEqualTo(PrivacyGroup.Id.fromBytes("group".getBytes()));
assertThat(result.sender()).isEqualTo(PublicKey.from("sender".getBytes()));
assertThat(result.getManagedParties()).containsExactly(PublicKey.from("ownKey".getBytes()));
}
use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.
the class SendRequestTest method buildWithMandatoryRecipients.
@Test
public void buildWithMandatoryRecipients() {
byte[] payload = "Payload".getBytes();
PublicKey sender = mock(PublicKey.class);
PrivacyGroup.Id groupId = mock(PrivacyGroup.Id.class);
List<PublicKey> recipients = List.of(mock(PublicKey.class));
MessageHash affectedTransaction = mock(MessageHash.class);
SendRequest sendRequest = SendRequest.Builder.create().withPayload(payload).withSender(sender).withRecipients(recipients).withPrivacyMode(PrivacyMode.MANDATORY_RECIPIENTS).withMandatoryRecipients(Set.of(PublicKey.from("key".getBytes()))).withAffectedContractTransactions(Set.of(affectedTransaction)).withPrivacyGroupId(groupId).build();
assertThat(sendRequest).isNotNull();
assertThat(sendRequest.getSender()).isSameAs(sender);
assertThat(sendRequest.getPayload()).containsExactly(payload);
assertThat(sendRequest.getRecipients()).containsAll(recipients);
assertThat(sendRequest.getPrivacyMode()).isEqualTo(PrivacyMode.MANDATORY_RECIPIENTS);
assertThat(sendRequest.getAffectedContractTransactions()).containsExactly(affectedTransaction);
assertThat(sendRequest.getMandatoryRecipients()).containsExactly(PublicKey.from("key".getBytes()));
assertThat(sendRequest.getPrivacyGroupId()).isPresent().get().isSameAs(groupId);
}
use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.
the class SendRequestTest method buildWithEverything.
@Test
public void buildWithEverything() {
byte[] payload = "Payload".getBytes();
PublicKey sender = mock(PublicKey.class);
PrivacyGroup.Id groupId = mock(PrivacyGroup.Id.class);
List<PublicKey> recipients = List.of(mock(PublicKey.class));
MessageHash affectedTransaction = mock(MessageHash.class);
final byte[] execHash = "ExecHash".getBytes();
SendRequest sendRequest = SendRequest.Builder.create().withPayload(payload).withSender(sender).withRecipients(recipients).withPrivacyMode(PrivacyMode.PRIVATE_STATE_VALIDATION).withExecHash(execHash).withAffectedContractTransactions(Set.of(affectedTransaction)).withPrivacyGroupId(groupId).build();
assertThat(sendRequest).isNotNull();
assertThat(sendRequest.getSender()).isSameAs(sender);
assertThat(sendRequest.getPayload()).containsExactly(payload);
assertThat(sendRequest.getRecipients()).containsAll(recipients);
assertThat(sendRequest.getPrivacyMode()).isEqualTo(PrivacyMode.PRIVATE_STATE_VALIDATION);
assertThat(sendRequest.getExecHash()).containsExactly(execHash);
assertThat(sendRequest.getAffectedContractTransactions()).containsExactly(affectedTransaction);
assertThat(sendRequest.getPrivacyGroupId()).isPresent().get().isSameAs(groupId);
}
Aggregations