use of com.quorum.tessera.partyinfo.node.Recipient 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.Recipient 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.Recipient 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.Recipient 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;
}
use of com.quorum.tessera.partyinfo.node.Recipient in project tessera by ConsenSys.
the class PartyInfoServiceUtilTest method validateSameRecipientListsAsValid.
@Test
public void validateSameRecipientListsAsValid() {
final String url = "http://somedomain.com";
final PublicKey key = PublicKey.from("ONE".getBytes());
final Set<Recipient> existingRecipients = Collections.singleton(Recipient.of(key, "http://one.com"));
final NodeInfo existingPartyInfo = NodeInfo.Builder.create().withUrl(url).withRecipients(existingRecipients).build();
final Set<Recipient> newRecipients = Collections.singleton(Recipient.of(key, "http://one.com"));
final NodeInfo newPartyInfo = NodeInfo.Builder.create().withUrl(url).withRecipients(newRecipients).build();
assertThat(PartyInfoServiceUtil.validateKeysToUrls(existingPartyInfo, newPartyInfo)).isTrue();
}
Aggregations