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();
}
}
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();
}
}
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();
}
}
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));
}
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);
}
Aggregations