Search in sources :

Example 11 with Enclave

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);
}
Also used : PayloadPublisher(com.quorum.tessera.transaction.publish.PayloadPublisher) Enclave(com.quorum.tessera.enclave.Enclave) Discovery(com.quorum.tessera.discovery.Discovery) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO)

Example 12 with Enclave

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();
}
Also used : ConfigConverter(com.quorum.tessera.cli.parsers.ConfigConverter) TesseraServerFactory(com.quorum.tessera.server.TesseraServerFactory) ServerConfig(com.quorum.tessera.config.ServerConfig) Config(com.quorum.tessera.config.Config) CountDownLatch(java.util.concurrent.CountDownLatch) ServerConfig(com.quorum.tessera.config.ServerConfig) TesseraServer(com.quorum.tessera.server.TesseraServer) CommandLine(picocli.CommandLine) CliResult(com.quorum.tessera.cli.CliResult) EnclaveCliAdapter(com.quorum.tessera.enclave.server.EnclaveCliAdapter) Enclave(com.quorum.tessera.enclave.Enclave) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 13 with Enclave

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);
}
Also used : Enclave(com.quorum.tessera.enclave.Enclave)

Example 14 with Enclave

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);
    }
}
Also used : Enclave(com.quorum.tessera.enclave.Enclave) BatchTransactionRequester(com.quorum.tessera.recovery.resend.BatchTransactionRequester) Test(org.junit.Test)

Example 15 with Enclave

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();
    }
}
Also used : ResendManager(com.quorum.tessera.transaction.resend.ResendManager) BatchPayloadPublisher(com.quorum.tessera.transaction.publish.BatchPayloadPublisher) PayloadPublisher(com.quorum.tessera.transaction.publish.PayloadPublisher) BatchPayloadPublisher(com.quorum.tessera.transaction.publish.BatchPayloadPublisher) Config(com.quorum.tessera.config.Config) EncryptedRawTransactionDAO(com.quorum.tessera.data.EncryptedRawTransactionDAO) Enclave(com.quorum.tessera.enclave.Enclave) PayloadDigest(com.quorum.tessera.enclave.PayloadDigest) TransactionManager(com.quorum.tessera.transaction.TransactionManager) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO) PrivacyHelper(com.quorum.tessera.transaction.PrivacyHelper) ConfigFactory(com.quorum.tessera.config.ConfigFactory) Test(org.junit.Test)

Aggregations

Enclave (com.quorum.tessera.enclave.Enclave)29 Test (org.junit.Test)11 Discovery (com.quorum.tessera.discovery.Discovery)9 EncryptedTransactionDAO (com.quorum.tessera.data.EncryptedTransactionDAO)7 PayloadDigest (com.quorum.tessera.enclave.PayloadDigest)6 RuntimeContext (com.quorum.tessera.context.RuntimeContext)5 PayloadPublisher (com.quorum.tessera.transaction.publish.PayloadPublisher)5 NetworkStore (com.quorum.tessera.discovery.NetworkStore)4 PrivacyHelper (com.quorum.tessera.transaction.PrivacyHelper)4 TransactionManager (com.quorum.tessera.transaction.TransactionManager)4 Config (com.quorum.tessera.config.Config)3 PrivacyGroupManager (com.quorum.tessera.privacygroup.PrivacyGroupManager)3 LegacyResendManager (com.quorum.tessera.recovery.workflow.LegacyResendManager)3 Client (jakarta.ws.rs.client.Client)3 CliResult (com.quorum.tessera.cli.CliResult)2 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)2 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)2 RestClientFactory (com.quorum.tessera.context.RestClientFactory)2 PartyStore (com.quorum.tessera.p2p.partyinfo.PartyStore)2 ResendBatchPublisher (com.quorum.tessera.recovery.resend.ResendBatchPublisher)2