utils_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright 2015 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. // Contains a batch of utility type declarations used by the tests. As the node
  17. // operates on unique types, a lot of them are needed to check various features.
  18. package node
  19. import (
  20. "github.com/ethereum/go-ethereum/p2p"
  21. "github.com/ethereum/go-ethereum/rpc"
  22. )
  23. // NoopLifecycle is a trivial implementation of the Service interface.
  24. type NoopLifecycle struct{}
  25. func (s *NoopLifecycle) Start() error { return nil }
  26. func (s *NoopLifecycle) Stop() error { return nil }
  27. func NewNoop() *Noop {
  28. noop := new(Noop)
  29. return noop
  30. }
  31. // Set of services all wrapping the base NoopLifecycle resulting in the same method
  32. // signatures but different outer types.
  33. type Noop struct{ NoopLifecycle }
  34. // InstrumentedService is an implementation of Lifecycle for which all interface
  35. // methods can be instrumented both return value as well as event hook wise.
  36. type InstrumentedService struct {
  37. start error
  38. stop error
  39. startHook func()
  40. stopHook func()
  41. }
  42. func (s *InstrumentedService) Start() error {
  43. if s.startHook != nil {
  44. s.startHook()
  45. }
  46. return s.start
  47. }
  48. func (s *InstrumentedService) Stop() error {
  49. if s.stopHook != nil {
  50. s.stopHook()
  51. }
  52. return s.stop
  53. }
  54. type FullService struct{}
  55. func NewFullService(stack *Node) (*FullService, error) {
  56. fs := new(FullService)
  57. stack.RegisterProtocols(fs.Protocols())
  58. stack.RegisterAPIs(fs.APIs())
  59. stack.RegisterLifecycle(fs)
  60. return fs, nil
  61. }
  62. func (f *FullService) Start() error { return nil }
  63. func (f *FullService) Stop() error { return nil }
  64. func (f *FullService) Protocols() []p2p.Protocol {
  65. return []p2p.Protocol{
  66. {
  67. Name: "test1",
  68. Version: uint(1),
  69. },
  70. {
  71. Name: "test2",
  72. Version: uint(2),
  73. },
  74. }
  75. }
  76. func (f *FullService) APIs() []rpc.API {
  77. return []rpc.API{
  78. {
  79. Namespace: "admin",
  80. },
  81. {
  82. Namespace: "debug",
  83. },
  84. {
  85. Namespace: "net",
  86. },
  87. }
  88. }