示例#1
0
        public void ShouldUseRefferalOwnerDiscount()
        {
            // Arrange
            var currentTotal  = 20_000_000M;
            var amountUsd     = 1M;
            var txDateTimeUtc = DateTime.Now.ToUniversalTime().AddDays(14);

            var settings = _campaignSettings.Clone();

            settings.EnableReferralProgram = true;
            settings.ReferralOwnerDiscount = 15;

            var investor = _investor.Clone();

            investor.ReferralsNumber     = 1;
            investor.ReferralCodeApplied = "";

            // Act
            var priceList = TokenPrice.GetPriceList(settings, investor, txDateTimeUtc, amountUsd, currentTotal);

            // Assert
            Assert.Single(priceList);
            Assert.Equal("ReferralOwnerDiscount", priceList[0].Phase);
            Assert.Equal(0.8500M, priceList[0].Price);
            Assert.Equal(1.1764M, priceList[0].Count);
        }
示例#2
0
        public void ShouldReturnZeroPriceIfOutOfDates()
        {
            // Arrange
            var currentTotal  = 1000M;
            var amountUsd     = 1M;
            var txDateTimeUtc = DateTime.Now.AddDays(-20).ToUniversalTime();

            // Act
            var priceList = TokenPrice.GetPriceList(_campaignSettings, _investor, txDateTimeUtc, amountUsd, currentTotal);

            // Assert
            Assert.Null(priceList);
        }
示例#3
0
        public void ShouldReturnZeroCountButCorrectPriceIfAmountUsdIsZero()
        {
            // Arrange
            var currentTotal  = 0M;
            var amountUsd     = 0M;
            var txDateTimeUtc = DateTime.Now.ToUniversalTime();

            // Act
            var priceList = TokenPrice.GetPriceList(_campaignSettings, _investor, txDateTimeUtc, amountUsd, currentTotal);

            // Assert
            Assert.Single(priceList);
            Assert.Equal(0M, priceList[0].Count);
            Assert.Equal(0.75M, priceList[0].Price);
        }
示例#4
0
        public void ShouldReturn80PercentOfBasePrice()
        {
            // Arrange
            //  - Then, for the first 24 hours of the crowd sale, tokens will be sold at a 20% discount
            var currentTotal  = 20_000_000M;
            var amountUsd     = 1M;
            var txDateTimeUtc = DateTime.Now.ToUniversalTime();

            // Act
            var priceList = TokenPrice.GetPriceList(_campaignSettings, _investor, txDateTimeUtc, amountUsd, currentTotal);

            // Assert
            Assert.Single(priceList);
            Assert.Equal(0.8000M, priceList[0].Price);
            Assert.Equal(1.2500M, priceList[0].Count);
        }
示例#5
0
        public void ShouldReturn75PercentOfBasePrice()
        {
            // Arrange
            // - First 20,000,000 tokens will be sold at 25% discount
            var currentTotal  = 0M;
            var amountUsd     = 1M;
            var txDateTimeUtc = DateTime.Now.ToUniversalTime();

            // Act
            var priceList = TokenPrice.GetPriceList(_campaignSettings, _investor, txDateTimeUtc, amountUsd, currentTotal);

            // Assert
            Assert.Single(priceList);
            Assert.Equal(0.7500M, priceList[0].Price);
            Assert.Equal(1.3333M, priceList[0].Count);
        }
示例#6
0
        public void ShouldReturn85PercentOfBasePrice()
        {
            // Arrange
            // - Thereafter and for one week, tokens will be sold at a 15% discount
            var currentTotal  = 20_000_000M;
            var amountUsd     = 1M;
            var txDateTimeUtc = DateTime.Now.ToUniversalTime().AddDays(1);

            // Act
            var priceList = TokenPrice.GetPriceList(_campaignSettings, _investor, txDateTimeUtc, amountUsd, currentTotal);

            // Assert
            Assert.Single(priceList);
            Assert.Equal(0.8500M, priceList[0].Price);
            Assert.Equal(1.1764M, priceList[0].Count);
        }
示例#7
0
        public void ShouldReturnFullBasePrice()
        {
            // Arrange
            // - No discount will be granted the final week of the crowd sale
            var currentTotal  = 20000000M;
            var amountUsd     = 1M;
            var txDateTimeUtc = DateTime.Now.ToUniversalTime().AddDays(14);

            // Act
            var priceList = TokenPrice.GetPriceList(_campaignSettings, _investor, txDateTimeUtc, amountUsd, currentTotal);


            // Assert
            Assert.Single(priceList);
            Assert.Equal(1M, priceList[0].Price);
            Assert.Equal(1M, priceList[0].Count);
        }
示例#8
0
        public void ShouldReturnTwoPricesIfCrossingAmountThreshold()
        {
            // Arrange
            //  - First 20,000,000 tokens will be sold at 25% discount
            //  - Then, for the first 24 hours of the crowd sale, tokens will be sold at a 20% discount
            var currentTotal  = 19_999_999M;
            var amountUsd     = 1M;
            var txDateTimeUtc = DateTime.Now.ToUniversalTime();

            // Act
            var priceList = TokenPrice.GetPriceList(_campaignSettings, _investor, txDateTimeUtc, amountUsd, currentTotal);

            // Assert
            Assert.Equal(2, priceList.Count);
            Assert.Equal(0.7500M, priceList[0].Price);
            Assert.Equal(1.0000M, priceList[0].Count);
            Assert.Equal(0.8000M, priceList[1].Price);
            Assert.Equal(0.3125M, priceList[1].Count);
        }
示例#9
0
        private async Task<InvestorTransaction> SaveTransaction(TransactionMessage msg, 
            ICampaignSettings settings, decimal soldTokensAmount)
        {
            var investor = await _investorRepository.GetAsync(msg.Email);
            var exchangeRate = await GetExchangeRate(msg);
            var avgExchangeRate = Convert.ToDecimal(exchangeRate.AverageRate);
            var amountUsd = msg.Amount * avgExchangeRate;
            var tokenPriceList = TokenPrice.GetPriceList(settings, investor, msg.CreatedUtc, 
                amountUsd, soldTokensAmount);
            var amountToken = tokenPriceList.Sum(p => p.Count);
            var tokenPrice = tokenPriceList.Count == 1 ? tokenPriceList[0].Price : (amountUsd / amountToken);

            var tx = new InvestorTransaction
            {
                Email = msg.Email,
                UniqueId = msg.UniqueId,
                CreatedUtc = msg.CreatedUtc,
                Currency = msg.Currency,
                TransactionId = msg.TransactionId,
                BlockId = msg.BlockId,
                PayInAddress = msg.PayInAddress,
                Amount = msg.Amount,
                AmountUsd = amountUsd,
                AmountToken = amountToken,
                Fee = msg.Fee,
                TokenPrice = tokenPrice,
                TokenPriceContext = tokenPriceList.ToJson(),
                ExchangeRate = avgExchangeRate,
                ExchangeRateContext = exchangeRate.Rates.ToJson()
            };

            await _log.WriteInfoAsync(nameof(SaveTransaction),
                $"tx: {tx.ToJson()}", $"Save transaction");

            await _investorTransactionRepository.SaveAsync(tx);

            return tx;
        }