Search in sources :

Example 36 with SendRequest

use of com.quorum.tessera.api.SendRequest in project tessera by ConsenSys.

the class EncodedPayloadResourceTest method createPayload.

@Test
public void createPayload() {
    final String base64Key = "BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=";
    final SendRequest sendRequest = new SendRequest();
    sendRequest.setPayload(Base64.getEncoder().encode("PAYLOAD".getBytes()));
    sendRequest.setTo(base64Key);
    sendRequest.setAffectedContractTransactions("dHgx");
    final PublicKey sender = PublicKey.from(Base64.getDecoder().decode("oNspPPgszVUFw0qmGFfWwh1uxVUXgvBxleXORHj07g8="));
    when(transactionManager.defaultPublicKey()).thenReturn(sender);
    final EncodedPayload samplePayload = EncodedPayload.Builder.create().withSenderKey(sender).withRecipientKeys(List.of(PublicKey.from(Base64.getDecoder().decode(base64Key)))).withRecipientBoxes(List.of("boxOne".getBytes())).withRecipientNonce("recipientNonce".getBytes()).withCipherText("testPayload".getBytes()).withCipherTextNonce("cipherTextNonce".getBytes()).withPrivacyMode(PrivacyMode.STANDARD_PRIVATE).withAffectedContractTransactions(Map.of(TxHash.from("tx1".getBytes()), "tx1val".getBytes())).withExecHash(new byte[0]).build();
    when(encodedPayloadManager.create(any(com.quorum.tessera.transaction.SendRequest.class))).thenReturn(samplePayload);
    final Response result = encodedPayloadResource.createEncodedPayload(sendRequest);
    assertThat(result.getStatus()).isEqualTo(200);
    final PayloadEncryptResponse payloadEncryptResponse = PayloadEncryptResponse.class.cast(result.getEntity());
    assertThat(PublicKey.from(payloadEncryptResponse.getSenderKey())).isEqualTo(sender);
    assertThat(payloadEncryptResponse.getCipherText()).isEqualTo("testPayload".getBytes());
    assertThat(payloadEncryptResponse.getCipherTextNonce()).isEqualTo("cipherTextNonce".getBytes());
    assertThat(payloadEncryptResponse.getRecipientBoxes()).hasSize(1).containsExactly("boxOne".getBytes());
    assertThat(payloadEncryptResponse.getRecipientNonce()).isEqualTo("recipientNonce".getBytes());
    assertThat(payloadEncryptResponse.getRecipientKeys()).hasSize(1);
    assertThat(payloadEncryptResponse.getRecipientKeys().get(0)).isEqualTo(Base64.getDecoder().decode(base64Key));
    assertThat(payloadEncryptResponse.getPrivacyMode()).isEqualTo(0);
    assertThat(payloadEncryptResponse.getAffectedContractTransactions()).contains(entry("dHgx", "dHgxdmFs"));
    assertThat(payloadEncryptResponse.getExecHash()).isEmpty();
    final ArgumentCaptor<com.quorum.tessera.transaction.SendRequest> argumentCaptor = ArgumentCaptor.forClass(com.quorum.tessera.transaction.SendRequest.class);
    verify(encodedPayloadManager).create(argumentCaptor.capture());
    verify(transactionManager).defaultPublicKey();
    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).encodeToBase64()).isEqualTo(base64Key);
    assertThat(businessObject.getPrivacyMode()).isEqualTo(PrivacyMode.STANDARD_PRIVATE);
    assertThat(businessObject.getAffectedContractTransactions()).containsExactly(new MessageHash("tx1".getBytes()));
    assertThat(businessObject.getExecHash()).isEmpty();
}
Also used : SendRequest(com.quorum.tessera.api.SendRequest) PayloadEncryptResponse(com.quorum.tessera.api.PayloadEncryptResponse) PublicKey(com.quorum.tessera.encryption.PublicKey) MessageHash(com.quorum.tessera.data.MessageHash) PayloadEncryptResponse(com.quorum.tessera.api.PayloadEncryptResponse) ReceiveResponse(com.quorum.tessera.transaction.ReceiveResponse) Response(jakarta.ws.rs.core.Response) Test(org.junit.Test)

