Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileStore.IndexBlockhash return null when index out of range #317

Merged
merged 2 commits into from Jun 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.md
Expand Up @@ -88,9 +88,13 @@ To be released.
- Fixed a bug that `TurnClient` had not stopped properly. [[#287]]
- Fixed a bug that `TurnClient` had been trying to use an already closed
connection. [[#303], [#308]]
- Fixed a bug that `KeyNotFoundException` had been thrown instead of
`ArgumentOutOfRangeException` when `Blockchain<T>[int]` called while the
index of a block that does not exist locally. [[#208], [#317]]


[LiteDB]: https://www.litedb.org/
[#208]: https://github.com/planetarium/libplanet/issues/208
[#267]: https://github.com/planetarium/libplanet/issues/267
[#269]: https://github.com/planetarium/libplanet/pull/269
[#270]: https://github.com/planetarium/libplanet/pull/270
Expand All @@ -112,6 +116,7 @@ To be released.
[#308]: https://github.com/planetarium/libplanet/pull/308
[#309]: https://github.com/planetarium/libplanet/issues/309
[#310]: https://github.com/planetarium/libplanet/pull/310
[#317]: https://github.com/planetarium/libplanet/pull/317


Version 0.3.0
Expand Down
9 changes: 9 additions & 0 deletions Libplanet.Tests/Store/StoreTest.cs
Expand Up @@ -470,5 +470,14 @@ public void TxNonce()
Fx.Store.ListTxNonces(Fx.StoreNamespace).ToDictionary(p => p.Key, p => p.Value)
);
}

[Fact]
public void IndexBlockHashReturnNull()
{
Fx.Store.PutBlock(Fx.Block1);
Fx.Store.AppendIndex(Fx.StoreNamespace, Fx.Block1.Hash);
Assert.Equal(1, Fx.Store.CountIndex(Fx.StoreNamespace));
Assert.Null(Fx.Store.IndexBlockHash(Fx.StoreNamespace, 2));
}
}
}
4 changes: 4 additions & 0 deletions Libplanet/Store/FileStore.cs
Expand Up @@ -362,6 +362,10 @@ long index
return null;
}
}
else if (CountIndex(@namespace) < index)
{
return null;
}

if (!File.Exists(GetIndexPath(@namespace)))
{
Expand Down