Skip to content

Commit

Permalink
add check in list hook (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
yutianwu authored Apr 1, 2019
1 parent 192ee3c commit c9c61bc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugins/dex/list/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func (hooks ListHooks) OnProposalSubmitted(ctx sdk.Context, proposal gov.Proposa
return errors.New("quote asset symbol should not be empty")
}

if listParams.BaseAssetSymbol == listParams.QuoteAssetSymbol {
return errors.New("base token and quote token should not be the same")
}

if listParams.InitPrice <= 0 {
return errors.New("init price should larger than zero")
}
Expand Down
22 changes: 22 additions & 0 deletions plugins/dex/list/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,28 @@ func TestQuoteAssetEmpty(t *testing.T) {
require.Contains(t, err.Error(), "quote asset symbol should not be empty")
}

func TestEqualBaseAssetAndQuoteAsset(t *testing.T) {
hooks := NewListHooks(nil, nil)

listParams := gov.ListTradingPairParams{
BaseAssetSymbol: "BNB",
QuoteAssetSymbol: "BNB",
}

listParamsBz, err := json.Marshal(listParams)
require.Nil(t, err, "marshal list params error")

proposal := gov.TextProposal{
ProposalType: gov.ProposalTypeListTradingPair,
Description: string(listParamsBz),
}

err = hooks.OnProposalSubmitted(sdk.Context{}, &proposal)
require.NotNil(t, err, "err should not be nil")

require.Contains(t, err.Error(), "base token and quote token should not be the same")
}

func TestWrongPrice(t *testing.T) {
hooks := NewListHooks(nil, nil)

Expand Down

0 comments on commit c9c61bc

Please sign in to comment.