Search in sources :

Example 1 with ReceiveResponse

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

the class TransactionForwardingIT method sendTransactionToNode3AddsNode1AsRecipient.

@Test
public void sendTransactionToNode3AddsNode1AsRecipient() throws UnsupportedEncodingException {
    final String hash = this.sendNewTransaction(otherRecipient);
    // check the transaction is in node 1
    final Response response = sender.getRestClient().target(sender.getQ2TUri()).path("transaction").path(URLEncoder.encode(hash, UTF_8.toString())).property("to", URLEncoder.encode(sender.getPublicKey(), UTF_8.toString())).request().get();
    // validate result
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(200);
    final ReceiveResponse result = response.readEntity(ReceiveResponse.class);
    assertThat(result.getPayload()).isEqualTo(transactionData);
}
Also used : SendResponse(com.quorum.tessera.api.SendResponse) Response(jakarta.ws.rs.core.Response) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) Test(org.junit.Test)

Example 2 with ReceiveResponse

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

the class ReceiveIT method fetchExistingTransactionNotUsingKey.

@Test
public void fetchExistingTransactionNotUsingKey() {
    final Response response = partyOne.getRestClient().target(partyOne.getQ2TUri()).path(RECEIVE_PATH).path(encodedHash).request().accept(MIME_TYPE_JSON_2_1).buildGet().invoke();
    // validate result
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(200);
    final ReceiveResponse result = response.readEntity(ReceiveResponse.class);
    assertThat(result.getPayload()).isEqualTo(transactionData);
    assertThat(result.getManagedParties()).containsExactly(partyOne.getPublicKey());
    assertThat(result.getSenderKey()).isEqualTo(partyOne.getPublicKey());
}
Also used : SendResponse(com.quorum.tessera.api.SendResponse) Response(jakarta.ws.rs.core.Response) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) Test(org.junit.Test)

Example 3 with ReceiveResponse

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

the class SendIT method firstPartyForwardsToTwoOtherParties.

/**
 * Quorum sends transaction with multiple public recipient keys
 */
