Search in sources :

Example 11 with Party

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

the class SendIT method missingPayloadFails.

@Test
public void missingPayloadFails() {
    Party sendingParty = partyHelper.getParties().findAny().get();
    Party recipient = partyHelper.getParties().filter(p -> p != sendingParty).findAny().get();
    final String sendRequest = Json.createObjectBuilder().add("from", sendingParty.getPublicKey()).add("to", Json.createArrayBuilder().add(recipient.getPublicKey())).build().toString();
    final Response response = sendingParty.getRestClient().target(sendingParty.getQ2TUri()).path(SEND_PATH).request().post(Entity.entity(sendRequest, MIME_TYPE_JSON_2_1));
    // validate result
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(400);
}
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) Test(org.junit.Test)

Example 12 with Party

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

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

the class PrivacyGroupIT method testDelete.

@Test
public void testDelete() {
    final String output = privacyGroupTestUtil.create("C", "A", "B", "D");
    final JsonObject jsonObj = Json.createReader(new StringReader(output)).readObject();
    final String privacyGroupId = jsonObj.getString("privacyGroupId");
    final Party sender = partyHelper.findByAlias("C");
    privacyGroupTestUtil.retrieve("A", privacyGroupId);
    privacyGroupTestUtil.retrieve("B", privacyGroupId);
    privacyGroupTestUtil.retrieve("C", privacyGroupId);
    privacyGroupTestUtil.retrieve("D", privacyGroupId);
    JsonObject json = Json.createObjectBuilder().add("from", sender.getPublicKey()).add("privacyGroupId", privacyGroupId).build();
    final Response response = sender.getRestClient().target(sender.getQ2TUri()).path("/deletePrivacyGroup").request().post(Entity.entity(json, MediaType.APPLICATION_JSON));
    assertThat(response.getStatus()).isEqualTo(200);
    assertThatThrownBy(() -> privacyGroupTestUtil.retrieve("A", privacyGroupId)).isInstanceOf(AssertionError.class);
    assertThatThrownBy(() -> privacyGroupTestUtil.retrieve("B", privacyGroupId)).isInstanceOf(AssertionError.class);
    assertThatThrownBy(() -> privacyGroupTestUtil.retrieve("C", privacyGroupId)).isInstanceOf(AssertionError.class);
    assertThatThrownBy(() -> privacyGroupTestUtil.retrieve("D", privacyGroupId)).isInstanceOf(AssertionError.class);
}
Also used : Response(jakarta.ws.rs.core.Response) Party(com.quorum.tessera.test.Party) StringReader(java.io.StringReader) JsonObject(jakarta.json.JsonObject) JsonString(jakarta.json.JsonString) Test(org.junit.Test)

Example 14 with Party

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

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

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