Skip to content

Commit

Permalink
squash commits
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandr Bezobchuk committed Feb 19, 2019
1 parent 1b18df8 commit e03285d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
7 changes: 6 additions & 1 deletion client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func WriteGenerateStdTxResponse(w http.ResponseWriter, cdc *codec.Codec,
br.Simulate, br.ChainID, br.Memo, br.Fees, br.GasPrices,
)

if simAndExec {
if br.Simulate || simAndExec {
if gasAdj < 0 {
rest.WriteErrorResponse(w, http.StatusBadRequest, client.ErrInvalidGasAdjustment.Error())
return
Expand All @@ -47,6 +47,11 @@ func WriteGenerateStdTxResponse(w http.ResponseWriter, cdc *codec.Codec,
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

if br.Simulate {
rest.WriteSimulationResponse(w, cdc, txBldr.Gas())
return
}
}

stdMsg, err := txBldr.BuildSignMsg(msgs)
Expand Down
4 changes: 2 additions & 2 deletions types/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func (br BaseReq) ValidateBasic(w http.ResponseWriter) bool {
}
}

if len(br.From) == 0 {
WriteErrorResponse(w, http.StatusUnauthorized, "name or address required but not specified")
if _, err := sdk.AccAddressFromBech32(br.From); err != nil || len(br.From) == 0 {
WriteErrorResponse(w, http.StatusUnauthorized, fmt.Sprintf("invalid from address: %s", br.From))
return false
}

Expand Down
9 changes: 5 additions & 4 deletions types/rest/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,26 @@ import (
type mockResponseWriter struct{}

func TestBaseReqValidateBasic(t *testing.T) {
fromAddr := "cosmos1cq0sxam6x4l0sv9yz3a2vlqhdhvt2k6jtgcse0"
tenstakes, err := types.ParseCoins("10stake")
require.NoError(t, err)
onestake, err := types.ParseDecCoins("1.0stake")
require.NoError(t, err)

req1 := NewBaseReq(
"nonempty", "", "nonempty", "", "", 0, 0, tenstakes, nil, false,
fromAddr, "", "nonempty", "", "", 0, 0, tenstakes, nil, false,
)
req2 := NewBaseReq(
"", "", "nonempty", "", "", 0, 0, tenstakes, nil, false,
)
req3 := NewBaseReq(
"nonempty", "", "", "", "", 0, 0, tenstakes, nil, false,
fromAddr, "", "", "", "", 0, 0, tenstakes, nil, false,
)
req4 := NewBaseReq(
"nonempty", "", "nonempty", "", "", 0, 0, tenstakes, onestake, false,
fromAddr, "", "nonempty", "", "", 0, 0, tenstakes, onestake, false,
)
req5 := NewBaseReq(
"nonempty", "", "nonempty", "", "", 0, 0, types.Coins{}, types.DecCoins{}, false,
fromAddr, "", "nonempty", "", "", 0, 0, types.Coins{}, types.DecCoins{}, false,
)

tests := []struct {
Expand Down
2 changes: 1 addition & 1 deletion x/auth/client/rest/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import "github.com/cosmos/cosmos-sdk/x/auth"
// BroadcastReq requests broadcasting a transaction
type BroadcastReq struct {
Tx auth.StdTx `json:"tx"`
Return string `json:"return"`
Return string `json:"return"` // TODO: Do we need this?
}

0 comments on commit e03285d

Please sign in to comment.