use of com.quorum.tessera.api.SendResponse in project tessera by ConsenSys.
the class TransactionForwardingIT method sendNewTransaction.
private String sendNewTransaction(final Party party) {
final URI node = party.getQ2TUri();
final String from = party.getPublicKey();
SendRequest sendRequest = new SendRequest();
sendRequest.setFrom(from);
sendRequest.setPayload(transactionData);
LOGGER.debug("Sending {} to {}", sendRequest, node);
final Response response = party.getRestClient().target(node).path("/send").request().post(Entity.entity(sendRequest, MediaType.APPLICATION_JSON));
assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(201);
LOGGER.debug("Sent {} to {}", sendRequest, node);
// check the call was success
final SendResponse result = response.readEntity(SendResponse.class);
LOGGER.debug("Response status : {}, body: {}", response.getStatus(), result);
assertThat(result.getKey()).isNotBlank();
return result.getKey();
}
use of com.quorum.tessera.api.SendResponse 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, 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 = thirdParty.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));
}
use of com.quorum.tessera.api.SendResponse in project tessera by ConsenSys.
the class SendIT method sendToMultipleRecipientsOnSameNode.
@Test
public void sendToMultipleRecipientsOnSameNode() 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 sendingParty = partyHelper.findByAlias(NodeAlias.A);
final Party recipientParty = partyHelper.findByAlias(NodeAlias.C);
final byte[] transactionData = utils.createTransactionData();
final SendRequest sendRequest = new SendRequest();
sendRequest.setFrom(sendingParty.getPublicKey());
sendRequest.setTo(recipientPublicKeys);
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 = recipientParty.getRestClient().target(location).request().get();
assertThat(checkPersistedTxnResponse.getStatus()).isEqualTo(200);
ReceiveResponse receiveResponse = checkPersistedTxnResponse.readEntity(ReceiveResponse.class);
assertThat(receiveResponse.getPayload()).isEqualTo(transactionData);
assertThat(result.getManagedParties()).containsExactlyInAnyOrder(sendingParty.getPublicKey());
assertThat(result.getSenderKey()).isEqualTo(sendingParty.getPublicKey());
}
{
String encodedId = URLEncoder.encode(result.getKey(), StandardCharsets.UTF_8.toString());
Stream.of(recipientParty).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(sendingParty.getPublicKey());
});
}
}
use of com.quorum.tessera.api.SendResponse in project tessera by ConsenSys.
the class SendIT method sendTransactionWithoutASender.
@Test
public void sendTransactionWithoutASender() {
Party recipient = partyHelper.getParties().findAny().get();
byte[] transactionData = utils.createTransactionData();
final SendRequest sendRequest = new SendRequest();
sendRequest.setTo(recipient.getPublicKey());
sendRequest.setPayload(transactionData);
final Response response = recipient.getRestClient().target(recipient.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(recipient.getPublicKey());
assertThat(result.getSenderKey()).isEqualTo(recipient.getPublicKey());
assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(201);
URI location = response.getLocation();
final Response checkPersistedTxnResponse = recipient.getRestClient().target(location).request().get();
assertThat(checkPersistedTxnResponse.getStatus()).isEqualTo(200);
ReceiveResponse receiveResponse = checkPersistedTxnResponse.readEntity(ReceiveResponse.class);
assertThat(receiveResponse.getPayload()).isEqualTo(transactionData);
}
use of com.quorum.tessera.api.SendResponse 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));
}
Aggregations