public void Node_issues_while_building_transfer_amount_transaction() { //ARRANGE var client = PrepareClient <AppSettings>((options) => { var aggregator = CreateMocksAndSetupFactories(options); options.IntegrationName = $"{nameof(TransactionExecutorClientTests)}+{nameof(Node_issues_while_building_transfer_amount_transaction)}"; aggregator.HealthProvider.Setup(x => x.GetDiseaseAsync()).ReturnsAsync(Disease); aggregator.TransferAmountTransactionBuilder.Setup(x => x.BuildTransferAmountAsync(It.IsAny <BuildTransferAmountTransactionRequest>())) .ThrowsAsync( new TransactionBuildingException( TransactionBuildingError.RetryLater, "Node is too busy")); }); //ACT && ASSERT Assert.ThrowsAsync <TransactionBuildingWebApiException>(async() => { var transfers = new[] { new Transfer( new Asset("asset"), UMoney.Create(1000000000, 4), new Address("x1"), new Address("x2")), }; var request = new BuildTransferAmountTransactionRequest(transfers, Array.Empty <Fee>()); await client.BuildTransferAmountTransactionAsync(request); }); }
public async Task Build_transfer_amount_transaction() { //ARRANGE string transactionResponse = "transactionResponse"; var client = PrepareClient <AppSettings>((options) => { var aggregator = CreateMocksAndSetupFactories(options); options.IntegrationName = $"{nameof(TransactionExecutorClientTests)}+{nameof(Build_transfer_amount_transaction)}"; aggregator.HealthProvider.Setup(x => x.GetDiseaseAsync()).ReturnsAsync(Disease); aggregator.TransferAmountTransactionBuilder.Setup(x => x.BuildTransferAmountAsync(It.IsAny <BuildTransferAmountTransactionRequest>())) .ReturnsAsync(new BuildTransactionResponse(Base64String.Encode(transactionResponse))); }); //ACT var transfers = new[] { new Transfer( new Asset("asset"), UMoney.Create(1000000000, 4), new Address("x1"), new Address("x2")), }; var request = new BuildTransferAmountTransactionRequest(transfers, Array.Empty <Fee>()); var result = await client.BuildTransferAmountTransactionAsync(request); //ASSERT Assert.True(result != null); Assert.True(result.TransactionContext.DecodeToString() == transactionResponse); }
public Task <BuildTransactionResponse> BuildTransferAmountAsync(BuildTransferAmountTransactionRequest request) { var entropy = _random.Next(0, 100); if (entropy < 10) { throw new TransactionBuildingException(TransactionBuildingError.RetryLater, "Node is too busy"); } if (request.Transfers.Count > 1) { throw new RequestValidationException("Only single input is supported", request.Transfers.Count, nameof(request.Transfers.Count)); } var context = JsonConvert.SerializeObject(request).ToBase64(); return(Task.FromResult(new BuildTransactionResponse(context))); }
public async Task <BuildTransactionResponse> BuildTransferAmountAsync(BuildTransferAmountTransactionRequest request) { // TODO: prepare data required for signing, return as base58 encoded string // // Throw: // - Lykke.Bil2.Contract.Common.Exceptions.RequestValidationException: // if a transaction can’t be built with the given parameters and // it will be never possible to build the transaction with exactly the same parameters. // // - Lykke.Bil2.Sdk.TransactionsExecutor.Exceptions.SendingTransactionBuildingException: // if a transaction cannot be built and the reason can be mapped // to the Lykke.Bil2.Contract.TransactionsExecutor.SendingTransactionBuildingError // // - Lykke.Bil2.Sdk.Exceptions.OperationNotSupportedException: // if "transfer amount" transactions model is not supported by the blockchain. // // - System.Exception: // if there are any other errors. // Likely a temporary issue with infrastructure or configuration, // request should be repeated later. throw new System.NotImplementedException(); }
public Task <BuildTransactionResponse> BuildTransferAmountAsync(BuildTransferAmountTransactionRequest request) { throw new OperationNotSupportedException("Integration does not support \"Transfer amount\" transactions model."); }
public async Task <ActionResult <BuildTransactionResponse> > BuildTransferAmount([FromBody] BuildTransferAmountTransactionRequest request) { try { var response = await _transferAmountTransactionsBuilder.BuildTransferAmountAsync(request); if (response == null) { throw new InvalidOperationException("Not null response object expected"); } return(Ok(response)); } catch (TransactionBuildingException ex) { var errorResponse = BlockchainErrorResponse.CreateFromCode(ex.Error, ex.Message); return(BadRequest(errorResponse)); } }