Repository: NethermindEth/juno
Pull request #142 (2022-04-25 01:52:50)

Implement NumberOfItems for the KeyValueDb
## Changes:
I saw (working on another problem) that `KeyValueDb` is not implementing the `Databaser` interface and I think it should. The reason is that `KeyValueDb` doesn't have the `NumberOfItems` function, but it does have the `Count` function, with the same functionality, so I just rename it.
- Rename the struct method `Count` to `NumberOfItems` to achieve the `Databaser` interface
- Add a new test to check the `KeyValueDb` implements the `Databaser` interface

## Types of changes

What types of changes does your code introduce?
_Put an `x` in the boxes that apply_

- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation Update
- [ ] Code style update (formatting, renaming)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] Other (please describe): 

## Testing
**Requires testing**

- [x] Yes
- [ ] No

**In case you checked yes, did you write tests??**

- [x] Yes
- [ ] No

codecov[bot]: # [Codecov](https://codecov.io/gh/NethermindEth/juno/pull/142?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth) Report
> Merging [#142](https://codecov.io/gh/NethermindEth/juno/pull/142?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth) (da8127b) into [main](https://codecov.io/gh/NethermindEth/juno/commit/be48e4f5d2c7654252725dd4dab5e3d7b26fef66?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth) (be48e4f) will **decrease** coverage by `0.16%`.
> The diff coverage is `100.00%`.

```diff
@@             Coverage Diff             @@
##              main     #142      +/-   ##
===========================================
- Coverage   100.00%   99.83%   -0.17%     
===========================================
  Files           19       19              
  Lines         1204     1195       -9     
===========================================
- Hits          1204     1193      -11     
- Misses           0        1       +1     
- Partials         0        1       +1     
```

| Flag | Coverage Δ | |
|---|---|---|
| unittests | `99.83% <100.00%> (-0.17%)` | :arrow_down: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/NethermindEth/juno/pull/142?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth) | Coverage Δ | |
|---|---|---|
| [pkg/db/db.go](https://codecov.io/gh/NethermindEth/juno/pull/142/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth#diff-cGtnL2RiL2RiLmdv) | `100.00% <100.00%> (ø)` | |
| [pkg/crypto/weierstrass/weierstrass.go](https://codecov.io/gh/NethermindEth/juno/pull/142/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth#diff-cGtnL2NyeXB0by93ZWllcnN0cmFzcy93ZWllcnN0cmFzcy5nbw==) | `99.28% <0.00%> (-0.72%)` | :arrow_down: |
| [pkg/rpc/server.go](https://codecov.io/gh/NethermindEth/juno/pull/142/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth#diff-cGtnL3JwYy9zZXJ2ZXIuZ28=) | `100.00% <0.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/NethermindEth/juno/pull/142?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/NethermindEth/juno/pull/142?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth). Last update [be48e4f...da8127b](https://codecov.io/gh/NethermindEth/juno/pull/142?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth).


Patch:
diff --git a/pkg/crypto/weierstrass/weierstrass.go b/pkg/crypto/weierstrass/weierstrass.go
index c301812a..37c3d08a 100644
--- a/pkg/crypto/weierstrass/weierstrass.go
+++ b/pkg/crypto/weierstrass/weierstrass.go
@@ -389,6 +389,7 @@ func GenerateKey(
 		pvt[1] ^= 0x42
 
 		// If the scalar is out of range, sample another random number.
+		// notest
 		if new(big.Int).SetBytes(pvt).Cmp(N) >= 0 {
 			continue
 		}
diff --git a/pkg/db/db.go b/pkg/db/db.go
index fe537983..5b12f635 100644
--- a/pkg/db/db.go
+++ b/pkg/db/db.go
@@ -152,8 +152,8 @@ func (d *KeyValueDb) Delete(key []byte) error {
 	return err
 }
 
-// Count returns the number of items in the database.
-func (d *KeyValueDb) Count() (uint64, error) {
+// NumberOfItems returns the number of items in the database.
+func (d *KeyValueDb) NumberOfItems() (uint64, error) {
 	log.Default.Info("Getting the number of items in the database.")
 	stats, err := d.env.Stat()
 	if err != nil {


Test patch:
diff --git a/pkg/db/db_test.go b/pkg/db/db_test.go
index 32ed3bee..1dd2d916 100644
--- a/pkg/db/db_test.go
+++ b/pkg/db/db_test.go
@@ -32,7 +32,7 @@ func TestAddKey(t *testing.T) {
 // TestNumberOfItems Checks that in every moment the collection contains the right amount of items
 func TestNumberOfItems(t *testing.T) {
 	database := setupDatabaseForTest(t.TempDir())
-	n, err := database.Count()
+	n, err := database.NumberOfItems()
 	if err != nil {
 		t.Log(err)
 		t.Fail()
@@ -51,7 +51,7 @@ func TestNumberOfItems(t *testing.T) {
 			return
 		}
 	}
-	n, err = database.Count()
+	n, err = database.NumberOfItems()
 	if err != nil {
 		t.Log(err)
 		t.Fail()
@@ -74,7 +74,7 @@ func TestAddMultipleKeys(t *testing.T) {
 			return
 		}
 	}
-	n, err := database.Count()
+	n, err := database.NumberOfItems()
 	if err != nil {
 		t.Log(err)
 		t.Fail()
@@ -220,6 +220,11 @@ func TestClose(t *testing.T) {
 	database.Close()
 }
 
+func TestKeyValueDbIsDatabaser(t *testing.T) {
+	a := new(KeyValueDb)
+	_ = Databaser(a)
+}
+
 // BenchmarkEntriesInDatabase Benchmark the entry of key-value pairs to the db
 func BenchmarkEntriesInDatabase(b *testing.B) {
 	database := setupDatabaseForTest(b.TempDir())
@@ -231,7 +236,7 @@ func BenchmarkEntriesInDatabase(b *testing.B) {
 			return
 		}
 	}
-	n, err := database.Count()
+	n, err := database.NumberOfItems()
 	if err != nil {
 		b.Errorf("Benchmarking fails, error getting the number of items: %s\n", err)
 		b.Fail()