aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/storage/mock/mock.go
diff options
context:
space:
mode:
authorJanoš Guljaš <janos@users.noreply.github.com>2019-02-23 17:47:33 +0800
committerViktor Trón <viktor.tron@gmail.com>2019-02-23 17:47:33 +0800
commit64d10c08726af33048e8eeb8df257628a3944870 (patch)
tree00002e147d650e1d6ec571731bbf900e77d9e307 /swarm/storage/mock/mock.go
parent02c28046a04ebf649af5d1b2a702d0da1c8a2a39 (diff)
downloadgo-tangerine-64d10c08726af33048e8eeb8df257628a3944870.tar
go-tangerine-64d10c08726af33048e8eeb8df257628a3944870.tar.gz
go-tangerine-64d10c08726af33048e8eeb8df257628a3944870.tar.bz2
go-tangerine-64d10c08726af33048e8eeb8df257628a3944870.tar.lz
go-tangerine-64d10c08726af33048e8eeb8df257628a3944870.tar.xz
go-tangerine-64d10c08726af33048e8eeb8df257628a3944870.tar.zst
go-tangerine-64d10c08726af33048e8eeb8df257628a3944870.zip
swarm: mock store listings (#19157)
* swarm/storage/mock: implement listings methods for mem and rpc stores * swarm/storage/mock/rpc: add comments and newTestStore helper function * swarm/storage/mock/mem: add missing comments * swarm/storage/mock: add comments to new types and constants * swarm/storage/mock/db: implement listings for mock/db global store * swarm/storage/mock/test: add comments for MockStoreListings * swarm/storage/mock/explorer: initial implementation * cmd/swarm/global-store: add chunk explorer * cmd/swarm/global-store: add chunk explorer tests * swarm/storage/mock/explorer: add tests * swarm/storage/mock/explorer: add swagger api definition * swarm/storage/mock/explorer: not-zero test values for invalid addr and key * swarm/storage/mock/explorer: test wildcard cors origin * swarm/storage/mock/db: renames based on Fabio's suggestions * swarm/storage/mock/explorer: add more comments to testHandler function * cmd/swarm/global-store: terminate subprocess with Kill in tests
Diffstat (limited to 'swarm/storage/mock/mock.go')
-rw-r--r--swarm/storage/mock/mock.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/swarm/storage/mock/mock.go b/swarm/storage/mock/mock.go
index 626ba3fe1..586112a98 100644
--- a/swarm/storage/mock/mock.go
+++ b/swarm/storage/mock/mock.go
@@ -39,6 +39,17 @@ import (
"github.com/ethereum/go-ethereum/common"
)
+const (
+ // DefaultLimit should be used as default limit for
+ // Keys, Nodes, NodeKeys and KeyNodes GlobarStorer
+ // methids implementations.
+ DefaultLimit = 100
+ // MaxLimit should be used as the maximal returned number
+ // of items for Keys, Nodes, NodeKeys and KeyNodes GlobarStorer
+ // methids implementations, regardless of provided limit.
+ MaxLimit = 1000
+)
+
// ErrNotFound indicates that the chunk is not found.
var ErrNotFound = errors.New("not found")
@@ -76,6 +87,10 @@ func (n *NodeStore) Delete(key []byte) error {
return n.store.Delete(n.addr, key)
}
+func (n *NodeStore) Keys(startKey []byte, limit int) (keys Keys, err error) {
+ return n.store.NodeKeys(n.addr, startKey, limit)
+}
+
// GlobalStorer defines methods for mock db store
// that stores chunk data for all swarm nodes.
// It is used in tests to construct mock NodeStores
@@ -85,12 +100,28 @@ type GlobalStorer interface {
Put(addr common.Address, key []byte, data []byte) error
Delete(addr common.Address, key []byte) error
HasKey(addr common.Address, key []byte) bool
+ Keys(startKey []byte, limit int) (keys Keys, err error)
+ Nodes(startAddr *common.Address, limit int) (nodes Nodes, err error)
+ NodeKeys(addr common.Address, startKey []byte, limit int) (keys Keys, err error)
+ KeyNodes(key []byte, startAddr *common.Address, limit int) (nodes Nodes, err error)
// NewNodeStore creates an instance of NodeStore
// to be used by a single swarm node with
// address addr.
NewNodeStore(addr common.Address) *NodeStore
}
+// Keys are returned results by Keys and NodeKeys GlobalStorer methods.
+type Keys struct {
+ Keys [][]byte
+ Next []byte
+}
+
+// Nodes are returned results by Nodes and KeyNodes GlobalStorer methods.
+type Nodes struct {
+ Addrs []common.Address
+ Next *common.Address
+}
+
// Importer defines method for importing mock store data
// from an exported tar archive.
type Importer interface {