use of com.quorum.tessera.api.ReceiveRequest in project tessera by ConsenSys.
the class SendReceiveBesuIT method sendAndReceivePrivacyGroup.
@Test
public void sendAndReceivePrivacyGroup() {
final Party a = partyHelper.findByAlias("A");
final Party b = partyHelper.findByAlias("B");
final String output = privacyGroupTestUtil.create("A", "B");
final JsonObject jsonObj = Json.createReader(new StringReader(output)).readObject();
final String groupId = jsonObj.getString("privacyGroupId");
byte[] transactionData = utils.createTransactionData();
final SendRequest sendRequest = new SendRequest();
sendRequest.setPrivacyGroupId(groupId);
sendRequest.setPayload(transactionData);
final Response response = client.target(partyHelper.findByAlias("A").getQ2TUri()).path("/send").request().post(Entity.entity(sendRequest, MediaType.APPLICATION_JSON));
final SendResponse result = response.readEntity(SendResponse.class);
final String hash = result.getKey();
assertThat(hash).isNotNull().isNotBlank();
// Hash length = 32 bytes
assertThat(Base64.getDecoder().decode(hash)).hasSize(32);
assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(200);
ReceiveRequest receiveRequest = new ReceiveRequest();
receiveRequest.setKey(hash);
final Response receiveResponse = client.target(a.getQ2TUri()).path("/receive").request().post(Entity.entity(receiveRequest, MediaType.APPLICATION_JSON));
// validate result
assertThat(receiveResponse).isNotNull();
assertThat(receiveResponse.getStatus()).isEqualTo(200);
final ReceiveResponse receiveResult = receiveResponse.readEntity(ReceiveResponse.class);
assertThat(receiveResult.getPayload()).isEqualTo(transactionData);
assertThat(receiveResult.getSenderKey()).isEqualTo(a.getPublicKey());
assertThat(receiveResult.getPrivacyGroupId()).isEqualTo(groupId);
final Response receiveResponseOnB = client.target(b.getQ2TUri()).path("/receive").request().post(Entity.entity(receiveRequest, MediaType.APPLICATION_JSON));
// validate result
assertThat(receiveResponseOnB).isNotNull();
assertThat(receiveResponseOnB.getStatus()).isEqualTo(200);
final ReceiveResponse receiveResultOnB = receiveResponseOnB.readEntity(ReceiveResponse.class);
assertThat(receiveResultOnB.getPayload()).isEqualTo(transactionData);
assertThat(receiveResultOnB.getSenderKey()).isEqualTo(a.getPublicKey());
assertThat(receiveResultOnB.getPrivacyGroupId()).isEqualTo(groupId);
}
use of com.quorum.tessera.api.ReceiveRequest in project tessera by ConsenSys.
the class BesuTransactionResourceTest method receive.
@Test
public void receive() {
String key = Base64.getEncoder().encodeToString("KEY".getBytes());
ReceiveRequest receiveRequest = new ReceiveRequest();
receiveRequest.setKey(key);
String recipient = Base64.getEncoder().encodeToString("Bobby Sixkiller".getBytes());
receiveRequest.setTo(recipient);
ReceiveResponse receiveResponse = mock(ReceiveResponse.class);
when(receiveResponse.getAffectedTransactions()).thenReturn(Set.of());
when(receiveResponse.getUnencryptedTransactionData()).thenReturn("Result".getBytes());
when(receiveResponse.getPrivacyMode()).thenReturn(PrivacyMode.STANDARD_PRIVATE);
when(receiveResponse.sender()).thenReturn(PublicKey.from("sender".getBytes()));
when(receiveResponse.getPrivacyGroupId()).thenReturn(Optional.of(PrivacyGroup.Id.fromBytes("group".getBytes())));
when(transactionManager.receive(any(com.quorum.tessera.transaction.ReceiveRequest.class))).thenReturn(receiveResponse);
BesuTransactionResource resource = new BesuTransactionResource(transactionManager, privacyGroupManager);
final Response result = resource.receive(receiveRequest);
assertThat(result.getStatus()).isEqualTo(200);
BesuReceiveResponse resultResponse = (BesuReceiveResponse) result.getEntity();
assertThat(resultResponse.getPayload()).isEqualTo("Result".getBytes());
assertThat(resultResponse.getSenderKey()).isEqualTo(PublicKey.from("sender".getBytes()).encodeToBase64());
assertThat(resultResponse.getPrivacyGroupId()).isEqualTo(PublicKey.from("group".getBytes()).encodeToBase64());
verify(transactionManager).receive(any(com.quorum.tessera.transaction.ReceiveRequest.class));
}
use of com.quorum.tessera.api.ReceiveRequest in project tessera by ConsenSys.
the class BesuTransactionResourceTest method receiveWithRecipient.
@Test
public void receiveWithRecipient() {
String key = Base64.getEncoder().encodeToString("KEY".getBytes());
ReceiveRequest receiveRequest = new ReceiveRequest();
receiveRequest.setKey(key);
receiveRequest.setTo(Base64.getEncoder().encodeToString("Reno Raynes".getBytes()));
ReceiveResponse receiveResponse = mock(ReceiveResponse.class);
when(receiveResponse.getPrivacyMode()).thenReturn(PrivacyMode.STANDARD_PRIVATE);
when(transactionManager.receive(any())).thenReturn(receiveResponse);
when(receiveResponse.getUnencryptedTransactionData()).thenReturn("Result".getBytes());
when(receiveResponse.sender()).thenReturn(PublicKey.from("sender".getBytes()));
when(receiveResponse.getPrivacyGroupId()).thenReturn(Optional.of(PrivacyGroup.Id.fromBytes("group".getBytes())));
BesuTransactionResource resource = new BesuTransactionResource(transactionManager, privacyGroupManager);
final Response result = resource.receive(receiveRequest);
assertThat(result.getStatus()).isEqualTo(200);
BesuReceiveResponse resultResponse = (BesuReceiveResponse) result.getEntity();
assertThat(resultResponse.getPayload()).isEqualTo("Result".getBytes());
assertThat(resultResponse.getSenderKey()).isEqualTo(PublicKey.from("sender".getBytes()).encodeToBase64());
assertThat(resultResponse.getPrivacyGroupId()).isEqualTo(PublicKey.from("group".getBytes()).encodeToBase64());
verify(transactionManager).receive(any(com.quorum.tessera.transaction.ReceiveRequest.class));
}
use of com.quorum.tessera.api.ReceiveRequest in project tessera by ConsenSys.
the class SendReceiveBesuIT method sendAndReceivePrivacyFor.
@Test
public void sendAndReceivePrivacyFor() throws InterruptedException {
final Party a = partyHelper.findByAlias("A");
final Party d = partyHelper.findByAlias("D");
byte[] transactionData = utils.createTransactionData();
final SendRequest sendRequest = new SendRequest();
sendRequest.setPayload(transactionData);
sendRequest.setTo(d.getPublicKey());
final Response response = client.target(a.getQ2TUri()).path("/send").request().post(Entity.entity(sendRequest, MediaType.APPLICATION_JSON));
assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(200);
final SendResponse result = response.readEntity(SendResponse.class);
final String hash = result.getKey();
// Hash length = 32 bytes
assertThat(Base64.getDecoder().decode(hash)).hasSize(32);
String findOutput = privacyGroupTestUtil.find("A", "A", "D");
final JsonArray json = Json.createReader(new StringReader(findOutput)).readArray();
Optional<JsonObject> legacyGroup = json.getValuesAs(JsonObject.class).stream().filter(v -> v.getString("type").equals("LEGACY")).findAny();
// Legacy privacy group was created
assertThat(legacyGroup).isPresent();
final String groupId = legacyGroup.get().getString("privacyGroupId");
ReceiveRequest receiveRequest = new ReceiveRequest();
receiveRequest.setKey(hash);
final Response receiveResponse = client.target(a.getQ2TUri()).path("/receive").request().post(Entity.entity(receiveRequest, MediaType.APPLICATION_JSON));
// validate result
assertThat(receiveResponse).isNotNull();
assertThat(receiveResponse.getStatus()).isEqualTo(200);
final ReceiveResponse receiveResult = receiveResponse.readEntity(ReceiveResponse.class);
assertThat(receiveResult.getPayload()).isEqualTo(transactionData);
assertThat(receiveResult.getSenderKey()).isEqualTo(a.getPublicKey());
assertThat(receiveResult.getPrivacyGroupId()).isEqualTo(groupId);
final Response receiveResponseOnB = client.target(d.getQ2TUri()).path("/receive").request().post(Entity.entity(receiveRequest, MediaType.APPLICATION_JSON));
// validate result
assertThat(receiveResponseOnB).isNotNull();
assertThat(receiveResponseOnB.getStatus()).isEqualTo(200);
final ReceiveResponse receiveResultOnB = receiveResponseOnB.readEntity(ReceiveResponse.class);
assertThat(receiveResultOnB.getPayload()).isEqualTo(transactionData);
assertThat(receiveResultOnB.getSenderKey()).isEqualTo(a.getPublicKey());
assertThat(receiveResultOnB.getPrivacyGroupId()).isEqualTo(groupId);
}
Aggregations