mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
swarm/storage/mock/rpc: add comments and newTestStore helper function
This commit is contained in:
parent
2628a0c4f5
commit
9aa451c54e
2 changed files with 26 additions and 13 deletions
|
|
@ -89,21 +89,25 @@ func (s *GlobalStore) HasKey(addr common.Address, key []byte) bool {
|
||||||
return has
|
return has
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Keys returns a paginated list of keys on all nodes.
|
||||||
func (s *GlobalStore) Keys(startKey []byte, limit int) (keys mock.Keys, err error) {
|
func (s *GlobalStore) Keys(startKey []byte, limit int) (keys mock.Keys, err error) {
|
||||||
err = s.client.Call(&keys, "mockStore_keys", startKey, limit)
|
err = s.client.Call(&keys, "mockStore_keys", startKey, limit)
|
||||||
return keys, err
|
return keys, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Nodes returns a paginated list of all known nodes.
|
||||||
func (s *GlobalStore) Nodes(startAddr *common.Address, limit int) (nodes mock.Nodes, err error) {
|
func (s *GlobalStore) Nodes(startAddr *common.Address, limit int) (nodes mock.Nodes, err error) {
|
||||||
err = s.client.Call(&nodes, "mockStore_nodes", startAddr, limit)
|
err = s.client.Call(&nodes, "mockStore_nodes", startAddr, limit)
|
||||||
return nodes, err
|
return nodes, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NodeKeys returns a paginated list of keys on a node with provided address.
|
||||||
func (s *GlobalStore) NodeKeys(addr common.Address, startKey []byte, limit int) (keys mock.Keys, err error) {
|
func (s *GlobalStore) NodeKeys(addr common.Address, startKey []byte, limit int) (keys mock.Keys, err error) {
|
||||||
err = s.client.Call(&keys, "mockStore_nodeKeys", addr, startKey, limit)
|
err = s.client.Call(&keys, "mockStore_nodeKeys", addr, startKey, limit)
|
||||||
return keys, err
|
return keys, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// KeyNodes returns a paginated list of nodes that contain a particular key.
|
||||||
func (s *GlobalStore) KeyNodes(key []byte, startAddr *common.Address, limit int) (nodes mock.Nodes, err error) {
|
func (s *GlobalStore) KeyNodes(key []byte, startAddr *common.Address, limit int) (nodes mock.Nodes, err error) {
|
||||||
err = s.client.Call(&nodes, "mockStore_keyNodes", key, startAddr, limit)
|
err = s.client.Call(&nodes, "mockStore_keyNodes", key, startAddr, limit)
|
||||||
return nodes, err
|
return nodes, err
|
||||||
|
|
|
||||||
|
|
@ -27,20 +27,27 @@ import (
|
||||||
// TestDBStore is running test for a GlobalStore
|
// TestDBStore is running test for a GlobalStore
|
||||||
// using test.MockStore function.
|
// using test.MockStore function.
|
||||||
func TestRPCStore(t *testing.T) {
|
func TestRPCStore(t *testing.T) {
|
||||||
serverStore := mem.NewGlobalStore()
|
store, cleanup := newTestStore(t)
|
||||||
|
defer cleanup()
|
||||||
server := rpc.NewServer()
|
|
||||||
if err := server.RegisterName("mockStore", serverStore); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
store := NewGlobalStore(rpc.DialInProc(server))
|
|
||||||
defer store.Close()
|
|
||||||
|
|
||||||
test.MockStore(t, store, 30)
|
test.MockStore(t, store, 30)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGlobalStoreListings(t *testing.T) {
|
// TestRPCStoreListings is running test for a GlobalStore
|
||||||
|
// using test.MockStoreListings function.
|
||||||
|
func TestRPCStoreListings(t *testing.T) {
|
||||||
|
store, cleanup := newTestStore(t)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
test.MockStoreListings(t, store, 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
// newTestStore creates a temporary GlobalStore
|
||||||
|
// that will be closed when returned cleanup function
|
||||||
|
// is called.
|
||||||
|
func newTestStore(t *testing.T) (s *GlobalStore, cleanup func()) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
serverStore := mem.NewGlobalStore()
|
serverStore := mem.NewGlobalStore()
|
||||||
|
|
||||||
server := rpc.NewServer()
|
server := rpc.NewServer()
|
||||||
|
|
@ -49,7 +56,9 @@ func TestGlobalStoreListings(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
store := NewGlobalStore(rpc.DialInProc(server))
|
store := NewGlobalStore(rpc.DialInProc(server))
|
||||||
defer store.Close()
|
return store, func() {
|
||||||
|
if err := store.Close(); err != nil {
|
||||||
test.MockStoreListings(t, store, 1000)
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue