Search in sources :

Example 11 with SendRequest

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

the class SendIT method partyAlwaysSendsToPartyOne.

/**
 * config3.json has party 1's key in always send to list
 */
@Test
public void partyAlwaysSendsToPartyOne() {
    Party sender = partyHelper.findByAlias(NodeAlias.C);
    Party recipient = partyHelper.findByAlias(NodeAlias.D);
    byte[] transactionData = utils.createTransactionData();
    final SendRequest sendRequest = new SendRequest();
    sendRequest.setFrom(sender.getPublicKey());
    sendRequest.setTo(recipient.getPublicKey());
    sendRequest.setPayload(transactionData);
    final Response response = sender.getRestClient().target(sender.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(sender.getPublicKey());
    assertThat(result.getSenderKey()).isEqualTo(sender.getPublicKey());
    // Party one received by always send to
    utils.findTransaction(result.getKey(), sender, recipient, partyHelper.findByAlias(NodeAlias.A)).forEach(r -> assertThat(r.getStatus()).isEqualTo(200));
    // Party 2 is out of the loop
    utils.findTransaction(result.getKey(), partyHelper.findByAlias("B")).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) Test(org.junit.Test)

Example 12 with SendRequest

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

the class PrivacyIT method sendTransactionsWithFlagMismatched.

@Test
public void sendTransactionsWithFlagMismatched() {
    Party sender = partyHelper.findByAlias(NodeAlias.A);
    final String originalHash = sendContractCreationTransaction(PrivacyMode.PARTY_PROTECTION);
    SendRequest secondRequest = new SendRequest();
    secondRequest.setPayload(new RestUtils().createTransactionData());
    secondRequest.setFrom(sender.getPublicKey());
    List<String> recipientList = List.of(partyHelper.findByAlias(NodeAlias.B).getPublicKey());
    secondRequest.setTo(recipientList.toArray(new String[recipientList.size()]));
    secondRequest.setPrivacyFlag(PrivacyMode.STANDARD_PRIVATE.getPrivacyFlag());
    secondRequest.setAffectedContractTransactions(originalHash);
    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 13 with SendRequest

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

the class PrivacyIT method sendPSVTransactionWithoutExecHashWillBeRejected.

@Test
public void sendPSVTransactionWithoutExecHashWillBeRejected() {
    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.PRIVATE_STATE_VALIDATION.getPrivacyFlag());
    sendRequest.setAffectedContractTransactions(new String[0]);
    Response response = sender.getRestClientWebTarget().path("send").request().post(Entity.entity(sendRequest, MediaType.APPLICATION_JSON));
    assertThat(response.getStatus()).isEqualTo(400);
}
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 14 with SendRequest

use of com.quorum.tessera.api.SendRequest 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 15 with SendRequest

use of com.quorum.tessera.api.SendRequest 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)

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