Search in sources :

Example 36 with NodeInfo

use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.

the class RestPayloadPublisherTest method publishEnhancedTransactionsToNodesThatDoNotSupport.

@Test
public void publishEnhancedTransactionsToNodesThatDoNotSupport() {
    Map<PrivacyMode, Set<String>> privacyModeAndVersions = new HashMap<>();
    privacyModeAndVersions.put(PrivacyMode.PARTY_PROTECTION, Set.of("v1"));
    privacyModeAndVersions.put(PrivacyMode.PRIVATE_STATE_VALIDATION, Set.of("v1"));
    for (Map.Entry<PrivacyMode, Set<String>> pair : privacyModeAndVersions.entrySet()) {
        String targetUrl = "http://someplace.com";
        EncodedPayload encodedPayload = mock(EncodedPayload.class);
        when(encodedPayload.getPrivacyMode()).thenReturn(pair.getKey());
        byte[] payloadData = "Some Data".getBytes();
        when(payloadEncoder.encode(encodedPayload)).thenReturn(payloadData);
        PublicKey recipientKey = mock(PublicKey.class);
        NodeInfo nodeInfo = mock(NodeInfo.class);
        when(nodeInfo.supportedApiVersions()).thenReturn(pair.getValue());
        Recipient recipient = mock(Recipient.class);
        when(recipient.getKey()).thenReturn(recipientKey);
        when(recipient.getUrl()).thenReturn(targetUrl);
        when(nodeInfo.getRecipients()).thenReturn(Set.of(recipient));
        when(discovery.getRemoteNodeInfo(recipientKey)).thenReturn(nodeInfo);
        EnhancedPrivacyNotSupportedException exception = catchThrowableOfType(() -> payloadPublisher.publishPayload(encodedPayload, recipientKey), EnhancedPrivacyNotSupportedException.class);
        assertThat(exception).hasMessageContaining("Transactions with enhanced privacy is not currently supported");
        verify(discovery).getRemoteNodeInfo(eq(recipientKey));
    }
    payloadEncoderFactoryFunction.verify(times(2), () -> PayloadEncoder.create(any(EncodedPayloadCodec.class)));
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) PublicKey(com.quorum.tessera.encryption.PublicKey) PrivacyMode(com.quorum.tessera.enclave.PrivacyMode) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Recipient(com.quorum.tessera.partyinfo.node.Recipient) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) HashMap(java.util.HashMap) Map(java.util.Map) EnhancedPrivacyNotSupportedException(com.quorum.tessera.transaction.exception.EnhancedPrivacyNotSupportedException) Test(org.junit.Test)

Example 37 with NodeInfo

use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.

the class RestPrivacyGroupPublisherTest method testPublishSingleSuccess.

@Test
public void testPublishSingleSuccess() {
    String targetUrl = "https://sometargeturl.com";
    PublicKey recipient = PublicKey.from("PUBLIC_KEY".getBytes());
    NodeInfo nodeInfo = mock(NodeInfo.class);
    when(nodeInfo.supportedApiVersions()).thenReturn(Set.of(PrivacyGroupVersion.API_VERSION_3));
    when(nodeInfo.getUrl()).thenReturn(targetUrl);
    when(discovery.getRemoteNodeInfo(recipient)).thenReturn(nodeInfo);
    WebTarget webTarget = mock(WebTarget.class);
    when(client.target(targetUrl)).thenReturn(webTarget);
    when(webTarget.path(anyString())).thenReturn(webTarget);
    Invocation.Builder invocationBuilder = mock(Invocation.Builder.class);
    when(webTarget.request()).thenReturn(invocationBuilder);
    Response response = Response.ok().build();
    ArgumentCaptor<Entity> argumentCaptor = ArgumentCaptor.forClass(Entity.class);
    when(invocationBuilder.post(argumentCaptor.capture())).thenReturn(response);
    final byte[] data = new byte[] { 15 };
    publisher.publishPrivacyGroup(data, recipient);
    assertThat(argumentCaptor.getAllValues()).hasSize(1);
    Entity<byte[]> result = argumentCaptor.getValue();
    assertThat(result.getEntity()).isSameAs(data);
    assertThat(result.getMediaType()).isEqualTo(MediaType.APPLICATION_OCTET_STREAM_TYPE);
    verify(discovery).getRemoteNodeInfo(recipient);
    verify(client).target(targetUrl);
}
Also used : Response(jakarta.ws.rs.core.Response) Entity(jakarta.ws.rs.client.Entity) Invocation(jakarta.ws.rs.client.Invocation) PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) WebTarget(jakarta.ws.rs.client.WebTarget) Test(org.junit.Test)

Example 38 with NodeInfo

use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.

the class RestPrivacyGroupPublisherTest method testPublishSingleError.

