helper_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2014 The go-ethereum Authors
  2. // This file is part of go-ethereum.
  3. //
  4. // go-ethereum 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. // go-ethereum 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 go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  16. package core
  17. import (
  18. "container/list"
  19. "fmt"
  20. "github.com/ethereum/go-ethereum/core/types"
  21. // "github.com/ethereum/go-ethereum/crypto"
  22. "github.com/ethereum/go-ethereum/common"
  23. "github.com/ethereum/go-ethereum/ethdb"
  24. "github.com/ethereum/go-ethereum/event"
  25. )
  26. // Implement our EthTest Manager
  27. type TestManager struct {
  28. // stateManager *StateManager
  29. eventMux *event.TypeMux
  30. db common.Database
  31. txPool *TxPool
  32. blockChain *ChainManager
  33. Blocks []*types.Block
  34. }
  35. func (s *TestManager) IsListening() bool {
  36. return false
  37. }
  38. func (s *TestManager) IsMining() bool {
  39. return false
  40. }
  41. func (s *TestManager) PeerCount() int {
  42. return 0
  43. }
  44. func (s *TestManager) Peers() *list.List {
  45. return list.New()
  46. }
  47. func (s *TestManager) ChainManager() *ChainManager {
  48. return s.blockChain
  49. }
  50. func (tm *TestManager) TxPool() *TxPool {
  51. return tm.txPool
  52. }
  53. // func (tm *TestManager) StateManager() *StateManager {
  54. // return tm.stateManager
  55. // }
  56. func (tm *TestManager) EventMux() *event.TypeMux {
  57. return tm.eventMux
  58. }
  59. // func (tm *TestManager) KeyManager() *crypto.KeyManager {
  60. // return nil
  61. // }
  62. func (tm *TestManager) Db() common.Database {
  63. return tm.db
  64. }
  65. func NewTestManager() *TestManager {
  66. db, err := ethdb.NewMemDatabase()
  67. if err != nil {
  68. fmt.Println("Could not create mem-db, failing")
  69. return nil
  70. }
  71. testManager := &TestManager{}
  72. testManager.eventMux = new(event.TypeMux)
  73. testManager.db = db
  74. // testManager.txPool = NewTxPool(testManager)
  75. // testManager.blockChain = NewChainManager(testManager)
  76. // testManager.stateManager = NewStateManager(testManager)
  77. return testManager
  78. }