Skip to content

Commit

Permalink
Fix ncTransactions bug when startingBlockIndex is the same as the…
Browse files Browse the repository at this point in the history
… tip index
  • Loading branch information
moreal committed Nov 17, 2023
1 parent 9aa46cd commit 8e2de2a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using GraphQL;
using GraphQL.Execution;
using GraphQL.NewtonsoftJson;
using Lib9c;
using Libplanet;
using Libplanet.Action;
using Libplanet.Action.Loader;
Expand Down Expand Up @@ -340,6 +341,30 @@ public async Task TransactionResultIsSuccess()
var txStatus = (string)((Dictionary<string, object>)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<string, object>)((ExecutionNode)result.Data!).ToValue()!)["ncTransactions"]);
var ncTransaction = Assert.IsType<Dictionary<string, object>>(Assert.Single(ncTransactions));
Assert.Equal(tx.Id.ToString(), ncTransaction["id"]);
}

private Task<ExecutionResult> ExecuteAsync(string query)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ private IEnumerable<Block> ListBlocks(BlockChain chain, long from, long limit)
return new List<Block>();
}

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()
Expand Down

0 comments on commit 8e2de2a

Please sign in to comment.