From 6165ae3d8f3c031e27db2b8197e932e7ad826510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=BF=97=E5=BC=BA?= Date: Mon, 22 Mar 2021 11:10:11 +0800 Subject: [PATCH 1/4] fix bug --- modules/coinswap/client/rest/grpc_query_test.go | 3 +-- modules/coinswap/client/rest/tx.go | 6 +----- modules/coinswap/keeper/grpc_query.go | 5 +---- modules/coinswap/keeper/keeper.go | 7 ++++--- modules/coinswap/keeper/querier.go | 5 +---- modules/coinswap/keeper/swap_test.go | 5 ++--- modules/coinswap/types/utils.go | 7 ++----- modules/coinswap/types/validation.go | 4 ---- 8 files changed, 12 insertions(+), 30 deletions(-) diff --git a/modules/coinswap/client/rest/grpc_query_test.go b/modules/coinswap/client/rest/grpc_query_test.go index e5cdee2c..64167d14 100644 --- a/modules/coinswap/client/rest/grpc_query_test.go +++ b/modules/coinswap/client/rest/grpc_query_test.go @@ -73,8 +73,7 @@ func (s *IntegrationTestSuite) TestCoinswap() { maxSupply := int64(200000000) mintable := true baseURL := val.APIAddress - uniKitty, err := coinswaptypes.GetUniDenomFromDenom(symbol) - s.Require().NoError(err) + uniKitty := coinswaptypes.GetUniDenomFromDenom(symbol) //------test GetCmdIssueToken()------------- args := []string{ diff --git a/modules/coinswap/client/rest/tx.go b/modules/coinswap/client/rest/tx.go index 9d71f1db..62a123d4 100644 --- a/modules/coinswap/client/rest/tx.go +++ b/modules/coinswap/client/rest/tx.go @@ -151,11 +151,7 @@ func removeLiquidityHandlerFn(cliCtx client.Context) http.HandlerFunc { return } - uniDenom, e := types.GetUniDenomFromDenom(denom) - if e != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, e.Error()) - return - } + uniDenom := types.GetUniDenomFromDenom(denom) msg := types.NewMsgRemoveLiquidity( minToken, sdk.NewCoin(uniDenom, liquidityAmt), minStandard, deadline.Unix(), req.Sender, diff --git a/modules/coinswap/keeper/grpc_query.go b/modules/coinswap/keeper/grpc_query.go index aa8dd50c..76aa8bb6 100644 --- a/modules/coinswap/keeper/grpc_query.go +++ b/modules/coinswap/keeper/grpc_query.go @@ -20,10 +20,7 @@ func (k Keeper) Liquidity(c context.Context, req *types.QueryLiquidityRequest) ( } tokenDenom := req.Denom - uniDenom, err := types.GetUniDenomFromDenom(tokenDenom) - if err != nil { - return nil, status.Errorf(codes.InvalidArgument, err.Error()) - } + uniDenom := types.GetUniDenomFromDenom(tokenDenom) ctx := sdk.UnwrapSDKContext(c) reservePool, err := k.GetReservePool(ctx, uniDenom) diff --git a/modules/coinswap/keeper/keeper.go b/modules/coinswap/keeper/keeper.go index 7208f250..fd8be911 100644 --- a/modules/coinswap/keeper/keeper.go +++ b/modules/coinswap/keeper/keeper.go @@ -92,10 +92,11 @@ func (k Keeper) Swap(ctx sdk.Context, msg *types.MsgSwapOrder) error { // AddLiquidity adds liquidity to the specified pool func (k Keeper) AddLiquidity(ctx sdk.Context, msg *types.MsgAddLiquidity) (sdk.Coin, error) { standardDenom := k.GetStandardDenom(ctx) - uniDenom, err := types.GetUniDenomFromDenom(msg.MaxToken.Denom) - if err != nil { - return sdk.Coin{}, err + if standardDenom == msg.MaxToken.Denom { + return sdk.Coin{}, sdkerrors.Wrapf(types.ErrInvalidDenom, + "MaxToken: %s should not be StandardDenom", msg.MaxToken.String()) } + uniDenom := types.GetUniDenomFromDenom(msg.MaxToken.Denom) liquidity := k.bk.GetSupply(ctx).GetTotal().AmountOf(uniDenom) diff --git a/modules/coinswap/keeper/querier.go b/modules/coinswap/keeper/querier.go index 1c693123..d6c6e645 100644 --- a/modules/coinswap/keeper/querier.go +++ b/modules/coinswap/keeper/querier.go @@ -31,10 +31,7 @@ func queryLiquidity(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuer return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } - uniDenom, err := types.GetUniDenomFromDenom(params.Denom) - if err != nil { - return nil, err - } + uniDenom := types.GetUniDenomFromDenom(params.Denom) standardDenom := k.GetStandardDenom(ctx) reservePool, err := k.GetReservePool(ctx, uniDenom) diff --git a/modules/coinswap/keeper/swap_test.go b/modules/coinswap/keeper/swap_test.go index 6d0103fe..aac982be 100644 --- a/modules/coinswap/keeper/swap_test.go +++ b/modules/coinswap/keeper/swap_test.go @@ -202,8 +202,7 @@ func createReservePool(suite *TestSuite, denom string) (sdk.AccAddress, sdk.AccA ), ) - uniDenom, err := types.GetUniDenomFromDenom(denom) - suite.NoError(err) + uniDenom := types.GetUniDenomFromDenom(denom) reservePoolAddr := types.GetReservePoolAddr(uniDenom) depositAmt, _ := sdk.NewIntFromString("1000") @@ -213,7 +212,7 @@ func createReservePool(suite *TestSuite, denom string) (sdk.AccAddress, sdk.AccA minReward := sdk.NewInt(1) deadline := time.Now().Add(1 * time.Minute) msg := types.NewMsgAddLiquidity(depositCoin, standardAmt, minReward, deadline.Unix(), addrSender.String()) - _, err = suite.app.CoinswapKeeper.AddLiquidity(suite.ctx, msg) + _, err := suite.app.CoinswapKeeper.AddLiquidity(suite.ctx, msg) suite.NoError(err) moduleAccountBalances := suite.app.BankKeeper.GetSupply(suite.ctx).GetTotal() diff --git a/modules/coinswap/types/utils.go b/modules/coinswap/types/utils.go index 0898f8e0..ce3c0359 100644 --- a/modules/coinswap/types/utils.go +++ b/modules/coinswap/types/utils.go @@ -20,11 +20,8 @@ func GetTokenPairByDenom(inputDenom, outputDenom string) string { } // GetUniDenomFromDenom returns the uni denom for the provided denomination. -func GetUniDenomFromDenom(denom string) (string, error) { - if denom == StandardDenom { - return "", ErrMustStandardDenom - } - return fmt.Sprintf(FormatUniDenom, denom), nil +func GetUniDenomFromDenom(denom string) string { + return fmt.Sprintf(FormatUniDenom, denom) } // GetCoinDenomFromUniDenom returns the token denom by uni denom diff --git a/modules/coinswap/types/validation.go b/modules/coinswap/types/validation.go index 35a57059..c031fc75 100644 --- a/modules/coinswap/types/validation.go +++ b/modules/coinswap/types/validation.go @@ -54,10 +54,6 @@ func ValidateMaxToken(maxToken sdk.Coin) error { return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "invalid maxToken (%s)", maxToken.String()) } - if maxToken.Denom == StandardDenom { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("max token must not be standard token: %s", StandardDenom)) - } - if strings.HasPrefix(maxToken.Denom, FormatUniABSPrefix) { return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "max token must be non-liquidity token") } From bca67e7ffc9115b4ff601e7e226afd967afbb7cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=BF=97=E5=BC=BA?= Date: Mon, 22 Mar 2021 15:46:05 +0800 Subject: [PATCH 2/4] fix test error --- modules/coinswap/types/msgs_test.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/modules/coinswap/types/msgs_test.go b/modules/coinswap/types/msgs_test.go index 87f64801..5af750ff 100644 --- a/modules/coinswap/types/msgs_test.go +++ b/modules/coinswap/types/msgs_test.go @@ -59,17 +59,6 @@ func TestMsgAddLiquidity_ValidateBasic(t *testing.T) { fields fields wantErr bool }{ - { - name: "right test case", - wantErr: true, - fields: fields{ - MaxToken: buildCoin("stake", 1000), - ExactStandardAmt: sdk.NewInt(100), - MinLiquidity: sdk.NewInt(100), - Deadline: 1611213344, - Sender: sender, - }, - }, { name: "invalid MaxToken denom", wantErr: true, From b71f6e7b28bf86556c0fd85d550e358e10867677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=BF=97=E5=BC=BA?= Date: Mon, 22 Mar 2021 16:52:47 +0800 Subject: [PATCH 3/4] remove unused code --- modules/coinswap/keeper/keeper_test.go | 2 +- modules/coinswap/types/genesis.go | 2 +- modules/coinswap/types/params.go | 5 ----- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/modules/coinswap/keeper/keeper_test.go b/modules/coinswap/keeper/keeper_test.go index 0327b414..ad0eba30 100644 --- a/modules/coinswap/keeper/keeper_test.go +++ b/modules/coinswap/keeper/keeper_test.go @@ -18,7 +18,7 @@ import ( ) const ( - denomStandard = types.StandardDenom + denomStandard = sdk.DefaultBondDenom denomBTC = "btc" denomETH = "eth" unidenomBTC = types.FormatUniABSPrefix + denomBTC diff --git a/modules/coinswap/types/genesis.go b/modules/coinswap/types/genesis.go index 2612d4bd..8ec808fc 100644 --- a/modules/coinswap/types/genesis.go +++ b/modules/coinswap/types/genesis.go @@ -14,7 +14,7 @@ func NewGenesisState(params Params, denom string) *GenesisState { // DefaultGenesisState creates a default GenesisState object func DefaultGenesisState() *GenesisState { - return NewGenesisState(DefaultParams(), StandardDenom) + return NewGenesisState(DefaultParams(), sdk.DefaultBondDenom) } // ValidateGenesis validates the given genesis state diff --git a/modules/coinswap/types/params.go b/modules/coinswap/types/params.go index 98a816b9..9783b8bb 100644 --- a/modules/coinswap/types/params.go +++ b/modules/coinswap/types/params.go @@ -9,11 +9,6 @@ import ( paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) -const ( - // StandardDenom for coinswap - StandardDenom = sdk.DefaultBondDenom -) - // Parameter store keys var ( KeyFee = []byte("Fee") // fee key From e77c9b9ad543b2d2009e431267296c4c87e3838c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=BF=97=E5=BC=BA?= Date: Mon, 22 Mar 2021 16:56:41 +0800 Subject: [PATCH 4/4] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b2dc544..1c46d6cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (modules/coinswap) [\#161](https://github.com/irisnet/irismod/pull/161) Fix coinswap token validation. * (modules/htlc) [\#157](https://github.com/irisnet/irismod/pull/157) Fix htlc params validation. * (modules/htlc) [\#156](https://github.com/irisnet/irismod/pull/156) Fix validation when creating HTLT. * (modules/coinswap) [\#155](https://github.com/irisnet/irismod/pull/155) Fix min liquidity check in add liquidity.