github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/swarm/storage/mru/testutil.go (about) 1 2 //此源码被清华学神尹成大魔王专业翻译分析并修改 3 //尹成QQ77025077 4 //尹成微信18510341407 5 //尹成所在QQ群721929980 6 //尹成邮箱 yinc13@mails.tsinghua.edu.cn 7 //尹成毕业于清华大学,微软区块链领域全球最有价值专家 8 //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620 9 // 10 // 11 // 12 // 13 // 14 // 15 // 16 // 17 // 18 // 19 // 20 // 21 // 22 // 23 // 24 25 package mru 26 27 import ( 28 "fmt" 29 "path/filepath" 30 31 "github.com/ethereum/go-ethereum/swarm/storage" 32 ) 33 34 const ( 35 testDbDirName = "mru" 36 ) 37 38 type TestHandler struct { 39 *Handler 40 } 41 42 func (t *TestHandler) Close() { 43 t.chunkStore.Close() 44 } 45 46 // 47 func NewTestHandler(datadir string, params *HandlerParams) (*TestHandler, error) { 48 path := filepath.Join(datadir, testDbDirName) 49 rh := NewHandler(params) 50 localstoreparams := storage.NewDefaultLocalStoreParams() 51 localstoreparams.Init(path) 52 localStore, err := storage.NewLocalStore(localstoreparams, nil) 53 if err != nil { 54 return nil, fmt.Errorf("localstore create fail, path %s: %v", path, err) 55 } 56 localStore.Validators = append(localStore.Validators, storage.NewContentAddressValidator(storage.MakeHashFunc(resourceHashAlgorithm))) 57 localStore.Validators = append(localStore.Validators, rh) 58 netStore := storage.NewNetStore(localStore, nil) 59 rh.SetStore(netStore) 60 return &TestHandler{rh}, nil 61 }