use of com.quorum.tessera.discovery.ActiveNode in project tessera by ConsenSys.
the class AutoDiscoveryTest method onUpdateSendHasTwoKeys.
@Test
public void onUpdateSendHasTwoKeys() {
String uri = "http://mynode.com";
PublicKey key = mock(PublicKey.class);
Recipient recipient = Recipient.of(key, uri);
PublicKey otherKey = mock(PublicKey.class);
Recipient other = Recipient.of(otherKey, uri);
List<Recipient> recipients = List.of(recipient, other);
NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl(uri).withRecipients(recipients).build();
List<ActiveNode> storedNodes = new ArrayList<>();
doAnswer(invocation -> {
storedNodes.add(invocation.getArgument(0));
return null;
}).when(networkStore).store(any(ActiveNode.class));
discovery.onUpdate(nodeInfo);
assertThat(storedNodes).hasSize(1);
ActiveNode result = storedNodes.iterator().next();
assertThat(result.getUri()).isEqualTo(NodeUri.create(uri));
assertThat(result.getKeys()).containsExactlyInAnyOrder(key, otherKey);
verify(networkStore).store(any(ActiveNode.class));
}
use of com.quorum.tessera.discovery.ActiveNode in project tessera by ConsenSys.
the class DisabledAutoDiscoveryTest method onUpdateIgnoreKeysNotOwnedBySender.
@Test
public void onUpdateIgnoreKeysNotOwnedBySender() {
String uri = "http://renoraynes.com";
PublicKey key = mock(PublicKey.class);
PublicKey key2 = mock(PublicKey.class);
Recipient recipient = Recipient.of(key, uri);
Recipient other = Recipient.of(key2, "http://othernode.com");
List<Recipient> recipients = List.of(recipient, other);
NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl(uri).withRecipients(recipients).withSupportedApiVersions(List.of("Two", "Fifty")).build();
List<ActiveNode> storedNodes = new ArrayList<>();
doAnswer(invocation -> {
storedNodes.add(invocation.getArgument(0));
return null;
}).when(networkStore).store(any(ActiveNode.class));
discovery.onUpdate(nodeInfo);
assertThat(storedNodes).hasSize(1);
ActiveNode result = storedNodes.iterator().next();
assertThat(result.getUri()).isEqualTo(NodeUri.create(uri));
assertThat(result.getKeys()).containsExactly(key);
assertThat(result.getSupportedVersions()).containsExactlyInAnyOrder("Two", "Fifty");
verify(networkStore).store(any(ActiveNode.class));
}
use of com.quorum.tessera.discovery.ActiveNode in project tessera by ConsenSys.
the class DisabledAutoDiscoveryTest method onUpdateNodeSendsNewKey.
@Test
public void onUpdateNodeSendsNewKey() {
String url = knownPeers.iterator().next().asString();
PublicKey key = mock(PublicKey.class);
List<Recipient> recipients = List.of(Recipient.of(key, url));
List<ActiveNode> storedNodes = new ArrayList<>();
doAnswer(invocation -> {
storedNodes.add(invocation.getArgument(0));
return null;
}).when(networkStore).store(any(ActiveNode.class));
NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl(url).withRecipients(recipients).build();
discovery.onUpdate(nodeInfo);
assertThat(storedNodes).hasSize(1);
ActiveNode savedNode = storedNodes.get(0);
assertThat(savedNode.getKeys()).containsExactly(key);
assertThat(savedNode.getUri()).isEqualTo(NodeUri.create(url));
verify(networkStore).store(any(ActiveNode.class));
}
use of com.quorum.tessera.discovery.ActiveNode 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.discovery.ActiveNode 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();
}
Aggregations