Esempio n. 1
0
        public void Bad_request_while_estimating_transfer_amount_transaction()
        {
            //ARRANGE
            var client = PrepareClient <AppSettings>((options) =>
            {
                var aggregator = CreateMocksAndSetupFactories(options);

                options.IntegrationName = $"{nameof(TransactionExecutorClientTests)}+{nameof(Bad_request_while_estimating_transfer_amount_transaction)}";
                aggregator.HealthProvider.Setup(x => x.GetDiseaseAsync()).ReturnsAsync(Disease);
                aggregator.TransactionEstimator.Setup(x => x.EstimateTransferAmountAsync(It.IsAny <EstimateTransferAmountTransactionRequest>()))
                .ThrowsAsync(new RequestValidationException("Not VALID"));
            });

            //ACT && ASSERT
            Assert.ThrowsAsync <BadRequestWebApiException>(async() =>
            {
                var transfers = new[]
                {
                    new Transfer(
                        new Asset("asset"),
                        UMoney.Create(1000000000, 4),
                        new Address("x1"),
                        new Address("x2")),
                };
                var request = new EstimateTransferAmountTransactionRequest(transfers);
                await client.EstimateTransferAmountTransactionAsync(request);
            });
        }
Esempio n. 2
0
        public async Task <EstimateTransactionResponse> EstimateTransferAmountAsync(EstimateTransferAmountTransactionRequest request)
        {
            // TODO: estimate transaction fees.
            //
            // Throw:
            // - Lykke.Bil2.Contract.Common.Exceptions.RequestValidationException:
            //     if a transaction can’t be estimated with the given parameters
            //     and it will be never possible to estimate the transaction with exactly the same
            //     parameters.
            //
            // - System.Exception:
            //     if there are any other errors.
            //     Likely a temporary issue with infrastructure or configuration,
            //     request should be repeated later.
            //
            // Result usually consists of single fee element,
            // but for some blockchains fees may be charged in multiple currencies/tokens.
            //
            // For example:
            //
            // var fee = ...;
            //
            // return new EstimateTransactionResponse
            // (
            //     new []
            //     {
            //         new Fee { new Asset("BTC"), UMoney.Create(fee, 8) }
            //     }
            // );
            //
            // If you can map error to the TransactionEstimationError, return EstimateTransactionResponse
            // with an error specified. Return calculated fee as well, if it's possible for particular error.
            //
            // For example:
            //
            // return new EstimateTransactionResponse
            // (
            //     new []
            //     {
            //         new Fee { new Asset("BTC"), UMoney.Create(fee, 8) }
            //     },
            //     new TransactionEstimationFailure
            //     (
            //         TransactionEstimationError.NotEnoughBalance,
            //         $"There is not enough balance on address {address}"
            //     )
            // );
            //

            throw new System.NotImplementedException();
        }
Esempio n. 3
0
        public Task <EstimateTransactionResponse> EstimateTransferAmountAsync(EstimateTransferAmountTransactionRequest request)
        {
            if (request.Transfers.Count > 1)
            {
                throw new RequestValidationException("Only single transfer is supported", request.Transfers.Count, nameof(request.Transfers.Count));
            }

            var fee = (UMoney)(request.Transfers.Single().Amount * 0.00001M);

            return(Task.FromResult(new EstimateTransactionResponse
                                   (
                                       new[]
            {
                new Fee
                (
                    request.Transfers.Single().Asset,
                    UMoney.Round(fee, 6)
                )
            }
                                   )));
        }
Esempio n. 4
0
        public async Task Estimate_transfer_amount_transaction()
        {
            //ARRANGE
            var fees = new[]
            {
                new Fee(new Asset("asset"), UMoney.Create(1000, 4))
            };

            var client = PrepareClient <AppSettings>((options) =>
            {
                var aggregator = CreateMocksAndSetupFactories(options);

                options.IntegrationName = $"{nameof(TransactionExecutorClientTests)}+{nameof(Estimate_transfer_amount_transaction)}";
                aggregator.HealthProvider.Setup(x => x.GetDiseaseAsync()).ReturnsAsync(Disease);
                aggregator.TransactionEstimator.Setup(x => x.EstimateTransferAmountAsync(It.IsAny <EstimateTransferAmountTransactionRequest>()))
                .ReturnsAsync(new EstimateTransactionResponse(fees));
            });

            //ACT
            var transfers = new[]
            {
                new Transfer(
                    new Asset("asset"),
                    UMoney.Create(1000000000, 4),
                    new Address("x1"),
                    new Address("x2")),
            };
            var request = new EstimateTransferAmountTransactionRequest(transfers);
            var result  = await client.EstimateTransferAmountTransactionAsync(request);

            //ASSERT
            Assert.NotNull(result);

            var estimation = result.EstimatedFees.SingleOrDefault();

            Assert.NotNull(estimation);
            Assert.AreEqual(new Asset("asset"), estimation.Asset);
            Assert.AreEqual(UMoney.Create(1000, 4), estimation.Amount);
        }
        public async Task <ActionResult <EstimateTransactionResponse> > EstimateTransferAmount([FromBody] EstimateTransferAmountTransactionRequest request)
        {
            var response = await _transferAmountTransactionsEstimator.EstimateTransferAmountAsync(request);

            if (response == null)
            {
                throw new InvalidOperationException("Not null response object expected");
            }

            return(Ok(response));
        }
Esempio n. 6
0
 public Task <EstimateTransactionResponse> EstimateTransferAmountAsync(EstimateTransferAmountTransactionRequest request)
 {
     throw new OperationNotSupportedException("Integration does not support \"Transfer amount\" transactions model.");
 }