MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / initNodeChainBusService

Function initNodeChainBusService

worker/chainbusservice_test.go:144–206  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

142}
143
144func initNodeChainBusService() (cleanupFunc func(), server *rpc.Server, err error) {
145 var d string
146 if d, err = ioutil.TempDir("", "db_test_"); err != nil {
147 return
148 }
149
150 // init conf
151 _, testFile, _, _ := runtime.Caller(0)
152 pubKeyStoreFile := filepath.Join(d, PubKeyStorePath)
153 utils.RemoveAll(pubKeyStoreFile + "*")
154 clientPubKeyStoreFile := filepath.Join(d, PubKeyStorePath+"_c")
155 utils.RemoveAll(clientPubKeyStoreFile + "*")
156 dupConfFile := filepath.Join(d, "config.yaml")
157 confFile := filepath.Join(filepath.Dir(testFile), "../test/node_standalone/config.yaml")
158 if err = utils.DupConf(confFile, dupConfFile); err != nil {
159 return
160 }
161 privateKeyPath := filepath.Join(filepath.Dir(testFile), "../test/node_standalone/private.key")
162
163 conf.GConf, _ = conf.LoadConfig(dupConfFile)
164 // reset the once
165 route.Once.Reset()
166 route.InitKMS(clientPubKeyStoreFile)
167
168 var dht *route.DHTService
169
170 // init dht
171 dht, err = route.NewDHTService(pubKeyStoreFile, new(consistent.KMSStorage), true)
172 if err != nil {
173 return
174 }
175
176 // init rpc
177 if server, err = rpc.NewServerWithService(rpc.ServiceMap{route.DHTRPCName: dht}); err != nil {
178 return
179 }
180
181 // register fake chain service
182 s := &stubBPService{}
183 s.Init()
184 if err = server.RegisterService(route.BlockProducerRPCName, s); err != nil {
185 return
186 }
187
188 // init private key
189 masterKey := []byte("")
190 if err = server.InitRPCServer(conf.GConf.ListenAddr, privateKeyPath, masterKey); err != nil {
191 return
192 }
193
194 // start server
195 go server.Serve()
196
197 cleanupFunc = func() {
198 os.RemoveAll(d)
199 server.Listener.Close()
200 server.Stop()
201 // clear the connection pool

Callers 1

TestNewBusServiceFunction · 0.85

Calls 12

InitMethod · 0.95
RemoveAllFunction · 0.92
DupConfFunction · 0.92
LoadConfigFunction · 0.92
InitKMSFunction · 0.92
NewDHTServiceFunction · 0.92
RegisterServiceMethod · 0.80
InitRPCServerMethod · 0.80
ResetMethod · 0.65
CloseMethod · 0.65
ServeMethod · 0.45
StopMethod · 0.45

Tested by

no test coverage detected