Example 37 with SendRequest

use of com.quorum.tessera.api.SendRequest in project tessera by ConsenSys.

the class EncodedPayloadResourceTest method createPayloadVersion21.

@Test
public void createPayloadVersion21() {
    final String base64Key = "BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=";
    final SendRequest sendRequest = new SendRequest();
    sendRequest.setPayload(Base64.getEncoder().encode("PAYLOAD".getBytes()));
    sendRequest.setTo(base64Key);
    sendRequest.setAffectedContractTransactions("dHgx");
    final PublicKey sender = PublicKey.from(Base64.getDecoder().decode("oNspPPgszVUFw0qmGFfWwh1uxVUXgvBxleXORHj07g8="));
    when(transactionManager.defaultPublicKey()).thenReturn(sender);
    final EncodedPayload samplePayload = EncodedPayload.Builder.create().withSenderKey(sender).withRecipientKeys(List.of(PublicKey.from(Base64.getDecoder().decode(base64Key)))).withRecipientBoxes(List.of("boxOne".getBytes())).withRecipientNonce("recipientNonce".getBytes()).withCipherText("testPayload".getBytes()).withCipherTextNonce("cipherTextNonce".getBytes()).withPrivacyMode(PrivacyMode.STANDARD_PRIVATE).withAffectedContractTransactions(Map.of(TxHash.from("tx1".getBytes()), "tx1val".getBytes())).withExecHash(new byte[0]).build();
    when(encodedPayloadManager.create(any(com.quorum.tessera.transaction.SendRequest.class))).thenReturn(samplePayload);
    final Response result = encodedPayloadResource.createEncodedPayload21(sendRequest);
    assertThat(result.getStatus()).isEqualTo(200);
    final PayloadEncryptResponse payloadEncryptResponse = Optional.of(result).map(Response::getEntity).map(PayloadEncryptResponse.class::cast).get();
    assertThat(PublicKey.from(payloadEncryptResponse.getSenderKey())).isEqualTo(sender);
    assertThat(payloadEncryptResponse.getCipherText()).isEqualTo("testPayload".getBytes());
    assertThat(payloadEncryptResponse.getCipherTextNonce()).isEqualTo("cipherTextNonce".getBytes());
    assertThat(payloadEncryptResponse.getRecipientBoxes()).hasSize(1).containsExactly("boxOne".getBytes());
    assertThat(payloadEncryptResponse.getRecipientNonce()).isEqualTo("recipientNonce".getBytes());
    assertThat(payloadEncryptResponse.getRecipientKeys()).hasSize(1);
    assertThat(payloadEncryptResponse.getRecipientKeys().get(0)).isEqualTo(Base64.getDecoder().decode(base64Key));
    assertThat(payloadEncryptResponse.getPrivacyMode()).isEqualTo(0);
    assertThat(payloadEncryptResponse.getAffectedContractTransactions()).contains(entry("dHgx", "dHgxdmFs"));
    assertThat(payloadEncryptResponse.getExecHash()).isEmpty();
    final ArgumentCaptor<com.quorum.tessera.transaction.SendRequest> argumentCaptor = ArgumentCaptor.forClass(com.quorum.tessera.transaction.SendRequest.class);
    verify(encodedPayloadManager).create(argumentCaptor.capture());
    verify(transactionManager).defaultPublicKey();
    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).encodeToBase64()).isEqualTo(base64Key);
    assertThat(businessObject.getPrivacyMode()).isEqualTo(PrivacyMode.STANDARD_PRIVATE);
    assertThat(businessObject.getAffectedContractTransactions()).containsExactly(new MessageHash("tx1".getBytes()));
    assertThat(businessObject.getExecHash()).isEmpty();
}
Also used : SendRequest(com.quorum.tessera.api.SendRequest) PayloadEncryptResponse(com.quorum.tessera.api.PayloadEncryptResponse) PublicKey(com.quorum.tessera.encryption.PublicKey) MessageHash(com.quorum.tessera.data.MessageHash) PayloadEncryptResponse(com.quorum.tessera.api.PayloadEncryptResponse) ReceiveResponse(com.quorum.tessera.transaction.ReceiveResponse) Response(jakarta.ws.rs.core.Response) Test(org.junit.Test)

