diff --git a/NineChronicles.Headless.Tests/GraphTypes/TransactionHeadlessQueryTest.cs b/NineChronicles.Headless.Tests/GraphTypes/TransactionHeadlessQueryTest.cs index a3bd08316..3a6cb5a0d 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; @@ -341,6 +342,30 @@ public async Task TransactionResultIsSuccess() 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(1, _blockChain.Tip.Index); + 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) { var currencyFactory = new CurrencyFactory(() => _blockChain.GetAccountState(_blockChain.Tip.Hash)); 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()