示例#1
0
        public async Task MonitoringOperationJobUnitTest_SkipIfNoBalance()
        {
            string operationId = Guid.NewGuid().ToString();
            OperationHashMatchMessage message = new OperationHashMatchMessage()
            {
                OperationId     = operationId,
                PutDateTime     = DateTime.UtcNow,
                TransactionHash = null
            };

            #region Arrange Mocks
            IPendingOperation pendingOperation = new PendingOperation()
            {
                Amount             = "1000000000000000000",
                FromAddress        = "fromAddress",
                OperationId        = operationId,
                OperationType      = OperationTypes.Transfer,
                ToAddress          = "toAddress",
                CoinAdapterAddress = "coinAdapter",
            };

            _pendingOperationService.Setup(x => x.GetOperationAsync(pendingOperation.OperationId)).Returns(Task.FromResult(pendingOperation));
            _transferContractService.Setup(x => x.GetBalanceOnAdapter(pendingOperation.CoinAdapterAddress, pendingOperation.FromAddress, true))
            .Returns(Task.FromResult(new BigInteger(0)));
            _coinEventService.Setup(x => x.PublishEvent(It.IsAny <ICoinEvent>(), It.IsAny <bool>())).Returns(Task.FromResult(0)).Verifiable();

            #endregion

            MonitoringOperationJob job = GetJob();
            await job.Execute(message, new Lykke.JobTriggers.Triggers.Bindings.QueueTriggeringContext(DateTimeOffset.UtcNow));

            _coinEventService.Verify(x => x.PublishEvent(It.IsAny <ICoinEvent>(), It.IsAny <bool>()), Times.Never);
        }
示例#2
0
        static async Task SendTransactionFromMainExchange()
        {
            string operationId = "";
            IPendingOperationService pendingOperationService = ServiceProvider.GetService <IPendingOperationService>();

            try
            {
                MonitoringOperationJob   job = ServiceProvider.GetService <MonitoringOperationJob>();
                IExchangeContractService exchangeContractService = ServiceProvider.GetService <IExchangeContractService>();
                string        filePath    = Path.Combine(AppContext.BaseDirectory, "transferTransaction.txt");
                var           content     = File.ReadAllText(filePath);
                TransferModel model       = Newtonsoft.Json.JsonConvert.DeserializeObject <TransferModel>(content);
                var           addressUtil = new AddressUtil();
                BigInteger    amount      = BigInteger.Parse(model.Amount);
                operationId = await pendingOperationService.TransferWithNoChecks(model.Id, model.CoinAdapterAddress,
                                                                                 addressUtil.ConvertToChecksumAddress(model.FromAddress), addressUtil.ConvertToChecksumAddress(model.ToAddress), amount, model.Sign);

                Console.WriteLine($"OperationId - {operationId}");
                await job.ProcessOperation(new Services.New.Models.OperationHashMatchMessage()
                {
                    OperationId = operationId,
                }, null, exchangeContractService.TransferWithoutSignCheck);

                Console.WriteLine("Start removing from processing queue");
                await pendingOperationService.RemoveFromPendingOperationQueue(operationId);

                Console.WriteLine("Stop removing from processing queue");
            }
            catch (Exception e)
            {
                Console.WriteLine($"{e.Message} - {e.StackTrace}");
                Console.WriteLine("Start removing from processing queue");
                await pendingOperationService.RemoveFromPendingOperationQueue(operationId);

                Console.WriteLine("Stop removing from processing queue");
            }
        }