Search in sources :

Example 6 with EncryptedTransactionDAO

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

the class BatchResendManagerImplTest method resendBatch.

@Test
public void resendBatch() {
    ResendBatchRequest request = ResendBatchRequest.Builder.create().withBatchSize(3).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)));
    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).getPublishedMessageCount();
    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)

Example 7 with EncryptedTransactionDAO

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

the class BatchResendManagerProviderTest method provider.

@Test
public void provider() {
    try (var staticEncryptedTransactionDAO = mockStatic(EncryptedTransactionDAO.class);
        var staticStagingEntityDAO = mockStatic(StagingEntityDAO.class);
        var staticBatchWorkflowFactory = mockStatic(BatchWorkflowFactory.class)) {
        staticEncryptedTransactionDAO.when(EncryptedTransactionDAO::create).thenReturn(mock(EncryptedTransactionDAO.class));
        staticStagingEntityDAO.when(StagingEntityDAO::create).thenReturn(mock(StagingEntityDAO.class));
        staticBatchWorkflowFactory.when(BatchWorkflowFactory::create).thenReturn(mock(BatchWorkflowFactory.class));
        BatchResendManager batchResendManager = BatchResendManagerProvider.provider();
        assertThat(batchResendManager).isNotNull().isExactlyInstanceOf(BatchResendManagerImpl.class);
        staticEncryptedTransactionDAO.verify(EncryptedTransactionDAO::create);
        staticStagingEntityDAO.verify(StagingEntityDAO::create);
        staticBatchWorkflowFactory.verify(BatchWorkflowFactory::create);
        staticEncryptedTransactionDAO.verifyNoMoreInteractions();
        staticStagingEntityDAO.verifyNoMoreInteractions();
        staticBatchWorkflowFactory.verifyNoMoreInteractions();
        assertThat(BatchResendManagerHolder.INSTANCE.getBatchResendManager()).isPresent().containsSame(batchResendManager);
        assertThat(BatchResendManagerProvider.provider()).isSameAs(batchResendManager);
    }
}
Also used : BatchWorkflowFactory(com.quorum.tessera.recovery.workflow.BatchWorkflowFactory) BatchResendManager(com.quorum.tessera.recovery.workflow.BatchResendManager) StagingEntityDAO(com.quorum.tessera.data.staging.StagingEntityDAO) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO) Test(org.junit.Test)

Example 8 with EncryptedTransactionDAO

use of com.quorum.tessera.data.EncryptedTransactionDAO 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 9 with EncryptedTransactionDAO

use of com.quorum.tessera.data.EncryptedTransactionDAO 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)

Example 10 with EncryptedTransactionDAO

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

the class PrivacyHelperProvider method provider.

public static PrivacyHelper provider() {
    RuntimeContext runtimeContext = RuntimeContext.getInstance();
    LOGGER.debug("Creating PrivacyHelper");
    boolean privacyEnabled = runtimeContext.isEnhancedPrivacy();
    EncryptedTransactionDAO encryptedTransactionDAO = EncryptedTransactionDAO.create();
    PrivacyHelper privacyHelper = new PrivacyHelperImpl(encryptedTransactionDAO, privacyEnabled);
    LOGGER.debug("Created PrivacyHelper {}", privacyHelper);
    return privacyHelper;
}
Also used : RuntimeContext(com.quorum.tessera.context.RuntimeContext) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO) PrivacyHelper(com.quorum.tessera.transaction.PrivacyHelper)

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