Search in sources :

Example 41 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(NodeAlias.A);
    Party secondParty = partyHelper.findByAlias(NodeAlias.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, MIME_TYPE_JSON_2_1));
    // validate result
    final SendResponse result = response.readEntity(SendResponse.class);
    assertThat(result.getKey()).isNotNull().isNotBlank();
    assertThat(result.getManagedParties()).containsExactlyInAnyOrder(firstParty.getPublicKey());
    assertThat(result.getSenderKey()).isEqualTo(firstParty.getPublicKey());
    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 42 with Party

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

the class MultipleKeyNodeIT method thenTransactionHasBeenPersistedOnOtherNode.

@Test
public void thenTransactionHasBeenPersistedOnOtherNode() throws UnsupportedEncodingException {
    final byte[] transactionData = RestUtils.generateTransactionData();
    Party recipient = partyHelper.findByAlias(recipientAlias);
    // retrieve the transaction
    final Response retrieveResponse = recipient.getRestClient().target(recipient.getQ2TUri()).path("transaction").path(URLEncoder.encode(txHash, "UTF-8")).queryParam("to", recipient.getPublicKey()).request().get();
    assertThat(retrieveResponse).isNotNull();
    assertThat(retrieveResponse.getStatus()).describedAs("%s should be present on other node", txHash).isEqualTo(200);
    final ReceiveResponse result = retrieveResponse.readEntity(ReceiveResponse.class);
    assertThat(result).isNotNull();
}
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) ReceiveResponse(com.quorum.tessera.api.ReceiveResponse) Test(org.junit.Test)

Example 43 with Party

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

the class MultipleKeyNodeIT method onSetUp.

@Before
public void onSetUp() {
    Party sender = partyHelper.findByAlias(NodeAlias.A);
    Party recipient = partyHelper.findByAlias(recipientAlias);
    byte[] transactionData = restUtils.createTransactionData();
    final SendResponse result = restUtils.sendRequestAssertSuccess(sender, transactionData, recipient);
    assertThat(result.getKey()).isNotBlank();
    this.txHash = result.getKey();
}
Also used : Party(com.quorum.tessera.test.Party) SendResponse(com.quorum.tessera.api.SendResponse) Before(org.junit.Before)

Example 44 with Party

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

the class PrivacyGroupTestUtil method find.

public String find(String targetNode, String... aliases) {
    JsonArrayBuilder members = Json.createArrayBuilder();
    Stream.of(aliases).map(partyHelper::findByAlias).map(Party::getPublicKey).forEach(members::add);
    JsonObject json = Json.createObjectBuilder().add("addresses", members).build();
    Party node = partyHelper.findByAlias(targetNode);
    final Response response = node.getRestClient().target(node.getQ2TUri()).path("/findPrivacyGroup").request().post(Entity.entity(json, MediaType.APPLICATION_JSON));
    assertThat(response.getStatus()).isEqualTo(200);
    return response.readEntity(String.class);
}
Also used : Response(jakarta.ws.rs.core.Response) Party(com.quorum.tessera.test.Party) JsonObject(jakarta.json.JsonObject) JsonArrayBuilder(jakarta.json.JsonArrayBuilder)

Example 45 with Party

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

the class PrivacyGroupTestUtil method retrieve.

public String retrieve(String targetNode, String groupId) {
    JsonObject reqJson = Json.createObjectBuilder().add("privacyGroupId", groupId).build();
    Party node = partyHelper.findByAlias(targetNode);
    final Response response = node.getRestClient().target(node.getQ2TUri()).path("/retrievePrivacyGroup").request().post(Entity.entity(reqJson, MediaType.APPLICATION_JSON));
    assertThat(response.getStatus()).isEqualTo(200);
    return response.readEntity(String.class);
}
Also used : Response(jakarta.ws.rs.core.Response) Party(com.quorum.tessera.test.Party) JsonObject(jakarta.json.JsonObject)

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