Search in sources :

Example 26 with ReceiveResponse

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

the class SendIT method sendTransactionWithoutASender.

@Test
public void sendTransactionWithoutASender() {
    Party recipient = partyHelper.getParties().findAny().get();
    byte[] transactionData = utils.createTransactionData();
    final SendRequest sendRequest = new SendRequest();
    sendRequest.setTo(recipient.getPublicKey());
    sendRequest.setPayload(transactionData);
    final Response response = recipient.getRestClient().target(recipient.getQ2TUri()).path(SEND_PATH).request().post(Entity.entity(sendRequest, MediaType.APPLICATION_JSON));
    final SendResponse result = response.readEntity(SendResponse.class);
    assertThat(result.getKey()).isNotNull().isNotBlank();
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(201);
    URI location = response.getLocation();
    final Response checkPersistedTxnResponse = recipient.getRestClient().target(location).request().get();
    assertThat(checkPersistedTxnResponse.getStatus()).isEqualTo(200);
    ReceiveResponse receiveResponse = checkPersistedTxnResponse.readEntity(ReceiveResponse.class);
    assertThat(receiveResponse.getPayload()).isEqualTo(transactionData);
}
Also used : SendResponse(com.quorum.tessera.api.SendResponse) Response(jakarta.ws.rs.core.Response) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) Party(com.quorum.tessera.test.Party) SendRequest(com.quorum.tessera.api.SendRequest) SendResponse(com.quorum.tessera.api.SendResponse) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) URI(java.net.URI) Test(org.junit.Test)

Example 27 with ReceiveResponse

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

the class SendRawIT method sendSingleTransactionToMultipleParties.

/**
 * Quorum sends transaction with multiple public recipient keys
 */
@Test
public void sendSingleTransactionToMultipleParties() {
    Party sender = partyHelper.findByAlias("A");
    Party firstRecipient = partyHelper.findByAlias("B");
    Party secondRecipient = partyHelper.findByAlias("D");
    byte[] transactionData = restUtils.createTransactionData();
    final Response response = restUtils.sendRaw(sender, transactionData, firstRecipient, secondRecipient);
    // validate result
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(200);
    String persistedKey = response.readEntity(String.class);
    assertThat(persistedKey).isNotNull();
    URI location = response.getLocation();
    final Response checkPersistedTxnResponse = client.target(location).request().get();
    assertThat(checkPersistedTxnResponse.getStatus()).isEqualTo(200);
    ReceiveResponse receiveResponse = checkPersistedTxnResponse.readEntity(ReceiveResponse.class);
    assertThat(receiveResponse.getPayload()).isEqualTo(transactionData);
    restUtils.findTransaction(persistedKey, sender, firstRecipient, secondRecipient).forEach(r -> {
        assertThat(r.getStatus()).isEqualTo(200);
    });
    restUtils.findTransaction(persistedKey, partyHelper.findByAlias("C")).forEach(r -> {
        assertThat(r.getStatus()).isEqualTo(404);
    });
}
Also used : Response(jakarta.ws.rs.core.Response) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) Party(com.quorum.tessera.test.Party) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) URI(java.net.URI) Test(org.junit.Test)

Example 28 with ReceiveResponse

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

the class SendRawIT method sendToSingleRecipient.

/**
 * Quorum sends transaction with singe public recipient key
 */
@Test
public void sendToSingleRecipient() {
    byte[] transactionData = restUtils.createTransactionData();
    final Response response = restUtils.sendRaw(sender, transactionData, recipient);
    // validate result
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(200);
    String persistedKey = response.readEntity(String.class);
    assertThat(persistedKey).isNotNull();
    URI location = response.getLocation();
    final Response checkPersistedTxnResponse = client.target(location).request().get();
    assertThat(checkPersistedTxnResponse.getStatus()).isEqualTo(200);
    ReceiveResponse receiveResponse = checkPersistedTxnResponse.readEntity(ReceiveResponse.class);
    assertThat(receiveResponse.getPayload()).isEqualTo(transactionData);
    restUtils.findTransaction(persistedKey, sender, recipient).forEach(r -> {
        assertThat(r.getStatus()).isEqualTo(200);
    });
    restUtils.findTransaction(persistedKey, partyHelper.findByAlias("C"), partyHelper.findByAlias("B")).forEach(r -> {
        assertThat(r.getStatus()).isEqualTo(404);
    });
}
Also used : Response(jakarta.ws.rs.core.Response) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) URI(java.net.URI) Test(org.junit.Test)

Example 29 with ReceiveResponse

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

the class SendRawIT method sendTransactionWithEmptyRecipients.

@Test
public void sendTransactionWithEmptyRecipients() {
    Party sender = partyHelper.findByAlias("A");
    byte[] txnData = restUtils.createTransactionData();
    final Response response = restUtils.sendRaw(sender, txnData);
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(200);
    String persistedKey = response.readEntity(String.class);
    assertThat(persistedKey).isNotNull();
    URI location = response.getLocation();
    final Response checkPersistedTxnResponse = client.target(location).request().get();
    assertThat(checkPersistedTxnResponse.getStatus()).isEqualTo(200);
    ReceiveResponse receiveResponse = checkPersistedTxnResponse.readEntity(ReceiveResponse.class);
    assertThat(receiveResponse.getPayload()).isEqualTo(txnData);
}
Also used : Response(jakarta.ws.rs.core.Response) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) Party(com.quorum.tessera.test.Party) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) URI(java.net.URI) Test(org.junit.Test)

