Search in sources :

Example 36 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, MIME_TYPE_JSON_2_1));
    assertThat(response.getStatus()).isEqualTo(201);
    final SendResponse result = response.readEntity(SendResponse.class);
    return result.getKey();
}
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) SendResponse(com.quorum.tessera.api.SendResponse) RestUtils(com.quorum.tessera.test.rest.RestUtils)

Example 37 with Party

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

the class SendIT method sendToUnknownPublicKey.

/**
 * Quorum sends transaction to unknown public key
 */
@Test
public void sendToUnknownPublicKey() {
    Party sendingParty = partyHelper.getParties().findAny().get();
    byte[] transactionData = utils.createTransactionData();
    final SendRequest sendRequest = new SendRequest();
    sendRequest.setFrom(sendingParty.getPublicKey());
    ExecutionContext executionContext = ExecutionContext.currentContext();
    final String unknownkey = generateValidButUnknownPublicKey(executionContext.getEncryptorType()).encodeToBase64();
    sendRequest.setTo(unknownkey);
    sendRequest.setPayload(transactionData);
    final Response response = sendingParty.getRestClient().target(sendingParty.getQ2TUri()).path(SEND_PATH).request().post(Entity.entity(sendRequest, MIME_TYPE_JSON_2_1));
    assertThat(response).isNotNull();
    assertThat(response.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) ExecutionContext(suite.ExecutionContext) Test(org.junit.Test)

Example 38 with Party

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

the class SendIT method sendTransactionWithMissingRecipients.

@Test
public void sendTransactionWithMissingRecipients() {
    final Party sendingParty = partyHelper.getParties().findAny().get();
    final byte[] transactionData = utils.createTransactionData();
    final SendRequest sendRequest = new SendRequest();
    sendRequest.setFrom(sendingParty.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 = sendingParty.getRestClient().target(location).request().get();
    assertThat(checkPersistedTxnResponse.getStatus()).isEqualTo(200);
    ReceiveResponse receiveResponse = checkPersistedTxnResponse.readEntity(ReceiveResponse.class);
    assertThat(receiveResponse.getPayload()).isEqualTo(transactionData);
    if (!sendingParty.getConfig().getServerConfigs().stream().anyMatch(ServerConfig::isUnixSocket)) {
        assertThat(location.getHost()).isEqualTo(sendingParty.getQ2TUri().getHost());
        assertThat(location.getPort()).isEqualTo(sendingParty.getQ2TUri().getPort());
    }
}
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 39 with Party

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

the class SendIT method emptyMessageFails.

@Test
public void emptyMessageFails() {
    Party sendingParty = partyHelper.getParties().findAny().get();
    final String sendRequest = "{}";
    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 40 with Party

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

the class SendIT method senderAndRecipientOnSameNode.

@Test
public void senderAndRecipientOnSameNode() 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 party = partyHelper.findByAlias(NodeAlias.C);
    final byte[] transactionData = utils.createTransactionData();
    final SendRequest sendRequest = new SendRequest();
    sendRequest.setFrom(recipientPublicKeys[0]);
    sendRequest.setTo(recipientPublicKeys[1]);
    sendRequest.setPayload(transactionData);
    final Response response = party.getRestClient().target(party.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(recipientPublicKeys);
    assertThat(result.getSenderKey()).isEqualTo(recipientPublicKeys[0]);
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(201);
    URI location = response.getLocation();
    {
        final Response checkPersistedTxnResponse = party.getRestClient().target(location).request().accept(MIME_TYPE_JSON_2_1).get();
        assertThat(checkPersistedTxnResponse.getStatus()).isEqualTo(200);
        ReceiveResponse receiveResponse = checkPersistedTxnResponse.readEntity(ReceiveResponse.class);
        assertThat(receiveResponse.getPayload()).isEqualTo(transactionData);
        assertThat(receiveResponse.getManagedParties()).containsExactlyInAnyOrder(recipientPublicKeys);
    }
    {
        String encodedId = URLEncoder.encode(result.getKey(), StandardCharsets.UTF_8.toString());
        Stream.of(party).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(recipientPublicKeys[0]);
        });
    }
}
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)

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