public async Task DataService_SearchTransactionByBlockAndEthAddress_should_return_one_tx()
        {
            BlockData blockData = new BlockData
            {
                Difficulty   = "1",
                Transactions = new Transaction[]
                {
                    new Transaction {
                        From = "0x29d7d1dd5b6f9c864d9db560d72a247c178ae86b"
                    },
                    new Transaction {
                        From = "0x29d7d1dd5b6f9c864d9db560d72a247c178ae86c"
                    }
                }
            };
            var dataResp = new DataResponse <BlockData>
            {
                Result = blockData
            };

            ApiResult <DataResponse <BlockData> > ss = new Core.Api.ApiResult <DataResponse <BlockData> >(dataResp);
            var @params = new EthBlockScanRequestParam("2.0", "eth_getBlockByNumber", new object[] { $"0x{1.ToString("X")}", true }, 1);

            _apiService.Setup(p => p.Execute(ApiUrls.GetTransactions, @params)).Returns(() => Task.FromResult(ss));

            _dataService = new BlockDataService(_logger.Object, _apiService.Object);
            var result = await _dataService.SearchTransactionByBlockAndEthAddress(@params, "0x29d7d1dd5b6f9c864d9db560d72a247c178ae86b");

            Assert.NotNull(result);
            Assert.Equal(1, result.Count);
        }
        public async Task DataService_SearchTransactionByBlockAndEthAddress_should_fire_KeyNotFoundException()
        {
            ApiResult <DataResponse <BlockData> > ss = new Core.Api.ApiResult <DataResponse <BlockData> >(new DataResponse <BlockData>());
            var @params = new EthBlockScanRequestParam("2.0", "eth_getBlockByNumber", new object[] { $"0x{1.ToString("X")}", true }, 1);

            _apiService.Setup(p => p.Execute(ApiUrls.GetTransactions, @params)).Returns(() => Task.FromResult(ss));

            _dataService = new BlockDataService(_logger.Object, _apiService.Object);
            await Assert.ThrowsAsync <KeyNotFoundException>(async() => await _dataService.SearchTransactionByBlockAndEthAddress(@params, ""));
        }
예제 #3
0
        public async Task <IActionResult> Post([FromBody] BlockScanRequest request)
        {
            int.TryParse(request.BlockId, out int blockId);

            var @params = new EthBlockScanRequestParam("2.0", "eth_getBlockByNumber", new object[] { $"0x{blockId.ToString("X")}", true }, 1);

            var result = await _blockDataService.SearchTransactionByBlockAndEthAddress(@params, request.EthAddress);

            if (result == null || !result.Any())
            {
                return(NotFound());
            }

            return(Ok(_mapper.Map <List <TransactionDTO> >(result)));
        }