From 1d937cb7f7fe8d87efa0bb2ef945c58a76d18f2d Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Wed, 17 Jan 2024 15:01:27 -0300 Subject: [PATCH 1/3] tree: add extracted test case from TestRandom showing Delete(...) failure Signed-off-by: Ignacio Hagopian --- tree_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tree_test.go b/tree_test.go index a9b665d8..79ac064f 100644 --- a/tree_test.go +++ b/tree_test.go @@ -1806,3 +1806,36 @@ func TestRandom(t *testing.T) { t.Fatal(err) } } + +func TestRandomExtracted(t *testing.T) { + t.Parallel() + + k1490, _ := hex.DecodeString("1490d65886f02ffa1a7dca88187dc8176ada23221c83e9f7da9e15c27d0b813d") + val_k1490_0, _ := hex.DecodeString("3a8ee0370c16ba642123f80692ee63ade4477fce3bf0c68b638e189a014d8b04") + k1413, _ := hex.DecodeString("1413dabef075cc47d380d740f7b24050568659c809830b1affbc765b7b651e1e") + val_k1413_0, _ := hex.DecodeString("7469fa29e0d049e80eed8f99f2418bc36ebc3c3b3041515fd519701d60f86b9f") + val_k1413_1, _ := hex.DecodeString("79702b187fa6f75ecd7cad23a2cafc3b13976dcefd99c3ff479300655ef9ef92") + + root := New() + + if err := root.Insert(k1490, val_k1490_0, nil); err != nil { + panic(err) + } + if err := root.Insert(k1413, val_k1413_0, nil); err != nil { + panic(err) + } + if _, err := root.Delete(k1413, nil); err != nil { + panic(err) + } + if err := root.Insert(k1413, val_k1413_1, nil); err != nil { + panic(err) + } + + val, err := root.Get(k1490, nil) + if err != nil { + t.Fatalf("error getting key: %v", err) + } + if !bytes.Equal(val, val_k1490_0) { + t.Fatalf("got %x, expected %x", val, val_k1490_0) + } +} From a0280d2446fc0c4c8ead440aa641d11018336423 Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Wed, 17 Jan 2024 15:01:42 -0300 Subject: [PATCH 2/3] tree: fix Delete(...) api Signed-off-by: Ignacio Hagopian --- tree.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tree.go b/tree.go index 0e314e58..b26d6989 100644 --- a/tree.go +++ b/tree.go @@ -618,7 +618,7 @@ func (n *InternalNode) Delete(key []byte, resolver NodeResolverFn) (bool, error) // as well. for _, c := range n.children { if _, ok := c.(Empty); !ok { - break + return false, nil } } From f491e4f9e0c338e0688855048c17a16e4b393c3d Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Wed, 17 Jan 2024 15:19:01 -0300 Subject: [PATCH 3/3] tree: further simplify test case Signed-off-by: Ignacio Hagopian --- tree_test.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tree_test.go b/tree_test.go index 79ac064f..8a6849ee 100644 --- a/tree_test.go +++ b/tree_test.go @@ -1814,21 +1814,17 @@ func TestRandomExtracted(t *testing.T) { val_k1490_0, _ := hex.DecodeString("3a8ee0370c16ba642123f80692ee63ade4477fce3bf0c68b638e189a014d8b04") k1413, _ := hex.DecodeString("1413dabef075cc47d380d740f7b24050568659c809830b1affbc765b7b651e1e") val_k1413_0, _ := hex.DecodeString("7469fa29e0d049e80eed8f99f2418bc36ebc3c3b3041515fd519701d60f86b9f") - val_k1413_1, _ := hex.DecodeString("79702b187fa6f75ecd7cad23a2cafc3b13976dcefd99c3ff479300655ef9ef92") root := New() if err := root.Insert(k1490, val_k1490_0, nil); err != nil { - panic(err) + t.Fatalf("error inserting key: %v", err) } if err := root.Insert(k1413, val_k1413_0, nil); err != nil { - panic(err) + t.Fatalf("error inserting key: %v", err) } if _, err := root.Delete(k1413, nil); err != nil { - panic(err) - } - if err := root.Insert(k1413, val_k1413_1, nil); err != nil { - panic(err) + t.Fatalf("error deleting key: %v", err) } val, err := root.Get(k1490, nil)