diff --git a/erisdb/erisdbss/http.go b/erisdb/erisdbss/http.go index 13a07c40f99c700fbb2e1041cbe5557e2dc9e106..9d79ee100c12a9d36b3f03e946fee48a8f1f314e 100644 --- a/erisdb/erisdbss/http.go +++ b/erisdb/erisdbss/http.go @@ -20,7 +20,7 @@ moniker = "anothertester" seeds = "" fast_sync = false db_backend = "leveldb" -log_level = "warn" +log_level = "debug" node_laddr = "" ` @@ -78,6 +78,7 @@ func (this *ServerServer) Running() bool { // Shut the server down. Will close all websocket sessions. func (this *ServerServer) ShutDown() { this.running = false + this.serverManager.killAll() } // Handle incoming requests. diff --git a/erisdb/erisdbss/server_manager.go b/erisdb/erisdbss/server_manager.go index 91141d73953bff8b7a8c0d30ae876e0677989f71..ae3c0e1bdbe7db78a7b79e96bae7fcb2e47590ab 100644 --- a/erisdb/erisdbss/server_manager.go +++ b/erisdb/erisdbss/server_manager.go @@ -193,6 +193,19 @@ func (this *ServerManager) add(data *RequestData) (*ResponseData, error) { return &ResponseData{URL: URL}, nil } +// Add a new erisdb process to the list. +func (this *ServerManager) killAll() { + this.mtx.Lock() + defer this.mtx.Unlock() + for len(this.running) > 0 { + task := this.running[0] + log.Debug("Closing down server.", "port", task.port) + task.sp.Kill() + this.running = this.running[1:] + this.idPool.ReleaseId(uint(task.port - PORT_BASE)) + } +} + // Creates a temp folder for the tendermint/erisdb node to run in. // Folder name is port based, so port=1337 meens folder="testnode1337" // Old folders are cleared out. before creating them, and the server will @@ -217,28 +230,28 @@ func (this *ServerManager) createWorkDir(data *RequestData, config *server.Serve if errCFG != nil { return "", errCFG } - log.Info("File written to %s.\n", cfgName) + log.Info("File written.", "name", cfgName) // Write validator. errPV := writeJSON(pvName, data.PrivValidator) if errPV != nil { return "", errPV } - log.Info("File written to %s.\n", pvName) + log.Info("File written.", "name", pvName) // Write genesis errG := writeJSON(genesisName, data.Genesis) if errG != nil { return "", errG } - log.Info("File written to %s.\n", genesisName) + log.Info("File written.", "name", genesisName) // Write server config. errWC := server.WriteServerConfig(scName, config) if errWC != nil { return "", errWC } - log.Info("File written to %s.\n", scName) + log.Info("File written.", "name", scName) return workDir, nil } diff --git a/erisdb/methods.go b/erisdb/methods.go index e04172a8835756b568a6f2b7a7dda5b1f9141894..261a57e14201f134d7fa4ba116d25d0cc37b2137 100644 --- a/erisdb/methods.go +++ b/erisdb/methods.go @@ -6,6 +6,7 @@ import ( "fmt" ep "github.com/eris-ltd/erisdb/erisdb/pipe" rpc "github.com/eris-ltd/erisdb/rpc" + "github.com/tendermint/tendermint/types" ) const ( @@ -364,13 +365,12 @@ func (this *ErisDbMethods) CallCode(request *rpc.RPCRequest, requester interface } func (this *ErisDbMethods) BroadcastTx(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { - param := &TxParam{} + param := &types.CallTx{} err := this.codec.DecodeBytes(param, request.Params) if err != nil { return nil, rpc.INVALID_PARAMS, err } - tx := param.Tx - receipt, errC := this.pipe.Transactor().BroadcastTx(tx) + receipt, errC := this.pipe.Transactor().BroadcastTx(param) if errC != nil { return nil, rpc.INTERNAL_ERROR, errC } diff --git a/erisdb/middleware_test.go b/erisdb/middleware_test.go index df19fa1c3e1c48821c19323c4ce1f47926540747..30b3597ab1b4b8c12cfe9f0f895658c536ed3f1e 100644 --- a/erisdb/middleware_test.go +++ b/erisdb/middleware_test.go @@ -21,7 +21,7 @@ func TestQueryNoColonSeparator(t *testing.T) { // Test no colon separated filter and proper filters mixed. func TestQueryNoColonSeparatorMulti(t *testing.T) { - _, err := _parseQuery("test + test1:24 + test2") + _, err := _parseQuery("test test1:24 test2") assert.Error(t, err, "Should detect missing colon.") } @@ -65,6 +65,22 @@ func TestQueryNEQ(t *testing.T) { testOp("!=", t) } +func TestCombined(t *testing.T) { + q := "balance:>=5 sequence:<8" + arr, err := _parseQuery(q) + assert.NoError(t, err) + assert.Len(t, arr, 2) + f0 := arr[0] + assert.Equal(t, f0.Field, "balance") + assert.Equal(t, f0.Op, ">=") + assert.Equal(t, f0.Value, "5") + f1 := arr[1] + assert.Equal(t, f1.Field, "sequence") + assert.Equal(t, f1.Op, "<") + assert.Equal(t, f1.Value, "8") + +} + // Test a working range query. func TestRangeQuery(t *testing.T) { assertRangeFilter(t, "5", "50", "5", "50") diff --git a/erisdb/params.go b/erisdb/params.go index 4f690db7e76209f88d77a36eb039474466e4dbe2..b5d8b6d4145b3c828dda38a085b437f54f27835a 100644 --- a/erisdb/params.go +++ b/erisdb/params.go @@ -23,11 +23,6 @@ type ( PrivKey []byte `json:"priv_key"` } - // Used to send a tx. Using a string as placeholder until the tx stuff is sorted out. - TxParam struct { - Tx types.Tx `json:"tx"` - } - // StorageAt StorageAtParam struct { Address []byte `json:"address"` @@ -72,7 +67,7 @@ type ( // Used when signing a tx. Uses placeholders just like TxParam SignTxParam struct { - Tx types.Tx `json:"tx"` + Tx *types.CallTx `json:"tx"` PrivAccounts []*account.PrivAccount `json:"priv_accounts"` } diff --git a/erisdb/restServer.go b/erisdb/restServer.go index a3e5ec8cd232dfdc644e1f4710432c8361e6ed9f..c0c74591bf3a2b1a11f86e4e41958a082d6e1d96 100644 --- a/erisdb/restServer.go +++ b/erisdb/restServer.go @@ -8,6 +8,7 @@ import ( "github.com/eris-ltd/erisdb/server" "github.com/eris-ltd/erisdb/util" "github.com/gin-gonic/gin" + "github.com/tendermint/tendermint/types" "strconv" "strings" ) @@ -99,7 +100,12 @@ func (this *RestServer) handleGenPrivAcc(c *gin.Context) { } func (this *RestServer) handleAccounts(c *gin.Context) { - accs, err := this.pipe.Accounts().Accounts(nil) + var filters []*ep.FilterData + fs, exists := c.Get("filters") + if exists { + filters = fs.([]*ep.FilterData) + } + accs, err := this.pipe.Accounts().Accounts(filters) if err != nil { c.AbortWithError(500, err) } @@ -326,12 +332,12 @@ func (this *RestServer) handlePeer(c *gin.Context) { // ********************************* Transactions ********************************* func (this *RestServer) handleBroadcastTx(c *gin.Context) { - param := &TxParam{} + param := &types.CallTx{} errD := this.codec.Decode(param, c.Request.Body) if errD != nil { c.AbortWithError(500, errD) } - receipt, err := this.pipe.Transactor().BroadcastTx(param.Tx) + receipt, err := this.pipe.Transactor().BroadcastTx(param) if err != nil { c.AbortWithError(500, err) } @@ -452,22 +458,24 @@ func peerAddressParam(c *gin.Context) { func parseQuery(c *gin.Context) { q := c.Query("q") - if q == "" { - c.Set("filters", nil) - } else { + if q != "" { data, err := _parseQuery(q) if err != nil { - c.AbortWithError(400, err) + c.Writer.WriteHeader(400) + c.Writer.Write([]byte(err.Error())) + c.Abort() + // c.AbortWithError(400, err) + return } c.Set("filters", data) } } func _parseQuery(queryString string) ([]*ep.FilterData, error) { - if queryString == "" { + if len(queryString) == 0 { return nil, nil } - filters := strings.Split(queryString, "+") + filters := strings.Split(queryString, " ") fdArr := []*ep.FilterData{} for _, f := range filters { kv := strings.Split(f, ":") diff --git a/erisdb/wsService.go b/erisdb/wsService.go index 8169996449a50e959ddc2ab94bc2f215060bd70c..0f88da101fb6bce121e7ae157e7d8880b7ceee97 100644 --- a/erisdb/wsService.go +++ b/erisdb/wsService.go @@ -5,6 +5,7 @@ import ( ep "github.com/eris-ltd/erisdb/erisdb/pipe" rpc "github.com/eris-ltd/erisdb/rpc" "github.com/eris-ltd/erisdb/server" + "encoding/json" ) // Used for ErisDb. Implements WebSocketService. @@ -32,11 +33,11 @@ func (this *ErisDbWsService) Process(msg []byte, session *server.WSSession) { fmt.Printf("REQUEST: %s\n", string(msg)) // Create new request object and unmarshal. req := &rpc.RPCRequest{} - errU := this.codec.DecodeBytes(req, msg) + errU := json.Unmarshal(msg, req) // Error when unmarshaling. if errU != nil { - this.writeError("Failed to parse request: "+errU.Error(), "", rpc.PARSE_ERROR, session) + this.writeError("Failed to parse request: " + errU.Error() + " . Raw: " + string(msg), "", rpc.PARSE_ERROR, session) return } diff --git a/server/server.go b/server/server.go index ef57cfb52ddd6f9c26a2f040f547dedb1094cb4b..7e470d37be9dfecab8a2dd378cab71729d25528a 100644 --- a/server/server.go +++ b/server/server.go @@ -135,6 +135,9 @@ func (this *ServeProcess) Start() error { // up until the timeout duration is passed, at which point it // will abort them and shut down. func (this *ServeProcess) Stop(timeout time.Duration) error { + for _, s := range this.servers { + s.ShutDown() + } toChan := make(chan struct{}) if timeout != 0 { go func() { diff --git a/server/websocket.go b/server/websocket.go index f6ea4c3a9d44cf60ebb498bd1b6de5d254054ac5..5b6546be9c1c3f50898c9de8475bf1fbfeb90d7c 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -24,7 +24,7 @@ const ( // Send pings to peer with this period. Must be less than pongWait. pingPeriod = (pongWait * 9) / 10 // Maximum message size allowed from a peer. - maxMessageSize = 512 + maxMessageSize = 2048 ) // Services requests. Message bytes are passed along with the session diff --git a/test/http_flood_test.go b/test/server/http_flood_test.go similarity index 98% rename from test/http_flood_test.go rename to test/server/http_flood_test.go index 18fd722edda6bac24b97a8d56b816cb8555eb37f..128f73c089f30bb5cba276490dfe5135b958a518 100644 --- a/test/http_flood_test.go +++ b/test/server/http_flood_test.go @@ -1,4 +1,4 @@ -package test +package server import ( "fmt" diff --git a/test/scumbag.go b/test/server/scumbag.go similarity index 97% rename from test/scumbag.go rename to test/server/scumbag.go index 8928bccf221f9764dcdc2e81ad53e985aaa23311..72d02c4d5b41bcffaa2d02ec228e72ff5611f05e 100644 --- a/test/scumbag.go +++ b/test/server/scumbag.go @@ -1,4 +1,4 @@ -package test +package server import ( "encoding/json" @@ -13,7 +13,7 @@ import ( func init() { runtime.GOMAXPROCS(runtime.NumCPU()) log15.Root().SetHandler(log15.LvlFilterHandler( - log15.LvlError, + log15.LvlWarn, log15.StreamHandler(os.Stdout, log15.TerminalFormat()), )) gin.SetMode(gin.ReleaseMode) diff --git a/test/ws_flood_test.go b/test/server/ws_flood_test.go similarity index 99% rename from test/ws_flood_test.go rename to test/server/ws_flood_test.go index cc8296fc67218d54f5501ef67f4fe099776d534f..1c9b3e6fa07f780ddd2b97f2f8e1df74204ad413 100644 --- a/test/ws_flood_test.go +++ b/test/server/ws_flood_test.go @@ -1,4 +1,4 @@ -package test +package server import ( "github.com/eris-ltd/erisdb/client" diff --git a/test/testdata/filters/testdata_filters.go b/test/testdata/filters/testdata_filters.go new file mode 100644 index 0000000000000000000000000000000000000000..ecab8cd32fe671c34d47e466fc990a1fa148e0b3 --- /dev/null +++ b/test/testdata/filters/testdata_filters.go @@ -0,0 +1,237 @@ +package filters + +import ( + edb "github.com/eris-ltd/erisdb/erisdb" + ep "github.com/eris-ltd/erisdb/erisdb/pipe" + "github.com/tendermint/tendermint/state" +) + +var testDataJson = `{ + "chain_data": { + "priv_validator": { + "address": "37236DF251AB70022B1DA351F08A20FB52443E37", + "pub_key": [1, "CB3688B7561D488A2A4834E1AEE9398BEF94844D8BDBBCA980C11E3654A45906"], + "priv_key": [1, "6B72D45EB65F619F11CE580C8CAED9E0BADC774E9C9C334687A65DCBAD2C4151CB3688B7561D488A2A4834E1AEE9398BEF94844D8BDBBCA980C11E3654A45906"], + "last_height": 0, + "last_round": 0, + "last_step": 0 + }, + "genesis": { + "chain_id": "my_tests", + "accounts": [ + { + "address": "1000000000000000000000000000000000000000", + "amount": 0 + }, + { + "address": "0000000000000000000000000000000000000001", + "amount": 1 + }, + { + "address": "0000000000000000000000000000000000000002", + "amount": 2 + }, + { + "address": "0000000000000000000000000000000000000003", + "amount": 3 + }, + { + "address": "0000000000000000000000000000000000000004", + "amount": 4 + }, + { + "address": "0000000000000000000000000000000000000005", + "amount": 5 + }, + { + "address": "0000000000000000000000000000000000000006", + "amount": 6 + }, + { + "address": "0000000000000000000000000000000000000007", + "amount": 7 + }, + { + "address": "0000000000000000000000000000000000000008", + "amount": 8 + }, + { + "address": "0000000000000000000000000000000000000009", + "amount": 9 + }, + { + "address": "000000000000000000000000000000000000000A", + "amount": 10 + }, + { + "address": "000000000000000000000000000000000000000B", + "amount": 11 + }, + { + "address": "000000000000000000000000000000000000000C", + "amount": 12 + }, + { + "address": "000000000000000000000000000000000000000D", + "amount": 13 + }, + { + "address": "000000000000000000000000000000000000000E", + "amount": 14 + }, + { + "address": "000000000000000000000000000000000000000F", + "amount": 15 + } + ], + "validators": [ + { + "pub_key": [1, "CB3688B7561D488A2A4834E1AEE9398BEF94844D8BDBBCA980C11E3654A45906"], + "amount": 5000000000, + "unbond_to": [ + { + "address": "93E243AC8A01F723DE353A4FA1ED911529CCB6E5", + "amount": 5000000000 + } + ] + } + ] + } + }, + "input": { + "filters0": [ + { + "field": "balance", + "op": "==", + "value": "0" + } + ], + "filters1": [ + { + "field": "balance", + "op": ">", + "value": "12" + } + ], + "filters2": [ + { + "field": "balance", + "op": ">=", + "value": "5" + }, + { + "field": "balance", + "op": "<", + "value": "8" + } + ] + }, + "output": { + "accounts0": { + "accounts": [ + { + "address": "1000000000000000000000000000000000000000", + "pub_key": null, + "sequence": 0, + "balance": 0, + "code": "", + "storage_root": "" + } + ] + }, + "accounts1": { + "accounts": [ + { + "address": "000000000000000000000000000000000000000D", + "pub_key": null, + "sequence": 0, + "balance": 13, + "code": "", + "storage_root": "" + }, + { + "address": "000000000000000000000000000000000000000E", + "pub_key": null, + "sequence": 0, + "balance": 14, + "code": "", + "storage_root": "" + }, + { + "address": "000000000000000000000000000000000000000F", + "pub_key": null, + "sequence": 0, + "balance": 15, + "code": "", + "storage_root": "" + } + ] + }, + "accounts2": { + "accounts": [ + { + "address": "0000000000000000000000000000000000000005", + "pub_key": null, + "sequence": 0, + "balance": 5, + "code": "", + "storage_root": "" + }, + { + "address": "0000000000000000000000000000000000000006", + "pub_key": null, + "sequence": 0, + "balance": 6, + "code": "", + "storage_root": "" + }, + { + "address": "0000000000000000000000000000000000000007", + "pub_key": null, + "sequence": 0, + "balance": 7, + "code": "", + "storage_root": "" + } + ] + } + } +}` + +var serverDuration uint = 100 + +type ( + ChainData struct { + PrivValidator *state.PrivValidator `json:"priv_validator"` + Genesis *state.GenesisDoc `json:"genesis"` + } + + Input struct { + Filters0 []*ep.FilterData `json:"filters0"` + Filters1 []*ep.FilterData `json:"filters1"` + Filters2 []*ep.FilterData `json:"filters2"` + } + + Output struct { + Accounts0 *ep.AccountList `json:"accounts0"` + Accounts1 *ep.AccountList `json:"accounts1"` + Accounts2 *ep.AccountList `json:"accounts2"` + } + + TestData struct { + ChainData *ChainData `json:"chain_data"` + Input *Input `json:"input"` + Output *Output `json:"output"` + } +) + +func LoadTestData() *TestData { + codec := edb.NewTCodec() + testData := &TestData{} + err := codec.DecodeBytes(testData, []byte(testDataJson)) + // TODO for now. + if err != nil { + panic(err) + } + return testData +} diff --git a/test/testdata.go b/test/testdata/testdata/testdata.go similarity index 93% rename from test/testdata.go rename to test/testdata/testdata/testdata.go index 20c4d64a252bde317f9767f6999a1967936671c8..1df8a4603c95c45521c3c2e4511b9db9a519e2c5 100644 --- a/test/testdata.go +++ b/test/testdata/testdata/testdata.go @@ -1,4 +1,4 @@ -package test +package testdata import ( edb "github.com/eris-ltd/erisdb/erisdb" @@ -81,6 +81,12 @@ var testDataJson = `{ "block_range": { "min": 0, "max": 0 + }, + "priv_account": { + "address": "B4F9DA82738D37A1D83AD2CDD0C0D3CBA76EA4E7", + "pub_key": [ 1, "9C74ECA0AF1DF930C69F5B9F72A1802C47D1A47E14D4572ADB24A63EA501D917" ], + "priv_key": [ 1, + "82197A833282E819D172A3CB19B4CA3FFCA2F2CBE042B01CCF66E5147AF3C3759C74ECA0AF1DF930C69F5B9F72A1802C47D1A47E14D4572ADB24A63EA501D917" ] } }, "output": { @@ -251,6 +257,11 @@ var testDataJson = `{ "min_height": 0, "max_height": 0, "block_metas": [] + }, + "gen_priv_account": { + "address": "", + "pub_key": [ 1, "" ], + "priv_key": [ 1, "" ] } } }` @@ -271,12 +282,13 @@ type ( } Input struct { - AccountAddress string `json:"account_address"` - StorageAddress string `json:"storage_address"` - TxCreate *edb.TransactParam `json:"tx_create"` - Tx *edb.TransactParam `json:"tx"` - CallCode *edb.CallCodeParam `json:"call_code"` - BlockRange *BlockRange `json:"block_range"` + AccountAddress string `json:"account_address"` + StorageAddress string `json:"storage_address"` + TxCreate *edb.TransactParam `json:"tx_create"` + Tx *edb.TransactParam `json:"tx"` + CallCode *edb.CallCodeParam `json:"call_code"` + BlockRange *BlockRange `json:"block_range"` + PrivAccount *account.PrivAccount `json:"priv_account"` } Output struct { @@ -301,6 +313,7 @@ type ( LatestBlockHeight *ep.LatestBlockHeight `json:"latest_block_height"` Block *types.Block `json:"block"` Blocks *ep.Blocks `json:"blocks"` + GenPrivAccount *account.PrivAccount `json:"gen_priv_account"` } TestData struct { diff --git a/test/web_api/query_test.go b/test/web_api/query_test.go new file mode 100644 index 0000000000000000000000000000000000000000..eb7e842037a8d38d483742861401587ea7f9f7e5 --- /dev/null +++ b/test/web_api/query_test.go @@ -0,0 +1,119 @@ +package web_api + +// Basic imports +import ( + "bytes" + "fmt" + edb "github.com/eris-ltd/erisdb/erisdb" + ess "github.com/eris-ltd/erisdb/erisdb/erisdbss" + ep "github.com/eris-ltd/erisdb/erisdb/pipe" + "github.com/eris-ltd/erisdb/rpc" + "github.com/eris-ltd/erisdb/server" + fd "github.com/eris-ltd/erisdb/test/testdata/filters" + "github.com/stretchr/testify/suite" + "net/http" + "os" + "path" + "testing" +) + +type QuerySuite struct { + suite.Suite + baseDir string + serveProcess *server.ServeProcess + codec rpc.Codec + sUrl string + testData *fd.TestData +} + +func (this *QuerySuite) SetupSuite() { + baseDir := path.Join(os.TempDir(), "/.edbservers") + ss := ess.NewServerServer(baseDir) + proc := server.NewServeProcess(nil, ss) + _ = proc.Start() + this.serveProcess = proc + testData := fd.LoadTestData() + this.codec = edb.NewTCodec() + + requestData := &ess.RequestData{testData.ChainData.PrivValidator, testData.ChainData.Genesis, SERVER_DURATION} + rBts, _ := this.codec.EncodeBytes(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 + this.testData = testData +} + +func (this *QuerySuite) TearDownSuite() { + sec := this.serveProcess.StopEventChannel() + this.serveProcess.Stop(0) + <-sec +} + +// ********************************************* Tests ********************************************* + + +// TODO make these functions into one. +func (this *QuerySuite) Test_Accounts0() { + fd := this.testData.Input.Filters0 + resp := this.get("/accounts?" + generateQuery(fd)) + ret := &ep.AccountList{} + errD := this.codec.Decode(ret, resp.Body) + this.NoError(errD) + this.Equal(this.testData.Output.Accounts0, ret) +} + +func (this *QuerySuite) Test_Accounts1() { + fd := this.testData.Input.Filters1 + resp := this.get("/accounts?" + generateQuery(fd)) + ret := &ep.AccountList{} + errD := this.codec.Decode(ret, resp.Body) + this.NoError(errD) + this.Equal(this.testData.Output.Accounts1, ret) +} + +func (this *QuerySuite) Test_Accounts2() { + fd := this.testData.Input.Filters2 + resp := this.get("/accounts?" + generateQuery(fd)) + ret := &ep.AccountList{} + errD := this.codec.Decode(ret, resp.Body) + this.NoError(errD) + this.Equal(this.testData.Output.Accounts2, ret) +} + +// ********************************************* Utilities ********************************************* + +func (this *QuerySuite) get(endpoint string) *http.Response { + resp, errG := http.Get(this.sUrl + endpoint) + this.NoError(errG) + this.Equal(200, resp.StatusCode) + return resp +} + +func (this *QuerySuite) postJson(endpoint string, v interface{}) *http.Response { + bts, errE := this.codec.EncodeBytes(v) + this.NoError(errE) + resp, errP := http.Post(this.sUrl+endpoint, "application/json", bytes.NewBuffer(bts)) + this.NoError(errP) + this.Equal(200, resp.StatusCode) + return resp +} + +func generateQuery(fda []*ep.FilterData) string { + query := "q=" + for i := 0; i < len(fda); i++ { + fd := fda[i] + query += fd.Field + ":" + fd.Op + fd.Value + if i != len(fda)-1 { + query += "+" + } + } + return query +} + +// ********************************************* Entrypoint ********************************************* + +func TestQuerySuite(t *testing.T) { + suite.Run(t, &QuerySuite{}) +} diff --git a/test/web_api/shared.go b/test/web_api/shared.go new file mode 100644 index 0000000000000000000000000000000000000000..9c1ad6f31802e92c144f1c55cb65a31a23de827b --- /dev/null +++ b/test/web_api/shared.go @@ -0,0 +1,20 @@ +package web_api + +import ( + "github.com/gin-gonic/gin" + "github.com/tendermint/log15" + "os" + "runtime" +) + +const SS_URL = "http://localhost:1337/server" +const SERVER_DURATION = 10 + +func init() { + runtime.GOMAXPROCS(runtime.NumCPU()) + log15.Root().SetHandler(log15.LvlFilterHandler( + log15.LvlWarn, + log15.StreamHandler(os.Stdout, log15.TerminalFormat()), + )) + gin.SetMode(gin.ReleaseMode) +} diff --git a/test/web_api_test.go b/test/web_api/web_api_test.go similarity index 96% rename from test/web_api_test.go rename to test/web_api/web_api_test.go index 9f2997f59329b3e59cdbc55fa29976e496888503..84f64835e7281e7b1bc4f03bcee8814d60302f5a 100644 --- a/test/web_api_test.go +++ b/test/web_api/web_api_test.go @@ -1,4 +1,4 @@ -package test +package web_api // Basic imports import ( @@ -10,6 +10,7 @@ import ( ep "github.com/eris-ltd/erisdb/erisdb/pipe" "github.com/eris-ltd/erisdb/rpc" "github.com/eris-ltd/erisdb/server" + td "github.com/eris-ltd/erisdb/test/testdata/testdata" "github.com/gin-gonic/gin" "github.com/stretchr/testify/suite" "github.com/tendermint/tendermint/account" @@ -17,12 +18,8 @@ import ( "os" "path" "testing" - "time" ) -const SS_URL = "http://localhost:1337/server" -const SERVER_DURATION = 5 - // type WebApiSuite struct { suite.Suite @@ -30,7 +27,7 @@ type WebApiSuite struct { serveProcess *server.ServeProcess codec rpc.Codec sUrl string - testData *TestData + testData *td.TestData } func (this *WebApiSuite) SetupSuite() { @@ -40,8 +37,7 @@ func (this *WebApiSuite) SetupSuite() { proc := server.NewServeProcess(nil, ss) _ = proc.Start() this.serveProcess = proc - time.Sleep(1 * time.Second) - testData := LoadTestData() + testData := td.LoadTestData() this.codec = edb.NewTCodec() requestData := &ess.RequestData{testData.ChainData.PrivValidator, testData.ChainData.Genesis, SERVER_DURATION} @@ -52,14 +48,12 @@ func (this *WebApiSuite) SetupSuite() { fmt.Println("Received URL: " + rd.URL) this.sUrl = rd.URL this.testData = testData - time.Sleep(1 * time.Second) } func (this *WebApiSuite) TearDownSuite() { sec := this.serveProcess.StopEventChannel() - this.serveProcess.Stop(time.Millisecond) + this.serveProcess.Stop(0) <-sec - os.RemoveAll(this.baseDir) } // ********************************************* Consensus ********************************************* @@ -241,7 +235,6 @@ func (this *WebApiSuite) Test_E4_Blocks() { func (this *WebApiSuite) get(endpoint string) *http.Response { resp, errG := http.Get(this.sUrl + endpoint) this.NoError(errG) - this.Equal(200, resp.StatusCode) return resp }