Beispiel #1
0
 public DepositProvider(IDepositDetailsRepository depositRepository,
                        IDepositUnitsCalculator depositUnitsCalculator, ILogManager logManager)
 {
     _depositRepository      = depositRepository;
     _depositUnitsCalculator = depositUnitsCalculator;
     _logger = logManager.GetClassLogger();
 }
        public void SetUp()
        {
            IDb db = new MemDb();

            depositUnitsCalculator = Substitute.For <IDepositUnitsCalculator>();
            repository             = new DepositDetailsRocksRepository(db, new DepositDetailsDecoder(), depositUnitsCalculator);
        }
 public async Task Can_add_async()
 {
     IMongoDatabase          database = MongoForTest.TempDb.GetDatabase();
     IDepositUnitsCalculator depositUnitsCalculator = Substitute.For <IDepositUnitsCalculator>();
     var            repo           = new DepositDetailsMongoRepository(database, depositUnitsCalculator);
     DepositDetails depositDetails = BuildDummyDepositDetails();
     await repo.AddAsync(depositDetails);
 }
Beispiel #4
0
 public DepositReportService(IDepositDetailsRepository depositRepository, IDepositUnitsCalculator depositUnitsCalculator, IReceiptRepository receiptRepository,
                             IConsumerSessionRepository sessionRepository, ITimestamper timestamper)
 {
     _depositUnitsCalculator = depositUnitsCalculator;
     _depositRepository      = depositRepository;
     _receiptRepository      = receiptRepository;
     _sessionRepository      = sessionRepository;
     _timestamper            = timestamper;
 }
Beispiel #5
0
        public async Task Get_assets_empty_db()
        {
            IDb db = new MemDb();
            IDepositUnitsCalculator       depositUnitsCalculator = Substitute.For <IDepositUnitsCalculator>();
            DepositDetailsRocksRepository detailsRocksRepository = new DepositDetailsRocksRepository(db, new DepositDetailsDecoder(), depositUnitsCalculator);
            ProviderRocksRepository       repository             = new ProviderRocksRepository(db, new DepositDetailsDecoder());

            var retrieved = await repository.GetDataAssetsAsync();

            retrieved.Count.Should().Be(0);
        }
        public async Task Can_get_by_id()
        {
            IMongoDatabase          database = MongoForTest.TempDb.GetDatabase();
            IDepositUnitsCalculator depositUnitsCalculator = Substitute.For <IDepositUnitsCalculator>();
            var            repo           = new DepositDetailsMongoRepository(database, depositUnitsCalculator);
            DepositDetails depositDetails = BuildDummyDepositDetails();
            await repo.AddAsync(depositDetails);

            DepositDetails result = await repo.GetAsync(depositDetails.Id);

            result.Should().BeEquivalentTo(depositDetails);
        }
        public void Can_get_a_single_item_report()
        {
            IDepositUnitsCalculator          depositUnitsCalculator = Substitute.For <IDepositUnitsCalculator>();
            DepositDetailsInMemoryRepository repository             = new DepositDetailsInMemoryRepository(new DepositsInMemoryDb(), depositUnitsCalculator);

            repository.AddAsync(_details);
            ConsumerSessionInMemoryRepository sessionInMemoryRepository = new ConsumerSessionInMemoryRepository();
            DepositReportService reportService = new DepositReportService(repository, new DepositUnitsCalculator(sessionInMemoryRepository, Timestamper.Default), new ReceiptInMemoryRepository(), new ConsumerSessionInMemoryRepository(), Timestamper.Default);
            var report = reportService.GetAsync(new GetDepositsReport());

            report.Result.Deposits.Items.Should().HaveCount(1);
        }
Beispiel #8
0
        public async Task Get_providers(DepositDetails depositDetails)
        {
            IDb db = new MemDb();
            IDepositUnitsCalculator       depositUnitsCalculator = Substitute.For <IDepositUnitsCalculator>();
            DepositDetailsRocksRepository detailsRocksRepository = new DepositDetailsRocksRepository(db, new DepositDetailsDecoder(), depositUnitsCalculator);
            await detailsRocksRepository.AddAsync(depositDetails);

            ProviderRocksRepository repository = new ProviderRocksRepository(db, new DepositDetailsDecoder());

            var retrieved = await repository.GetProvidersAsync();

            retrieved.Count.Should().Be(1);
        }
