rpc_test.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2018 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package rpc
  17. import (
  18. "testing"
  19. "github.com/ethereum/go-ethereum/rpc"
  20. "github.com/ethereum/go-ethereum/swarm/storage/mock/mem"
  21. "github.com/ethereum/go-ethereum/swarm/storage/mock/test"
  22. )
  23. // TestDBStore is running test for a GlobalStore
  24. // using test.MockStore function.
  25. func TestRPCStore(t *testing.T) {
  26. store, cleanup := newTestStore(t)
  27. defer cleanup()
  28. test.MockStore(t, store, 30)
  29. }
  30. // TestRPCStoreListings is running test for a GlobalStore
  31. // using test.MockStoreListings function.
  32. func TestRPCStoreListings(t *testing.T) {
  33. store, cleanup := newTestStore(t)
  34. defer cleanup()
  35. test.MockStoreListings(t, store, 1000)
  36. }
  37. // newTestStore creates a temporary GlobalStore
  38. // that will be closed when returned cleanup function
  39. // is called.
  40. func newTestStore(t *testing.T) (s *GlobalStore, cleanup func()) {
  41. t.Helper()
  42. serverStore := mem.NewGlobalStore()
  43. server := rpc.NewServer()
  44. if err := server.RegisterName("mockStore", serverStore); err != nil {
  45. t.Fatal(err)
  46. }
  47. store := NewGlobalStore(rpc.DialInProc(server))
  48. return store, func() {
  49. if err := store.Close(); err != nil {
  50. t.Error(err)
  51. }
  52. }
  53. }