github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/core/helper_test.go (about)

     1  // This file is part of the go-sberex library. The go-sberex library is 
     2  // free software: you can redistribute it and/or modify it under the terms 
     3  // of the GNU Lesser General Public License as published by the Free 
     4  // Software Foundation, either version 3 of the License, or (at your option)
     5  // any later version.
     6  //
     7  // The go-sberex library is distributed in the hope that it will be useful, 
     8  // but WITHOUT ANY WARRANTY; without even the implied warranty of
     9  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 
    10  // General Public License <http://www.gnu.org/licenses/> for more details.
    11  
    12  package core
    13  
    14  import (
    15  	"container/list"
    16  	"fmt"
    17  
    18  	"github.com/Sberex/go-sberex/core/types"
    19  	"github.com/Sberex/go-sberex/ethdb"
    20  	"github.com/Sberex/go-sberex/event"
    21  )
    22  
    23  // Implement our EthTest Manager
    24  type TestManager struct {
    25  	// stateManager *StateManager
    26  	eventMux *event.TypeMux
    27  
    28  	db         ethdb.Database
    29  	txPool     *TxPool
    30  	blockChain *BlockChain
    31  	Blocks     []*types.Block
    32  }
    33  
    34  func (tm *TestManager) IsListening() bool {
    35  	return false
    36  }
    37  
    38  func (tm *TestManager) IsMining() bool {
    39  	return false
    40  }
    41  
    42  func (tm *TestManager) PeerCount() int {
    43  	return 0
    44  }
    45  
    46  func (tm *TestManager) Peers() *list.List {
    47  	return list.New()
    48  }
    49  
    50  func (tm *TestManager) BlockChain() *BlockChain {
    51  	return tm.blockChain
    52  }
    53  
    54  func (tm *TestManager) TxPool() *TxPool {
    55  	return tm.txPool
    56  }
    57  
    58  // func (tm *TestManager) StateManager() *StateManager {
    59  // 	return tm.stateManager
    60  // }
    61  
    62  func (tm *TestManager) EventMux() *event.TypeMux {
    63  	return tm.eventMux
    64  }
    65  
    66  // func (tm *TestManager) KeyManager() *crypto.KeyManager {
    67  // 	return nil
    68  // }
    69  
    70  func (tm *TestManager) Db() ethdb.Database {
    71  	return tm.db
    72  }
    73  
    74  func NewTestManager() *TestManager {
    75  	db, err := ethdb.NewMemDatabase()
    76  	if err != nil {
    77  		fmt.Println("Could not create mem-db, failing")
    78  		return nil
    79  	}
    80  
    81  	testManager := &TestManager{}
    82  	testManager.eventMux = new(event.TypeMux)
    83  	testManager.db = db
    84  	// testManager.txPool = NewTxPool(testManager)
    85  	// testManager.blockChain = NewBlockChain(testManager)
    86  	// testManager.stateManager = NewStateManager(testManager)
    87  
    88  	return testManager
    89  }