use of com.quorum.tessera.api.ReceiveResponse 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());
}
}
use of com.quorum.tessera.api.ReceiveResponse 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]);
});
}
}
use of com.quorum.tessera.api.ReceiveResponse 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));
}
use of com.quorum.tessera.api.ReceiveResponse 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();
}
use of com.quorum.tessera.api.ReceiveResponse in project tessera by ConsenSys.
the class SendIT method firstPartyForwardsToTwoOtherParties.
/**
* Quorum sends transaction with multiple public recipient keys
*/
@Test
public void firstPartyForwardsToTwoOtherParties() {
final Party sendingParty = partyHelper.findByAlias("A");
final Party secondParty = partyHelper.findByAlias("B");
final Party thirdParty = partyHelper.findByAlias("D");
final Party excludedParty = partyHelper.findByAlias("C");
final byte[] transactionData = utils.createTransactionData();
final SendRequest sendRequest = new SendRequest();
sendRequest.setFrom(sendingParty.getPublicKey());
sendRequest.setTo(secondParty.getPublicKey(), thirdParty.getPublicKey());
sendRequest.setPayload(transactionData);
final Response response = sendingParty.getRestClient().target(sendingParty.getQ2TUri()).path(SEND_PATH).request().post(Entity.entity(sendRequest, MediaType.APPLICATION_JSON));
//
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()).isEqualTo(transactionData);
utils.findTransaction(result.getKey(), sendingParty, secondParty, thirdParty).forEach(r -> {
assertThat(r.getStatus()).isEqualTo(200);
});
utils.findTransaction(result.getKey(), excludedParty).forEach(r -> {
assertThat(r.getStatus()).isEqualTo(404);
});
}
Aggregations