Example #1
0
func (this *WebApiSuite) SetupSuite() {
	gin.SetMode(gin.ReleaseMode)
	baseDir := path.Join(os.TempDir(), "/.edbservers")
	ss := ess.NewServerServer(baseDir)
	cfg := server.DefaultServerConfig()
	cfg.Bind.Port = uint16(31404)
	proc := server.NewServeProcess(cfg, ss)
	err := proc.Start()
	if err != nil {
		panic(err)
	}
	this.serveProcess = proc
	testData := td.LoadTestData()
	this.codec = edb.NewTCodec()

	requestData := &ess.RequestData{testData.ChainData.PrivValidator, testData.ChainData.Genesis, SERVER_DURATION}
	rBts, _ := this.codec.EncodeBytes(requestData)
	resp, _ := http.Post(WAPIS_URL, "application/json", bytes.NewBuffer(rBts))
	rd := &ess.ResponseData{}
	err2 := this.codec.Decode(rd, resp.Body)
	if err2 != nil {
		panic(err2)
	}
	fmt.Println("Received Port: " + rd.Port)
	this.sUrl = "http://localhost:" + rd.Port
	this.testData = testData
}
Example #2
0
func (this *TxSuite) SetupSuite() {
	baseDir := path.Join(os.TempDir(), "/.edbservers")
	ss := ess.NewServerServer(baseDir)
	cfg := server.DefaultServerConfig()
	cfg.Bind.Port = uint16(31405)
	proc := server.NewServeProcess(cfg, ss)
	err := proc.Start()
	if err != nil {
		panic(err)
	}
	this.serveProcess = proc
	testData := td.LoadTestData()
	this.codec = edb.NewTCodec()

	requestData := &ess.RequestData{testData.ChainData.PrivValidator, testData.ChainData.Genesis, 30}
	rBts, _ := this.codec.EncodeBytes(requestData)
	resp, _ := http.Post(TX_URL, "application/json", bytes.NewBuffer(rBts))
	if resp.StatusCode != 200 {
		bts, _ := ioutil.ReadAll(resp.Body)
		fmt.Println("ERROR GETTING SS ADDRESS: " + string(bts))
		fmt.Printf("%v\n", resp)
		panic(fmt.Errorf(string(bts)))
	}
	rd := &ess.ResponseData{}
	err2 := this.codec.Decode(rd, resp.Body)
	if err2 != nil {
		panic(err2)
	}
	fmt.Println("Received Port: " + rd.Port)
	this.sUrl = "http://localhost:" + rd.Port
	fmt.Println("URL: " + this.sUrl)
	this.testData = testData
}
Example #3
0
// This function returns a properly configured ErisDb server process with a running
// tendermint node attached to it. To start listening for incoming requests, call
// 'Start()' on the process. Make sure to register any start event listeners before
// that.
func ServeErisDB(workDir string) (*server.ServeProcess, error) {
	log.Info("ErisDB Serve initializing.")
	errEns := EnsureDir(workDir)

	if errEns != nil {
		return nil, errEns
	}

	var sConf *server.ServerConfig

	sConfPath := path.Join(workDir, "server_conf.toml")
	if !FileExists(sConfPath) {
		log.Info("No server configuration, using default.")
		log.Info("Writing to: " + sConfPath)
		sConf = server.DefaultServerConfig()
		errW := server.WriteServerConfig(sConfPath, sConf)
		if errW != nil {
			panic(errW)
		}
	} else {
		var errRSC error
		sConf, errRSC = server.ReadServerConfig(sConfPath)
		if errRSC != nil {
			log.Error("Server config file error.", "error", errRSC.Error())
		}
	}

	// Get tendermint configuration
	tmConfig = tmcfg.GetConfig(workDir)
	tmConfig.Set("version", TENDERMINT_VERSION)
	cfg.ApplyConfig(tmConfig) // Notify modules of new config

	// Set the node up.
	nodeRd := make(chan struct{})
	nd := node.NewNode()
	// Load the supporting objects.
	pipe := ep.NewPipe(nd)
	codec := &TCodec{}
	evtSubs := NewEventSubscriptions(pipe.Events())
	// The services.
	tmwss := NewErisDbWsService(codec, pipe)
	tmjs := NewErisDbJsonService(codec, pipe, evtSubs)
	// The servers.
	jsonServer := NewJsonRpcServer(tmjs)
	restServer := NewRestServer(codec, pipe, evtSubs)
	wsServer := server.NewWebSocketServer(sConf.WebSocket.MaxWebSocketSessions, tmwss)
	// Create a server process.
	proc := server.NewServeProcess(sConf, jsonServer, restServer, wsServer)

	stopChan := proc.StopEventChannel()
	go startNode(nd, nodeRd, stopChan)
	<-nodeRd
	return proc, nil
}
Example #4
0
func CreateTempWorkDir(privValidator *types.PrivValidator, genesis *stypes.GenesisDoc, folderName string) (string, error) {

	workDir := path.Join(os.TempDir(), folderName)
	os.RemoveAll(workDir)
	errED := EnsureDir(workDir)

	if errED != nil {
		return "", errED
	}

	cfgName := path.Join(workDir, "config.toml")
	scName := path.Join(workDir, "server_conf.toml")
	pvName := path.Join(workDir, "priv_validator.json")
	genesisName := path.Join(workDir, "genesis.json")

	// Write config.
	errCFG := files.WriteFileRW(cfgName, []byte(TendermintConfigDefault))
	if errCFG != nil {
		return "", errCFG
	}
	fmt.Printf("File written: %s\n.", cfgName)

	// Write validator.
	errPV := writeJSON(pvName, privValidator)
	if errPV != nil {
		return "", errPV
	}
	fmt.Printf("File written: %s\n.", pvName)

	// Write genesis
	errG := writeJSON(genesisName, genesis)
	if errG != nil {
		return "", errG
	}
	fmt.Printf("File written: %s\n.", genesisName)

	// Write server config.
	errWC := server.WriteServerConfig(scName, server.DefaultServerConfig())
	if errWC != nil {
		return "", errWC
	}
	fmt.Printf("File written: %s\n.", scName)
	return workDir, nil
}
Example #5
0
// Add a new erisdb process to the list.
func (this *ServerManager) add(data *RequestData) (*ResponseData, error) {
	this.mtx.Lock()
	defer this.mtx.Unlock()
	config := server.DefaultServerConfig()
	// Port is PORT_BASE + a value between 1 and the max number of servers.
	id, errId := this.idPool.GetId()
	if errId != nil {
		return nil, errId
	}
	port := uint16(PORT_BASE + id)
	config.Bind.Port = port

	folderName := fmt.Sprintf("testnode%d", port)
	workDir, errCWD := this.createWorkDir(data, config, folderName)
	if errCWD != nil {
		return nil, errCWD
	}

	// TODO ...

	// Create a new erisdb process.
	cmd := exec.Command(EXECUTABLE_NAME, workDir)
	proc := &CmdProcess{cmd, "DONTMINDME55891"}

	errSt := waitForProcStarted(proc)

	if errSt != nil {
		return nil, errSt
	}

	maxDur := time.Duration(data.MaxDuration) * time.Second
	if maxDur == 0 {
		maxDur = REAPER_THRESHOLD
	}

	st := newServeTask(port, workDir, maxDur, proc)
	this.running = append(this.running, st)

	// TODO add validation data. The node should ideally return some post-deploy state data
	// and send it back with the server URL, so that the validity of the chain can be
	// established client-side before starting the tests.
	return &ResponseData{fmt.Sprintf("%d", port)}, nil
}
Example #6
0
func (this *MockSuite) SetupSuite() {
	gin.SetMode(gin.ReleaseMode)
	// Load the supporting objects.
	testData := td.LoadTestData()
	pipe := NewMockPipe(testData)
	codec := &edb.TCodec{}
	evtSubs := edb.NewEventSubscriptions(pipe.Events())
	// The server
	restServer := edb.NewRestServer(codec, pipe, evtSubs)
	sConf := server.DefaultServerConfig()
	sConf.Bind.Port = 31402
	// Create a server process.
	proc := server.NewServeProcess(sConf, restServer)
	err := proc.Start()
	if err != nil {
		panic(err)
	}
	this.serveProcess = proc
	this.codec = edb.NewTCodec()
	this.testData = testData
	this.sUrl = "http://localhost:31402"
}
Example #7
0
func NewServeScumSocket(wsServer *server.WebSocketServer) *server.ServeProcess {
	cfg := server.DefaultServerConfig()
	cfg.WebSocket.WebSocketEndpoint = "/scumsocket"
	cfg.Bind.Port = uint16(31401)
	return server.NewServeProcess(cfg, wsServer)
}
Example #8
0
func NewServeScumbag() *server.ServeProcess {
	cfg := server.DefaultServerConfig()
	cfg.Bind.Port = uint16(31400)
	return server.NewServeProcess(cfg, NewScumbagServer())
}
Example #9
0
// This function returns a properly configured ErisDb server process with a running
// tendermint node attached to it. To start listening for incoming requests, call
// 'Start()' on the process. Make sure to register any start event listeners before
// that.
func ServeErisDB(workDir string) (*server.ServeProcess, error) {
	log.Info("ErisDB Serve initializing.")
	errEns := EnsureDir(workDir)

	if errEns != nil {
		return nil, errEns
	}

	var sConf *server.ServerConfig

	sConfPath := path.Join(workDir, "server_conf.toml")
	if !FileExists(sConfPath) {
		log.Info("No server configuration, using default.")
		log.Info("Writing to: " + sConfPath)
		sConf = server.DefaultServerConfig()
		errW := server.WriteServerConfig(sConfPath, sConf)
		if errW != nil {
			panic(errW)
		}
	} else {
		var errRSC error
		sConf, errRSC = server.ReadServerConfig(sConfPath)
		if errRSC != nil {
			log.Error("Server config file error.", "error", errRSC.Error())
		}
	}

	// Get tendermint configuration
	tmConfig = tmcfg.GetConfig(workDir)
	tmConfig.Set("version", node.Version)
	cfg.ApplyConfig(tmConfig) // Notify modules of new config

	// load the priv validator
	privVal := types.LoadPrivValidator(tmConfig.GetString("priv_validator_file"))

	// possibly set the signer to use eris-keys
	signerCfg := tmConfig.GetString("signer")
	if !(signerCfg == "default" || signerCfg == "") {
		spl := strings.Split(signerCfg, ":")
		if len(spl) != 2 {
			panic(`"signer" field in config.toml should be "default" or "ERIS_KEYS_HOST:ERIS_KEYS_PORT"`)
		}

		// TODO: if a privKey is found in the privVal, warn the user that we want to import it to eris-keys and delete it

		host := signerCfg
		addr := hex.EncodeToString(privVal.Address)
		signer := NewErisSigner(host, addr)
		privVal.SetSigner(signer)
	}

	// Set the node up.
	nodeRd := make(chan struct{})
	nd := node.NewNode(privVal)
	// Load the supporting objects.
	pipe := ep.NewPipe(nd)
	codec := &TCodec{}
	evtSubs := NewEventSubscriptions(pipe.Events())
	// The services.
	tmwss := NewErisDbWsService(codec, pipe)
	tmjs := NewErisDbJsonService(codec, pipe, evtSubs)
	// The servers.
	jsonServer := NewJsonRpcServer(tmjs)
	restServer := NewRestServer(codec, pipe, evtSubs)
	wsServer := server.NewWebSocketServer(sConf.WebSocket.MaxWebSocketSessions, tmwss)
	// Create a server process.
	proc := server.NewServeProcess(sConf, jsonServer, restServer, wsServer)

	stopChan := proc.StopEventChannel()
	go startNode(nd, nodeRd, stopChan)
	<-nodeRd
	return proc, nil
}