Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update lcd process hash endpoint to use a dedicated request structure #1755

Merged
merged 2 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion e2e/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/mesg-foundation/engine/ownership"
"github.com/mesg-foundation/engine/process"
pb "github.com/mesg-foundation/engine/protobuf/api"
processrest "github.com/mesg-foundation/engine/x/process/client/rest"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -126,8 +127,13 @@ func testProcess(t *testing.T) {
})

t.Run("hash", func(t *testing.T) {
msg := processrest.HashRequest{
Name: req.Name,
Nodes: req.Nodes,
Edges: req.Edges,
}
var hash hash.Hash
lcdPost(t, "process/hash", req, &hash)
lcdPost(t, "process/hash", msg, &hash)
require.Equal(t, processHash, hash)
})

Expand Down
14 changes: 13 additions & 1 deletion e2e/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/mesg-foundation/engine/ownership"
pb "github.com/mesg-foundation/engine/protobuf/api"
"github.com/mesg-foundation/engine/service"
servicerest "github.com/mesg-foundation/engine/x/service/client/rest"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -73,8 +74,19 @@ func testService(t *testing.T) {
})

t.Run("hash", func(t *testing.T) {
msg := servicerest.HashRequest{
Sid: req.Sid,
Name: req.Name,
Description: req.Description,
Configuration: req.Configuration,
Tasks: req.Tasks,
Events: req.Events,
Dependencies: req.Dependencies,
Repository: req.Repository,
Source: req.Source,
}
var hash hash.Hash
lcdPost(t, "service/hash", req, &hash)
lcdPost(t, "service/hash", msg, &hash)
require.Equal(t, testServiceHash, hash)
})

Expand Down
10 changes: 8 additions & 2 deletions x/process/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/gorilla/mux"
"github.com/mesg-foundation/engine/process"
"github.com/mesg-foundation/engine/protobuf/api"
"github.com/mesg-foundation/engine/x/process/internal/types"
)

Expand Down Expand Up @@ -97,6 +96,13 @@ func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
}
}

// HashRequest is the request of the hash endpoint.
type HashRequest struct {
Name string `json:"name,omitempty"`
Nodes []*process.Process_Node `json:"nodes,omitempty"`
Edges []*process.Process_Edge `json:"edges,omitempty"`
}

func queryHashHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
Expand All @@ -110,7 +116,7 @@ func queryHashHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return
}

var req api.CreateProcessRequest
var req HashRequest
if err := cliCtx.Codec.UnmarshalJSON(data, &req); err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
Expand Down