Search in sources :

Example 16 with SendRequest

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

the class ReceiveIT method beforeTest.

// Persist a single transaction that can be used later
@Before
public void beforeTest() throws UnsupportedEncodingException {
    partyOne = partyHelper.findByAlias(NodeAlias.A);
    partyTwo = partyHelper.findByAlias(NodeAlias.B);
    partyThee = partyHelper.findByAlias(NodeAlias.C);
    SendRequest sendRequest = new SendRequest();
    sendRequest.setFrom(partyOne.getPublicKey());
    sendRequest.setTo(partyTwo.getPublicKey());
    sendRequest.setPayload(transactionData);
    final Response response = partyOne.getRestClient().target(partyOne.getQ2TUri()).path("/send").request().post(Entity.entity(sendRequest, MediaType.APPLICATION_JSON));
    assertThat(response.getStatus()).isEqualTo(201);
    final SendResponse result = response.readEntity(SendResponse.class);
    final String hash = result.getKey();
    this.encodedHash = URLEncoder.encode(hash, UTF_8.toString());
    this.encodedSender = URLEncoder.encode(partyOne.getPublicKey(), UTF_8.toString());
    this.encodedRecipientOne = URLEncoder.encode(partyThee.getPublicKey(), UTF_8.toString());
}
Also used : SendResponse(com.quorum.tessera.api.SendResponse) Response(jakarta.ws.rs.core.Response) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) SendRequest(com.quorum.tessera.api.SendRequest) SendResponse(com.quorum.tessera.api.SendResponse) Before(org.junit.Before)

Example 17 with SendRequest

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

the class RestUtils method sendRequestAssertSuccess.

public SendResponse sendRequestAssertSuccess(Party sender, byte[] transactionData, Party... recipients) {
    String[] recipientArray = Stream.of(recipients).map(Party::getPublicKey).collect(Collectors.toList()).toArray(new String[recipients.length]);
    final SendRequest sendRequest = new SendRequest();
    sendRequest.setFrom(sender.getPublicKey());
    sendRequest.setTo(recipientArray);
    sendRequest.setPayload(transactionData);
    final Response response = sender.getRestClientWebTarget().path("send").request().post(Entity.entity(sendRequest, MediaType.APPLICATION_JSON));
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(201);
    return response.readEntity(SendResponse.class);
}
Also used : SendResponse(com.quorum.tessera.api.SendResponse) Response(jakarta.ws.rs.core.Response) Party(com.quorum.tessera.test.Party) SendRequest(com.quorum.tessera.api.SendRequest)

Example 18 with SendRequest

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

the class RestUtils method send.

public Response send(Party sender, byte[] transactionData, Party... recipients) {
    String[] recipientArray = Stream.of(recipients).map(Party::getPublicKey).collect(Collectors.toList()).toArray(new String[recipients.length]);
    final SendRequest sendRequest = new SendRequest();
    sendRequest.setFrom(sender.getPublicKey());
    sendRequest.setTo(recipientArray);
    sendRequest.setPayload(transactionData);
    return sender.getRestClientWebTarget().path("send").request().post(Entity.entity(sendRequest, MediaType.APPLICATION_JSON));
}
Also used : Party(com.quorum.tessera.test.Party) SendRequest(com.quorum.tessera.api.SendRequest)

Example 19 with SendRequest

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

the class SendIT method sendToSingleRecipient.

/**
 * Quorum sends transaction with single public recipient key
 */
@Test
public void sendToSingleRecipient() {
    Party firstParty = partyHelper.findByAlias("A");
    Party secondParty = partyHelper.findByAlias("B");
    byte[] transactionData = utils.createTransactionData();
    final SendRequest sendRequest = new SendRequest();
    sendRequest.setFrom(firstParty.getPublicKey());
    sendRequest.setTo(secondParty.getPublicKey());
    sendRequest.setPayload(transactionData);
    final Response response = firstParty.getRestClient().target(firstParty.getQ2TUri()).path(SEND_PATH).request().post(Entity.entity(sendRequest, MediaType.APPLICATION_JSON));
    // validate result
    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 = secondParty.getRestClient().target(location).request().get();
    assertThat(checkPersistedTxnResponse.getStatus()).isEqualTo(200);
    ReceiveResponse receiveResponse = checkPersistedTxnResponse.readEntity(ReceiveResponse.class);
    assertThat(receiveResponse.getPayload()).describedAs("The response payload should be equal to the sent txn data").isEqualTo(transactionData);
    utils.findTransaction(result.getKey(), partyHelper.findByAlias("A"), partyHelper.findByAlias("B")).forEach(r -> {
        assertThat(r.getStatus()).isEqualTo(200);
    });
    utils.findTransaction(result.getKey(), partyHelper.findByAlias("D")).forEach(r -> {
        assertThat(r.getStatus()).isEqualTo(404);
    });
}
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 20 with SendRequest

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

the class SendIT method sendTransactionWithMissingRecipients.

@Test
public void sendTransactionWithMissingRecipients() {
    final Party sendingParty = partyHelper.getParties().findAny().get();
    final byte[] transactionData = utils.createTransactionData();
    final SendRequest sendRequest = new SendRequest();
    sendRequest.setFrom(sendingParty.getPublicKey());
    sendRequest.setPayload(transactionData);
    final Response response = sendingParty.getRestClient().target(sendingParty.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 = sendingParty.getRestClient().target(location).request().get();
    assertThat(checkPersistedTxnResponse.getStatus()).isEqualTo(200);
    ReceiveResponse receiveResponse = checkPersistedTxnResponse.readEntity(ReceiveResponse.class);
    assertThat(receiveResponse.getPayload()).isEqualTo(transactionData);
    if (sendingParty.getConfig().getServerConfigs().stream().allMatch(not(ServerConfig::isUnixSocket))) {
        assertThat(location.getHost()).isEqualTo(sendingParty.getQ2TUri().getHost());
        assertThat(location.getPort()).isEqualTo(sendingParty.getQ2TUri().getPort());
    }
}
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)

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