aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/storage/dbstore_test.go
diff options
context:
space:
mode:
authorΞTHΞЯSPHΞЯΞ <{viktor.tron,nagydani,zsfelfoldi}@gmail.com>2016-08-30 03:18:00 +0800
committerFelix Lange <fjl@twurst.com>2016-08-31 22:19:40 +0800
commit4d300e4dece56535f56ccc32330340ce89e42581 (patch)
tree135838bfae03437eb2a50c6d66de4d66b20c3220 /swarm/storage/dbstore_test.go
parent1f58b2d084b65eaec9aa2c2ecb1d3aae50d894b3 (diff)
downloaddexon-4d300e4dece56535f56ccc32330340ce89e42581.tar
dexon-4d300e4dece56535f56ccc32330340ce89e42581.tar.gz
dexon-4d300e4dece56535f56ccc32330340ce89e42581.tar.bz2
dexon-4d300e4dece56535f56ccc32330340ce89e42581.tar.lz
dexon-4d300e4dece56535f56ccc32330340ce89e42581.tar.xz
dexon-4d300e4dece56535f56ccc32330340ce89e42581.tar.zst
dexon-4d300e4dece56535f56ccc32330340ce89e42581.zip
swarm: plan bee for content storage and distribution on web3
This change imports the Swarm protocol codebase. Compared to the 'swarm' branch, a few mostly cosmetic changes had to be made: * The various redundant log message prefixes are gone. * All files now have LGPLv3 license headers. * Minor code changes were needed to please go vet and make the tests pass on Windows. * Further changes were required to adapt to the go-ethereum develop branch and its new Go APIs. Some code has not (yet) been brought over: * swarm/cmd/bzzhash: will reappear as cmd/bzzhash later * swarm/cmd/bzzup.sh: will be reimplemented in cmd/bzzup * swarm/cmd/makegenesis: will reappear somehow * swarm/examples/album: will move to a separate repository * swarm/examples/filemanager: ditto * swarm/examples/files: will not be merged * swarm/test/*: will not be merged * swarm/services/swear: will reappear as contracts/swear when needed
Diffstat (limited to 'swarm/storage/dbstore_test.go')
-rw-r--r--swarm/storage/dbstore_test.go191
1 files changed, 191 insertions, 0 deletions
diff --git a/swarm/storage/dbstore_test.go b/swarm/storage/dbstore_test.go
new file mode 100644
index 000000000..e2f36a6bc
--- /dev/null
+++ b/swarm/storage/dbstore_test.go
@@ -0,0 +1,191 @@
+// Copyright 2016 The go-ethereum Authors
+// This file is part of the go-ethereum library.
+//
+// The go-ethereum library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// The go-ethereum library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
+
+package storage
+
+import (
+ "bytes"
+ "io/ioutil"
+ "testing"
+
+ "github.com/ethereum/go-ethereum/common"
+)
+
+func initDbStore(t *testing.T) *DbStore {
+ dir, err := ioutil.TempDir("", "bzz-storage-test")
+ if err != nil {
+ t.Fatal(err)
+ }
+ m, err := NewDbStore(dir, MakeHashFunc(defaultHash), defaultDbCapacity, defaultRadius)
+ if err != nil {
+ t.Fatal("can't create store:", err)
+ }
+ return m
+}
+
+func testDbStore(l int64, branches int64, t *testing.T) {
+ m := initDbStore(t)
+ defer m.close()
+ testStore(m, l, branches, t)
+}
+
+func TestDbStore128_0x1000000(t *testing.T) {
+ testDbStore(0x1000000, 128, t)
+}
+
+func TestDbStore128_10000_(t *testing.T) {
+ testDbStore(10000, 128, t)
+}
+
+func TestDbStore128_1000_(t *testing.T) {
+ testDbStore(1000, 128, t)
+}
+
+func TestDbStore128_100_(t *testing.T) {
+ testDbStore(100, 128, t)
+}
+
+func TestDbStore2_100_(t *testing.T) {
+ testDbStore(100, 2, t)
+}
+
+func TestDbStoreNotFound(t *testing.T) {
+ m := initDbStore(t)
+ defer m.close()
+ _, err := m.Get(ZeroKey)
+ if err != notFound {
+ t.Errorf("Expected notFound, got %v", err)
+ }
+}
+
+func TestDbStoreSyncIterator(t *testing.T) {
+ m := initDbStore(t)
+ defer m.close()
+ keys := []Key{
+ Key(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000")),
+ Key(common.Hex2Bytes("4000000000000000000000000000000000000000000000000000000000000000")),
+ Key(common.Hex2Bytes("5000000000000000000000000000000000000000000000000000000000000000")),
+ Key(common.Hex2Bytes("3000000000000000000000000000000000000000000000000000000000000000")),
+ Key(common.Hex2Bytes("2000000000000000000000000000000000000000000000000000000000000000")),
+ Key(common.Hex2Bytes("1000000000000000000000000000000000000000000000000000000000000000")),
+ }
+ for _, key := range keys {
+ m.Put(NewChunk(key, nil))
+ }
+ it, err := m.NewSyncIterator(DbSyncState{
+ Start: Key(common.Hex2Bytes("1000000000000000000000000000000000000000000000000000000000000000")),
+ Stop: Key(common.Hex2Bytes("4000000000000000000000000000000000000000000000000000000000000000")),
+ First: 2,
+ Last: 4,
+ })
+ if err != nil {
+ t.Fatalf("unexpected error creating NewSyncIterator")
+ }
+
+ var chunk Key
+ var res []Key
+ for {
+ chunk = it.Next()
+ if chunk == nil {
+ break
+ }
+ res = append(res, chunk)
+ }
+ if len(res) != 1 {
+ t.Fatalf("Expected 1 chunk, got %v: %v", len(res), res)
+ }
+ if !bytes.Equal(res[0][:], keys[3]) {
+ t.Fatalf("Expected %v chunk, got %v", keys[3], res[0])
+ }
+
+ if err != nil {
+ t.Fatalf("unexpected error creating NewSyncIterator")
+ }
+
+ it, err = m.NewSyncIterator(DbSyncState{
+ Start: Key(common.Hex2Bytes("1000000000000000000000000000000000000000000000000000000000000000")),
+ Stop: Key(common.Hex2Bytes("5000000000000000000000000000000000000000000000000000000000000000")),
+ First: 2,
+ Last: 4,
+ })
+
+ res = nil
+ for {
+ chunk = it.Next()
+ if chunk == nil {
+ break
+ }
+ res = append(res, chunk)
+ }
+ if len(res) != 2 {
+ t.Fatalf("Expected 2 chunk, got %v: %v", len(res), res)
+ }
+ if !bytes.Equal(res[0][:], keys[3]) {
+ t.Fatalf("Expected %v chunk, got %v", keys[3], res[0])
+ }
+ if !bytes.Equal(res[1][:], keys[2]) {
+ t.Fatalf("Expected %v chunk, got %v", keys[2], res[1])
+ }
+
+ if err != nil {
+ t.Fatalf("unexpected error creating NewSyncIterator")
+ }
+
+ it, err = m.NewSyncIterator(DbSyncState{
+ Start: Key(common.Hex2Bytes("1000000000000000000000000000000000000000000000000000000000000000")),
+ Stop: Key(common.Hex2Bytes("4000000000000000000000000000000000000000000000000000000000000000")),
+ First: 2,
+ Last: 5,
+ })
+ res = nil
+ for {
+ chunk = it.Next()
+ if chunk == nil {
+ break
+ }
+ res = append(res, chunk)
+ }
+ if len(res) != 2 {
+ t.Fatalf("Expected 2 chunk, got %v", len(res))
+ }
+ if !bytes.Equal(res[0][:], keys[4]) {
+ t.Fatalf("Expected %v chunk, got %v", keys[4], res[0])
+ }
+ if !bytes.Equal(res[1][:], keys[3]) {
+ t.Fatalf("Expected %v chunk, got %v", keys[3], res[1])
+ }
+
+ it, err = m.NewSyncIterator(DbSyncState{
+ Start: Key(common.Hex2Bytes("2000000000000000000000000000000000000000000000000000000000000000")),
+ Stop: Key(common.Hex2Bytes("4000000000000000000000000000000000000000000000000000000000000000")),
+ First: 2,
+ Last: 5,
+ })
+ res = nil
+ for {
+ chunk = it.Next()
+ if chunk == nil {
+ break
+ }
+ res = append(res, chunk)
+ }
+ if len(res) != 1 {
+ t.Fatalf("Expected 1 chunk, got %v", len(res))
+ }
+ if !bytes.Equal(res[0][:], keys[3]) {
+ t.Fatalf("Expected %v chunk, got %v", keys[3], res[0])
+ }
+}