use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.
the class NodeInfoTest method createWithEverything.
@Test
public void createWithEverything() {
String url = "someurl";
final Recipient recipient = mock(Recipient.class);
PublicKey publicKey = mock(PublicKey.class);
when(recipient.getUrl()).thenReturn("http://someurl.com/");
when(recipient.getKey()).thenReturn(publicKey);
Collection<Recipient> recipients = List.of(recipient);
Collection<String> supportedVersions = List.of("ONE", "TWO");
NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl(url).withRecipients(recipients).withSupportedApiVersions(supportedVersions).build();
assertThat(nodeInfo.getUrl()).isEqualTo(url);
assertThat(nodeInfo.getRecipients()).isEqualTo(Set.copyOf(recipients));
assertThat(nodeInfo.getRecipientsAsMap()).containsKey(publicKey).containsValue("http://someurl.com/");
assertThat(nodeInfo.supportedApiVersions()).isEqualTo(Set.copyOf(supportedVersions));
}
use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.
the class TransactionManagerTest method sendSignedTransaction.
@Test
public void sendSignedTransaction() {
EncodedPayload payload = mock(EncodedPayload.class);
MessageHash hash = new MessageHash("HASH".getBytes());
EncryptedRawTransaction encryptedRawTransaction = mock(EncryptedRawTransaction.class);
when(encryptedRawTransaction.getHash()).thenReturn(hash);
when(encryptedRawTransaction.toRawTransaction()).thenReturn(mock((RawTransaction.class)));
when(encryptedRawTransactionDAO.retrieveByHash(hash)).thenReturn(Optional.of(encryptedRawTransaction));
when(payload.getCipherText()).thenReturn("ENCRYPTED_PAYLOAD".getBytes());
when(enclave.encryptPayload(any(RawTransaction.class), any(), any())).thenReturn(payload);
PublicKey receiver = PublicKey.from("RECEIVER".getBytes());
when(enclave.getPublicKeys()).thenReturn(Set.of(receiver));
SendSignedRequest sendSignedRequest = mock(SendSignedRequest.class);
when(sendSignedRequest.getRecipients()).thenReturn(List.of(receiver));
when(sendSignedRequest.getSignedData()).thenReturn("HASH".getBytes());
when(sendSignedRequest.getPrivacyMode()).thenReturn(PrivacyMode.STANDARD_PRIVATE);
SendResponse result = transactionManager.sendSignedTransaction(sendSignedRequest);
assertThat(result).isNotNull();
assertThat(result.getTransactionHash()).isEqualTo(new MessageHash("HASH".getBytes()));
assertThat(result.getManagedParties()).containsExactly(receiver);
ArgumentCaptor<PrivacyMetadata> data = ArgumentCaptor.forClass(PrivacyMetadata.class);
verify(enclave).encryptPayload(any(RawTransaction.class), any(), data.capture());
verify(encryptedTransactionDAO).save(any(EncryptedTransaction.class), any(Callable.class));
verify(encryptedRawTransactionDAO).retrieveByHash(any(MessageHash.class));
verify(enclave).getForwardingKeys();
verify(enclave).getPublicKeys();
final PrivacyMetadata passingData = data.getValue();
assertThat(passingData.getPrivacyMode()).isEqualTo(PrivacyMode.STANDARD_PRIVATE);
assertThat(passingData.getPrivacyGroupId()).isNotPresent();
}
use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.
the class TransactionManagerTest method getParticipantsReturnsAllRecipients.
@Test
public void getParticipantsReturnsAllRecipients() {
MessageHash transactionHash = mock(MessageHash.class);
final PublicKey senderKey = mock(PublicKey.class);
final PublicKey recipientKey = mock(PublicKey.class);
final EncryptedTransaction encryptedTransaction = mock(EncryptedTransaction.class);
final EncodedPayload encodedPayload = mock(EncodedPayload.class);
when(encodedPayload.getRecipientKeys()).thenReturn(List.of(senderKey, recipientKey));
when(encryptedTransaction.getPayload()).thenReturn(encodedPayload);
when(encryptedTransactionDAO.retrieveByHash(transactionHash)).thenReturn(Optional.of(encryptedTransaction));
final List<PublicKey> participants = transactionManager.getParticipants(transactionHash);
assertThat(participants).containsExactlyInAnyOrder(senderKey, recipientKey);
verify(encryptedTransactionDAO).retrieveByHash(any(MessageHash.class));
}
use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.
the class TransactionManagerTest method receiveWithAffectedContractTransactions.
@Test
public void receiveWithAffectedContractTransactions() {
PublicKey sender = PublicKey.from("sender".getBytes());
PublicKey recipient = PublicKey.from("recipient".getBytes());
MessageHash messageHash = mock(MessageHash.class);
ReceiveRequest receiveRequest = mock(ReceiveRequest.class);
when(receiveRequest.getRecipient()).thenReturn(Optional.of(recipient));
when(receiveRequest.getTransactionHash()).thenReturn(messageHash);
final String b64AffectedTxHash = "bfMIqWJ/QGQhkK4USxMBxduzfgo/SIGoCros5bWYfPKUBinlAUCqLVOUAP9q+BgLlsWni1M6rnzfmaqSw2J5hQ==";
final Map<TxHash, SecurityHash> affectedTxs = Map.of(new TxHash(b64AffectedTxHash), SecurityHash.from("encoded".getBytes()));
EncodedPayload payload = mock(EncodedPayload.class);
when(payload.getExecHash()).thenReturn("execHash".getBytes());
when(payload.getPrivacyMode()).thenReturn(PrivacyMode.PRIVATE_STATE_VALIDATION);
when(payload.getAffectedContractTransactions()).thenReturn(affectedTxs);
when(payload.getSenderKey()).thenReturn(sender);
final EncryptedTransaction encryptedTransaction = mock(EncryptedTransaction.class);
when(encryptedTransaction.getHash()).thenReturn(messageHash);
when(encryptedTransaction.getPayload()).thenReturn(payload);
when(encryptedTransactionDAO.retrieveByHash(eq(messageHash))).thenReturn(Optional.of(encryptedTransaction));
byte[] expectedOutcome = "Encrypted payload".getBytes();
when(enclave.unencryptTransaction(eq(payload), any(PublicKey.class))).thenReturn(expectedOutcome);
PublicKey publicKey = mock(PublicKey.class);
when(enclave.getPublicKeys()).thenReturn(Collections.singleton(publicKey));
ReceiveResponse receiveResponse = transactionManager.receive(receiveRequest);
assertThat(receiveResponse).isNotNull();
assertThat(receiveResponse.getUnencryptedTransactionData()).isEqualTo(expectedOutcome);
assertThat(receiveResponse.getExecHash()).isEqualTo("execHash".getBytes());
assertThat(receiveResponse.getAffectedTransactions()).hasSize(1);
assertThat(receiveResponse.sender()).isEqualTo(sender);
verify(encryptedTransactionDAO).retrieveByHash(any(MessageHash.class));
verify(enclave, times(2)).unencryptTransaction(any(EncodedPayload.class), any(PublicKey.class));
verify(enclave).getPublicKeys();
}
use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.
the class TransactionManagerTest method getMandatoryRecipients.
@Test
public void getMandatoryRecipients() {
MessageHash transactionHash = mock(MessageHash.class);
final PublicKey senderKey = mock(PublicKey.class);
final PublicKey recipientKey = mock(PublicKey.class);
final EncryptedTransaction encryptedTransaction = mock(EncryptedTransaction.class);
final EncodedPayload encodedPayload = mock(EncodedPayload.class);
when(encodedPayload.getRecipientKeys()).thenReturn(List.of(senderKey, recipientKey));
when(encodedPayload.getPrivacyMode()).thenReturn(PrivacyMode.MANDATORY_RECIPIENTS);
when(encodedPayload.getMandatoryRecipients()).thenReturn(Set.of(recipientKey));
when(encryptedTransaction.getPayload()).thenReturn(encodedPayload);
when(encryptedTransactionDAO.retrieveByHash(transactionHash)).thenReturn(Optional.of(encryptedTransaction));
final Set<PublicKey> participants = transactionManager.getMandatoryRecipients(transactionHash);
assertThat(participants).containsExactly(recipientKey);
verify(encryptedTransactionDAO).retrieveByHash(any(MessageHash.class));
}
Aggregations