use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.
the class DiscoveryHelperTest method buildCurrent.
@Test
public void buildCurrent() {
final URI uri = URI.create("http://somedomain.com");
when(runtimeContext.getP2pServerUri()).thenReturn(uri);
final List<PublicKey> keys = IntStream.range(0, 5).mapToObj(i -> mock(PublicKey.class)).collect(Collectors.toList());
final ActiveNode activeNode = ActiveNode.Builder.create().withUri(NodeUri.create(uri)).withKeys(keys).build();
when(networkStore.getActiveNodes()).thenReturn(Stream.of(activeNode));
NodeInfo result = discoveryHelper.buildCurrent();
assertThat(result).isNotNull();
assertThat(result.getUrl()).isEqualTo("http://somedomain.com/");
assertThat(result.getRecipients()).hasSize(5);
List<Recipient> recipients = List.copyOf(result.getRecipients());
assertThat(recipients.stream().map(Recipient::getKey).collect(Collectors.toList())).containsExactlyInAnyOrderElementsOf(keys);
verify(networkStore).getActiveNodes();
verify(runtimeContext).getP2pServerUri();
mockedRuntimeContext.verify(RuntimeContext::getInstance);
}
use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.
the class DiscoveryHelperTest method buildRemoteNodeInfo.
@Test
public void buildRemoteNodeInfo() {
String url = "http://nodeurl.com/";
final PublicKey key = PublicKey.from("key".getBytes());
final PublicKey anotherKey = PublicKey.from("anotherKey".getBytes());
final Recipient recipient = Recipient.of(key, url);
final Recipient sameNodeDifferentKey = Recipient.of(anotherKey, url);
ActiveNode activeNode = mock(ActiveNode.class);
when(activeNode.getUri()).thenReturn(NodeUri.create(url));
when(activeNode.getKeys()).thenReturn(Set.of(key, anotherKey));
when(activeNode.getSupportedVersions()).thenReturn(Set.of("v1", "v2"));
when(networkStore.getActiveNodes()).thenReturn(Stream.of(activeNode));
final NodeInfo result = discoveryHelper.buildRemoteNodeInfo(key);
assertThat(result).isNotNull();
assertThat(result.getUrl()).isEqualTo(url);
assertThat(result.getRecipients()).containsExactlyInAnyOrder(recipient, sameNodeDifferentKey);
assertThat(result.supportedApiVersions()).containsExactlyInAnyOrder("v1", "v2");
verify(networkStore).getActiveNodes();
}
use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.
the class DiscoveryHelperTest method buildAllNodeInfos.
@Test
public void buildAllNodeInfos() {
when(runtimeContext.getP2pServerUri()).thenReturn(URI.create("http://own.com"));
final ActiveNode node1 = ActiveNode.Builder.create().withUri(NodeUri.create("http://node1.com")).withKeys(List.of(PublicKey.from("key1".getBytes()))).withSupportedVersions(List.of("v1")).build();
final ActiveNode node2 = ActiveNode.Builder.create().withUri(NodeUri.create("http://node2.com")).withKeys(List.of(PublicKey.from("key2".getBytes()))).withSupportedVersions(List.of("v2")).build();
when(networkStore.getActiveNodes()).thenReturn(Stream.of(node1, node2));
final Set<NodeInfo> nodeInfos = discoveryHelper.buildRemoteNodeInfos();
assertThat(nodeInfos).hasSize(2);
Set<ActiveNode> activeNodes = nodeInfos.stream().map(nodeInfo -> ActiveNode.Builder.create().withUri(NodeUri.create(nodeInfo.getUrl())).withKeys(nodeInfo.getRecipients().stream().map(Recipient::getKey).collect(Collectors.toSet())).withSupportedVersions(nodeInfo.supportedApiVersions()).build()).collect(Collectors.toSet());
assertThat(activeNodes).containsExactlyInAnyOrder(node1, node2);
verify(networkStore).getActiveNodes();
verify(runtimeContext).getP2pServerUri();
mockedRuntimeContext.verify(RuntimeContext::getInstance);
}
use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.
the class PartyInfoResourceTest method getPartyInfoKeys.
@Test
public void getPartyInfoKeys() {
final String partyInfoJson = "{\"keys\":[{\"key\":\"BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=\"},{\"key\":\"QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc=\"}]}";
final NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl("http://localhost:9001/").withRecipients(List.of(Recipient.of(PublicKey.from(Base64.getDecoder().decode("QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc=")), "http://localhost:9002/"), Recipient.of(PublicKey.from(Base64.getDecoder().decode("BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=")), "http://localhost:9001/"))).build();
when(discovery.getCurrent()).thenReturn(nodeInfo);
final Response response = partyInfoResource.getPartyInfoKeys();
assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(200);
final String output = response.getEntity().toString();
final JsonReader expected = Json.createReader(new StringReader(partyInfoJson));
final JsonReader actual = Json.createReader(new StringReader(output));
JsonObject expectedJsonObject = expected.readObject();
JsonObject actualJsonObject = actual.readObject();
assertThat(actualJsonObject).containsOnlyKeys("keys");
assertThat(actualJsonObject.getJsonArray("keys")).containsExactlyInAnyOrderElementsOf(expectedJsonObject.getJsonArray("keys"));
verify(discovery).getCurrent();
}
use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.
the class DiscoveryHelperImpl method buildRemoteNodeInfo.
@Override
public NodeInfo buildRemoteNodeInfo(PublicKey recipientKey) {
final ActiveNode activeNode = networkStore.getActiveNodes().filter(node -> node.getKeys().contains(recipientKey)).findAny().orElseThrow(() -> new KeyNotFoundException("Recipient not found for key: " + recipientKey.encodeToBase64()));
final String nodeUrl = activeNode.getUri().asString();
final Set<Recipient> recipients = activeNode.getKeys().stream().map(k -> Recipient.of(k, nodeUrl)).collect(Collectors.toSet());
final NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl(nodeUrl).withRecipients(recipients).withSupportedApiVersions(activeNode.getSupportedVersions()).build();
return nodeInfo;
}
Aggregations