Search in sources :

Example 1 with EncryptedTransactionDAO

use of com.quorum.tessera.data.EncryptedTransactionDAO in project tessera by ConsenSys.

the class EncryptedTransactionDAOProviderTest method provides.

@Test
public void provides() {
    try (var mockedConfigFactory = mockStatic(ConfigFactory.class);
        var mockedDataSourceFactory = mockStatic(DataSourceFactory.class);
        var mockedPersistence = mockStatic(Persistence.class)) {
        mockedPersistence.when(() -> Persistence.createEntityManagerFactory(anyString(), anyMap())).thenReturn(mock(EntityManagerFactory.class));
        Config config = mock(Config.class);
        JdbcConfig jdbcConfig = mock(JdbcConfig.class);
        when(jdbcConfig.isAutoCreateTables()).thenReturn(autocreateTables);
        when(config.getJdbcConfig()).thenReturn(jdbcConfig);
        ConfigFactory configFactory = mock(ConfigFactory.class);
        when(configFactory.getConfig()).thenReturn(config);
        mockedConfigFactory.when(ConfigFactory::create).thenReturn(configFactory);
        mockedDataSourceFactory.when(DataSourceFactory::create).thenReturn(mock(DataSourceFactory.class));
        EncryptedTransactionDAO result = EncryptedTransactionDAOProvider.provider();
        assertThat(result).isNotNull().isExactlyInstanceOf(EncryptedTransactionDAOImpl.class);
        mockedPersistence.verify(() -> Persistence.createEntityManagerFactory(anyString(), anyMap()));
        mockedPersistence.verifyNoMoreInteractions();
        EncryptedTransactionDAOProvider.provider();
    }
}
Also used : DataSourceFactory(com.quorum.tessera.data.DataSourceFactory) JdbcConfig(com.quorum.tessera.config.JdbcConfig) Config(com.quorum.tessera.config.Config) EntityManagerFactory(jakarta.persistence.EntityManagerFactory) JdbcConfig(com.quorum.tessera.config.JdbcConfig) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO) ConfigFactory(com.quorum.tessera.config.ConfigFactory) Test(org.junit.Test)

Example 2 with EncryptedTransactionDAO

use of com.quorum.tessera.data.EncryptedTransactionDAO in project tessera by ConsenSys.

the class ResendManagerProviderTest method provider.

@Test
public void provider() {
    try (var mockedEncryptedTransactionDAO = mockStatic(EncryptedTransactionDAO.class);
        var mockedEnclave = mockStatic(Enclave.class);
        var mockedStaticPayloadDigest = mockStatic(PayloadDigest.class)) {
        Enclave enclave = mock(Enclave.class);
        mockedEnclave.when(Enclave::create).thenReturn(enclave);
        mockedEncryptedTransactionDAO.when(EncryptedTransactionDAO::create).thenReturn(mock(EncryptedTransactionDAO.class));
        mockedStaticPayloadDigest.when(PayloadDigest::create).thenReturn(mock(PayloadDigest.class));
        ResendManager resendManager = ResendManagerProvider.provider();
        assertThat(resendManager).isNotNull();
        mockedEncryptedTransactionDAO.verify(EncryptedTransactionDAO::create);
        mockedEncryptedTransactionDAO.verifyNoMoreInteractions();
        mockedEnclave.verify(Enclave::create);
        mockedEnclave.verifyNoMoreInteractions();
        mockedStaticPayloadDigest.verify(PayloadDigest::create);
        mockedStaticPayloadDigest.verifyNoMoreInteractions();
    }
}
Also used : ResendManager(com.quorum.tessera.transaction.resend.ResendManager) Enclave(com.quorum.tessera.enclave.Enclave) PayloadDigest(com.quorum.tessera.enclave.PayloadDigest) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO) Test(org.junit.Test)

Example 3 with EncryptedTransactionDAO

use of com.quorum.tessera.data.EncryptedTransactionDAO in project tessera by ConsenSys.

the class PrivacyHelperProviderTest method provider.

@Test
public void provider() {
    try (var mockedRuntimeContext = mockStatic(RuntimeContext.class);
        var mockedEncryptedTransactionDAO = mockStatic(EncryptedTransactionDAO.class)) {
        RuntimeContext runtimeContext = mock(RuntimeContext.class);
        when(runtimeContext.isEnhancedPrivacy()).thenReturn(true);
        mockedRuntimeContext.when(RuntimeContext::getInstance).thenReturn(runtimeContext);
        mockedEncryptedTransactionDAO.when(EncryptedTransactionDAO::create).thenReturn(mock(EncryptedTransactionDAO.class));
        PrivacyHelper privacyHelper = PrivacyHelperProvider.provider();
        assertThat(privacyHelper).isNotNull();
    }
}
Also used : RuntimeContext(com.quorum.tessera.context.RuntimeContext) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO) PrivacyHelper(com.quorum.tessera.transaction.PrivacyHelper) Test(org.junit.Test)

Example 4 with EncryptedTransactionDAO

use of com.quorum.tessera.data.EncryptedTransactionDAO in project tessera by ConsenSys.

the class TransactionManagerProvider method provider.

public static TransactionManager provider() {
    final TransactionManagerHolder transactionManagerHolder = TransactionManagerHolder.INSTANCE;
    if (transactionManagerHolder.getTransactionManager().isPresent()) {
        return transactionManagerHolder.getTransactionManager().get();
    }
    final EncryptedTransactionDAO encryptedTransactionDAO = EncryptedTransactionDAO.create();
    final Enclave enclave = Enclave.create();
    final EncryptedRawTransactionDAO encryptedRawTransactionDAO = EncryptedRawTransactionDAO.create();
    LOGGER.debug("Creating ResendManager");
    final ResendManager resendManager = ResendManager.create();
    LOGGER.debug("Created ResendManager {}", resendManager);
    LOGGER.debug("Creating payload publisher");
    final PayloadPublisher payloadPublisher = PayloadPublisher.create();
    LOGGER.debug("Created payload publisher {}", payloadPublisher);
    LOGGER.debug("Creating batchPayloadPublisher");
    final BatchPayloadPublisher batchPayloadPublisher = BatchPayloadPublisher.create();
    LOGGER.debug("Created batchPayloadPublisher {}", batchPayloadPublisher);
    LOGGER.debug("Creating PrivacyHelper");
    final PrivacyHelper privacyHelper = PrivacyHelper.create();
    LOGGER.debug("Created PrivacyHelper {}", privacyHelper);
    int resendBatchSize = 100;
    LOGGER.debug("Creating PayloadDigest");
    final PayloadDigest messageHashFactory = PayloadDigest.create();
    LOGGER.debug("Created PayloadDigest {}", messageHashFactory);
    return transactionManagerHolder.store(new TransactionManagerImpl(enclave, encryptedTransactionDAO, encryptedRawTransactionDAO, resendManager, batchPayloadPublisher, privacyHelper, messageHashFactory));
}
Also used : ResendManager(com.quorum.tessera.transaction.resend.ResendManager) PayloadPublisher(com.quorum.tessera.transaction.publish.PayloadPublisher) BatchPayloadPublisher(com.quorum.tessera.transaction.publish.BatchPayloadPublisher) BatchPayloadPublisher(com.quorum.tessera.transaction.publish.BatchPayloadPublisher) Enclave(com.quorum.tessera.enclave.Enclave) EncryptedRawTransactionDAO(com.quorum.tessera.data.EncryptedRawTransactionDAO) PayloadDigest(com.quorum.tessera.enclave.PayloadDigest) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO) PrivacyHelper(com.quorum.tessera.transaction.PrivacyHelper)

Example 5 with EncryptedTransactionDAO

use of com.quorum.tessera.data.EncryptedTransactionDAO in project tessera by ConsenSys.

the class BatchResendManagerImplTest method useMaxResultsAlsoWhenBatchSizeTooLarge.

