예제 #1
0
        public void CheckBalanceTest_TestIfBalanceIsCheckedAndReturnedProperly_VerifiesThroughReturnedValue()
        {
            ICoinClientService coinClientService = (ICoinClientService)ContextRegistry.GetContext()["BitcoinClientService"];

            decimal checkBalance = coinClientService.CheckBalance("BTC");

            Assert.AreNotEqual(0, checkBalance);
        }
예제 #2
0
        public void CreateNewAddressTest_TestsWhetherTheServiceCreatesNewAddressSuccessfullyOrNot_VerifiesByTheReturnedResult()
        {
            ICoinClientService coinClientService = (ICoinClientService)ContextRegistry.GetContext()["BitcoinClientService"];

            string newAddress = coinClientService.CreateNewAddress();

            Assert.IsNotNull(newAddress);
            Assert.IsFalse(string.IsNullOrEmpty(newAddress));
        }
        /// <summary>
        /// Sends request to generate a new address to the specific CoinClientService for the given currency
        /// </summary>
        /// <param name="currency"></param>
        /// <returns></returns>
        public string GenerateNewAddress(string currency)
        {
            ICoinClientService coinService = SelectCoinService(currency);

            if (coinService != null)
            {
                // Select the corresponding coin client service and return a response after requesting
                return(coinService.CreateNewAddress());
            }
            throw new InstanceNotFoundException(string.Format("No Client Service found for Currency: {0}", currency));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        public ClientInteractionService(IFundsPersistenceRepository fundsPersistenceRepository, IWithdrawRepository withdrawRepository,
                                        ICoinClientService bitcoinClientService, ICoinClientService litecoinClientService)
        {
            _fundsPersistenceRepository = fundsPersistenceRepository;
            _withdrawRepository         = withdrawRepository;
            _bitcoinClientService       = bitcoinClientService;
            _litecoinClientService      = litecoinClientService;

            _withdrawSubmissioInterval = Convert.ToDouble(ConfigurationManager.AppSettings.Get("WithdrawSubmitInterval"));
            Log.Debug(string.Format("Withdraw submission interval = {0}", _withdrawSubmissioInterval));

            HookEventHandlers();
        }
예제 #5
0
        public void CommitWithdrawTest_TestsIfTheWithdrawalIsMadeAsExpected_VerifiesTheReturnedResponseAndCheskTheBlockChainToConfirm()
        {
            if (_shouldRunTests)
            {
                ICoinClientService coinClientService =
                    (ICoinClientService)ContextRegistry.GetContext()["BitcoinClientService"];

                decimal   fee        = 0.0001m;
                AccountId accountId  = new AccountId(1);
                string    newAddress = coinClientService.CreateNewAddress();
                Withdraw  withdraw   = new Withdraw(new Currency("BTC", true), Guid.NewGuid().ToString(), DateTime.Now,
                                                    WithdrawType.Bitcoin, Amount, fee,
                                                    TransactionStatus.Pending, accountId,
                                                    new BitcoinAddress(newAddress));
                string transactionId = coinClientService.CommitWithdraw(withdraw.BitcoinAddress.Value, withdraw.Amount);
                Assert.IsNotNull(transactionId);
            }
        }
        /// <summary>
        /// Handler when the timer has been elapsed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="elapsedEventArgs"></param>
        private void OnTimerElapsed(object sender, ElapsedEventArgs elapsedEventArgs)
        {
            Log.Debug(string.Format("Withdraw Timer Elapsed."));
            Timer timer = sender as Timer;

            if (timer != null)
            {
                timer.Stop();
                timer.Dispose();
                Log.Debug(string.Format("Withdraw Timer Stopped"));
                Withdraw withdraw = null;
                _withdrawTimersDictionary.TryGetValue(timer, out withdraw);
                if (withdraw != null)
                {
                    Log.Debug(string.Format("Submitting Withdraw to network: Account ID = {0}, Currency = {1}", withdraw.AccountId.Value, withdraw.Currency.Name));
                    // Selecct the coin client service to which to send the withdraw
                    ICoinClientService coinClientService = SelectCoinService(withdraw.Currency.Name);
                    string             transactionId     = coinClientService.CommitWithdraw(
                        withdraw.BitcoinAddress.Value, withdraw.Amount);
                    if (string.IsNullOrEmpty(transactionId))
                    {
                        Log.Error(string.Format("Withdraw could not be submitted to network: Account ID = {0}, Currency = {1}", withdraw.AccountId.Value, withdraw.Currency.Name));
                    }
                    else
                    {
                        Log.Debug(string.Format("Withdraw submitted succcessfully to network: Account ID = {0}, Currency = {1}", withdraw.AccountId.Value, withdraw.Currency.Name));
                        // Set transaction Id recevied from the network
                        withdraw.SetTransactionId(transactionId);

                        /*
                         * // Set status as confirmed
                         * withdraw.StatusConfirmed();
                         * // Save the withdraw
                         * _fundsPersistenceRepository.SaveOrUpdate(withdraw);*/
                        _withdrawTimersDictionary.Remove(timer);
                        if (WithdrawExecuted != null)
                        {
                            WithdrawExecuted(withdraw);
                        }
                    }
                }
            }
        }
예제 #7
0
        public void DepositCheckNewTransactionsTest_TestIfDepositHandlingIsDoneAsExpected_VerifiesThroughReturnedValue()
        {
            // Submits withdraw to own address, after the first NewTransactionInterval has been elapsed.
            // Checks if new deposit has been created by the DepositAPplicationService and DepositAddress marked used
            if (_shouldRunTests)
            {
                ICoinClientService coinClientService =
                    (ICoinClientService)ContextRegistry.GetContext()["BitcoinClientService"];
                IFundsPersistenceRepository fundsPersistenceRepository =
                    (IFundsPersistenceRepository)ContextRegistry.GetContext()["FundsPersistenceRepository"];
                IDepositAddressRepository depositAddressRepository =
                    (IDepositAddressRepository)ContextRegistry.GetContext()["DepositAddressRepository"];
                IDepositRepository depositRepository =
                    (IDepositRepository)ContextRegistry.GetContext()["DepositRepository"];

                Currency       currency       = new Currency("BTC", true);
                AccountId      accountId      = new AccountId(1);
                string         newAddress     = coinClientService.CreateNewAddress();
                BitcoinAddress bitcoinAddress = new BitcoinAddress(newAddress);
                DepositAddress depositAddress = new DepositAddress(currency, bitcoinAddress,
                                                                   AddressStatus.New, DateTime.Now, accountId);
                fundsPersistenceRepository.SaveOrUpdate(depositAddress);

                // Check that there is no deposit with htis address present
                List <Deposit> deposits = depositRepository.GetDepositsByBitcoinAddress(bitcoinAddress);
                Assert.AreEqual(0, deposits.Count);

                ManualResetEvent manualResetEvent = new ManualResetEvent(false);

                // Wait for the first interval to elapse, and then withdraw, because only then we will be able to figure if a
                // new transaction has been received
                manualResetEvent.WaitOne(Convert.ToInt32(coinClientService.PollingInterval + 3000));

                manualResetEvent.Reset();
                bool eventFired = false;
                coinClientService.DepositArrived += delegate(string curr, List <Tuple <string, string, decimal, string> > pendingList)
                {
                    eventFired = true;
                    manualResetEvent.Set();
                };

                Withdraw withdraw = new Withdraw(currency, Guid.NewGuid().ToString(), DateTime.Now, WithdrawType.Bitcoin,
                                                 Amount, 0.001m, TransactionStatus.Pending, accountId,
                                                 new BitcoinAddress(newAddress));
                string withdrawTransactionId = coinClientService.CommitWithdraw(withdraw.BitcoinAddress.Value, withdraw.Amount);
                Assert.IsNotNull(withdrawTransactionId);
                Assert.IsFalse(string.IsNullOrEmpty(withdrawTransactionId));
                manualResetEvent.WaitOne();

                Assert.IsTrue(eventFired);
                depositAddress = depositAddressRepository.GetDepositAddressByAddress(bitcoinAddress);
                Assert.IsNotNull(depositAddress);
                Assert.AreEqual(AddressStatus.Used, depositAddress.Status);

                // See If DepositApplicationService created the deposit instance
                deposits = depositRepository.GetDepositsByBitcoinAddress(bitcoinAddress);
                Deposit deposit = deposits.Single();
                Assert.IsNotNull(deposit);
                Assert.AreEqual(Amount, deposit.Amount);
                Assert.AreEqual(currency.Name, deposit.Currency.Name);
                Assert.IsFalse(string.IsNullOrEmpty(deposit.TransactionId.Value));
                Assert.AreEqual(bitcoinAddress.Value, deposit.BitcoinAddress.Value);
                Assert.AreEqual(DepositType.Default, deposit.Type);
                Assert.AreEqual(0, deposit.Confirmations);
                Assert.AreEqual(accountId.Value, deposit.AccountId.Value);
                Assert.AreEqual(TransactionStatus.Pending, deposit.Status);

                Assert.AreEqual(withdrawTransactionId, deposit.TransactionId.Value);
            }
        }