Beispiel #9
0
        public void Setup()
        {
            DataAssetProvider       provider = new DataAssetProvider(_providerAddress, "provider");
            IDepositUnitsCalculator depositUnitsCalculator = Substitute.For <IDepositUnitsCalculator>();

            _asset   = new DataAsset(Keccak.Compute("1"), "name", "desc", 1, DataAssetUnitType.Unit, 1000, 10000, new DataAssetRules(new DataAssetRule(1)), provider, state: DataAssetState.Published);
            _deposit = new Deposit(Keccak.Zero, 1, 2, 3);
            _details = new DepositDetails(_deposit, _asset, Address.Zero, new byte[0], 1, new TransactionInfo[0]);

            DepositDetailsInMemoryRepository repository = new DepositDetailsInMemoryRepository(new DepositsInMemoryDb(), depositUnitsCalculator);

            repository.AddAsync(_details);

            ConsumerSessionInMemoryRepository sessionInMemoryRepository = new ConsumerSessionInMemoryRepository();

            _depositProvider = new DepositProvider(repository, new DepositUnitsCalculator(sessionInMemoryRepository, Timestamper.Default), LimboLogs.Instance);
        }
        public void Setup()
        {
            DataAssetProvider provider = new DataAssetProvider(_providerAddress, "provider");

            _asset                 = new DataAsset(Keccak.Compute("1"), "name", "desc", 1, DataAssetUnitType.Unit, 1000, 10000, new DataAssetRules(new DataAssetRule(1)), provider, state: DataAssetState.Published);
            _closedAsset           = new DataAsset(Keccak.Compute("2"), "name", "desc", 1, DataAssetUnitType.Unit, 1000, 10000, new DataAssetRules(new DataAssetRule(1)), provider, state: DataAssetState.Closed);
            _assetUnderMaintenance = new DataAsset(Keccak.Compute("3"), "name", "desc", 1, DataAssetUnitType.Unit, 1000, 10000, new DataAssetRules(new DataAssetRule(1)), provider, state: DataAssetState.UnderMaintenance);
            _withKyc               = new DataAsset(Keccak.Compute("4"), "name", "desc", 1, DataAssetUnitType.Unit, 1000, 10000, new DataAssetRules(new DataAssetRule(1)), provider, state: DataAssetState.Published, kycRequired: true);

            _deposit = new Deposit(Keccak.Zero, 1, 2, 3);
            _details = new DepositDetails(_deposit, _asset, Address.Zero, new byte[0], 1, new TransactionInfo[0]);

            INdmBlockchainBridge blockchainBridge = BlockchainBridgeBuilder.BuildABridge();

            _wallet = new DevWallet(new WalletConfig(), LimboLogs.Instance);
            DepositService             depositService     = new DepositService(blockchainBridge, new AbiEncoder(), _wallet, Address.Zero);
            IConsumerSessionRepository sessionRepository  = new ConsumerSessionInMemoryRepository();
            DepositUnitsCalculator     unitsCalculator    = new DepositUnitsCalculator(sessionRepository, Timestamper.Default);
            DepositsInMemoryDb         depositsInMemoryDb = new DepositsInMemoryDb();

            depositsInMemoryDb.Add(_details);

            IProviderRepository     providerRepository     = new ProviderInMemoryRepository(depositsInMemoryDb);
            IConsumerNotifier       notifier               = new ConsumerNotifier(Substitute.For <INdmNotifier>());
            DataAssetService        dataAssetService       = new DataAssetService(providerRepository, notifier, LimboLogs.Instance);
            IDepositUnitsCalculator depositUnitsCalculator = Substitute.For <IDepositUnitsCalculator>();
            INdmPeer peer = Substitute.For <INdmPeer>();

            peer.NodeId.Returns(TestItem.PublicKeyB);
            peer.ProviderAddress.Returns(_providerAddress);

            dataAssetService.AddDiscovered(_asset, peer);
            dataAssetService.AddDiscovered(_closedAsset, peer);
            dataAssetService.AddDiscovered(_assetUnderMaintenance, peer);
            dataAssetService.AddDiscovered(_withKyc, peer);

            _kycVerifier = Substitute.For <IKycVerifier>();
            ProviderService providerService = new ProviderService(providerRepository, notifier, LimboLogs.Instance);

            providerService.Add(peer);

            _depositManager = new DepositManager(depositService, unitsCalculator, dataAssetService, _kycVerifier, providerService, new AbiEncoder(), new CryptoRandom(), _wallet, Substitute.For <IGasPriceService>(), new DepositDetailsInMemoryRepository(depositsInMemoryDb, depositUnitsCalculator), Timestamper.Default, LimboLogs.Instance, 6, false);
        }
        public async Task Can_browse_with_query_and_pagination()
        {
            IMongoDatabase          database = MongoForTest.TempDb.GetDatabase();
            IDepositUnitsCalculator depositUnitsCalculator = Substitute.For <IDepositUnitsCalculator>();
            var            repo           = new DepositDetailsMongoRepository(database, depositUnitsCalculator);
            DepositDetails depositDetails = BuildDummyDepositDetails();
            await repo.AddAsync(depositDetails);

            GetDeposits query = new GetDeposits();

            query.OnlyUnconfirmed       = true;
            query.OnlyNotRejected       = true;
            query.OnlyPending           = true;
            query.CurrentBlockTimestamp = 1;
            query.EligibleToRefund      = true;
            query.Page    = 0;
            query.Results = 10;
            await repo.BrowseAsync(query);
        }