@Test
public void testPublishSingleError() {
    String targetUrl = "https://sometargeturl.com";
    PublicKey recipient = PublicKey.from("PUBLIC_KEY".getBytes());
    NodeInfo nodeInfo = mock(NodeInfo.class);
    when(nodeInfo.supportedApiVersions()).thenReturn(Set.of(PrivacyGroupVersion.API_VERSION_3));
    when(nodeInfo.getUrl()).thenReturn(targetUrl);
    when(discovery.getRemoteNodeInfo(recipient)).thenReturn(nodeInfo);
    Invocation.Builder invocationBuilder = mock(Invocation.Builder.class);
    when(invocationBuilder.post(any(Entity.class))).thenReturn(Response.serverError().build());
    WebTarget webTarget = mock(WebTarget.class);
    when(client.target(targetUrl)).thenReturn(webTarget);
    when(webTarget.path(anyString())).thenReturn(webTarget);
    when(webTarget.request()).thenReturn(invocationBuilder);
    final byte[] data = new byte[5];
    try {
        publisher.publishPrivacyGroup(data, recipient);
        failBecauseExceptionWasNotThrown(PrivacyGroupPublishException.class);
    } catch (PrivacyGroupPublishException ex) {
        verify(discovery).getRemoteNodeInfo(recipient);
        verify(client).target(targetUrl);
    }
}
Also used : Entity(jakarta.ws.rs.client.Entity) PrivacyGroupPublishException(com.quorum.tessera.privacygroup.exception.PrivacyGroupPublishException) Invocation(jakarta.ws.rs.client.Invocation) PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) WebTarget(jakarta.ws.rs.client.WebTarget) Test(org.junit.Test)

Example 39 with NodeInfo

use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.

the class RestPrivacyGroupPublisherTest method testPublishSingleNodeOffline.

@Test
public void testPublishSingleNodeOffline() {
    String targetUrl = "https://sometargeturl.com";
    PublicKey recipient = PublicKey.from("PUBLIC_KEY".getBytes());
    NodeInfo nodeInfo = mock(NodeInfo.class);
    when(nodeInfo.supportedApiVersions()).thenReturn(Set.of(PrivacyGroupVersion.API_VERSION_3));
    when(nodeInfo.getUrl()).thenReturn(targetUrl);
    when(discovery.getRemoteNodeInfo(recipient)).thenReturn(nodeInfo);
    Invocation.Builder invocationBuilder = mock(Invocation.Builder.class);
    when(invocationBuilder.post(any(Entity.class))).thenThrow(ProcessingException.class);
    WebTarget webTarget = mock(WebTarget.class);
    when(client.target(targetUrl)).thenReturn(webTarget);
    when(webTarget.path(anyString())).thenReturn(webTarget);
    when(webTarget.request()).thenReturn(invocationBuilder);
    final byte[] data = new byte[5];
    try {
        publisher.publishPrivacyGroup(data, PublicKey.from("PUBLIC_KEY".getBytes()));
        failBecauseExceptionWasNotThrown(NodeOfflineException.class);
    } catch (NodeOfflineException ex) {
        verify(discovery).getRemoteNodeInfo(recipient);
        verify(client).target(targetUrl);
    }
}
Also used : Entity(jakarta.ws.rs.client.Entity) Invocation(jakarta.ws.rs.client.Invocation) PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) WebTarget(jakarta.ws.rs.client.WebTarget) NodeOfflineException(com.quorum.tessera.transaction.publish.NodeOfflineException) Test(org.junit.Test)

Example 40 with NodeInfo

use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.

the class SyncPollerTest method init.

@Before
public void init() {
    this.executorService = mock(ExecutorService.class);
    this.resendPartyStore = mock(ResendPartyStore.class);
    this.transactionRequester = mock(TransactionRequester.class);
    this.partyInfoService = mock(Discovery.class);
    this.partyInfoParser = mock(PartyInfoParser.class);
    this.p2pClient = mock(P2pClient.class);
    doReturn(true).when(p2pClient).sendPartyInfo(anyString(), any());
    NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl("myurl").build();
    when(partyInfoService.getCurrent()).thenReturn(nodeInfo);
    this.syncPoller = new SyncPoller(executorService, resendPartyStore, transactionRequester, partyInfoService, partyInfoParser, p2pClient);
}
Also used : P2pClient(com.quorum.tessera.partyinfo.P2pClient) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) ExecutorService(java.util.concurrent.ExecutorService) Discovery(com.quorum.tessera.discovery.Discovery) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) Before(org.junit.Before)

Aggregations

NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)49 Test (org.junit.Test)37 PublicKey (com.quorum.tessera.encryption.PublicKey)31 Recipient (com.quorum.tessera.partyinfo.node.Recipient)19 ActiveNode (com.quorum.tessera.discovery.ActiveNode)12 Response (jakarta.ws.rs.core.Response)11 PartyInfo (com.quorum.tessera.partyinfo.model.PartyInfo)10 NodeUri (com.quorum.tessera.discovery.NodeUri)8 URI (java.net.URI)8 Collectors (java.util.stream.Collectors)8 RuntimeContext (com.quorum.tessera.context.RuntimeContext)7 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)7 Set (java.util.Set)7 KeyNotFoundException (com.quorum.tessera.encryption.KeyNotFoundException)6 Logger (org.slf4j.Logger)6 Discovery (com.quorum.tessera.discovery.Discovery)5 DiscoveryHelper (com.quorum.tessera.discovery.DiscoveryHelper)5 NetworkStore (com.quorum.tessera.discovery.NetworkStore)5 Enclave (com.quorum.tessera.enclave.Enclave)5 Entity (jakarta.ws.rs.client.Entity)5