@Test
public void firstPartyForwardsToTwoOtherParties() {
    final Party sendingParty = partyHelper.findByAlias("A");
    final Party secondParty = partyHelper.findByAlias("B");
    final Party thirdParty = partyHelper.findByAlias("D");
    final Party excludedParty = partyHelper.findByAlias("C");
    final byte[] transactionData = utils.createTransactionData();
    final SendRequest sendRequest = new SendRequest();
    sendRequest.setFrom(sendingParty.getPublicKey());
    sendRequest.setTo(secondParty.getPublicKey(), thirdParty.getPublicKey());
    sendRequest.setPayload(transactionData);
    final Response response = sendingParty.getRestClient().target(sendingParty.getQ2TUri()).path(SEND_PATH).request().post(Entity.entity(sendRequest, MIME_TYPE_JSON_2_1));
    final SendResponse result = response.readEntity(SendResponse.class);
    assertThat(result.getKey()).isNotNull().isNotBlank();
    assertThat(result.getManagedParties()).containsExactlyInAnyOrder(sendingParty.getPublicKey());
    assertThat(result.getSenderKey()).isEqualTo(sendingParty.getPublicKey());
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(201);
    URI location = response.getLocation();
    final Response checkPersistedTxnResponse = thirdParty.getRestClient().target(location).request().get();
    assertThat(checkPersistedTxnResponse.getStatus()).isEqualTo(200);
    ReceiveResponse receiveResponse = checkPersistedTxnResponse.readEntity(ReceiveResponse.class);
    assertThat(receiveResponse.getPayload()).isEqualTo(transactionData);
    utils.findTransaction(result.getKey(), sendingParty, secondParty, thirdParty).forEach(r -> assertThat(r.getStatus()).isEqualTo(200));
    utils.findTransaction(result.getKey(), excludedParty).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 4 with ReceiveResponse

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

the class SendIT method sendToMultipleRecipientsOnSameNode.

@Test
public void sendToMultipleRecipientsOnSameNode() throws UnsupportedEncodingException {
    // Node C has 2 keys, use them both
    final String[] recipientPublicKeys = ExecutionContext.currentContext().getConfigs().stream().filter(c -> c.getAlias() == NodeAlias.C).findFirst().map(ConfigDescriptor::getAllKeys).get().stream().map(ConfigKeyPair::getPublicKey).toArray(String[]::new);
    final Party sendingParty = partyHelper.findByAlias(NodeAlias.A);
    final Party recipientParty = partyHelper.findByAlias(NodeAlias.C);
    final byte[] transactionData = utils.createTransactionData();
    final SendRequest sendRequest = new SendRequest();
    sendRequest.setFrom(sendingParty.getPublicKey());
    sendRequest.setTo(recipientPublicKeys);
    sendRequest.setPayload(transactionData);
    final Response response = sendingParty.getRestClient().target(sendingParty.getQ2TUri()).path(SEND_PATH).request().post(Entity.entity(sendRequest, MIME_TYPE_JSON_2_1));
    final SendResponse result = response.readEntity(SendResponse.class);
    assertThat(result.getKey()).isNotNull().isNotBlank();
    assertThat(result.getManagedParties()).containsExactlyInAnyOrder(sendingParty.getPublicKey());
    assertThat(result.getSenderKey()).isEqualTo(sendingParty.getPublicKey());
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(201);
    URI location = response.getLocation();
    {
        final Response checkPersistedTxnResponse = recipientParty.getRestClient().target(location).request().get();
        assertThat(checkPersistedTxnResponse.getStatus()).isEqualTo(200);
        ReceiveResponse receiveResponse = checkPersistedTxnResponse.readEntity(ReceiveResponse.class);
        assertThat(receiveResponse.getPayload()).isEqualTo(transactionData);
        assertThat(result.getManagedParties()).containsExactlyInAnyOrder(sendingParty.getPublicKey());
        assertThat(result.getSenderKey()).isEqualTo(sendingParty.getPublicKey());
    }
    {
        String encodedId = URLEncoder.encode(result.getKey(), StandardCharsets.UTF_8.toString());
        Stream.of(recipientParty).map(Party::getRestClientWebTarget).map(target -> target.path("transaction")).map(target -> target.path(encodedId)).map(target -> target.request().accept(MIME_TYPE_JSON_2_1).get()).forEach(r -> {
            assertThat(r.getStatus()).isEqualTo(200);
            ReceiveResponse receiveResponse = r.readEntity(ReceiveResponse.class);
            assertThat(receiveResponse.getManagedParties()).containsExactlyInAnyOrder(recipientPublicKeys);
            assertThat(receiveResponse.getSenderKey()).isEqualTo(sendingParty.getPublicKey());
        });
    }
}
Also used : SendResponse(com.quorum.tessera.api.SendResponse) Response(jakarta.ws.rs.core.Response) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) ConfigKeyPair(com.quorum.tessera.config.keypairs.ConfigKeyPair) ExecutionContext(suite.ExecutionContext) SendResponse(com.quorum.tessera.api.SendResponse) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) PartyHelper(com.quorum.tessera.test.PartyHelper) ServerConfig(com.quorum.tessera.config.ServerConfig) RestUtils(com.quorum.tessera.test.rest.RestUtils) Utils.generateValidButUnknownPublicKey(transaction.utils.Utils.generateValidButUnknownPublicKey) StandardCharsets(java.nio.charset.StandardCharsets) Json(jakarta.json.Json) Entity(jakarta.ws.rs.client.Entity) Response(jakarta.ws.rs.core.Response) URLEncoder(java.net.URLEncoder) SendRequest(com.quorum.tessera.api.SendRequest) Stream(java.util.stream.Stream) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) MIME_TYPE_JSON_2_1(com.quorum.tessera.version.MultiTenancyVersion.MIME_TYPE_JSON_2_1) NodeAlias(suite.NodeAlias) URI(java.net.URI) ConfigDescriptor(config.ConfigDescriptor) Party(com.quorum.tessera.test.Party) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Party(com.quorum.tessera.test.Party) SendRequest(com.quorum.tessera.api.SendRequest) SendResponse(com.quorum.tessera.api.SendResponse) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) ConfigDescriptor(config.ConfigDescriptor) URI(java.net.URI) Test(org.junit.Test)

Example 5 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, MIME_TYPE_JSON_2_1));
    final SendResponse result = response.readEntity(SendResponse.class);
    assertThat(result.getKey()).isNotNull().isNotBlank();
    assertThat(result.getManagedParties()).containsExactlyInAnyOrder(recipient.getPublicKey());
    assertThat(result.getSenderKey()).isEqualTo(recipient.getPublicKey());
    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)

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