From 77374085d66decc1da5648c301c7e66e8eca459a Mon Sep 17 00:00:00 2001 From: Benjamin Bollen <ben@erisindustries.com> Date: Wed, 20 Jul 2016 12:20:28 +0200 Subject: [PATCH] restore testdata test for rpc v0 --- rpc/{tendermint => }/jsonrpc.go | 2 +- rpc/{tendermint => }/rpc_test.go | 2 +- rpc/v0/json_service.go | 33 +++++++++---------- ...k_web_api_test.g_ => mock_web_api_test.go} | 8 ++--- test/mock/{pipe.g_ => pipe.go} | 18 ++++++---- test/testdata/{helpers.g_ => helpers.go} | 0 .../testdata/{testdata.g_ => testdata.go} | 22 ++++++------- 7 files changed, 44 insertions(+), 41 deletions(-) rename rpc/{tendermint => }/jsonrpc.go (98%) rename rpc/{tendermint => }/rpc_test.go (96%) rename test/mock/{mock_web_api_test.g_ => mock_web_api_test.go} (98%) rename test/mock/{pipe.g_ => pipe.go} (93%) rename test/testdata/{helpers.g_ => helpers.go} (100%) rename test/testdata/testdata/{testdata.g_ => testdata.go} (97%) diff --git a/rpc/tendermint/jsonrpc.go b/rpc/jsonrpc.go similarity index 98% rename from rpc/tendermint/jsonrpc.go rename to rpc/jsonrpc.go index f0be57ee..72115138 100644 --- a/rpc/tendermint/jsonrpc.go +++ b/rpc/jsonrpc.go @@ -1,4 +1,4 @@ -package rpc_tendermint +package rpc import ( "encoding/json" diff --git a/rpc/tendermint/rpc_test.go b/rpc/rpc_test.go similarity index 96% rename from rpc/tendermint/rpc_test.go rename to rpc/rpc_test.go index 5764ef64..bfafa4c2 100644 --- a/rpc/tendermint/rpc_test.go +++ b/rpc/rpc_test.go @@ -1,4 +1,4 @@ -package rpc_tendermint +package rpc import ( "github.com/stretchr/testify/assert" diff --git a/rpc/v0/json_service.go b/rpc/v0/json_service.go index adce33f2..822c5e7e 100644 --- a/rpc/v0/json_service.go +++ b/rpc/v0/json_service.go @@ -11,7 +11,6 @@ import ( definitions "github.com/eris-ltd/eris-db/definitions" event "github.com/eris-ltd/eris-db/event" rpc "github.com/eris-ltd/eris-db/rpc" - rpc_tendermint "github.com/eris-ltd/eris-db/rpc/tendermint" server "github.com/eris-ltd/eris-db/server" ) @@ -80,21 +79,21 @@ func NewErisDbJsonService(codec rpc.Codec, pipe definitions.Pipe, func (this *ErisDbJsonService) Process(r *http.Request, w http.ResponseWriter) { // Create new request object and unmarshal. - req := &rpc_tendermint.RPCRequest{} + req := &rpc.RPCRequest{} decoder := json.NewDecoder(r.Body) errU := decoder.Decode(req) // Error when decoding. if errU != nil { this.writeError("Failed to parse request: "+errU.Error(), "", - rpc_tendermint.PARSE_ERROR, w) + rpc.PARSE_ERROR, w) return } // Wrong protocol version. if req.JSONRPC != "2.0" { this.writeError("Wrong protocol version: "+req.JSONRPC, req.Id, - rpc_tendermint.INVALID_REQUEST, w) + rpc.INVALID_REQUEST, w) return } @@ -108,13 +107,13 @@ func (this *ErisDbJsonService) Process(r *http.Request, w http.ResponseWriter) { this.writeResponse(req.Id, resp, w) } } else { - this.writeError("Method not found: "+mName, req.Id, rpc_tendermint.METHOD_NOT_FOUND, w) + this.writeError("Method not found: "+mName, req.Id, rpc.METHOD_NOT_FOUND, w) } } // Helper for writing error responses. func (this *ErisDbJsonService) writeError(msg, id string, code int, w http.ResponseWriter) { - response := rpc_tendermint.NewRPCErrorResponse(id, code, msg) + response := rpc.NewRPCErrorResponse(id, code, msg) err := this.codec.Encode(response, w) // If there's an error here all bets are off. if err != nil { @@ -127,11 +126,11 @@ func (this *ErisDbJsonService) writeError(msg, id string, code int, w http.Respo // Helper for writing responses. func (this *ErisDbJsonService) writeResponse(id string, result interface{}, w http.ResponseWriter) { log.Debug("Result: %v\n", result) - response := rpc_tendermint.NewRPCResponse(id, result) + response := rpc.NewRPCResponse(id, result) err := this.codec.Encode(response, w) log.Debug("Response: %v\n", response) if err != nil { - this.writeError("Internal error: "+err.Error(), id, rpc_tendermint.INTERNAL_ERROR, w) + this.writeError("Internal error: "+err.Error(), id, rpc.INTERNAL_ERROR, w) return } w.WriteHeader(200) @@ -140,51 +139,51 @@ func (this *ErisDbJsonService) writeResponse(id string, result interface{}, w ht // *************************************** Events ************************************ // Subscribe to an event. -func (this *ErisDbJsonService) EventSubscribe(request *rpc_tendermint.RPCRequest, +func (this *ErisDbJsonService) EventSubscribe(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &EventIdParam{} err := json.Unmarshal(request.Params, param) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } eventId := param.EventId subId, errC := this.eventSubs.Add(eventId) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return &event.EventSub{subId}, 0, nil } // Un-subscribe from an event. -func (this *ErisDbJsonService) EventUnsubscribe(request *rpc_tendermint.RPCRequest, +func (this *ErisDbJsonService) EventUnsubscribe(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &SubIdParam{} err := json.Unmarshal(request.Params, param) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } subId := param.SubId result, errC := this.pipe.Events().Unsubscribe(subId) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return &event.EventUnsub{result}, 0, nil } // Check subscription event cache for new data. -func (this *ErisDbJsonService) EventPoll(request *rpc_tendermint.RPCRequest, +func (this *ErisDbJsonService) EventPoll(request *rpc.RPCRequest, requester interface{}) (interface{}, int, error) { param := &SubIdParam{} err := json.Unmarshal(request.Params, param) if err != nil { - return nil, rpc_tendermint.INVALID_PARAMS, err + return nil, rpc.INVALID_PARAMS, err } subId := param.SubId result, errC := this.eventSubs.Poll(subId) if errC != nil { - return nil, rpc_tendermint.INTERNAL_ERROR, errC + return nil, rpc.INTERNAL_ERROR, errC } return &event.PollResponse{result}, 0, nil } diff --git a/test/mock/mock_web_api_test.g_ b/test/mock/mock_web_api_test.go similarity index 98% rename from test/mock/mock_web_api_test.g_ rename to test/mock/mock_web_api_test.go index 68abad45..3435935b 100644 --- a/test/mock/mock_web_api_test.g_ +++ b/test/mock/mock_web_api_test.go @@ -252,7 +252,7 @@ func (this *MockSuite) TestGetPeer() { func (this *MockSuite) TestTransactCreate() { resp := this.postJson("/unsafe/txpool", this.testData.TransactCreate.Input) - ret := &core_types.Receipt{} + ret := &txs.Receipt{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.TransactCreate.Output) @@ -260,7 +260,7 @@ func (this *MockSuite) TestTransactCreate() { func (this *MockSuite) TestTransact() { resp := this.postJson("/unsafe/txpool", this.testData.Transact.Input) - ret := &core_types.Receipt{} + ret := &txs.Receipt{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.Transact.Output) @@ -268,7 +268,7 @@ func (this *MockSuite) TestTransact() { func (this *MockSuite) TestTransactNameReg() { resp := this.postJson("/unsafe/namereg/txpool", this.testData.TransactNameReg.Input) - ret := &core_types.Receipt{} + ret := &txs.Receipt{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.TransactNameReg.Output) @@ -276,7 +276,7 @@ func (this *MockSuite) TestTransactNameReg() { func (this *MockSuite) TestGetUnconfirmedTxs() { resp := this.get("/txpool") - ret := &core_types.UnconfirmedTxs{} + ret := &txs.UnconfirmedTxs{} errD := this.codec.Decode(ret, resp.Body) this.NoError(errD) this.Equal(ret, this.testData.GetUnconfirmedTxs.Output) diff --git a/test/mock/pipe.g_ b/test/mock/pipe.go similarity index 93% rename from test/mock/pipe.g_ rename to test/mock/pipe.go index 61fc0398..1eb3b84e 100644 --- a/test/mock/pipe.g_ +++ b/test/mock/pipe.go @@ -92,6 +92,10 @@ func (this *MockPipe) SetConsensusEngine(_ definitions.ConsensusEngine) error { return nil } +func (this *MockPipe) GetConsensusEngine() definitions.ConsensusEngine { + return nil +} + func (this *MockPipe) GetTendermintPipe() (definitions.TendermintPipe, error) { return nil, fmt.Errorf("Tendermint pipe is not supported by mocked pipe.") } @@ -191,7 +195,7 @@ type namereg struct { testData *td.TestData } -func (this *namereg) Entry(key string) (*types.NameRegEntry, error) { +func (this *namereg) Entry(key string) (*core_types.NameRegEntry, error) { return this.testData.GetNameRegEntry.Output, nil } @@ -246,15 +250,15 @@ func (this *transactor) CallCode(from, code, data []byte) (*core_types.Call, err return this.testData.CallCode.Output, nil } -func (this *transactor) BroadcastTx(tx types.Tx) (*core_types.Receipt, error) { +func (this *transactor) BroadcastTx(tx types.Tx) (*types.Receipt, error) { return nil, nil } -func (this *transactor) UnconfirmedTxs() (*core_types.UnconfirmedTxs, error) { +func (this *transactor) UnconfirmedTxs() (*types.UnconfirmedTxs, error) { return this.testData.GetUnconfirmedTxs.Output, nil } -func (this *transactor) Transact(privKey, address, data []byte, gasLimit, fee int64) (*core_types.Receipt, error) { +func (this *transactor) Transact(privKey, address, data []byte, gasLimit, fee int64) (*types.Receipt, error) { if address == nil || len(address) == 0 { return this.testData.TransactCreate.Output, nil } @@ -265,15 +269,15 @@ func (this *transactor) TransactAndHold(privKey, address, data []byte, gasLimit, return nil, nil } -func (this *transactor) Send(privKey, toAddress []byte, amount int64) (*core_types.Receipt, error) { +func (this *transactor) Send(privKey, toAddress []byte, amount int64) (*types.Receipt, error) { return nil, nil } -func (this *transactor) SendAndHold(privKey, toAddress []byte, amount int64) (*core_types.Receipt, error) { +func (this *transactor) SendAndHold(privKey, toAddress []byte, amount int64) (*types.Receipt, error) { return nil, nil } -func (this *transactor) TransactNameReg(privKey []byte, name, data string, amount, fee int64) (*core_types.Receipt, error) { +func (this *transactor) TransactNameReg(privKey []byte, name, data string, amount, fee int64) (*types.Receipt, error) { return this.testData.TransactNameReg.Output, nil } diff --git a/test/testdata/helpers.g_ b/test/testdata/helpers.go similarity index 100% rename from test/testdata/helpers.g_ rename to test/testdata/helpers.go diff --git a/test/testdata/testdata/testdata.g_ b/test/testdata/testdata/testdata.go similarity index 97% rename from test/testdata/testdata/testdata.g_ rename to test/testdata/testdata/testdata.go index d780d80a..c1dd9e9e 100644 --- a/test/testdata/testdata/testdata.g_ +++ b/test/testdata/testdata/testdata.go @@ -2,12 +2,12 @@ package testdata import ( - account "github.com/eris-ltd/eris-db/account" - core_types "github.com/eris-ltd/eris-db/core/types" - event "github.com/eris-ltd/eris-db/event" - rpc_v0 "github.com/eris-ltd/eris-db/rpc/v0" - stypes "github.com/eris-ltd/eris-db/manager/eris-mint/state/types" - types "github.com/eris-ltd/eris-db/txs" + account "github.com/eris-ltd/eris-db/account" + core_types "github.com/eris-ltd/eris-db/core/types" + event "github.com/eris-ltd/eris-db/event" + rpc_v0 "github.com/eris-ltd/eris-db/rpc/v0" + stypes "github.com/eris-ltd/eris-db/manager/eris-mint/state/types" + transaction "github.com/eris-ltd/eris-db/txs" mintTypes "github.com/tendermint/tendermint/types" ) @@ -604,16 +604,16 @@ type ( TransactData struct { Input *rpc_v0.TransactParam `json:"input"` - Output *core_types.Receipt `json:"output"` + Output *transaction.Receipt `json:"output"` } TransactCreateData struct { Input *rpc_v0.TransactParam `json:"input"` - Output *core_types.Receipt `json:"output"` + Output *transaction.Receipt `json:"output"` } GetUnconfirmedTxsData struct { - Output *core_types.UnconfirmedTxs `json:"output"` + Output *transaction.UnconfirmedTxs `json:"output"` } CallCodeData struct { @@ -638,12 +638,12 @@ type ( TransactNameRegData struct { Input *rpc_v0.TransactNameRegParam `json:"input"` - Output *core_types.Receipt `json:"output"` + Output *transaction.Receipt `json:"output"` } GetNameRegEntryData struct { Input *rpc_v0.NameRegEntryParam `json:"input"` - Output *types.NameRegEntry `json:"output"` + Output *core_types.NameRegEntry `json:"output"` } GetNameRegEntriesData struct { -- GitLab