use of com.quorum.tessera.discovery.ActiveNode in project tessera by ConsenSys.
the class DiscoveryHelperTest method buildAllNodeInfosFilteredOutOwn.
@Test
public void buildAllNodeInfosFilteredOutOwn() {
when(runtimeContext.getP2pServerUri()).thenReturn(URI.create("http://node1.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(1);
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(node2);
verify(networkStore).getActiveNodes();
verify(runtimeContext).getP2pServerUri();
mockedRuntimeContext.verify(RuntimeContext::getInstance);
}
use of com.quorum.tessera.discovery.ActiveNode in project tessera by ConsenSys.
the class DiscoveryHelperTest method getCurrentWithNoKeys.
@Test
public void getCurrentWithNoKeys() {
final URI uri = URI.create("http://somedomain.com");
when(runtimeContext.getP2pServerUri()).thenReturn(uri);
final List<PublicKey> keys = List.of();
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();
verify(runtimeContext).getP2pServerUri();
assertThat(result.getUrl()).isEqualTo("http://somedomain.com/");
verify(networkStore).getActiveNodes();
assertThat(result.getRecipients()).isEmpty();
mockedRuntimeContext.verify(RuntimeContext::getInstance);
}
use of com.quorum.tessera.discovery.ActiveNode in project tessera by ConsenSys.
the class DiscoveryHelperTest method recipientKeyNotFound.
@Test
public void recipientKeyNotFound() {
String url = "http://nodeurl.com/";
final PublicKey key = PublicKey.from("key".getBytes());
final PublicKey anotherKey = PublicKey.from("anotherKey".getBytes());
ActiveNode activeNode = mock(ActiveNode.class);
when(activeNode.getUri()).thenReturn(NodeUri.create(url));
when(activeNode.getKeys()).thenReturn(Set.of(key));
when(activeNode.getSupportedVersions()).thenReturn(Set.of("v1", "v2"));
when(networkStore.getActiveNodes()).thenReturn(Stream.of(activeNode));
assertThatExceptionOfType(KeyNotFoundException.class).isThrownBy(() -> discoveryHelper.buildRemoteNodeInfo(anotherKey));
verify(networkStore).getActiveNodes();
}
use of com.quorum.tessera.discovery.ActiveNode in project tessera by ConsenSys.
the class EnclaveKeySynchroniserTest method syncWithChanges.
@Test
public void syncWithChanges() {
URI uri = URI.create("http://somedomain.com/");
when(runtimeContext.getP2pServerUri()).thenReturn(uri);
NodeUri nodeUri = NodeUri.create(uri);
Set<PublicKey> newKeys = Set.of(mock(PublicKey.class));
ActiveNode activeNode = mock(ActiveNode.class);
when(activeNode.getUri()).thenReturn(nodeUri);
when(activeNode.getKeys()).thenReturn(newKeys);
when(networkStore.getActiveNodes()).thenReturn(Stream.of(activeNode));
when(enclave.getPublicKeys()).thenReturn(Set.of(mock(PublicKey.class)));
enclaveKeySynchroniser.syncKeys();
verify(runtimeContext).getP2pServerUri();
verify(networkStore).getActiveNodes();
verify(enclave).getPublicKeys();
verify(networkStore).store(any(ActiveNode.class));
mockedStaticRuntimeContext.verify(RuntimeContext::getInstance);
}
use of com.quorum.tessera.discovery.ActiveNode in project tessera by ConsenSys.
the class EnclaveKeySynchroniserTest method syncKeysNoChanges.
@Test
public void syncKeysNoChanges() {
URI uri = URI.create("http://somedomain.com/");
when(runtimeContext.getP2pServerUri()).thenReturn(uri);
NodeUri nodeUri = NodeUri.create(uri);
Set<PublicKey> keys = Set.of(mock(PublicKey.class));
ActiveNode activeNode = mock(ActiveNode.class);
when(activeNode.getKeys()).thenReturn(keys);
when(activeNode.getUri()).thenReturn(nodeUri);
when(networkStore.getActiveNodes()).thenReturn(Stream.of(activeNode));
when(enclave.getPublicKeys()).thenReturn(keys);
enclaveKeySynchroniser.syncKeys();
verify(runtimeContext).getP2pServerUri();
verify(networkStore).getActiveNodes();
verify(enclave).getPublicKeys();
mockedStaticRuntimeContext.verify(RuntimeContext::getInstance);
}
Aggregations