Skip to content

Commit

Permalink
Bugfix on Remove method.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodoufu committed Nov 13, 2018
1 parent 65f6113 commit 9cdd257
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion NeoDataStructure/MerklePatricia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,11 @@ private string Remove(string nodeHash, string path)
{
if (node[node.Length - 1] == null)
{
var innerNode = _db[node[indexInnerNode]];
var innerNodeHash = node[indexInnerNode];
var innerNode = _db[innerNodeHash];
if (innerNode.Length == LeafSize)
{
_db.Remove(innerNodeHash);
node = new[]
{
2 + innerNode[0].Length % 2 + "" + indexInnerNode + innerNode[0].Substring(1),
Expand Down
6 changes: 6 additions & 0 deletions NeoDataStructureTest/MerklePatriciaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ void RemoverTestar(string x, string y)
Assert.True(mp.Remove("a123"));
// TODO Solve problem on the remove method, not removing from _db
Assert.Equal(1, mp.Count());
Assert.False(mp.ContainsKey("a123"));
Assert.True(mp.ContainsKey("123"));
Assert.True(mp.ContainsKey("123"));

var mp2 = new MerklePatricia {["123"] = "abc"};
Assert.Equal(mp2, mp);
}

[Fact]
Expand Down

0 comments on commit 9cdd257

Please sign in to comment.