Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanchriswhite committed Jul 15, 2024
1 parent e3e6ed5 commit 9ab524a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func TestMerkleRoot_TrieTypes(t *testing.T) {
for i := uint64(0); i < 10; i++ {
require.NoError(t, trie.Update([]byte(fmt.Sprintf("key%d", i)), []byte(fmt.Sprintf("value%d", i)), i))
}
require.NotNil(t, trie.Sum())
require.EqualValues(t, 45, trie.Sum())
require.EqualValues(t, 10, trie.Count())
require.NotNil(t, trie.MustSum())
require.EqualValues(t, 45, trie.MustSum())
require.EqualValues(t, 10, trie.MustCount())

return
}
Expand Down
6 changes: 3 additions & 3 deletions smst_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestExampleSMST(t *testing.T) {
_ = trie.Commit()

// Calculate the total sum of the trie
_ = trie.Sum() // 20
_ = trie.MustSum() // 20

// Generate a Merkle proof for "foo"
proof1, _ := trie.Prove([]byte("foo"))
Expand All @@ -52,8 +52,8 @@ func TestExampleSMST(t *testing.T) {
require.False(t, valid_false1)

// Verify the total sum of the trie
require.EqualValues(t, 20, trie.Sum())
require.EqualValues(t, 20, trie.MustSum())

// Verify the number of non-empty leafs in the trie
require.EqualValues(t, 3, trie.Count())
require.EqualValues(t, 3, trie.MustCount())
}
40 changes: 20 additions & 20 deletions smst_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,36 +359,36 @@ func TestSMST_OrphanRemoval(t *testing.T) {
err = smst.Update([]byte("testKey"), []byte("testValue"), 5)
require.NoError(t, err)
require.Equal(t, 1, nodeCount(t)) // only root node
require.Equal(t, uint64(1), impl.Count())
require.Equal(t, uint64(1), impl.MustCount())
}

t.Run("delete 1", func(t *testing.T) {
setup()
err = smst.Delete([]byte("testKey"))
require.NoError(t, err)
require.Equal(t, 0, nodeCount(t))
require.Equal(t, uint64(0), impl.Count())
require.Equal(t, uint64(0), impl.MustCount())
})

t.Run("overwrite 1", func(t *testing.T) {
setup()
err = smst.Update([]byte("testKey"), []byte("testValue2"), 10)
require.NoError(t, err)
require.Equal(t, 1, nodeCount(t))
require.Equal(t, uint64(1), impl.Count())
require.Equal(t, uint64(1), impl.MustCount())
})

t.Run("overwrite and delete", func(t *testing.T) {
setup()
err = smst.Update([]byte("testKey"), []byte("testValue2"), 2)
require.NoError(t, err)
require.Equal(t, 1, nodeCount(t))
require.Equal(t, uint64(1), impl.Count())
require.Equal(t, uint64(1), impl.MustCount())

err = smst.Delete([]byte("testKey"))
require.NoError(t, err)
require.Equal(t, 0, nodeCount(t))
require.Equal(t, uint64(0), impl.Count())
require.Equal(t, uint64(0), impl.MustCount())
})

type testCase struct {
Expand Down Expand Up @@ -436,29 +436,29 @@ func TestSMST_OrphanRemoval(t *testing.T) {
require.NoError(t, err, tci)
}
require.Equal(t, tc.expectedNodeCount, nodeCount(t), tci)
require.Equal(t, uint64(tc.expectedLeafCount), impl.Count())
require.Equal(t, uint64(tc.expectedLeafCount), impl.MustCount())

// Overwrite doesn't change node or leaf count
for _, key := range tc.keys {
err = smst.Update([]byte(key), []byte("testValue3"), 10)
require.NoError(t, err, tci)
}
require.Equal(t, tc.expectedNodeCount, nodeCount(t), tci)
require.Equal(t, uint64(tc.expectedLeafCount), impl.Count())
require.Equal(t, uint64(tc.expectedLeafCount), impl.MustCount())

// Deletion removes all nodes except root
for _, key := range tc.keys {
err = smst.Delete([]byte(key))
require.NoError(t, err, tci)
}
require.Equal(t, 1, nodeCount(t), tci)
require.Equal(t, uint64(1), impl.Count())
require.Equal(t, uint64(1), impl.MustCount())

// Deleting and re-inserting a persisted node doesn't change count
require.NoError(t, smst.Delete([]byte("testKey")))
require.NoError(t, smst.Update([]byte("testKey"), []byte("testValue"), 10))
require.Equal(t, 1, nodeCount(t), tci)
require.Equal(t, uint64(1), impl.Count())
require.Equal(t, uint64(1), impl.MustCount())
})
}
}
Expand Down Expand Up @@ -486,12 +486,12 @@ func TestSMST_TotalSum(t *testing.T) {
rootCount := binary.BigEndian.Uint64(countBz)

// Retrieve and compare the sum
sum := smst.Sum()
sum := smst.MustSum()
require.Equal(t, sum, uint64(15))
require.Equal(t, sum, rootSum)

// Retrieve and compare the count
count := smst.Count()
count := smst.MustCount()
require.Equal(t, count, uint64(3))
require.Equal(t, count, rootCount)

Expand All @@ -506,22 +506,22 @@ func TestSMST_TotalSum(t *testing.T) {
// Check that the sum is correct after deleting a key
err = smst.Delete([]byte("key1"))
require.NoError(t, err)
sum = smst.Sum()
sum = smst.MustSum()
require.Equal(t, sum, uint64(10))

// Check that the count is correct after deleting a key
count = smst.Count()
count = smst.MustCount()
require.Equal(t, count, uint64(2))

// Check that the sum is correct after importing the trie
require.NoError(t, smst.Commit())
root2 := smst.Root()
smst = ImportSparseMerkleSumTrie(snm, sha256.New(), root2)
sum = smst.Sum()
sum = smst.MustSum()
require.Equal(t, sum, uint64(10))

// Check that the count is correct after importing the trie
count = smst.Count()
count = smst.MustCount()
require.Equal(t, count, uint64(2))

// Calculate the total sum of a larger trie
Expand All @@ -532,11 +532,11 @@ func TestSMST_TotalSum(t *testing.T) {
require.NoError(t, err)
}
require.NoError(t, smst.Commit())
sum = smst.Sum()
sum = smst.MustSum()
require.Equal(t, sum, uint64(49995000))

// Check that the count is correct after building a larger trie
count = smst.Count()
count = smst.MustCount()
require.Equal(t, count, uint64(9999))
}

Expand Down Expand Up @@ -584,7 +584,7 @@ func TestSMST_Retrieval(t *testing.T) {
require.Equal(t, uint64(5), sum)

root := smst.Root()
sum = smst.Sum()
sum = smst.MustSum()
require.Equal(t, sum, uint64(15))

lazy := ImportSparseMerkleSumTrie(snm, sha256.New(), root, WithValueHasher(nil))
Expand All @@ -604,9 +604,9 @@ func TestSMST_Retrieval(t *testing.T) {
require.Equal(t, []byte("value3"), value)
require.Equal(t, uint64(5), sum)

sum = lazy.Sum()
sum = lazy.MustSum()
require.Equal(t, sum, uint64(15))

count := lazy.Count()
count := lazy.MustCount()
require.Equal(t, count, uint64(3))
}

0 comments on commit 9ab524a

Please sign in to comment.