()
| 142 | } |
| 143 | |
| 144 | func 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 |
no test coverage detected