aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/storage/localstore_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'swarm/storage/localstore_test.go')
-rw-r--r--swarm/storage/localstore_test.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/swarm/storage/localstore_test.go b/swarm/storage/localstore_test.go
index 7a4162a47..ec69951c4 100644
--- a/swarm/storage/localstore_test.go
+++ b/swarm/storage/localstore_test.go
@@ -209,3 +209,36 @@ func setupLocalStore(t *testing.T, ldbCap int) (ls *LocalStore, cleanup func())
return store, cleanup
}
+
+func TestHas(t *testing.T) {
+ ldbCap := defaultGCRatio
+ store, cleanup := setupLocalStore(t, ldbCap)
+ defer cleanup()
+
+ nonStoredAddr := GenerateRandomChunk(128).Address()
+
+ has := store.Has(context.Background(), nonStoredAddr)
+ if has {
+ t.Fatal("Expected Has() to return false, but returned true!")
+ }
+
+ storeChunks := GenerateRandomChunks(128, 3)
+ for _, ch := range storeChunks {
+ err := store.Put(context.Background(), ch)
+ if err != nil {
+ t.Fatalf("Expected store to store chunk, but it failed: %v", err)
+ }
+
+ has := store.Has(context.Background(), ch.Address())
+ if !has {
+ t.Fatal("Expected Has() to return true, but returned false!")
+ }
+ }
+
+ //let's be paranoic and test again that the non-existent chunk returns false
+ has = store.Has(context.Background(), nonStoredAddr)
+ if has {
+ t.Fatal("Expected Has() to return false, but returned true!")
+ }
+
+}