diff --git a/NineChronicles.Headless.Tests/GraphTypes/TransactionHeadlessQueryTest.cs b/NineChronicles.Headless.Tests/GraphTypes/TransactionHeadlessQueryTest.cs index a3bd08316..0d61007b5 100644 --- a/NineChronicles.Headless.Tests/GraphTypes/TransactionHeadlessQueryTest.cs +++ b/NineChronicles.Headless.Tests/GraphTypes/TransactionHeadlessQueryTest.cs @@ -9,6 +9,7 @@ using GraphQL; using GraphQL.Execution; using GraphQL.NewtonsoftJson; +using Lib9c; using Libplanet; using Libplanet.Action; using Libplanet.Action.Loader; @@ -340,6 +341,30 @@ public async Task TransactionResultIsSuccess() var txStatus = (string)((Dictionary)transactionResult)["txStatus"]; Assert.Equal("SUCCESS", txStatus); } + + [Fact] + public async Task NcTransactionsOnTip() + { + var privateKey = new PrivateKey(); + var action = new TransferAsset(default, default, Currencies.Crystal * 1); + Transaction tx = _blockChain.MakeTransaction(privateKey, new ActionBase[] { action }); + + Block block = _blockChain.ProposeBlock(_proposer); + _blockChain.Append(block, GenerateBlockCommit(block.Index, block.Hash, _proposer)); + Assert.Equal(_blockChain.Tip.Index, 1); + var query = @"query { + ncTransactions(startingBlockIndex: 1, actionType: ""^transfer_asset.*$"", limit: 1) { + id + } + }"; + var result = await ExecuteAsync(query); + Assert.NotNull(result.Data); + var ncTransactions = + (object[])( + ((Dictionary)((ExecutionNode)result.Data!).ToValue()!)["ncTransactions"]); + var ncTransaction = Assert.IsType>(Assert.Single(ncTransactions)); + Assert.Equal(tx.Id.ToString(), ncTransaction["id"]); + } private Task ExecuteAsync(string query) { diff --git a/NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs b/NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs index 86f227fe0..8474db53d 100644 --- a/NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs +++ b/NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs @@ -319,7 +319,7 @@ private IEnumerable ListBlocks(BlockChain chain, long from, long limit) return new List(); } - var count = (int)Math.Min(limit, chain.Tip.Index - from); + var count = (int)Math.Min(limit, chain.Tip.Index - from + 1); var blocks = Enumerable.Range(0, count) .ToList() .AsParallel()