use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.
the class NodeInfoUtilTest method from.
@Test
public void from() {
PartyInfo partyInfo = mock(PartyInfo.class);
VersionInfo versionInfo = mock(VersionInfo.class);
Recipient recipient = Recipient.of(mock(PublicKey.class), "someurl");
when(partyInfo.getUrl()).thenReturn("someurl");
when(versionInfo.supportedApiVersions()).thenReturn(Set.of("v1", "v3"));
when(partyInfo.getRecipients()).thenReturn(Set.of(recipient));
NodeInfo nodeInfo = NodeInfoUtil.from(partyInfo, Set.of("v1", "v3"));
assertThat(nodeInfo).isNotNull();
assertThat(nodeInfo.getUrl()).isEqualTo("someurl");
assertThat(nodeInfo.supportedApiVersions()).isEqualTo(Set.of("v3", "v1"));
assertThat(nodeInfo.getRecipients()).hasSize(1);
assertThat(nodeInfo.getRecipients().iterator().next().getUrl()).isEqualTo("someurl");
}
use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.
the class BatchWorkflowFactoryImplTest method createBatchWorkflowFactoryImplAndExecuteWorkflow.
@Test
public void createBatchWorkflowFactoryImplAndExecuteWorkflow() {
BatchWorkflowFactoryImpl batchWorkflowFactory = new BatchWorkflowFactoryImpl(enclave, discovery, resendBatchPublisher);
BatchWorkflow batchWorkflow = batchWorkflowFactory.create(1L);
assertThat(batchWorkflow).isNotNull();
BatchWorkflowContext batchWorkflowContext = new BatchWorkflowContext();
PublicKey recipientKey = mock(PublicKey.class);
batchWorkflowContext.setRecipientKey(recipientKey);
PublicKey ownedKey = mock(PublicKey.class);
EncodedPayload encodedPayload = mock(EncodedPayload.class);
when(encodedPayload.getSenderKey()).thenReturn(ownedKey);
when(encodedPayload.getRecipientKeys()).thenReturn(List.of(recipientKey));
EncryptedTransaction encryptedTransaction = mock(EncryptedTransaction.class);
when(encryptedTransaction.getPayload()).thenReturn(encodedPayload);
batchWorkflowContext.setEncryptedTransaction(encryptedTransaction);
batchWorkflowContext.setEncodedPayload(encodedPayload);
batchWorkflowContext.setBatchSize(100);
when(mockPayloadBuilder.build()).thenReturn(encodedPayload);
when(enclave.status()).thenReturn(Service.Status.STARTED);
when(enclave.getPublicKeys()).thenReturn(Set.of(ownedKey));
NodeInfo nodeInfo = mock(NodeInfo.class);
when(nodeInfo.getRecipients()).thenReturn(Set.of(Recipient.of(recipientKey, "url")));
when(discovery.getCurrent()).thenReturn(nodeInfo);
assertThat(batchWorkflow.execute(batchWorkflowContext)).isTrue();
assertThat(batchWorkflow.getPublishedMessageCount()).isOne();
verify(enclave).status();
verify(enclave, times(2)).getPublicKeys();
mockStaticPayloadBuilder.verify(() -> EncodedPayload.Builder.forRecipient(any(), any()));
verify(mockPayloadBuilder).build();
verify(discovery).getCurrent();
verify(resendBatchPublisher).publishBatch(any(), any());
}
use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.
the class LegacyResendWorkflowFactoryTest method successForAllStagesReturnsTrue.
@Test
public void successForAllStagesReturnsTrue() {
final PublicKey targetResendKey = PublicKey.from("target".getBytes());
final PublicKey localRecipient = PublicKey.from("local-recipient".getBytes());
final EncodedPayload payload = EncodedPayload.Builder.create().withSenderKey(targetResendKey).withRecipientBox("testbox".getBytes()).build();
final NodeInfo nodeInfo = mock(NodeInfo.class);
when(nodeInfo.getRecipients()).thenReturn(Set.of(Recipient.of(targetResendKey, "url")));
when(discovery.getCurrent()).thenReturn(nodeInfo);
final EncryptedTransaction encryptedTx = mock(EncryptedTransaction.class);
when(enclave.getPublicKeys()).thenReturn(Set.of(localRecipient));
when(enclave.unencryptTransaction(any(EncodedPayload.class), eq(localRecipient))).thenReturn(new byte[0]);
final BatchWorkflow batchWorkflow = wfFactory.create();
final BatchWorkflowContext context = new BatchWorkflowContext();
context.setEncryptedTransaction(encryptedTx);
context.setEncodedPayload(payload);
context.setRecipientKey(targetResendKey);
context.setBatchSize(1);
final boolean success = batchWorkflow.execute(context);
assertThat(success).isTrue();
verify(discovery).getCurrent();
verify(payloadPublisher).publishPayload(any(EncodedPayload.class), eq(targetResendKey));
verify(enclave).status();
verify(enclave, times(2)).getPublicKeys();
verify(enclave).unencryptTransaction(any(EncodedPayload.class), eq(localRecipient));
}
use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.
the class AutoDiscoveryTest method onUpdateIgnoresKeysThatAreNotOwnedBySender.
@Test
public void onUpdateIgnoresKeysThatAreNotOwnedBySender() {
String uri = "http://mynode.com";
PublicKey key = mock(PublicKey.class);
Recipient recipient = Recipient.of(key, uri);
Recipient other = Recipient.of(mock(PublicKey.class), "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.partyinfo.node.NodeInfo in project tessera by ConsenSys.
the class DisabledAutoDiscoveryTest method onUpdateFromUnknownPeer.
@Test
public void onUpdateFromUnknownPeer() {
NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl("http://donalddutchdixon.com").build();
try {
discovery.onUpdate(nodeInfo);
failBecauseExceptionWasNotThrown(AutoDiscoveryDisabledException.class);
} catch (AutoDiscoveryDisabledException exception) {
assertThat(exception).isNotNull();
}
}
Aggregations