github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/swarm/storage/mru/testutil.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 12:09:50</date>
    10  //</624342683837534208>
    11  
    12  //
    13  //
    14  //
    15  //
    16  //
    17  //
    18  //
    19  //
    20  //
    21  //
    22  //
    23  //
    24  //
    25  //
    26  //
    27  
    28  package mru
    29  
    30  import (
    31  	"fmt"
    32  	"path/filepath"
    33  
    34  	"github.com/ethereum/go-ethereum/swarm/storage"
    35  )
    36  
    37  const (
    38  	testDbDirName = "mru"
    39  )
    40  
    41  type TestHandler struct {
    42  	*Handler
    43  }
    44  
    45  func (t *TestHandler) Close() {
    46  	t.chunkStore.Close()
    47  }
    48  
    49  //
    50  func NewTestHandler(datadir string, params *HandlerParams) (*TestHandler, error) {
    51  	path := filepath.Join(datadir, testDbDirName)
    52  	rh := NewHandler(params)
    53  	localstoreparams := storage.NewDefaultLocalStoreParams()
    54  	localstoreparams.Init(path)
    55  	localStore, err := storage.NewLocalStore(localstoreparams, nil)
    56  	if err != nil {
    57  		return nil, fmt.Errorf("localstore create fail, path %s: %v", path, err)
    58  	}
    59  	localStore.Validators = append(localStore.Validators, storage.NewContentAddressValidator(storage.MakeHashFunc(resourceHashAlgorithm)))
    60  	localStore.Validators = append(localStore.Validators, rh)
    61  	netStore := storage.NewNetStore(localStore, nil)
    62  	rh.SetStore(netStore)
    63  	return &TestHandler{rh}, nil
    64  }
    65