Beispiel #12
0
 public DepositManager(IDepositService depositService, IDepositUnitsCalculator depositUnitsCalculator,
                       IDataAssetService dataAssetService, IKycVerifier kycVerifier, IProviderService providerService,
                       IAbiEncoder abiEncoder, ICryptoRandom cryptoRandom, IWallet wallet,
                       IDepositDetailsRepository depositRepository, IConsumerSessionRepository sessionRepository,
                       ITimestamper timestamper, ILogManager logManager, uint requiredBlockConfirmations)
 {
     _depositService             = depositService;
     _depositUnitsCalculator     = depositUnitsCalculator;
     _depositRepository          = depositRepository;
     _sessionRepository          = sessionRepository;
     _dataAssetService           = dataAssetService;
     _kycVerifier                = kycVerifier;
     _providerService            = providerService;
     _abiEncoder                 = abiEncoder;
     _cryptoRandom               = cryptoRandom;
     _timestamper                = timestamper;
     _requiredBlockConfirmations = requiredBlockConfirmations;
     _wallet = wallet;
     _logger = logManager.GetClassLogger();
 }
Beispiel #13
0
 public DepositManager(IDepositService depositService, IDepositUnitsCalculator depositUnitsCalculator,
                       IDataAssetService dataAssetService, IKycVerifier kycVerifier, IProviderService providerService,
                       IAbiEncoder abiEncoder, ICryptoRandom cryptoRandom, IWallet wallet, IGasPriceService gasPriceService,
                       IDepositDetailsRepository depositRepository, ITimestamper timestamper, ILogManager logManager,
                       uint requiredBlockConfirmations, bool disableSendingDepositTransaction = false)
 {
     _depositService                   = depositService;
     _depositUnitsCalculator           = depositUnitsCalculator;
     _depositRepository                = depositRepository;
     _dataAssetService                 = dataAssetService;
     _kycVerifier                      = kycVerifier;
     _providerService                  = providerService;
     _abiEncoder                       = abiEncoder;
     _cryptoRandom                     = cryptoRandom;
     _timestamper                      = timestamper;
     _requiredBlockConfirmations       = requiredBlockConfirmations;
     _disableSendingDepositTransaction = disableSendingDepositTransaction;
     _wallet          = wallet;
     _gasPriceService = gasPriceService;
     _logger          = logManager.GetClassLogger();
 }
Beispiel #14
0
        public void Setup()
        {
            DataAssetProvider provider = new DataAssetProvider(_providerAddress, "provider");

            _asset   = new DataAsset(Keccak.Compute("1"), "name", "desc", 1, DataAssetUnitType.Unit, 1000, 10000, new DataAssetRules(new DataAssetRule(1)), provider, state: DataAssetState.Published);
            _deposit = new Deposit(Keccak.Zero, 1, 2, 3);
            _details = new DepositDetails(_deposit, _asset, Address.Zero, new byte[0], 1, new TransactionInfo[0]);

            _accountService = Substitute.For <IAccountService>();
            _refundClaimant = Substitute.For <IRefundClaimant>();
            IDepositConfirmationService depositConfirmationService = Substitute.For <IDepositConfirmationService>();
            IPriceService           priceService           = Substitute.For <IPriceService>();
            IGasPriceService        gasPriceService        = Substitute.For <IGasPriceService>();
            IDepositUnitsCalculator depositUnitsCalculator = Substitute.For <IDepositUnitsCalculator>();

            _depositRepository = Substitute.For <IDepositDetailsRepository>();
            _blockProcessor    = Substitute.For <IBlockProcessor>();
            _consumerNotifier  = Substitute.For <IConsumerNotifier>();
            IDepositDetailsRepository repository = new DepositDetailsInMemoryRepository(new DepositsInMemoryDb(), depositUnitsCalculator);

            repository.AddAsync(_details);
            _processor = new ConsumerServicesBackgroundProcessor(_accountService, _refundClaimant, depositConfirmationService, gasPriceService, _blockProcessor, _depositRepository, _consumerNotifier, LimboLogs.Instance, priceService);
        }
Beispiel #15
0
 public void Setup()
 {
     _sessionRepository = Substitute.For <IConsumerSessionRepository>();
     _timestamper       = new Timestamper(Date);
     _calculator        = new DepositUnitsCalculator(_sessionRepository, _timestamper);
 }
 public DepositDetailsInMemoryRepository(DepositsInMemoryDb db, IDepositUnitsCalculator depositUnitsCalculator)
 {
     _db = db;
     _depositUnitsCalculator = depositUnitsCalculator;
 }
 public DepositDetailsMongoRepository(IMongoDatabase database, IDepositUnitsCalculator depositUnitsCalculator)
 {
     _database = database;
     _depositUnitsCalculator = depositUnitsCalculator;
 }
 public DepositDetailsRocksRepository(IDb database, IRlpNdmDecoder <DepositDetails> rlpDecoder, IDepositUnitsCalculator depositUnitsCalculator)
 {
     _database               = database;
     _rlpDecoder             = rlpDecoder;
     _depositUnitsCalculator = depositUnitsCalculator;
 }