Example 38 with SendRequest

use of com.quorum.tessera.api.SendRequest in project tessera by ConsenSys.

the class TransactionResource3Test method sendWithPrivacy.

@Test
public void sendWithPrivacy() {
    final Base64.Encoder base64Encoder = Base64.getEncoder();
    final String base64Key = "BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=";
    final String base64Hash = "yKNxAAPdBMiEZFkyQifH1PShwHTHTdE92T3hAfSQ3RtGce9IB8jrsrXxGuCe+Vu3Wyv2zgSbUnt+QBN2Rf48qQ==";
    final SendRequest sendRequest = new SendRequest();
    sendRequest.setPayload(base64Encoder.encode("PAYLOAD".getBytes()));
    sendRequest.setTo(base64Key);
    sendRequest.setPrivacyFlag(3);
    sendRequest.setAffectedContractTransactions(base64Hash);
    sendRequest.setExecHash("executionHash");
    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));
    SendResponse resultSendResponse = (SendResponse) result.getEntity();
    assertThat(resultSendResponse.getKey());
    ArgumentCaptor<com.quorum.tessera.transaction.SendRequest> argumentCaptor = ArgumentCaptor.forClass(com.quorum.tessera.transaction.SendRequest.class);
    verify(transactionManager).send(argumentCaptor.capture());
    verify(transactionManager).defaultPublicKey();
    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).encodeToBase64()).isEqualTo(base64Key);
    assertThat(businessObject.getPrivacyMode()).isEqualTo(PrivacyMode.PRIVATE_STATE_VALIDATION);
    assertThat(businessObject.getAffectedContractTransactions()).hasSize(1);
    final MessageHash hash = businessObject.getAffectedContractTransactions().iterator().next();
    assertThat(Base64.getEncoder().encodeToString(hash.getHashBytes())).isEqualTo(base64Hash);
    assertThat(businessObject.getExecHash()).isEqualTo("executionHash".getBytes());
}
Also used : SendRequest(com.quorum.tessera.api.SendRequest) PublicKey(com.quorum.tessera.encryption.PublicKey) SendResponse(com.quorum.tessera.api.SendResponse) MessageHash(com.quorum.tessera.data.MessageHash) SendResponse(com.quorum.tessera.api.SendResponse) ReceiveResponse(com.quorum.tessera.transaction.ReceiveResponse) Response(jakarta.ws.rs.core.Response) Test(org.junit.Test)

Example 39 with SendRequest

use of com.quorum.tessera.api.SendRequest in project tessera by ConsenSys.

the class TransactionResource3Test 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 = transactionResource.send(sendRequest);
    assertThat(result.getStatus()).isEqualTo(201);
    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);
}
Also used : SendRequest(com.quorum.tessera.api.SendRequest) PublicKey(com.quorum.tessera.encryption.PublicKey) SendResponse(com.quorum.tessera.api.SendResponse) MessageHash(com.quorum.tessera.data.MessageHash) PrivacyGroup(com.quorum.tessera.enclave.PrivacyGroup) SendResponse(com.quorum.tessera.api.SendResponse) ReceiveResponse(com.quorum.tessera.transaction.ReceiveResponse) Response(jakarta.ws.rs.core.Response) Test(org.junit.Test)