@Test
public void useMaxResultsAlsoWhenBatchSizeTooLarge() {
    final ResendBatchRequest request = ResendBatchRequest.Builder.create().withBatchSize(10000000).withPublicKey(KEY_STRING).build();
    List<EncryptedTransaction> transactions = IntStream.range(0, 5).mapToObj(i -> mock(EncryptedTransaction.class)).collect(Collectors.toUnmodifiableList());
    when(encryptedTransactionDAO.transactionCount()).thenReturn(101L);
    when(encryptedTransactionDAO.retrieveTransactions(lt(100), anyInt())).thenReturn(transactions);
    when(encryptedTransactionDAO.retrieveTransactions(gt(99), anyInt())).thenReturn(singletonList(mock(EncryptedTransaction.class)));
    final BatchWorkflow batchWorkflow = mock(BatchWorkflow.class);
    when(batchWorkflow.getPublishedMessageCount()).thenReturn(999L);
    when(batchWorkflowFactory.create(101L)).thenReturn(batchWorkflow);
    final ResendBatchResponse result = manager.resendBatch(request);
    assertThat(result.getTotal()).isEqualTo(999L);
    verify(batchWorkflow, times(101)).execute(any(BatchWorkflowContext.class));
    verify(encryptedTransactionDAO, times(21)).retrieveTransactions(anyInt(), anyInt());
    verify(encryptedTransactionDAO).transactionCount();
    verify(batchWorkflowFactory).create(101L);
}
Also used : AdditionalMatchers.lt(org.mockito.AdditionalMatchers.lt) ResendBatchRequest(com.quorum.tessera.recovery.resend.ResendBatchRequest) IntStream(java.util.stream.IntStream) PublicKey(com.quorum.tessera.encryption.PublicKey) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BatchWorkflowFactory(com.quorum.tessera.recovery.workflow.BatchWorkflowFactory) BatchResendManager(com.quorum.tessera.recovery.workflow.BatchResendManager) Base64Codec(com.quorum.tessera.base64.Base64Codec) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) BatchWorkflow(com.quorum.tessera.recovery.workflow.BatchWorkflow) Collections.singletonList(java.util.Collections.singletonList) PushBatchRequest(com.quorum.tessera.recovery.resend.PushBatchRequest) BatchWorkflowContext(com.quorum.tessera.recovery.workflow.BatchWorkflowContext) StagingEntityDAO(com.quorum.tessera.data.staging.StagingEntityDAO) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO) After(org.junit.After) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) AdditionalMatchers.gt(org.mockito.AdditionalMatchers.gt) com.quorum.tessera.enclave(com.quorum.tessera.enclave) Nonce(com.quorum.tessera.encryption.Nonce) ServiceLoader(java.util.ServiceLoader) Test(org.junit.Test) StagingTransaction(com.quorum.tessera.data.staging.StagingTransaction) Collectors(java.util.stream.Collectors) Mockito(org.mockito.Mockito) List(java.util.List) ResendBatchResponse(com.quorum.tessera.recovery.resend.ResendBatchResponse) Optional(java.util.Optional) ResendBatchResponse(com.quorum.tessera.recovery.resend.ResendBatchResponse) ResendBatchRequest(com.quorum.tessera.recovery.resend.ResendBatchRequest) BatchWorkflow(com.quorum.tessera.recovery.workflow.BatchWorkflow) BatchWorkflowContext(com.quorum.tessera.recovery.workflow.BatchWorkflowContext) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) Test(org.junit.Test)

Aggregations

EncryptedTransactionDAO (com.quorum.tessera.data.EncryptedTransactionDAO)14 Test (org.junit.Test)9 Enclave (com.quorum.tessera.enclave.Enclave)6 StagingEntityDAO (com.quorum.tessera.data.staging.StagingEntityDAO)5 BatchResendManager (com.quorum.tessera.recovery.workflow.BatchResendManager)5 BatchWorkflowFactory (com.quorum.tessera.recovery.workflow.BatchWorkflowFactory)5 PayloadDigest (com.quorum.tessera.enclave.PayloadDigest)4 PrivacyHelper (com.quorum.tessera.transaction.PrivacyHelper)4 PayloadPublisher (com.quorum.tessera.transaction.publish.PayloadPublisher)4 Base64Codec (com.quorum.tessera.base64.Base64Codec)3 EncryptedTransaction (com.quorum.tessera.data.EncryptedTransaction)3 StagingTransaction (com.quorum.tessera.data.staging.StagingTransaction)3 com.quorum.tessera.enclave (com.quorum.tessera.enclave)3 Nonce (com.quorum.tessera.encryption.Nonce)3 PublicKey (com.quorum.tessera.encryption.PublicKey)3 PushBatchRequest (com.quorum.tessera.recovery.resend.PushBatchRequest)3 ResendBatchRequest (com.quorum.tessera.recovery.resend.ResendBatchRequest)3 ResendBatchResponse (com.quorum.tessera.recovery.resend.ResendBatchResponse)3 BatchWorkflow (com.quorum.tessera.recovery.workflow.BatchWorkflow)3 BatchWorkflowContext (com.quorum.tessera.recovery.workflow.BatchWorkflowContext)3