use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.
the class BesuTransactionResourceTest method sendToPrivacyGroup.
@Test
public void sendToPrivacyGroup() {
final Base64.Encoder base64Encoder = Base64.getEncoder();
final String base64Key = "BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=";
final SendRequest sendRequest = new SendRequest();
sendRequest.setPayload(base64Encoder.encode("PAYLOAD".getBytes()));
sendRequest.setPrivacyGroupId(base64Key);
final PublicKey sender = mock(PublicKey.class);
when(transactionManager.defaultPublicKey()).thenReturn(sender);
final com.quorum.tessera.transaction.SendResponse sendResponse = mock(com.quorum.tessera.transaction.SendResponse.class);
final MessageHash messageHash = mock(MessageHash.class);
final byte[] txnData = "TxnData".getBytes();
when(messageHash.getHashBytes()).thenReturn(txnData);
when(sendResponse.getTransactionHash()).thenReturn(messageHash);
when(transactionManager.send(any(com.quorum.tessera.transaction.SendRequest.class))).thenReturn(sendResponse);
PrivacyGroup retrieved = mock(PrivacyGroup.class);
PrivacyGroup.Id groupId = PrivacyGroup.Id.fromBase64String(base64Key);
PublicKey member = PublicKey.from("member".getBytes());
when(retrieved.getId()).thenReturn(groupId);
when(retrieved.getMembers()).thenReturn(List.of(member));
when(privacyGroupManager.retrievePrivacyGroup(groupId)).thenReturn(retrieved);
final Response result = besuTransactionResource.send(sendRequest);
// jersey.target("send").request().post(Entity.entity(sendRequest,
// MediaType.APPLICATION_JSON));
assertThat(result.getStatus()).isEqualTo(200);
assertThat(result.getLocation().getPath()).isEqualTo("transaction/" + base64Encoder.encodeToString(txnData));
SendResponse resultSendResponse = (SendResponse) result.getEntity();
assertThat(resultSendResponse.getKey()).isEqualTo(Base64.getEncoder().encodeToString(txnData));
ArgumentCaptor<com.quorum.tessera.transaction.SendRequest> argumentCaptor = ArgumentCaptor.forClass(com.quorum.tessera.transaction.SendRequest.class);
verify(transactionManager).send(argumentCaptor.capture());
verify(transactionManager).defaultPublicKey();
verify(privacyGroupManager).retrievePrivacyGroup(groupId);
com.quorum.tessera.transaction.SendRequest businessObject = argumentCaptor.getValue();
assertThat(businessObject).isNotNull();
assertThat(businessObject.getPayload()).isEqualTo(sendRequest.getPayload());
assertThat(businessObject.getSender()).isEqualTo(sender);
assertThat(businessObject.getRecipients()).hasSize(1);
assertThat(businessObject.getRecipients().get(0)).isEqualTo(member);
assertThat(businessObject.getPrivacyMode()).isEqualTo(PrivacyMode.STANDARD_PRIVATE);
assertThat(businessObject.getAffectedContractTransactions()).isEmpty();
assertThat(businessObject.getExecHash()).isEmpty();
assertThat(businessObject.getPrivacyGroupId()).isPresent().get().isEqualTo(groupId);
}
use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.
the class EncodedPayloadResourceTest method decryptPayloadVersion21.
@Test
public void decryptPayloadVersion21() {
final Base64.Decoder decoder = Base64.getDecoder();
final PayloadDecryptRequest request = new PayloadDecryptRequest();
request.setSenderKey(decoder.decode("BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo="));
request.setCipherText(decoder.decode("h7av/vhPlaPFECB1K30hNWugv/Bu"));
request.setCipherTextNonce(decoder.decode("8MVXAESCQuRHWxrQ6b5MXuYApjia+2h0"));
request.setRecipientBoxes(List.of(decoder.decode("FNirZRc2ayMaYopCBaWQ/1I7VWFiCM0lNw533Hckzxb+qpvngdWVVzJlsE05dbxl")));
request.setRecipientNonce(decoder.decode("p9gYDJlEoBvLdUQ+ZoONl2Jl9AirV1en"));
request.setRecipientKeys(List.of(decoder.decode("BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=")));
request.setPrivacyMode(3);
request.setAffectedContractTransactions(Map.of("dHgx", "dHgxdmFs", "dHgy", "dHgydmFs"));
request.setExecHash("execHash".getBytes());
final ReceiveResponse response = ReceiveResponse.Builder.create().withUnencryptedTransactionData("decryptedData".getBytes()).withPrivacyMode(PrivacyMode.PRIVATE_STATE_VALIDATION).withAffectedTransactions(Set.of(new MessageHash("tx1val".getBytes()), new MessageHash("tx2val".getBytes()))).withExecHash("execHash".getBytes()).withSender(PublicKey.from(request.getSenderKey())).build();
when(encodedPayloadManager.decrypt(any(), eq(null))).thenReturn(response);
final Response result = encodedPayloadResource.receive21(request);
assertThat(result.getStatus()).isEqualTo(200);
final com.quorum.tessera.api.ReceiveResponse payloadEncryptResponse = Optional.of(result).map(Response::getEntity).map(com.quorum.tessera.api.ReceiveResponse.class::cast).get();
assertThat(payloadEncryptResponse.getPayload()).isEqualTo("decryptedData".getBytes());
assertThat(payloadEncryptResponse.getPrivacyFlag()).isEqualTo(3);
assertThat(payloadEncryptResponse.getAffectedContractTransactions()).containsExactlyInAnyOrder("dHgxdmFs", "dHgydmFs");
assertThat(payloadEncryptResponse.getExecHash()).isEqualTo("execHash");
final ArgumentCaptor<EncodedPayload> argumentCaptor = ArgumentCaptor.forClass(EncodedPayload.class);
verify(encodedPayloadManager).decrypt(argumentCaptor.capture(), eq(null));
final EncodedPayload payloadBeforeDecryption = argumentCaptor.getValue();
assertThat(payloadBeforeDecryption.getSenderKey().encodeToBase64()).isEqualTo("BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=");
assertThat(payloadBeforeDecryption.getCipherText()).isEqualTo(decoder.decode("h7av/vhPlaPFECB1K30hNWugv/Bu"));
assertThat(payloadBeforeDecryption.getCipherTextNonce().getNonceBytes()).isEqualTo(decoder.decode("8MVXAESCQuRHWxrQ6b5MXuYApjia+2h0"));
assertThat(payloadBeforeDecryption.getRecipientBoxes()).containsExactly(RecipientBox.from(decoder.decode("FNirZRc2ayMaYopCBaWQ/1I7VWFiCM0lNw533Hckzxb+qpvngdWVVzJlsE05dbxl")));
assertThat(payloadBeforeDecryption.getRecipientNonce().getNonceBytes()).isEqualTo(decoder.decode("p9gYDJlEoBvLdUQ+ZoONl2Jl9AirV1en"));
assertThat(payloadBeforeDecryption.getRecipientKeys()).containsExactly(PublicKey.from(decoder.decode("BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=")));
assertThat(payloadBeforeDecryption.getPrivacyMode()).isEqualTo(PrivacyMode.PRIVATE_STATE_VALIDATION);
assertThat(payloadBeforeDecryption.getAffectedContractTransactions()).contains(entry(TxHash.from("tx1".getBytes()), SecurityHash.from("tx1val".getBytes())), entry(TxHash.from("tx2".getBytes()), SecurityHash.from("tx2val".getBytes())));
assertThat(payloadBeforeDecryption.getExecHash()).isEqualTo("execHash".getBytes());
}
use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.
the class TransactionResource3Test method deleteKey.
@Test
public void deleteKey() {
String encodedTxnHash = Base64.getEncoder().encodeToString("KEY".getBytes());
List<MessageHash> results = new ArrayList<>();
doAnswer((iom) -> results.add(iom.getArgument(0))).when(transactionManager).delete(any(MessageHash.class));
Response response = transactionResource.deleteKey(encodedTxnHash);
assertThat(results).hasSize(1).extracting(MessageHash::getHashBytes).containsExactly("KEY".getBytes());
assertThat(response.getStatus()).isEqualTo(204);
verify(transactionManager).delete(any(MessageHash.class));
}
use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.
the class TransactionResource3Test method sendForRecipient.
@Test
public void sendForRecipient() {
final Base64.Encoder base64Encoder = Base64.getEncoder();
final SendRequest sendRequest = new SendRequest();
sendRequest.setPayload(base64Encoder.encode("PAYLOAD".getBytes()));
sendRequest.setTo(Base64.getEncoder().encodeToString("Mr Benn".getBytes()));
final PublicKey sender = mock(PublicKey.class);
when(transactionManager.defaultPublicKey()).thenReturn(sender);
final com.quorum.tessera.transaction.SendResponse sendResponse = mock(com.quorum.tessera.transaction.SendResponse.class);
final MessageHash messageHash = mock(MessageHash.class);
final byte[] txnData = "TxnData".getBytes();
when(messageHash.getHashBytes()).thenReturn(txnData);
when(sendResponse.getTransactionHash()).thenReturn(messageHash);
when(transactionManager.send(any(com.quorum.tessera.transaction.SendRequest.class))).thenReturn(sendResponse);
final Response result = transactionResource.send(sendRequest);
assertThat(result.getStatus()).isEqualTo(201);
assertThat(result.getLocation().getPath()).isEqualTo("transaction/" + base64Encoder.encodeToString(txnData));
verify(transactionManager).send(any(com.quorum.tessera.transaction.SendRequest.class));
verify(transactionManager).defaultPublicKey();
}
use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.
the class TransactionResource3Test method sendSignedTransactionEmptyRecipients.
@Test
public void sendSignedTransactionEmptyRecipients() {
final PublicKey sender = PublicKey.from("sender".getBytes());
com.quorum.tessera.transaction.SendResponse sendResponse = mock(com.quorum.tessera.transaction.SendResponse.class);
byte[] transactionHashData = "I Love Sparrows".getBytes();
final String base64EncodedTransactionHAshData = Base64.getEncoder().encodeToString(transactionHashData);
MessageHash transactionHash = mock(MessageHash.class);
when(transactionHash.getHashBytes()).thenReturn(transactionHashData);
when(sendResponse.getTransactionHash()).thenReturn(transactionHash);
when(sendResponse.getSender()).thenReturn(sender);
when(transactionManager.sendSignedTransaction(any(com.quorum.tessera.transaction.SendSignedRequest.class))).thenReturn(sendResponse);
SendSignedRequest sendSignedRequest = new SendSignedRequest();
sendSignedRequest.setHash("SOMEDATA".getBytes());
Response result = transactionResource.sendSignedTransaction(sendSignedRequest);
// jersey.target("sendsignedtx")
// .request()
// .header("Content-Type", "application/vnd.tessera-2.1+json")
// .header("Accept", "application/vnd.tessera-2.1+json")
// .post(Entity.entity(sendSignedRequest,
// "application/vnd.tessera-2.1+json"));
assertThat(result.getStatus()).isEqualTo(201);
SendResponse resultResponse = (SendResponse) result.getEntity();
assertThat(resultResponse.getKey()).isEqualTo(base64EncodedTransactionHAshData);
assertThat(resultResponse.getSenderKey()).isEqualTo(sender.encodeToBase64());
assertThat(result.getLocation()).hasPath("transaction/".concat(base64EncodedTransactionHAshData));
ArgumentCaptor<com.quorum.tessera.transaction.SendSignedRequest> argumentCaptor = ArgumentCaptor.forClass(com.quorum.tessera.transaction.SendSignedRequest.class);
verify(transactionManager).sendSignedTransaction(argumentCaptor.capture());
com.quorum.tessera.transaction.SendSignedRequest obj = argumentCaptor.getValue();
assertThat(obj).isNotNull();
assertThat(obj.getSignedData()).isEqualTo("SOMEDATA".getBytes());
assertThat(obj.getRecipients()).hasSize(0);
assertThat(obj.getPrivacyMode()).isEqualTo(PrivacyMode.STANDARD_PRIVATE);
assertThat(obj.getAffectedContractTransactions()).isEmpty();
assertThat(obj.getExecHash()).isEmpty();
}
Aggregations