diff --git a/erisdb/erisdbss/server_manager.go b/erisdb/erisdbss/server_manager.go index faae58fc4d63161159fbc469ad7a0402dd0b5e18..0cee9966c18caee199df3770147ad06e7a13a4ab 100644 --- a/erisdb/erisdbss/server_manager.go +++ b/erisdb/erisdbss/server_manager.go @@ -133,7 +133,7 @@ func reap(sm *ServerManager) { // a time is below reaper threshold, then break. for len(sm.running) > 0 { task := sm.running[0] - if time.Since(task.start) > task.maxDuration { + if task.maxDuration != 0 && time.Since(task.start) > task.maxDuration { fmt.Printf("[SERVER REAPER] Closing down server on port: %d\n", task.port) task.sp.Kill() sm.running = sm.running[1:] @@ -184,7 +184,7 @@ func (this *ServerManager) add(data *RequestData) (*ResponseData, error) { st := newServeTask(port, workDir, maxDur, proc) this.running = append(this.running, st) - URL := "http://" + config.Bind.Address + ":" + fmt.Sprintf("%d", port) + config.HTTP.JsonRpcPath + URL := "http://" + config.Bind.Address + ":" + fmt.Sprintf("%d", port) // 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 diff --git a/erisdb/restServer.go b/erisdb/restServer.go index c50f840fbb0601a336fe6f78193ea9bdb7bdab7d..4db79487f2efc4ac0b5276755ef085b02d7c810f 100644 --- a/erisdb/restServer.go +++ b/erisdb/restServer.go @@ -43,7 +43,7 @@ func (this *RestServer) Start(config *server.ServerConfig, router *gin.Engine) { router.GET("/blockchain/blocks", this.handleBlocks) router.GET("/blockchain/block/:height", heightParam, this.handleBlock) // Consensus - router.GET("/consensus/state", this.handleConsensusState) + router.GET("/consensus", this.handleConsensusState) router.GET("/consensus/validators", this.handleValidatorList) // Events router.POST("/event_subs", this.handleEventSubscribe) diff --git a/test/temp/testdata.go b/test/temp/testdata.go new file mode 100644 index 0000000000000000000000000000000000000000..6438a3984c3ff315526e8a1aa0efafe99cf97c8e --- /dev/null +++ b/test/temp/testdata.go @@ -0,0 +1,73 @@ +package test + +import ( + "github.com/tendermint/tendermint/state" + edb "github.com/eris-ltd/erisdb/erisdb" + ess "github.com/eris-ltd/erisdb/erisdb/erisdbss" +) + + +var privValidator = []byte(`{ + "address": "37236DF251AB70022B1DA351F08A20FB52443E37", + "pub_key": [1, "CB3688B7561D488A2A4834E1AEE9398BEF94844D8BDBBCA980C11E3654A45906"], + "priv_key": [1, "6B72D45EB65F619F11CE580C8CAED9E0BADC774E9C9C334687A65DCBAD2C4151CB3688B7561D488A2A4834E1AEE9398BEF94844D8BDBBCA980C11E3654A45906"], + "last_height": 0, + "last_round": 0, + "last_step": 0 +}`); + +var genesisDoc = []byte(`{ + "chain_id": "my_tests", + "accounts": [ + { + "address": "F81CB9ED0A868BD961C4F5BBC0E39B763B89FCB6", + "amount": 690000000000 + }, + { + "address": "0000000000000000000000000000000000000002", + "amount": 565000000000 + }, + { + "address": "9E54C9ECA9A3FD5D4496696818DA17A9E17F69DA", + "amount": 525000000000 + }, + { + "address": "0000000000000000000000000000000000000004", + "amount": 110000000000 + }, + { + "address": "37236DF251AB70022B1DA351F08A20FB52443E37", + "amount": 110000000000 + } + + ], + "validators": [ + { + "pub_key": [1, "CB3688B7561D488A2A4834E1AEE9398BEF94844D8BDBBCA980C11E3654A45906"], + "amount": 5000000000, + "unbond_to": [ + { + "address": "93E243AC8A01F723DE353A4FA1ED911529CCB6E5", + "amount": 5000000000 + } + ] + } + ] +}`); + +var serverDuration uint = 100 + +type TestData struct { + requestData *ess.RequestData +} + +func LoadTestData() *TestData { + codec := edb.NewTCodec() + pvd := &state.PrivValidator{} + _ = codec.DecodeBytes(pvd, privValidator) + genesis := &state.GenesisDoc{} + _ = codec.DecodeBytes(genesis, genesisDoc) + td := &TestData{} + td.requestData = &ess.RequestData{pvd, genesis, serverDuration} + return td +} \ No newline at end of file diff --git a/test/temp/web_api_test.go b/test/temp/web_api_test.go new file mode 100644 index 0000000000000000000000000000000000000000..8656820afd6d49eef4bad330156461db414cced7 --- /dev/null +++ b/test/temp/web_api_test.go @@ -0,0 +1,143 @@ +package test + +// Basic imports +import ( + "bytes" + "fmt" + // edb "github.com/eris-ltd/erisdb/erisdb" + ess "github.com/eris-ltd/erisdb/erisdb/erisdbss" + edb "github.com/eris-ltd/erisdb/erisdb" + ep "github.com/eris-ltd/erisdb/erisdb/pipe" + "github.com/eris-ltd/erisdb/rpc" + "github.com/eris-ltd/erisdb/server" + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/suite" + // "io/ioutil" + "net/http" + "os" + "path" + "testing" + "time" +) + +const SS_URL = "http://localhost:1337/server" + +// +type WebApiSuite struct { + suite.Suite + baseDir string + serveProcess *server.ServeProcess + codec rpc.Codec + sUrl string + testData *TestData +} + +func (this *WebApiSuite) SetupSuite() { + gin.SetMode(gin.ReleaseMode) + baseDir := path.Join(os.TempDir(), "/.edbservers") + ss := ess.NewServerServer(baseDir) + proc := server.NewServeProcess(nil, ss) + _ = proc.Start() + this.serveProcess = proc + time.Sleep(1*time.Second) + this.testData = LoadTestData() + this.codec = edb.NewTCodec() + rBts, _ := this.codec.EncodeBytes(this.testData.requestData) + resp, _ := http.Post(SS_URL, "application/json", bytes.NewBuffer(rBts)) + rd := &ess.ResponseData{} + _ = this.codec.Decode(rd, resp.Body) + fmt.Println("Received URL: " + rd.URL) + this.sUrl = rd.URL + time.Sleep(1*time.Second) +} + +func (this *WebApiSuite) TearDownSuite() { + sec := this.serveProcess.StopEventChannel() + this.serveProcess.Stop(time.Millisecond) + <-sec + os.RemoveAll(this.baseDir) +} + +// ********************************************* Consensus ********************************************* + +func (this *WebApiSuite) Test_A0_ConsensusState() { + resp, errG := http.Get(this.sUrl + "/consensus") + this.NoError(errG) + ret := &ep.ConsensusState{} + errD := this.codec.Decode(ret, resp.Body) + this.NoError(errD) + fmt.Printf("Consensus state: %v\n", ret) +} + +func (this *WebApiSuite) Test_A1_Validators() { + resp, errG := http.Get(this.sUrl + "/consensus/validators") + this.NoError(errG) + ret := &ep.ValidatorList{} + errD := this.codec.Decode(ret, resp.Body) + this.NoError(errD) + fmt.Printf("Validators: %v\n", ret) +} + +// ********************************************* Network ********************************************* + +func (this *WebApiSuite) Test_B0_NetworkInfo() { + resp, errG := http.Get(this.sUrl + "/network") + this.NoError(errG) + ni := &ep.NetworkInfo{} + errD := this.codec.Decode(ni, resp.Body) + this.NoError(errD) + fmt.Printf("NetworkInfo: %v\n", ni) +} + +func (this *WebApiSuite) Test_B1_Moniker() { + resp, errG := http.Get(this.sUrl + "/network/moniker") + this.NoError(errG) + ret := &ep.Moniker{} + errD := this.codec.Decode(ret, resp.Body) + this.NoError(errD) + fmt.Printf("Moniker: %v\n", ret) +} + +func (this *WebApiSuite) Test_B2_Listening() { + resp, errG := http.Get(this.sUrl + "/network/listening") + this.NoError(errG) + ret := &ep.Listening{} + errD := this.codec.Decode(ret, resp.Body) + this.NoError(errD) + fmt.Printf("Listening: %v\n", ret) +} + +func (this *WebApiSuite) Test_B3_Listeners() { + resp, errG := http.Get(this.sUrl + "/network/listeners") + this.NoError(errG) + ret := &ep.Listeners{} + errD := this.codec.Decode(ret, resp.Body) + this.NoError(errD) + fmt.Printf("Listeners: %v\n", ret) +} + +func (this *WebApiSuite) Test_B4_Peers() { + resp, errG := http.Get(this.sUrl + "/network/peers") + this.NoError(errG) + ret := &ep.Peers{} + errD := this.codec.Decode(ret, resp.Body) + this.NoError(errD) + fmt.Printf("Listeners: %v\n", ret) +} + +// ********************************************* Transactions ********************************************* + +func (this *WebApiSuite) Test_C0_TransactContractCreate() { + resp, errG := http.Get(this.sUrl + "/unsafe/txpool") + this.NoError(errG) + ni := &ep.NetworkInfo{} + errD := this.codec.Decode(ni, resp.Body) + this.NoError(errD) + fmt.Printf("NetworkInfo: %v\n", ni) +} + +// ********************************************* Teardown ********************************************* + +func TestWebApiSuite(t *testing.T) { + suite.Run(t, &WebApiSuite{}) +} \ No newline at end of file