use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.
the class LegacyResendManagerProvider method provider.
public static LegacyResendManager provider() {
final Enclave enclave = Enclave.create();
final EncryptedTransactionDAO encryptedTransactionDAO = EncryptedTransactionDAO.create();
final int resendFetchSize = 100;
final PayloadPublisher payloadPublisher = PayloadPublisher.create();
final Discovery discovery = Discovery.create();
return new LegacyResendManagerImpl(enclave, encryptedTransactionDAO, resendFetchSize, payloadPublisher, discovery);
}
use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.
the class Main method main.
public static void main(String... args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
final CommandLine commandLine = new CommandLine(new EnclaveCliAdapter());
commandLine.registerConverter(Config.class, new ConfigConverter()).setSeparator(" ").setCaseInsensitiveEnumValuesAllowed(true);
commandLine.execute(args);
final CliResult cliResult = commandLine.getExecutionResult();
if (cliResult == null) {
System.exit(1);
}
if (!cliResult.getConfig().isPresent()) {
System.exit(cliResult.getStatus());
}
final TesseraServerFactory restServerFactory = TesseraServerFactory.create(CommunicationType.REST);
final Config config = cliResult.getConfig().get();
ConfigFactory.create().store(config);
final ServerConfig serverConfig = config.getServerConfigs().stream().findFirst().get();
Enclave enclave = EnclaveServer.create();
LOGGER.debug("Created enclave {}", enclave);
final TesseraServer server = restServerFactory.createServer(serverConfig, Set.of(new EnclaveApplication(enclave)));
server.start();
CountDownLatch latch = new CountDownLatch(1);
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
server.stop();
} catch (Exception ex) {
LOGGER.error(null, ex);
} finally {
}
}));
latch.await();
}
use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.
the class BatchTransactionRequesterProvider method provider.
public static BatchTransactionRequester provider() {
final Enclave enclave = Enclave.create();
final RecoveryClient client = RecoveryClient.create();
return new RestBatchTransactionRequester(enclave, client, 100);
}
use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.
the class BatchTransactionRequesterProviderTest method provider.
@Test
public void provider() {
try (var enclaveMockedStatic = mockStatic(Enclave.class);
var recoveryClientMockedStatic = mockStatic(RecoveryClient.class)) {
enclaveMockedStatic.when(Enclave::create).thenReturn(mock(Enclave.class));
recoveryClientMockedStatic.when(RecoveryClient::create).thenReturn(mock(RecoveryClient.class));
BatchTransactionRequester batchTransactionRequester = BatchTransactionRequesterProvider.provider();
assertThat(batchTransactionRequester).isNotNull().isExactlyInstanceOf(RestBatchTransactionRequester.class);
enclaveMockedStatic.verify(Enclave::create);
recoveryClientMockedStatic.verify(RecoveryClient::create);
}
}
use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.
the class TransactionManagerProviderTest method provider.
@Test
public void provider() {
try (var mockedStaticConfigFactory = mockStatic(ConfigFactory.class);
var mockedStaticEncryptedTransactionDAO = mockStatic(EncryptedTransactionDAO.class);
var mockedStaticEnclave = mockStatic(Enclave.class);
var mockedStaticEncryptedRawTransactionDAO = mockStatic(EncryptedRawTransactionDAO.class);
var mockedStaticPayloadPublisher = mockStatic(PayloadPublisher.class);
var mockedStaticBatchPayloadPublisher = mockStatic(BatchPayloadPublisher.class);
var mockedStaticPrivacyHelper = mockStatic(PrivacyHelper.class);
var mockedStaticResendManager = mockStatic(ResendManager.class);
var mockedStaticPayloadDigest = mockStatic(PayloadDigest.class)) {
ConfigFactory configFactory = mock(ConfigFactory.class);
Config config = mock(Config.class);
when(configFactory.getConfig()).thenReturn(config);
mockedStaticConfigFactory.when(ConfigFactory::create).thenReturn(configFactory);
PayloadPublisher payloadPublisher = mock(PayloadPublisher.class);
mockedStaticPayloadPublisher.when(PayloadPublisher::create).thenReturn(payloadPublisher);
BatchPayloadPublisher batchPayloadPublisher = mock(BatchPayloadPublisher.class);
mockedStaticBatchPayloadPublisher.when(BatchPayloadPublisher::create).thenReturn(batchPayloadPublisher);
mockedStaticEncryptedRawTransactionDAO.when(EncryptedRawTransactionDAO::create).thenReturn(mock(EncryptedRawTransactionDAO.class));
mockedStaticEnclave.when(Enclave::create).thenReturn(mock(Enclave.class));
mockedStaticEncryptedTransactionDAO.when(EncryptedTransactionDAO::create).thenReturn(mock(EncryptedTransactionDAO.class));
mockedStaticPrivacyHelper.when(PrivacyHelper::create).thenReturn(mock(PrivacyHelper.class));
mockedStaticResendManager.when(ResendManager::create).thenReturn(mock(ResendManager.class));
mockedStaticPayloadDigest.when(PayloadDigest::create).thenReturn(mock(PayloadDigest.class));
TransactionManager transactionManager = TransactionManagerProvider.provider();
assertThat(transactionManager).isNotNull();
assertThat(TransactionManagerProvider.provider()).describedAs("Second invocation should return same instance").isSameAs(transactionManager);
mockedStaticEncryptedTransactionDAO.verify(EncryptedTransactionDAO::create);
mockedStaticEncryptedTransactionDAO.verifyNoMoreInteractions();
mockedStaticEnclave.verify(Enclave::create);
mockedStaticEnclave.verifyNoMoreInteractions();
mockedStaticEncryptedRawTransactionDAO.verify(EncryptedRawTransactionDAO::create);
mockedStaticEncryptedRawTransactionDAO.verifyNoMoreInteractions();
mockedStaticPayloadPublisher.verify(PayloadPublisher::create);
mockedStaticPayloadPublisher.verifyNoMoreInteractions();
mockedStaticBatchPayloadPublisher.verify(BatchPayloadPublisher::create);
mockedStaticBatchPayloadPublisher.verifyNoMoreInteractions();
mockedStaticPrivacyHelper.verify(PrivacyHelper::create);
mockedStaticPrivacyHelper.verifyNoMoreInteractions();
mockedStaticResendManager.verify(ResendManager::create);
mockedStaticResendManager.verifyNoMoreInteractions();
mockedStaticPayloadDigest.verify(PayloadDigest::create);
mockedStaticPayloadDigest.verifyNoMoreInteractions();
}
}
Aggregations