public async Task <EthereumTransactionSearchResult> Search( EthereumTransactionSearchRequest searchRequest) { var result = new EthereumTransactionSearchResult(); IEnumerable <EthereumTransaction> transactions; try { transactions = await _ethereumService.GetTransactionsByBlockNumberAsync( searchRequest.BlockNumberNumerical); } catch { // if we got here, we possibly encountered a transient error result.TransientError = true; return(result); } // filter transactions down if they are associated with an address var addressToMatch = searchRequest.Address.Trim(); transactions = transactions .Where(t => t.To == addressToMatch || t.From == addressToMatch); // map transactions to DTO model foreach (var transaction in transactions) { var dtoTransaction = _mapper.Map(transaction); result.Transactions.Add(dtoTransaction); } return(result); }
public async Task TransactionSearch_EmptySearchResult_ShouldSucceed() { var mapper = new EthereumTransactionMapper(); var ethereumServiceMock = new Mock <IEthereumService>(); // mock returning an empty list ethereumServiceMock.Setup(s => s.GetTransactionsByBlockNumberAsync(It.IsAny <long>())) .ReturnsAsync(new List <EthereumTransaction>()); var action = new EthereumTransactionSearchActionHandler(ethereumServiceMock.Object, mapper); var searchRequest = new EthereumTransactionSearchRequest { Address = "0x12345", BlockNumber = "12345" }; // act var actual = await action.Search(searchRequest); // assert Assert.NotNull(actual); Assert.Empty(actual.Transactions); Assert.False(actual.TransientError); }
public async Task TransactionSearch_ShouldMatchOneTransaction_UsingToField(string addressToMatch) { var mapper = new EthereumTransactionMapper(); var ethereumServiceMock = new Mock <IEthereumService>(); // mock returning a list of transactions var transactions = TestFactory.MakeMockTransactions(); ethereumServiceMock.Setup(s => s.GetTransactionsByBlockNumberAsync(It.IsAny <long>())) .ReturnsAsync(transactions); var action = new EthereumTransactionSearchActionHandler(ethereumServiceMock.Object, mapper); var searchRequest = new EthereumTransactionSearchRequest { Address = addressToMatch, BlockNumber = "0x8b99c9" }; // act var actual = await action.Search(searchRequest); // assert Assert.NotNull(actual); Assert.Single(actual.Transactions); Assert.False(actual.TransientError); }
public async Task TransactionSearch_ThrowException_ShouldReturnEmpty() { var mapper = new EthereumTransactionMapper(); var ethereumServiceMock = new Mock <IEthereumService>(); // mock returning a list of transactions var transactions = TestFactory.MakeMockTransactions(); ethereumServiceMock.Setup(s => s.GetTransactionsByBlockNumberAsync(It.IsAny <long>())) .ThrowsAsync(new HttpRequestException()); var action = new EthereumTransactionSearchActionHandler(ethereumServiceMock.Object, mapper); var searchRequest = new EthereumTransactionSearchRequest { Address = "invalidAddress", BlockNumber = "0x8b99c9" }; // act var actual = await action.Search(searchRequest); // assert Assert.NotNull(actual); Assert.Empty(actual.Transactions); Assert.True(actual.TransientError); }