Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Modify price precision function adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
ludete committed Oct 29, 2019
1 parent 8c46dc6 commit 15dda0e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
8 changes: 1 addition & 7 deletions modules/market/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,17 +495,11 @@ func handleMsgModifyPricePrecision(ctx sdk.Context, msg types.MsgModifyPricePrec
}

func checkMsgModifyPricePrecision(ctx sdk.Context, msg types.MsgModifyPricePrecision, k keepers.Keeper) sdk.Error {
info, err := k.GetMarketInfo(ctx, msg.TradingPair)
_, err := k.GetMarketInfo(ctx, msg.TradingPair)
if err != nil {
return types.ErrInvalidMarket("Error retrieving market information: " + err.Error())
}

if info.PricePrecision > msg.PricePrecision {
return types.ErrInvalidPricePrecisionChange(fmt.Sprintf(
"Price Precision can only be increased; tradingPair price_precision : %d, msg price_precision : %d",
info.PricePrecision, msg.PricePrecision))
}

stock, _ := SplitSymbol(msg.TradingPair)
tokenInfo := k.GetToken(ctx, stock)
if !tokenInfo.GetOwner().Equals(msg.Sender) {
Expand Down
10 changes: 4 additions & 6 deletions modules/market/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1384,16 +1384,14 @@ func TestCheckMsgModifyPricePrecision(t *testing.T) {
ret := createCetMarket(input, stock, 7)
require.EqualValues(t, sdk.CodeOK, ret.Code)

for i := 0; i < 8; i++ {
msg.PricePrecision = byte(i)
err := checkMsgModifyPricePrecision(input.ctx, msg, input.mk)
require.EqualValues(t, types.CodeInvalidPricePrecision, err.Code())
}

// Invalid tx sender
msg.PricePrecision = 9
msg.Sender = forbidAddr
err = checkMsgModifyPricePrecision(input.ctx, msg, input.mk)
require.EqualValues(t, types.CodeNotMatchSender, err.Code())

msg.PricePrecision = 3
msg.Sender = forbidAddr
err = checkMsgModifyPricePrecision(input.ctx, msg, input.mk)
require.EqualValues(t, types.CodeNotMatchSender, err.Code())
}

0 comments on commit 15dda0e

Please sign in to comment.