Search in sources :

Example 1 with ActiveNode

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));
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) ArrayList(java.util.ArrayList) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) Test(org.junit.Test)

Example 2 with ActiveNode

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));
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) ArrayList(java.util.ArrayList) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) Test(org.junit.Test)

Example 3 with ActiveNode

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));
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) ArrayList(java.util.ArrayList) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) Test(org.junit.Test)

Example 4 with ActiveNode

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);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) KeyNotFoundException(com.quorum.tessera.encryption.KeyNotFoundException) PublicKey(com.quorum.tessera.encryption.PublicKey) DiscoveryHelper(com.quorum.tessera.discovery.DiscoveryHelper) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Test(org.junit.Test) NodeUri(com.quorum.tessera.discovery.NodeUri) Collectors(java.util.stream.Collectors) Recipient(com.quorum.tessera.partyinfo.node.Recipient) Mockito(org.mockito.Mockito) ActiveNode(com.quorum.tessera.discovery.ActiveNode) NetworkStore(com.quorum.tessera.discovery.NetworkStore) List(java.util.List) MockedStatic(org.mockito.MockedStatic) Stream(java.util.stream.Stream) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) After(org.junit.After) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) RuntimeContext(com.quorum.tessera.context.RuntimeContext) Enclave(com.quorum.tessera.enclave.Enclave) URI(java.net.URI) Before(org.junit.Before) PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) RuntimeContext(com.quorum.tessera.context.RuntimeContext) URI(java.net.URI) Test(org.junit.Test)

Example 5 with ActiveNode

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();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) Test(org.junit.Test)

Aggregations

ActiveNode (com.quorum.tessera.discovery.ActiveNode)18 PublicKey (com.quorum.tessera.encryption.PublicKey)17 Test (org.junit.Test)12 NodeUri (com.quorum.tessera.discovery.NodeUri)11 NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)11 RuntimeContext (com.quorum.tessera.context.RuntimeContext)10 Recipient (com.quorum.tessera.partyinfo.node.Recipient)10 URI (java.net.URI)8 NetworkStore (com.quorum.tessera.discovery.NetworkStore)6 Enclave (com.quorum.tessera.enclave.Enclave)6 KeyNotFoundException (com.quorum.tessera.encryption.KeyNotFoundException)6 List (java.util.List)6 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 DiscoveryHelper (com.quorum.tessera.discovery.DiscoveryHelper)5 ArrayList (java.util.ArrayList)4 Stream (java.util.stream.Stream)4 Optional (java.util.Optional)3 IntStream (java.util.stream.IntStream)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3