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)));
}
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);
}
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);
}
}
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);
}
}
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);
}
Aggregations