Search in sources :

Example 16 with Party

use of com.quorum.tessera.test.Party in project tessera by ConsenSys.

the class PrivacyIT method sendPSVTransactionsWithRecipientsMismatched.

@Test
public void sendPSVTransactionsWithRecipientsMismatched() {
    Party sender = partyHelper.findByAlias(NodeAlias.A);
    final String originalHash = sendContractCreationTransaction(PrivacyMode.PRIVATE_STATE_VALIDATION);
    SendRequest secondRequest = new SendRequest();
    secondRequest.setPayload(new RestUtils().createTransactionData());
    secondRequest.setFrom(sender.getPublicKey());
    List<String> anotherList = List.of(partyHelper.findByAlias(NodeAlias.B).getPublicKey(), partyHelper.findByAlias(NodeAlias.C).getPublicKey());
    secondRequest.setTo(anotherList.toArray(new String[anotherList.size()]));
    secondRequest.setPrivacyFlag(PrivacyMode.PRIVATE_STATE_VALIDATION.getPrivacyFlag());
    secondRequest.setAffectedContractTransactions(originalHash);
    secondRequest.setExecHash("execHash");
    Response secondResponse = sender.getRestClientWebTarget().path("send").request().post(Entity.entity(secondRequest, MediaType.APPLICATION_JSON));
    assertThat(secondResponse.getStatus()).isEqualTo(403);
}
Also used : Response(jakarta.ws.rs.core.Response) SendResponse(com.quorum.tessera.api.SendResponse) Party(com.quorum.tessera.test.Party) SendRequest(com.quorum.tessera.api.SendRequest)

Example 17 with Party

use of com.quorum.tessera.test.Party in project tessera by ConsenSys.

the class PrivacyIT method sendContractCreationTransaction.

private String sendContractCreationTransaction(PrivacyMode privacyMode) {
    Party sender = partyHelper.findByAlias(NodeAlias.A);
    SendRequest sendRequest = new SendRequest();
    sendRequest.setPayload(new RestUtils().createTransactionData());
    sendRequest.setFrom(sender.getPublicKey());
    List<String> recipientList = List.of(partyHelper.findByAlias(NodeAlias.B).getPublicKey());
    sendRequest.setTo(recipientList.toArray(new String[recipientList.size()]));
    sendRequest.setPrivacyFlag(privacyMode.getPrivacyFlag());
    sendRequest.setAffectedContractTransactions(new String[0]);
    if (privacyMode == PrivacyMode.PRIVATE_STATE_VALIDATION) {
        sendRequest.setExecHash("execHash");
    }
    Response response = sender.getRestClientWebTarget().path("send").request().post(Entity.entity(sendRequest, MediaType.APPLICATION_JSON));
    assertThat(response.getStatus()).isEqualTo(201);
    final SendResponse result = response.readEntity(SendResponse.class);
    return result.getKey();
}
Also used : Response(jakarta.ws.rs.core.Response) SendResponse(com.quorum.tessera.api.SendResponse) Party(com.quorum.tessera.test.Party) SendRequest(com.quorum.tessera.api.SendRequest) SendResponse(com.quorum.tessera.api.SendResponse)

Example 18 with Party

use of com.quorum.tessera.test.Party 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 19 with Party

use of com.quorum.tessera.test.Party 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 20 with Party

use of com.quorum.tessera.test.Party 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)

Aggregations

Party (com.quorum.tessera.test.Party)63 Response (jakarta.ws.rs.core.Response)60 Test (org.junit.Test)46 SendResponse (com.quorum.tessera.api.SendResponse)45 SendRequest (com.quorum.tessera.api.SendRequest)43 ReceiveResponse (com.quorum.tessera.api.ReceiveResponse)32 URI (java.net.URI)16 RestUtils (com.quorum.tessera.test.rest.RestUtils)11 JsonObject (jakarta.json.JsonObject)7 PartyHelper (com.quorum.tessera.test.PartyHelper)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 PayloadEncryptResponse (com.quorum.tessera.api.PayloadEncryptResponse)4 Entity (jakarta.ws.rs.client.Entity)4 StringReader (java.io.StringReader)4 ExecutionContext (suite.ExecutionContext)4 ServerConfig (com.quorum.tessera.config.ServerConfig)3 ConfigDescriptor (config.ConfigDescriptor)3 Json (jakarta.json.Json)3 Client (jakarta.ws.rs.client.Client)3 Before (org.junit.Before)3