public async Task <EstimateTransactionResponse> EstimateTransferCoinsAsync(EstimateTransferCoinsTransactionRequest 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) }
            //     }
            // );


            throw new System.NotImplementedException();
        }
示例#2
0
        public async Task Estimate_transfer_coins_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_coins_transaction)}";
                aggregator.HealthProvider.Setup(x => x.GetDiseaseAsync()).ReturnsAsync(Disease);
                aggregator.TransferCoinsTransactionsEstimator
                .Setup(x => x.EstimateTransferCoinsAsync(It.IsAny <EstimateTransferCoinsTransactionRequest>()))
                .ReturnsAsync(new EstimateTransactionResponse(fees));
            });

            //ACT
            var coinsToSpend = new[]
            {
                new CoinToSpend(new CoinId("tx1", 0),
                                new Asset("assetId"),
                                UMoney.Create(1000, 4),
                                new Address("0x1"),
                                Base64String.Encode("context"),
                                1),
            };
            var coinsToReceive = new[]
            {
                new CoinToReceive(0,
                                  new Asset("assetId"),
                                  UMoney.Create(1000, 4),
                                  new Address("0x2"),
                                  new AddressTag("tag"),
                                  AddressTagType.Text
                                  ),
            };

            var request = new EstimateTransferCoinsTransactionRequest(coinsToSpend, coinsToReceive);
            var result  = await client.EstimateTransferCoinsTransactionAsync(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);
        }
示例#3
0
        public void Bad_request_estimate_transfer_coins_transaction()
        {
            //ARRANGE
            var client = PrepareClient <AppSettings>((options) =>
            {
                var aggregator = CreateMocksAndSetupFactories(options);

                options.IntegrationName =
                    $"{nameof(TransactionExecutorClientTests)}+{nameof(Bad_request_estimate_transfer_coins_transaction)}";
                aggregator.HealthProvider.Setup(x => x.GetDiseaseAsync()).ReturnsAsync(Disease);
                aggregator.TransferCoinsTransactionsEstimator
                .Setup(x => x.EstimateTransferCoinsAsync(It.IsAny <EstimateTransferCoinsTransactionRequest>()))
                .ThrowsAsync(new RequestValidationException("some error"));
            });

            //ACT && ASSERT
            var coinsToSpend = new[]
            {
                new CoinToSpend(new CoinId("tx1", 0),
                                new Asset("assetId"),
                                UMoney.Create(1000, 4),
                                new Address("0x1"),
                                Base64String.Encode("context"),
                                1),
            };
            var coinsToReceive = new[]
            {
                new CoinToReceive(0,
                                  new Asset("assetId"),
                                  UMoney.Create(1000, 4),
                                  new Address("0x2"),
                                  new AddressTag("tag"),
                                  AddressTagType.Text
                                  ),
            };

            Assert.ThrowsAsync <BadRequestWebApiException>(async() =>
            {
                var request = new EstimateTransferCoinsTransactionRequest(coinsToSpend, coinsToReceive);
                await client.EstimateTransferCoinsTransactionAsync(request);
            });
        }
        public async Task <ActionResult <EstimateTransactionResponse> > EstimateTransferCoins([FromBody] EstimateTransferCoinsTransactionRequest request)
        {
            var response = await _transferCoinsTransactionsEstimator.EstimateTransferCoinsAsync(request);

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

            return(Ok(response));
        }
示例#5
0
 public Task <EstimateTransactionResponse> EstimateTransferCoinsAsync(EstimateTransferCoinsTransactionRequest request)
 {
     throw new OperationNotSupportedException("Integration does not support \"Transfer coins\" transactions model.");
 }