Example 30 with ReceiveResponse

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

the class SendReceiveBesuIT method sendAndReceivePrivacyFor.

@Test
public void sendAndReceivePrivacyFor() throws InterruptedException {
    final Party a = partyHelper.findByAlias("A");
    final Party d = partyHelper.findByAlias("D");
    byte[] transactionData = utils.createTransactionData();
    final SendRequest sendRequest = new SendRequest();
    sendRequest.setPayload(transactionData);
    sendRequest.setTo(d.getPublicKey());
    final Response response = client.target(a.getQ2TUri()).path("/send").request().post(Entity.entity(sendRequest, MediaType.APPLICATION_JSON));
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(200);
    final SendResponse result = response.readEntity(SendResponse.class);
    final String hash = result.getKey();
    // Hash length = 32 bytes
    assertThat(Base64.getDecoder().decode(hash)).hasSize(32);
    String findOutput = privacyGroupTestUtil.find("A", "A", "D");
    final JsonArray json = Json.createReader(new StringReader(findOutput)).readArray();
    Optional<JsonObject> legacyGroup = json.getValuesAs(JsonObject.class).stream().filter(v -> v.getString("type").equals("LEGACY")).findAny();
    // Legacy privacy group was created
    assertThat(legacyGroup).isPresent();
    final String groupId = legacyGroup.get().getString("privacyGroupId");
    ReceiveRequest receiveRequest = new ReceiveRequest();
    receiveRequest.setKey(hash);
    final Response receiveResponse = client.target(a.getQ2TUri()).path("/receive").request().post(Entity.entity(receiveRequest, MediaType.APPLICATION_JSON));
    // validate result
    assertThat(receiveResponse).isNotNull();
    assertThat(receiveResponse.getStatus()).isEqualTo(200);
    final ReceiveResponse receiveResult = receiveResponse.readEntity(ReceiveResponse.class);
    assertThat(receiveResult.getPayload()).isEqualTo(transactionData);
    assertThat(receiveResult.getSenderKey()).isEqualTo(a.getPublicKey());
    assertThat(receiveResult.getPrivacyGroupId()).isEqualTo(groupId);
    final Response receiveResponseOnB = client.target(d.getQ2TUri()).path("/receive").request().post(Entity.entity(receiveRequest, MediaType.APPLICATION_JSON));
    // validate result
    assertThat(receiveResponseOnB).isNotNull();
    assertThat(receiveResponseOnB.getStatus()).isEqualTo(200);
    final ReceiveResponse receiveResultOnB = receiveResponseOnB.readEntity(ReceiveResponse.class);
    assertThat(receiveResultOnB.getPayload()).isEqualTo(transactionData);
    assertThat(receiveResultOnB.getSenderKey()).isEqualTo(a.getPublicKey());
    assertThat(receiveResultOnB.getPrivacyGroupId()).isEqualTo(groupId);
}
Also used : Client(jakarta.ws.rs.client.Client) SendResponse(com.quorum.tessera.api.SendResponse) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) PartyHelper(com.quorum.tessera.test.PartyHelper) Json(jakarta.json.Json) Entity(jakarta.ws.rs.client.Entity) ReceiveRequest(com.quorum.tessera.api.ReceiveRequest) Response(jakarta.ws.rs.core.Response) Base64(java.util.Base64) SendRequest(com.quorum.tessera.api.SendRequest) MediaType(jakarta.ws.rs.core.MediaType) StringReader(java.io.StringReader) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) JsonObject(jakarta.json.JsonObject) Optional(java.util.Optional) Party(com.quorum.tessera.test.Party) JsonArray(jakarta.json.JsonArray) ClientBuilder(jakarta.ws.rs.client.ClientBuilder) SendRequest(com.quorum.tessera.api.SendRequest) SendResponse(com.quorum.tessera.api.SendResponse) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) JsonObject(jakarta.json.JsonObject) SendResponse(com.quorum.tessera.api.SendResponse) Response(jakarta.ws.rs.core.Response) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) JsonArray(jakarta.json.JsonArray) Party(com.quorum.tessera.test.Party) StringReader(java.io.StringReader) ReceiveRequest(com.quorum.tessera.api.ReceiveRequest) Test(org.junit.Test)

Aggregations

ReceiveResponse (com.quorum.tessera.api.ReceiveResponse)30 Response (jakarta.ws.rs.core.Response)29 Test (org.junit.Test)26 SendResponse (com.quorum.tessera.api.SendResponse)21 Party (com.quorum.tessera.test.Party)19 SendRequest (com.quorum.tessera.api.SendRequest)16 URI (java.net.URI)15 MIME_TYPE_JSON_2_1 (com.quorum.tessera.version.MultiTenancyVersion.MIME_TYPE_JSON_2_1)4 Stream (java.util.stream.Stream)4 PayloadEncryptResponse (com.quorum.tessera.api.PayloadEncryptResponse)3 MessageHash (com.quorum.tessera.data.MessageHash)3 PublicKey (com.quorum.tessera.encryption.PublicKey)3 PartyHelper (com.quorum.tessera.test.PartyHelper)3 Operation (io.swagger.v3.oas.annotations.Operation)3 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)3 Json (jakarta.json.Json)3 Entity (jakarta.ws.rs.client.Entity)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 PayloadDecryptRequest (com.quorum.tessera.api.PayloadDecryptRequest)2 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)2