diff options
author | holisticode <holistic.computing@gmail.com> | 2019-02-07 22:49:19 +0800 |
---|---|---|
committer | Rafael Matias <rafael@skyle.net> | 2019-02-19 20:06:13 +0800 |
commit | d1ace4f344616fb6fa8643872c1f9cac89f8549e (patch) | |
tree | 807c6d7af3875e3aedc5fe6b24c463205cffab19 /swarm/storage/localstore_test.go | |
parent | 637a75d61a13ee8a89a702a2eadb5ace3c79e7da (diff) | |
download | go-tangerine-d1ace4f344616fb6fa8643872c1f9cac89f8549e.tar.gz go-tangerine-d1ace4f344616fb6fa8643872c1f9cac89f8549e.tar.zst go-tangerine-d1ace4f344616fb6fa8643872c1f9cac89f8549e.zip |
swarm: Debug API and HasChunks() API endpoint (#18980)
(cherry picked from commit 41597c2856d6ac7328baca1340c3e36ab0edd382)
Diffstat (limited to 'swarm/storage/localstore_test.go')
-rw-r--r-- | swarm/storage/localstore_test.go | 33 |
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!") + } + +} |