Beispiel #1
0
        private async Task <IOperationsFetcher> CreateSutInstanceAsync(
            string inMemoryDatabaseName = "operations_fetcher_tests",
            Func <IOperationsRepository, IOperationRequestsRepository, Task> seedAction = null)
        {
            var options = new DbContextOptionsBuilder <PbfContext>()
                          .UseInMemoryDatabase(inMemoryDatabaseName)
                          .Options;

            var dbFactory = new MsSqlContextFactory <PbfContext>(opts => new PbfContext(options, true), options);

            _operationsRepository = new OperationsRepository(dbFactory);

            _operationRequestsRepository = new OperationRequestsRepository(
                dbFactory,
                new SqlRepositoryHelper(new MemoryCache(new MemoryCacheOptions()), EmptyLogFactory.Instance));

            _executorClient = Mock.Of <IQuorumOperationExecutorClient>();

            if (seedAction != null)
            {
                await seedAction.Invoke(_operationsRepository, _operationRequestsRepository);
            }

            return(new OperationsFetcher(
                       MaxNewOperationsAmount,
                       MaxAcceptedOperationsAmount,
                       _operationsRepository,
                       _operationRequestsRepository
                       ));
        }
Beispiel #2
0
            public static async Task GetTransfersInProgressAsync_OperationTypeConditionCheck(
                IOperationsRepository repo,
                IOperationRequestsRepository requestsRepo,
                IQuorumOperationExecutorClient executorClient)
            {
                var rnd = new Random();

                var statusUpdater = new OperationStatusUpdater(
                    EmptyLogFactory.Instance,
                    new TransactionScopeHandler(EmptyLogFactory.Instance),
                    repo,
                    executorClient,
                    requestsRepo);

                var o1 = await repo.AddAsync(
                    Guid.NewGuid(),
                    FakeCustomerId,
                    1,
                    FakeWalletAddress,
                    OperationType.TokensTransfer,
                    new TokensTransferContext
                {
                    SenderWalletAddress = FakeWalletAddress, RecipientWalletAddress = FakeWalletAddress, Amount = rnd.Next()
                }.ToJson(),
                    DateTime.UtcNow,
                    ValidTransactionHashes[0]);

                var o2 = await repo.AddAsync(
                    Guid.NewGuid(),
                    FakeCustomerId,
                    2,
                    FakeWalletAddress,
                    OperationType.CustomerWalletCreation,
                    new CustomerWalletContext { CustomerId = FakeCustomerId, WalletAddress = FakeWalletAddress }.ToJson(),
                    DateTime.UtcNow,
                    ValidTransactionHashes[1]);

                await statusUpdater.SucceedAsync(ValidTransactionHashes[1]);

                var o3 = await repo.AddAsync(
                    Guid.NewGuid(),
                    FakeCustomerId,
                    3,
                    FakeWalletAddress,
                    OperationType.CustomerBonusReward,
                    new CustomerBonusRewardContext
                {
                    CustomerId    = FakeCustomerId,
                    WalletAddress = FakeWalletAddress,
                    Amount        = rnd.Next(),
                    MinterAddress = FakeWalletAddress
                }.ToJson(),
                    DateTime.UtcNow,
                    ValidTransactionHashes[2]);

                await statusUpdater.SucceedAsync(ValidTransactionHashes[2]);
            }
Beispiel #3
0
 public OperationRequestsProducer(
     string walletCreationMasterWalletAddress,
     IOperationRequestsRepository operationRequestsRepository,
     ILogFactory logFactory)
 {
     _walletCreationMasterWalletAddress = walletCreationMasterWalletAddress;
     _operationRequestsRepository       = operationRequestsRepository;
     _log = logFactory.CreateLog(this);
 }
Beispiel #4
0
 public OperationStatusUpdater(ILogFactory logFactory,
                               ITransactionScopeHandler transactionScopeHandler,
                               IOperationsRepository operationsRepository,
                               IQuorumOperationExecutorClient executorClient,
                               IOperationRequestsRepository operationRequestsRepository)
 {
     _transactionScopeHandler     = transactionScopeHandler;
     _operationsRepository        = operationsRepository;
     _executorClient              = executorClient;
     _operationRequestsRepository = operationRequestsRepository;
     _log = logFactory.CreateLog(this);
 }
        public OperationsFetcher(
            int maxNewOperationsAmount,
            int maxAcceptedOperationsAmount,
            IOperationsRepository operationsRepository,
            IOperationRequestsRepository operationRequestsRepository)
        {
            _operationsRepository        = operationsRepository;
            _operationRequestsRepository = operationRequestsRepository;

            _maxNewOperationsAmount = maxNewOperationsAmount > 0
                ? maxNewOperationsAmount
                : MaxNewOperationsDefault;

            _maxAcceptedOperationsAmount = maxAcceptedOperationsAmount > 0
                ? maxAcceptedOperationsAmount
                : MaxAcceptedOperationsDefault;
        }
Beispiel #6
0
            public static async Task GetTransfersInProgressAsync_WalletAddressConditionCheck(
                IOperationsRepository repo,
                IOperationRequestsRepository requestsRepo,
                IQuorumOperationExecutorClient executorClient,
                string includeWalletAddress)
            {
                var rnd = new Random();

                var o = await repo.AddAsync(
                    Guid.NewGuid(),
                    FakeCustomerId,
                    1,
                    includeWalletAddress,
                    OperationType.TokensTransfer,
                    new TokensTransferContext
                {
                    SenderWalletAddress = FakeWalletAddress, RecipientWalletAddress = FakeWalletAddress, Amount = rnd.Next()
                }.ToJson(),
                    DateTime.UtcNow,
                    ValidTransactionHashes[0]);

                await repo.AddAsync(
                    Guid.NewGuid(),
                    FakeCustomerId,
                    2,
                    includeWalletAddress,
                    OperationType.TokensTransfer,
                    new TokensTransferContext
                {
                    SenderWalletAddress = FakeWalletAddress, RecipientWalletAddress = FakeWalletAddress, Amount = rnd.Next()
                }.ToJson(),
                    DateTime.UtcNow,
                    string.Empty);

                await repo.AddAsync(
                    Guid.NewGuid(),
                    FakeCustomerId,
                    3,
                    $"{includeWalletAddress}-{rnd.Next()}",
                    OperationType.CustomerWalletCreation,
                    new CustomerWalletContext { CustomerId = FakeCustomerId, WalletAddress = includeWalletAddress }
                    .ToJson(),
                    DateTime.UtcNow,
                    string.Empty);
            }