Example 40 with SendRequest

use of com.quorum.tessera.api.SendRequest in project tessera by ConsenSys.

the class TransactionResource4Test method sendWithMandatoryRecipients.

@Test
public void sendWithMandatoryRecipients() {
    final Base64.Encoder base64Encoder = Base64.getEncoder();
    final String base64Key = "BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=";
    final String base64Hash = "yKNxAAPdBMiEZFkyQifH1PShwHTHTdE92T3hAfSQ3RtGce9IB8jrsrXxGuCe+Vu3Wyv2zgSbUnt+QBN2Rf48qQ==";
    final SendRequest sendRequest = new SendRequest();
    sendRequest.setPayload(base64Encoder.encode("PAYLOAD".getBytes()));
    sendRequest.setTo(base64Key);
    sendRequest.setPrivacyFlag(2);
    sendRequest.setMandatoryRecipients(new String[] { base64Key });
    sendRequest.setAffectedContractTransactions(base64Hash);
    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));
    SendResponse resultSendResponse = (SendResponse) result.getEntity();
    assertThat(resultSendResponse.getKey());
    ArgumentCaptor<com.quorum.tessera.transaction.SendRequest> argumentCaptor = ArgumentCaptor.forClass(com.quorum.tessera.transaction.SendRequest.class);
    verify(transactionManager).send(argumentCaptor.capture());
    verify(transactionManager).defaultPublicKey();
    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).encodeToBase64()).isEqualTo(base64Key);
    assertThat(businessObject.getPrivacyMode()).isEqualTo(PrivacyMode.MANDATORY_RECIPIENTS);
    assertThat(businessObject.getAffectedContractTransactions()).hasSize(1);
    final MessageHash hash = businessObject.getAffectedContractTransactions().iterator().next();
    assertThat(Base64.getEncoder().encodeToString(hash.getHashBytes())).isEqualTo(base64Hash);
    assertThat(businessObject.getMandatoryRecipients().iterator().next().encodeToBase64()).isEqualTo(base64Key);
}
Also used : Base64(java.util.Base64) SendRequest(com.quorum.tessera.api.SendRequest) PublicKey(com.quorum.tessera.encryption.PublicKey) SendResponse(com.quorum.tessera.api.SendResponse) MessageHash(com.quorum.tessera.data.MessageHash) SendResponse(com.quorum.tessera.api.SendResponse) Response(jakarta.ws.rs.core.Response) Test(org.junit.Test)

Aggregations

SendRequest (com.quorum.tessera.api.SendRequest)64 Response (jakarta.ws.rs.core.Response)60 SendResponse (com.quorum.tessera.api.SendResponse)50 Party (com.quorum.tessera.test.Party)43 Test (org.junit.Test)43 ReceiveResponse (com.quorum.tessera.api.ReceiveResponse)27 MessageHash (com.quorum.tessera.data.MessageHash)13 PublicKey (com.quorum.tessera.encryption.PublicKey)13 URI (java.net.URI)13 RestUtils (com.quorum.tessera.test.rest.RestUtils)11 PayloadEncryptResponse (com.quorum.tessera.api.PayloadEncryptResponse)8 ReceiveResponse (com.quorum.tessera.transaction.ReceiveResponse)8 Stream (java.util.stream.Stream)6 PrivacyGroup (com.quorum.tessera.enclave.PrivacyGroup)5 PrivacyMode (com.quorum.tessera.enclave.PrivacyMode)5 MIME_TYPE_JSON_2_1 (com.quorum.tessera.version.MultiTenancyVersion.MIME_TYPE_JSON_2_1)5 TransactionManager (com.quorum.tessera.transaction.TransactionManager)4 Operation (io.swagger.v3.oas.annotations.Operation)4 PartyHelper (com.quorum.tessera.test.PartyHelper)3 Content (io.swagger.v3.oas.annotations.media.Content)3