From 14778aad3bdcb63ea3c440b3ac567ddebf360b43 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Tue, 11 Jun 2024 13:41:39 +0900 Subject: [PATCH 01/11] chore: add more test for grpc_query --- x/fswap/keeper/grpc_query_test.go | 236 ++++++++++++++++++++++++++---- 1 file changed, 209 insertions(+), 27 deletions(-) diff --git a/x/fswap/keeper/grpc_query_test.go b/x/fswap/keeper/grpc_query_test.go index d947121578..66f68a63a3 100644 --- a/x/fswap/keeper/grpc_query_test.go +++ b/x/fswap/keeper/grpc_query_test.go @@ -11,6 +11,7 @@ import ( "github.com/Finschia/finschia-sdk/baseapp" "github.com/Finschia/finschia-sdk/simapp" sdk "github.com/Finschia/finschia-sdk/types" + "github.com/Finschia/finschia-sdk/types/query" bank "github.com/Finschia/finschia-sdk/x/bank/types" "github.com/Finschia/finschia-sdk/x/fswap/keeper" "github.com/Finschia/finschia-sdk/x/fswap/types" @@ -42,17 +43,17 @@ func (s *FSwapQueryTestSuite) SetupTest() { s.queryClient = types.NewQueryClient(queryHelper) s.keeper = s.app.FswapKeeper - pebSwapRateForCony, err := sdk.NewDecFromStr("148079656000000") + kaiSwapRateForCony, err := sdk.NewDecFromStr("148079656000000") s.Require().NoError(err) swapCap := sdk.NewInt(1000) s.Require().NoError(err) s.fromDenom = "cony" - s.toDenom = "kei" + s.toDenom = "kai" s.swap = types.Swap{ FromDenom: s.fromDenom, ToDenom: s.toDenom, AmountCapForToDenom: swapCap, - SwapRate: pebSwapRateForCony, + SwapRate: kaiSwapRateForCony, } s.toDenomMetadata = bank.Metadata{ Description: "This is metadata for to-coin", @@ -88,48 +89,229 @@ func (s *FSwapQueryTestSuite) SetupTest() { func (s *FSwapQueryTestSuite) TestQuerySwapRequest() { tests := []struct { name string - FromDenom string - ToDenom string - wantErr bool + request *types.QuerySwapRequest + expectedResponse *types.QuerySwapResponse expectedGrpcCode codes.Code }{ { - name: "valid", - FromDenom: s.fromDenom, - ToDenom: s.toDenom, - wantErr: false, + name: "valid", + request: &types.QuerySwapRequest{ + FromDenom: s.fromDenom, + ToDenom: s.toDenom, + }, + expectedResponse: &types.QuerySwapResponse{ + Swap: types.Swap{ + FromDenom: s.swap.FromDenom, + ToDenom: s.swap.ToDenom, + AmountCapForToDenom: s.swap.AmountCapForToDenom, + SwapRate: s.swap.SwapRate, + }, + }, expectedGrpcCode: codes.OK, }, { - name: "invalid: empty fromDenom", - FromDenom: "", - ToDenom: s.toDenom, - wantErr: true, + name: "invalid: empty fromDenom", + request: &types.QuerySwapRequest{ + FromDenom: "", + ToDenom: s.toDenom, + }, expectedGrpcCode: codes.InvalidArgument, }, { - name: "invalid: empty toDenom", - FromDenom: s.fromDenom, - ToDenom: "", - wantErr: true, + name: "invalid: empty toDenom", + request: &types.QuerySwapRequest{ + FromDenom: s.fromDenom, + ToDenom: "", + }, expectedGrpcCode: codes.InvalidArgument, }, { - name: "invalid: the same fromDenom and toDenom", - FromDenom: s.fromDenom, - ToDenom: s.fromDenom, - wantErr: true, + name: "invalid: the same fromDenom and toDenom", + request: &types.QuerySwapRequest{ + FromDenom: s.fromDenom, + ToDenom: s.fromDenom, + }, expectedGrpcCode: codes.InvalidArgument, }, + { + name: "invalid: unregistered swap", + request: &types.QuerySwapRequest{ + FromDenom: s.toDenom, + ToDenom: s.fromDenom, + }, + expectedGrpcCode: codes.NotFound, + }, + } + for _, tc := range tests { + s.Run(tc.name, func() { + response, err := s.queryClient.Swap(s.ctx.Context(), tc.request) + s.Require().Equal(tc.expectedResponse, response) + actualGrpcCode := status.Code(err) + s.Require().Equal(tc.expectedGrpcCode, actualGrpcCode, actualGrpcCode.String()) + }) + } +} + +func (s *FSwapQueryTestSuite) TestQuerySwappedRequest() { + tests := []struct { + name string + request *types.QuerySwappedRequest + expectedResponse *types.QuerySwappedResponse + expectedGrpcCode codes.Code + }{ + { + name: "valid", + request: &types.QuerySwappedRequest{ + FromDenom: s.fromDenom, + ToDenom: s.toDenom, + }, + expectedResponse: &types.QuerySwappedResponse{ + FromCoinAmount: sdk.NewCoin(s.fromDenom, sdk.ZeroInt()), + ToCoinAmount: sdk.NewCoin(s.toDenom, sdk.ZeroInt()), + }, + expectedGrpcCode: codes.OK, + }, + { + name: "invalid: empty fromDenom", + request: &types.QuerySwappedRequest{ + FromDenom: "", + ToDenom: s.toDenom, + }, + expectedResponse: nil, + expectedGrpcCode: codes.Unknown, + }, + { + name: "invalid: empty toDenom", + request: &types.QuerySwappedRequest{ + FromDenom: s.fromDenom, + ToDenom: "", + }, + expectedResponse: nil, + expectedGrpcCode: codes.Unknown, + }, + { + name: "invalid: unregistered swap", + request: &types.QuerySwappedRequest{ + FromDenom: s.toDenom, + ToDenom: s.fromDenom, + }, + expectedResponse: nil, + expectedGrpcCode: codes.Unknown, + }, } for _, tc := range tests { s.Run(tc.name, func() { - m := &types.QuerySwapRequest{ - FromDenom: tc.FromDenom, - ToDenom: tc.ToDenom, - } + response, err := s.queryClient.Swapped(s.ctx.Context(), tc.request) + s.Require().Equal(tc.expectedResponse, response) + actualGrpcCode := status.Code(err) + s.Require().Equal(tc.expectedGrpcCode, actualGrpcCode, actualGrpcCode.String()) + }) + } +} - _, err := s.queryClient.Swap(s.ctx.Context(), m) +func (s *FSwapQueryTestSuite) TestQueryTotalSwappableToCoinAmountRequest() { + tests := []struct { + name string + request *types.QueryTotalSwappableToCoinAmountRequest + expectedResponse *types.QueryTotalSwappableToCoinAmountResponse + expectedGrpcCode codes.Code + }{ + { + name: "valid", + request: &types.QueryTotalSwappableToCoinAmountRequest{ + FromDenom: s.fromDenom, + ToDenom: s.toDenom, + }, + expectedResponse: &types.QueryTotalSwappableToCoinAmountResponse{ + SwappableAmount: sdk.NewCoin(s.toDenom, s.swap.AmountCapForToDenom), + }, + expectedGrpcCode: codes.OK, + }, + { + name: "invalid: empty fromDenom", + request: &types.QueryTotalSwappableToCoinAmountRequest{ + FromDenom: "", + ToDenom: s.toDenom, + }, + expectedResponse: nil, + expectedGrpcCode: codes.Unknown, + }, + { + name: "invalid: empty toDenom", + request: &types.QueryTotalSwappableToCoinAmountRequest{ + FromDenom: s.fromDenom, + ToDenom: "", + }, + expectedResponse: nil, + expectedGrpcCode: codes.Unknown, + }, + { + name: "invalid: unregistered swap", + request: &types.QueryTotalSwappableToCoinAmountRequest{ + FromDenom: s.toDenom, + ToDenom: s.fromDenom, + }, + expectedResponse: nil, + expectedGrpcCode: codes.Unknown, + }, + } + for _, tc := range tests { + s.Run(tc.name, func() { + response, err := s.queryClient.TotalSwappableToCoinAmount(s.ctx.Context(), tc.request) + s.Require().Equal(tc.expectedResponse, response) + actualGrpcCode := status.Code(err) + s.Require().Equal(tc.expectedGrpcCode, actualGrpcCode, actualGrpcCode.String()) + }) + } +} + +func (s *FSwapQueryTestSuite) TestQuerySwapsRequest() { + tests := []struct { + name string + request *types.QuerySwapsRequest + expectedResponse *types.QuerySwapsResponse + expectedGrpcCode codes.Code + }{ + { + name: "valid", + request: &types.QuerySwapsRequest{ + Pagination: nil, + }, + expectedResponse: &types.QuerySwapsResponse{ + Swaps: []types.Swap{ + { + FromDenom: s.swap.FromDenom, + ToDenom: s.swap.ToDenom, + AmountCapForToDenom: s.swap.AmountCapForToDenom, + SwapRate: s.swap.SwapRate, + }, + }, + Pagination: &query.PageResponse{ + NextKey: nil, + Total: 1, + }, + }, + expectedGrpcCode: codes.OK, + }, + { + name: "invalid request", + request: &types.QuerySwapsRequest{ + Pagination: &query.PageRequest{ + Key: []byte("invalid-key"), + Offset: 1, + Limit: 0, + CountTotal: false, + Reverse: false, + }, + }, + expectedResponse: nil, + expectedGrpcCode: codes.Unknown, + }, + } + for _, tc := range tests { + s.Run(tc.name, func() { + response, err := s.queryClient.Swaps(s.ctx.Context(), tc.request) + s.Require().Equal(tc.expectedResponse, response) actualGrpcCode := status.Code(err) s.Require().Equal(tc.expectedGrpcCode, actualGrpcCode, actualGrpcCode.String()) }) From 2d8c7a020edcf2608a84e6be86c6c1bf9dff6d12 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Tue, 11 Jun 2024 16:26:57 +0900 Subject: [PATCH 02/11] chore: add more test for config and msg validation --- x/fswap/types/config_test.go | 14 ++ x/fswap/types/msgs_test.go | 330 ++++++++++++++++++++++++++++++++--- 2 files changed, 320 insertions(+), 24 deletions(-) create mode 100644 x/fswap/types/config_test.go diff --git a/x/fswap/types/config_test.go b/x/fswap/types/config_test.go new file mode 100644 index 0000000000..90a078a4d7 --- /dev/null +++ b/x/fswap/types/config_test.go @@ -0,0 +1,14 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestDefaultConfig(t *testing.T) { + config := DefaultConfig() + + require.Equal(t, false, config.UpdateAllowed) + require.Equal(t, 1, config.MaxSwaps) +} diff --git a/x/fswap/types/msgs_test.go b/x/fswap/types/msgs_test.go index e3dd86b7dd..ade5e13883 100644 --- a/x/fswap/types/msgs_test.go +++ b/x/fswap/types/msgs_test.go @@ -1,13 +1,16 @@ package types_test import ( + "errors" "testing" "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "github.com/Finschia/finschia-sdk/crypto/keys/secp256k1" sdk "github.com/Finschia/finschia-sdk/types" + sdkerrors "github.com/Finschia/finschia-sdk/types/errors" "github.com/Finschia/finschia-sdk/x/auth/legacy/legacytx" banktypes "github.com/Finschia/finschia-sdk/x/bank/types" fswaptypes "github.com/Finschia/finschia-sdk/x/fswap/types" @@ -89,49 +92,328 @@ func TestAminoJSON(t *testing.T) { func TestQuerySwapRequestValidate(t *testing.T) { tests := []struct { name string - FromDenom string - ToDenom string - wantErr bool + msg *fswaptypes.QuerySwapRequest expectedGrpcCode codes.Code }{ { - name: "valid", - FromDenom: "cony", - ToDenom: "peb", - wantErr: false, + name: "valid", + msg: &fswaptypes.QuerySwapRequest{ + FromDenom: "cony", + ToDenom: "kai", + }, expectedGrpcCode: codes.OK, }, { - name: "invalid: empty fromDenom", - FromDenom: "", - ToDenom: "peb", - wantErr: true, + name: "invalid: nil request", + msg: nil, + expectedGrpcCode: codes.InvalidArgument, + }, + { + name: "invalid: empty fromDenom", + msg: &fswaptypes.QuerySwapRequest{ + FromDenom: "", + ToDenom: "kai", + }, expectedGrpcCode: codes.InvalidArgument, }, { - name: "invalid: empty toDenom", - FromDenom: "cony", - ToDenom: "", - wantErr: true, + name: "invalid: empty toDenom", + msg: &fswaptypes.QuerySwapRequest{ + FromDenom: "cony", + ToDenom: "", + }, expectedGrpcCode: codes.InvalidArgument, }, { - name: "invalid: the same fromDenom and toDenom", - FromDenom: "cony", - ToDenom: "cony", - wantErr: true, + name: "invalid: the same fromDenom and toDenom", + msg: &fswaptypes.QuerySwapRequest{ + FromDenom: "cony", + ToDenom: "cony", + }, expectedGrpcCode: codes.InvalidArgument, }, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - m := &fswaptypes.QuerySwapRequest{ - FromDenom: tc.FromDenom, - ToDenom: tc.ToDenom, - } - err := m.Validate() + err := tc.msg.Validate() actualGrpcCode := status.Code(err) require.Equal(t, tc.expectedGrpcCode, actualGrpcCode) }) } } + +func TestMsgSwapValidate(t *testing.T) { + pk := secp256k1.GenPrivKey().PubKey() + address, err := sdk.Bech32ifyAddressBytes("link", pk.Address()) + if err != nil { + return + } + tests := []struct { + name string + msg *fswaptypes.MsgSwap + expectedError error + }{ + { + name: "valid", + msg: &fswaptypes.MsgSwap{ + FromAddress: address, + FromCoinAmount: sdk.NewCoin("fromDenom", sdk.OneInt()), + ToDenom: "kai", + }, + expectedError: nil, + }, + { + name: "invalid: address", + msg: &fswaptypes.MsgSwap{ + FromAddress: "invalid-address", + FromCoinAmount: sdk.NewCoin("fromDenom", sdk.OneInt()), + ToDenom: "kai", + }, + expectedError: sdkerrors.ErrInvalidAddress, + }, + { + name: "invalid: FromCoinAmount empty denom", + msg: &fswaptypes.MsgSwap{ + FromAddress: address, + FromCoinAmount: sdk.Coin{ + "", + sdk.OneInt(), + }, + ToDenom: "kai", + }, + expectedError: sdkerrors.ErrInvalidCoins, + }, + { + name: "invalid: FromCoinAmount zero amount", + msg: &fswaptypes.MsgSwap{ + FromAddress: address, + FromCoinAmount: sdk.Coin{ + "cony", + sdk.ZeroInt(), + }, + ToDenom: "kai", + }, + expectedError: sdkerrors.ErrInvalidCoins, + }, + { + name: "invalid: ToDenom", + msg: &fswaptypes.MsgSwap{ + FromAddress: address, + FromCoinAmount: sdk.NewCoin("fromDenom", sdk.OneInt()), + ToDenom: "", + }, + expectedError: sdkerrors.ErrInvalidRequest, + }, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + err := tc.msg.ValidateBasic() + require.ErrorIs(t, err, tc.expectedError) + }) + } +} + +func TestMsgSwapAllValidate(t *testing.T) { + pk := secp256k1.GenPrivKey().PubKey() + address, err := sdk.Bech32ifyAddressBytes("link", pk.Address()) + if err != nil { + return + } + tests := []struct { + name string + msg *fswaptypes.MsgSwapAll + expectedError error + }{ + { + name: "valid", + msg: &fswaptypes.MsgSwapAll{ + FromAddress: address, + FromDenom: "cony", + ToDenom: "kai", + }, + expectedError: nil, + }, + { + name: "invalid: address", + msg: &fswaptypes.MsgSwapAll{ + FromAddress: "invalid-address", + FromDenom: "cony", + ToDenom: "kai", + }, + expectedError: sdkerrors.ErrInvalidAddress, + }, + { + name: "invalid: FromDenom", + msg: &fswaptypes.MsgSwapAll{ + FromAddress: address, + FromDenom: "", + ToDenom: "kai", + }, + expectedError: sdkerrors.ErrInvalidRequest, + }, + { + name: "invalid: ToDenom", + msg: &fswaptypes.MsgSwapAll{ + FromAddress: address, + FromDenom: "cony", + ToDenom: "", + }, + expectedError: sdkerrors.ErrInvalidRequest, + }, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + err := tc.msg.ValidateBasic() + require.ErrorIs(t, err, tc.expectedError) + }) + } +} + +func TestMsgSetSwapValidate(t *testing.T) { + pk := secp256k1.GenPrivKey().PubKey() + address, err := sdk.Bech32ifyAddressBytes("link", pk.Address()) + if err != nil { + return + } + tests := []struct { + name string + msg *fswaptypes.MsgSetSwap + expectedError error + }{ + { + name: "valid", + msg: &fswaptypes.MsgSetSwap{ + Authority: address, + Swap: fswaptypes.Swap{ + FromDenom: "cony", + ToDenom: "kai", + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.NewDec(123), + }, + ToDenomMetadata: banktypes.Metadata{ + Description: "desc", + DenomUnits: []*banktypes.DenomUnit{ + { + Denom: "kai", + Exponent: 0, + Aliases: nil, + }, + }, + Base: "kai", + Display: "kai", + Name: "kai", + Symbol: "KAIA", + }, + }, + expectedError: nil, + }, + { + name: "invalid: address", + msg: &fswaptypes.MsgSetSwap{ + Authority: "invalid-address", + Swap: fswaptypes.Swap{ + FromDenom: "cony", + ToDenom: "kai", + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.NewDec(123), + }, + ToDenomMetadata: banktypes.Metadata{ + Description: "desc", + DenomUnits: []*banktypes.DenomUnit{ + { + Denom: "kai", + Exponent: 0, + Aliases: nil, + }, + }, + Base: "kai", + Display: "kai", + Name: "kai", + Symbol: "KAIA", + }, + }, + expectedError: sdkerrors.ErrInvalidAddress, + }, + { + name: "invalid: Swap", + msg: &fswaptypes.MsgSetSwap{ + Authority: address, + Swap: fswaptypes.Swap{}, + ToDenomMetadata: banktypes.Metadata{ + Description: "desc", + DenomUnits: []*banktypes.DenomUnit{ + { + Denom: "kai", + Exponent: 0, + Aliases: nil, + }, + }, + Base: "kai", + Display: "kai", + Name: "kai", + Symbol: "KAIA", + }, + }, + expectedError: sdkerrors.ErrInvalidRequest, + }, + { + name: "invalid: ToDenomMetadata", + msg: &fswaptypes.MsgSetSwap{ + Authority: address, + Swap: fswaptypes.Swap{ + FromDenom: "cony", + ToDenom: "kai", + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.NewDec(123), + }, + ToDenomMetadata: banktypes.Metadata{ + Description: "", + DenomUnits: []*banktypes.DenomUnit{ + { + Denom: "kai", + Exponent: 0, + Aliases: nil, + }, + }, + }, + }, + expectedError: errors.New("name field cannot be blank"), + }, + + { + name: "invalid: mismatched toDenom", + msg: &fswaptypes.MsgSetSwap{ + Authority: address, + Swap: fswaptypes.Swap{ + FromDenom: "cony", + ToDenom: "kai", + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.NewDec(123), + }, + ToDenomMetadata: banktypes.Metadata{ + Description: "desc", + DenomUnits: []*banktypes.DenomUnit{ + { + Denom: "fkai", + Exponent: 0, + Aliases: nil, + }, + }, + Base: "fkai", + Display: "fkai", + Name: "fkai", + Symbol: "KAIA", + }, + }, + expectedError: sdkerrors.ErrInvalidRequest, + }, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + err := tc.msg.ValidateBasic() + if tc.expectedError != nil { + require.Contains(t, err.Error(), tc.expectedError.Error()) + } + }) + } +} From 0c45906d208273c7ff609264c930f64867b466f6 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Tue, 11 Jun 2024 17:58:05 +0900 Subject: [PATCH 03/11] chore: add more test for genesis-related things --- x/fswap/keeper/genesis_test.go | 81 ++++++++++++++++++++++++++++++++++ x/fswap/types/genesis_test.go | 22 +++++++++ 2 files changed, 103 insertions(+) diff --git a/x/fswap/keeper/genesis_test.go b/x/fswap/keeper/genesis_test.go index 1df6f28c75..935067b75a 100644 --- a/x/fswap/keeper/genesis_test.go +++ b/x/fswap/keeper/genesis_test.go @@ -2,7 +2,13 @@ package keeper_test import ( "fmt" + "testing" + "github.com/stretchr/testify/require" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + "github.com/Finschia/finschia-sdk/simapp" + "github.com/Finschia/finschia-sdk/testutil/testdata" sdk "github.com/Finschia/finschia-sdk/types" "github.com/Finschia/finschia-sdk/x/fswap/types" ) @@ -45,3 +51,78 @@ func (s *KeeperTestSuite) TestInitAndExportGenesis() { s.Require().Equal(testGenesis.GetSwapStats(), exportGenesis.GetSwapStats()) s.Require().Equal(testGenesis.GetSwappeds(), exportGenesis.GetSwappeds()) } + +func TestInitGenesis(t *testing.T) { + generateState := func() *types.GenesisState { + testSwapRate, _ := sdk.NewDecFromStr("1234567890") + return &types.GenesisState{ + Swaps: []types.Swap{ + { + FromDenom: "aaa", + ToDenom: "bbb", + AmountCapForToDenom: sdk.NewInt(1234567890000), + SwapRate: testSwapRate, + }, + }, + SwapStats: types.SwapStats{ + SwapCount: 1, + }, + Swappeds: []types.Swapped{ + { + FromCoinAmount: sdk.Coin{ + Denom: "aaa", + Amount: sdk.ZeroInt(), + }, + ToCoinAmount: sdk.Coin{ + Denom: "bbb", + Amount: sdk.ZeroInt(), + }, + }, + }, + } + } + checkTx := false + app := simapp.Setup(checkTx) + testdata.RegisterInterfaces(app.InterfaceRegistry()) + testdata.RegisterMsgServer(app.MsgServiceRouter(), testdata.MsgServerImpl{}) + ctx := app.BaseApp.NewContext(checkTx, tmproto.Header{}) + keeper := app.FswapKeeper + + tests := []struct { + name string + genState *types.GenesisState + expectedError error + }{ + { + name: "valid", + genState: generateState(), + expectedError: nil, + }, + { + name: "invalid: swapCount", + genState: func() *types.GenesisState { + state := generateState() + state.SwapStats.SwapCount = -1 + return state + }(), + expectedError: types.ErrInvalidState, + }, + { + name: "invalid: swaps count exceeds limit", + genState: func() *types.GenesisState { + state := generateState() + state.Swaps = append(state.Swaps, state.Swaps[0]) + state.Swappeds = append(state.Swappeds, state.Swappeds[0]) + state.SwapStats.SwapCount = 2 + return state + }(), + expectedError: types.ErrCanNotHaveMoreSwap, + }, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + err := keeper.InitGenesis(ctx, tc.genState) + require.ErrorIs(t, tc.expectedError, err) + }) + } +} diff --git a/x/fswap/types/genesis_test.go b/x/fswap/types/genesis_test.go index fc2ed9a781..289e1626af 100644 --- a/x/fswap/types/genesis_test.go +++ b/x/fswap/types/genesis_test.go @@ -6,7 +6,10 @@ import ( "github.com/stretchr/testify/require" sdk "github.com/Finschia/finschia-sdk/types" + authtypes "github.com/Finschia/finschia-sdk/x/auth/types" + "github.com/Finschia/finschia-sdk/x/foundation" "github.com/Finschia/finschia-sdk/x/fswap/types" + govtypes "github.com/Finschia/finschia-sdk/x/gov/types" ) func TestGenesisStateValidate(t *testing.T) { @@ -174,3 +177,22 @@ func TestGenesisStateValidate(t *testing.T) { }) } } + +func TestDefaultAuthority(t *testing.T) { + expectedDefaultAuthority := authtypes.NewModuleAddress(foundation.ModuleName) + + defaultAuthority := types.DefaultAuthority() + + require.Equal(t, expectedDefaultAuthority, defaultAuthority) +} + +func TestAuthorityCandidates(t *testing.T) { + defaultAuthorityCandidates := []sdk.AccAddress{ + authtypes.NewModuleAddress(govtypes.ModuleName), + authtypes.NewModuleAddress(foundation.ModuleName), + } + + authorityCandidates := types.AuthorityCandidates() + + require.Equal(t, defaultAuthorityCandidates, authorityCandidates) +} From f2cdd58e1b5a89e02f2f0d04d3982f5ae59995df Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Tue, 11 Jun 2024 19:33:43 +0900 Subject: [PATCH 04/11] chore: add TestMsgSetSwap for msg server --- x/fswap/keeper/msg_server_test.go | 125 ++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/x/fswap/keeper/msg_server_test.go b/x/fswap/keeper/msg_server_test.go index ab8be87e04..af53db8ca9 100644 --- a/x/fswap/keeper/msg_server_test.go +++ b/x/fswap/keeper/msg_server_test.go @@ -1,8 +1,19 @@ package keeper_test import ( + "testing" + + "github.com/stretchr/testify/require" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + "github.com/Finschia/finschia-sdk/simapp" + "github.com/Finschia/finschia-sdk/testutil/testdata" sdk "github.com/Finschia/finschia-sdk/types" sdkerrors "github.com/Finschia/finschia-sdk/types/errors" + authtypes "github.com/Finschia/finschia-sdk/x/auth/types" + bank "github.com/Finschia/finschia-sdk/x/bank/types" + "github.com/Finschia/finschia-sdk/x/foundation" + fkeeper "github.com/Finschia/finschia-sdk/x/fswap/keeper" "github.com/Finschia/finschia-sdk/x/fswap/types" ) @@ -133,3 +144,117 @@ func (s *KeeperTestSuite) TestMsgSwapAll() { }) } } + +func TestMsgSetSwap(t *testing.T) { + authority := authtypes.NewModuleAddress(foundation.ModuleName) + checkTx := false + app := simapp.Setup(checkTx) + testdata.RegisterInterfaces(app.InterfaceRegistry()) + testdata.RegisterMsgServer(app.MsgServiceRouter(), testdata.MsgServerImpl{}) + ctx := app.BaseApp.NewContext(checkTx, tmproto.Header{}) + keeper := app.FswapKeeper + msgServer := fkeeper.NewMsgServer(keeper) + fromDenomStr := "cony" + fromDenom := bank.Metadata{ + Description: "This is metadata for from-coin", + DenomUnits: []*bank.DenomUnit{ + {Denom: fromDenomStr, Exponent: 0}, + }, + Base: fromDenomStr, + Display: fromDenomStr, + Name: "FROM", + Symbol: "FROM", + } + app.BankKeeper.SetDenomMetaData(ctx, fromDenom) + + testCases := map[string]struct { + request *types.MsgSetSwap + expectedError error + }{ + "valid": { + request: &types.MsgSetSwap{ + Authority: authority.String(), + Swap: types.Swap{ + FromDenom: fromDenomStr, + ToDenom: "kai", + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.NewDec(1), + }, + ToDenomMetadata: bank.Metadata{ + Description: "desc", + DenomUnits: []*bank.DenomUnit{ + { + Denom: "kai", + Exponent: 0, + Aliases: nil, + }, + }, + Base: "kai", + Display: "kai", + Name: "kai", + Symbol: "KAIA", + }, + }, + expectedError: nil, + }, + "invalid: authority": { + request: &types.MsgSetSwap{ + Authority: "invalid-authority", + Swap: types.Swap{ + FromDenom: fromDenomStr, + ToDenom: "kai", + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.NewDec(1), + }, + ToDenomMetadata: bank.Metadata{ + Description: "desc", + DenomUnits: []*bank.DenomUnit{ + { + Denom: "kai", + Exponent: 0, + Aliases: nil, + }, + }, + Base: "kai", + Display: "kai", + Name: "kai", + Symbol: "KAIA", + }, + }, + expectedError: sdkerrors.ErrUnauthorized, + }, + "invalid: Swap.ToDenom": { + request: &types.MsgSetSwap{ + Authority: authority.String(), + Swap: types.Swap{ + FromDenom: fromDenomStr, + ToDenom: fromDenomStr, + AmountCapForToDenom: sdk.OneInt(), + SwapRate: sdk.NewDec(1), + }, + ToDenomMetadata: bank.Metadata{ + Description: "desc", + DenomUnits: []*bank.DenomUnit{ + { + Denom: "kai", + Exponent: 0, + Aliases: nil, + }, + }, + Base: "kai", + Display: "kai", + Name: "kai", + Symbol: "KAIA", + }, + }, + expectedError: sdkerrors.ErrInvalidRequest, + }, + } + for name, tc := range testCases { + t.Run(name, func(t *testing.T) { + context, _ := ctx.CacheContext() + _, err := msgServer.SetSwap(sdk.WrapSDKContext(context), tc.request) + require.ErrorIs(t, err, tc.expectedError) + }) + } +} From de070c21dd069de9e597dc67b82a7480ff4f21cc Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Tue, 11 Jun 2024 19:52:48 +0900 Subject: [PATCH 05/11] chore: add more test for keeper --- x/fswap/keeper/keeper_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/x/fswap/keeper/keeper_test.go b/x/fswap/keeper/keeper_test.go index 1ebffa116a..f5f45c3c9f 100644 --- a/x/fswap/keeper/keeper_test.go +++ b/x/fswap/keeper/keeper_test.go @@ -242,6 +242,22 @@ func (s *KeeperTestSuite) TestSwap() { true, sdkerrors.ErrInsufficientFunds, }, + "invalid: unregistered swap": { + s.accWithToCoin, + sdk.NewCoin(s.swap.GetFromDenom(), sdk.NewInt(100)), + "nono", + sdk.ZeroInt(), + true, + sdkerrors.ErrNotFound, + }, + "invalid: amount exceed": { + s.accWithToCoin, + sdk.NewCoin(s.swap.GetFromDenom(), s.swap.AmountCapForToDenom.Add(sdk.OneInt())), + s.swap.GetToDenom(), + sdk.ZeroInt(), + true, + types.ErrExceedSwappableToCoinAmount, + }, } for name, tc := range testCases { s.Run(name, func() { From 2328e3f94444df6c5086858c6fb751996083a8b4 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Tue, 11 Jun 2024 19:56:03 +0900 Subject: [PATCH 06/11] chore: fix for lint --- x/fswap/types/msgs_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x/fswap/types/msgs_test.go b/x/fswap/types/msgs_test.go index ade5e13883..a1e2403ba5 100644 --- a/x/fswap/types/msgs_test.go +++ b/x/fswap/types/msgs_test.go @@ -176,8 +176,8 @@ func TestMsgSwapValidate(t *testing.T) { msg: &fswaptypes.MsgSwap{ FromAddress: address, FromCoinAmount: sdk.Coin{ - "", - sdk.OneInt(), + Denom: "", + Amount: sdk.OneInt(), }, ToDenom: "kai", }, @@ -188,8 +188,8 @@ func TestMsgSwapValidate(t *testing.T) { msg: &fswaptypes.MsgSwap{ FromAddress: address, FromCoinAmount: sdk.Coin{ - "cony", - sdk.ZeroInt(), + Denom: "cony", + Amount: sdk.ZeroInt(), }, ToDenom: "kai", }, From 0b8661879c1858b41d409a091ad9e90b54792d40 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Tue, 11 Jun 2024 20:53:37 +0900 Subject: [PATCH 07/11] chore: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8deaccf23f..26c6543a53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/fbridge) [\#1395](https://github.com/Finschia/finschia-sdk/pull/1395) Return error instead of panic for behaviors triggered by client * (x/fswap) [\#1396](https://github.com/Finschia/finschia-sdk/pull/1396) refactor to use snake_case in proto * (x/fswap) [\#1391](https://github.com/Finschia/finschia-sdk/pull/1391) add cli_test for fswap module +* (x/fswap) [\#1415](https://github.com/Finschia/finschia-sdk/pull/1415) add more testcases for fswap module ### Bug Fixes * chore(deps) [\#1141](https://github.com/Finschia/finschia-sdk/pull/1141) Bump github.com/cosmos/ledger-cosmos-go from 0.12.2 to 0.13.2 to fix ledger signing issue From 199612a7761f770c59344cbb4d89bf4ecb9011df Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Wed, 12 Jun 2024 18:03:10 +0900 Subject: [PATCH 08/11] chore: rename kai to kei --- x/fswap/keeper/grpc_query_test.go | 6 ++-- x/fswap/keeper/msg_server_test.go | 28 +++++++-------- x/fswap/types/msgs_test.go | 60 +++++++++++++++---------------- 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/x/fswap/keeper/grpc_query_test.go b/x/fswap/keeper/grpc_query_test.go index 66f68a63a3..089ce05bdd 100644 --- a/x/fswap/keeper/grpc_query_test.go +++ b/x/fswap/keeper/grpc_query_test.go @@ -43,17 +43,17 @@ func (s *FSwapQueryTestSuite) SetupTest() { s.queryClient = types.NewQueryClient(queryHelper) s.keeper = s.app.FswapKeeper - kaiSwapRateForCony, err := sdk.NewDecFromStr("148079656000000") + keiSwapRateForCony, err := sdk.NewDecFromStr("148079656000000") s.Require().NoError(err) swapCap := sdk.NewInt(1000) s.Require().NoError(err) s.fromDenom = "cony" - s.toDenom = "kai" + s.toDenom = "kei" s.swap = types.Swap{ FromDenom: s.fromDenom, ToDenom: s.toDenom, AmountCapForToDenom: swapCap, - SwapRate: kaiSwapRateForCony, + SwapRate: keiSwapRateForCony, } s.toDenomMetadata = bank.Metadata{ Description: "This is metadata for to-coin", diff --git a/x/fswap/keeper/msg_server_test.go b/x/fswap/keeper/msg_server_test.go index af53db8ca9..81ce7529ac 100644 --- a/x/fswap/keeper/msg_server_test.go +++ b/x/fswap/keeper/msg_server_test.go @@ -176,7 +176,7 @@ func TestMsgSetSwap(t *testing.T) { Authority: authority.String(), Swap: types.Swap{ FromDenom: fromDenomStr, - ToDenom: "kai", + ToDenom: "kei", AmountCapForToDenom: sdk.OneInt(), SwapRate: sdk.NewDec(1), }, @@ -184,14 +184,14 @@ func TestMsgSetSwap(t *testing.T) { Description: "desc", DenomUnits: []*bank.DenomUnit{ { - Denom: "kai", + Denom: "kei", Exponent: 0, Aliases: nil, }, }, - Base: "kai", - Display: "kai", - Name: "kai", + Base: "kei", + Display: "kei", + Name: "kei", Symbol: "KAIA", }, }, @@ -202,7 +202,7 @@ func TestMsgSetSwap(t *testing.T) { Authority: "invalid-authority", Swap: types.Swap{ FromDenom: fromDenomStr, - ToDenom: "kai", + ToDenom: "kei", AmountCapForToDenom: sdk.OneInt(), SwapRate: sdk.NewDec(1), }, @@ -210,14 +210,14 @@ func TestMsgSetSwap(t *testing.T) { Description: "desc", DenomUnits: []*bank.DenomUnit{ { - Denom: "kai", + Denom: "kei", Exponent: 0, Aliases: nil, }, }, - Base: "kai", - Display: "kai", - Name: "kai", + Base: "kei", + Display: "kei", + Name: "kei", Symbol: "KAIA", }, }, @@ -236,14 +236,14 @@ func TestMsgSetSwap(t *testing.T) { Description: "desc", DenomUnits: []*bank.DenomUnit{ { - Denom: "kai", + Denom: "kei", Exponent: 0, Aliases: nil, }, }, - Base: "kai", - Display: "kai", - Name: "kai", + Base: "kei", + Display: "kei", + Name: "kei", Symbol: "KAIA", }, }, diff --git a/x/fswap/types/msgs_test.go b/x/fswap/types/msgs_test.go index a1e2403ba5..d4769b1666 100644 --- a/x/fswap/types/msgs_test.go +++ b/x/fswap/types/msgs_test.go @@ -99,7 +99,7 @@ func TestQuerySwapRequestValidate(t *testing.T) { name: "valid", msg: &fswaptypes.QuerySwapRequest{ FromDenom: "cony", - ToDenom: "kai", + ToDenom: "kei", }, expectedGrpcCode: codes.OK, }, @@ -112,7 +112,7 @@ func TestQuerySwapRequestValidate(t *testing.T) { name: "invalid: empty fromDenom", msg: &fswaptypes.QuerySwapRequest{ FromDenom: "", - ToDenom: "kai", + ToDenom: "kei", }, expectedGrpcCode: codes.InvalidArgument, }, @@ -158,7 +158,7 @@ func TestMsgSwapValidate(t *testing.T) { msg: &fswaptypes.MsgSwap{ FromAddress: address, FromCoinAmount: sdk.NewCoin("fromDenom", sdk.OneInt()), - ToDenom: "kai", + ToDenom: "kei", }, expectedError: nil, }, @@ -167,7 +167,7 @@ func TestMsgSwapValidate(t *testing.T) { msg: &fswaptypes.MsgSwap{ FromAddress: "invalid-address", FromCoinAmount: sdk.NewCoin("fromDenom", sdk.OneInt()), - ToDenom: "kai", + ToDenom: "kei", }, expectedError: sdkerrors.ErrInvalidAddress, }, @@ -179,7 +179,7 @@ func TestMsgSwapValidate(t *testing.T) { Denom: "", Amount: sdk.OneInt(), }, - ToDenom: "kai", + ToDenom: "kei", }, expectedError: sdkerrors.ErrInvalidCoins, }, @@ -191,7 +191,7 @@ func TestMsgSwapValidate(t *testing.T) { Denom: "cony", Amount: sdk.ZeroInt(), }, - ToDenom: "kai", + ToDenom: "kei", }, expectedError: sdkerrors.ErrInvalidCoins, }, @@ -229,7 +229,7 @@ func TestMsgSwapAllValidate(t *testing.T) { msg: &fswaptypes.MsgSwapAll{ FromAddress: address, FromDenom: "cony", - ToDenom: "kai", + ToDenom: "kei", }, expectedError: nil, }, @@ -238,7 +238,7 @@ func TestMsgSwapAllValidate(t *testing.T) { msg: &fswaptypes.MsgSwapAll{ FromAddress: "invalid-address", FromDenom: "cony", - ToDenom: "kai", + ToDenom: "kei", }, expectedError: sdkerrors.ErrInvalidAddress, }, @@ -247,7 +247,7 @@ func TestMsgSwapAllValidate(t *testing.T) { msg: &fswaptypes.MsgSwapAll{ FromAddress: address, FromDenom: "", - ToDenom: "kai", + ToDenom: "kei", }, expectedError: sdkerrors.ErrInvalidRequest, }, @@ -286,7 +286,7 @@ func TestMsgSetSwapValidate(t *testing.T) { Authority: address, Swap: fswaptypes.Swap{ FromDenom: "cony", - ToDenom: "kai", + ToDenom: "kei", AmountCapForToDenom: sdk.OneInt(), SwapRate: sdk.NewDec(123), }, @@ -294,14 +294,14 @@ func TestMsgSetSwapValidate(t *testing.T) { Description: "desc", DenomUnits: []*banktypes.DenomUnit{ { - Denom: "kai", + Denom: "kei", Exponent: 0, Aliases: nil, }, }, - Base: "kai", - Display: "kai", - Name: "kai", + Base: "kei", + Display: "kei", + Name: "kei", Symbol: "KAIA", }, }, @@ -313,7 +313,7 @@ func TestMsgSetSwapValidate(t *testing.T) { Authority: "invalid-address", Swap: fswaptypes.Swap{ FromDenom: "cony", - ToDenom: "kai", + ToDenom: "kei", AmountCapForToDenom: sdk.OneInt(), SwapRate: sdk.NewDec(123), }, @@ -321,14 +321,14 @@ func TestMsgSetSwapValidate(t *testing.T) { Description: "desc", DenomUnits: []*banktypes.DenomUnit{ { - Denom: "kai", + Denom: "kei", Exponent: 0, Aliases: nil, }, }, - Base: "kai", - Display: "kai", - Name: "kai", + Base: "kei", + Display: "kei", + Name: "kei", Symbol: "KAIA", }, }, @@ -343,14 +343,14 @@ func TestMsgSetSwapValidate(t *testing.T) { Description: "desc", DenomUnits: []*banktypes.DenomUnit{ { - Denom: "kai", + Denom: "kei", Exponent: 0, Aliases: nil, }, }, - Base: "kai", - Display: "kai", - Name: "kai", + Base: "kei", + Display: "kei", + Name: "kei", Symbol: "KAIA", }, }, @@ -362,7 +362,7 @@ func TestMsgSetSwapValidate(t *testing.T) { Authority: address, Swap: fswaptypes.Swap{ FromDenom: "cony", - ToDenom: "kai", + ToDenom: "kei", AmountCapForToDenom: sdk.OneInt(), SwapRate: sdk.NewDec(123), }, @@ -370,7 +370,7 @@ func TestMsgSetSwapValidate(t *testing.T) { Description: "", DenomUnits: []*banktypes.DenomUnit{ { - Denom: "kai", + Denom: "kei", Exponent: 0, Aliases: nil, }, @@ -386,7 +386,7 @@ func TestMsgSetSwapValidate(t *testing.T) { Authority: address, Swap: fswaptypes.Swap{ FromDenom: "cony", - ToDenom: "kai", + ToDenom: "kei", AmountCapForToDenom: sdk.OneInt(), SwapRate: sdk.NewDec(123), }, @@ -394,14 +394,14 @@ func TestMsgSetSwapValidate(t *testing.T) { Description: "desc", DenomUnits: []*banktypes.DenomUnit{ { - Denom: "fkai", + Denom: "fkei", Exponent: 0, Aliases: nil, }, }, - Base: "fkai", - Display: "fkai", - Name: "fkai", + Base: "fkei", + Display: "fkei", + Name: "fkei", Symbol: "KAIA", }, }, From 5d137b83878ac04805596a77406faf9aa9da778d Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Wed, 12 Jun 2024 18:10:47 +0900 Subject: [PATCH 09/11] chore: introduce stubGenesisState func for DRY --- x/fswap/keeper/genesis_test.go | 90 +++++++++++++--------------------- 1 file changed, 33 insertions(+), 57 deletions(-) diff --git a/x/fswap/keeper/genesis_test.go b/x/fswap/keeper/genesis_test.go index 935067b75a..f9a8e415ed 100644 --- a/x/fswap/keeper/genesis_test.go +++ b/x/fswap/keeper/genesis_test.go @@ -15,32 +15,7 @@ import ( func (s *KeeperTestSuite) TestInitAndExportGenesis() { ctx, _ := s.ctx.CacheContext() - testSwapRate, _ := sdk.NewDecFromStr("1234567890") - testGenesis := &types.GenesisState{ - Swaps: []types.Swap{ - { - FromDenom: "aaa", - ToDenom: "bbb", - AmountCapForToDenom: sdk.NewInt(1234567890000), - SwapRate: testSwapRate, - }, - }, - SwapStats: types.SwapStats{ - SwapCount: 1, - }, - Swappeds: []types.Swapped{ - { - FromCoinAmount: sdk.Coin{ - Denom: "aaa", - Amount: sdk.ZeroInt(), - }, - ToCoinAmount: sdk.Coin{ - Denom: "bbb", - Amount: sdk.ZeroInt(), - }, - }, - }, - } + testGenesis := stubGenesisState() err := s.keeper.InitGenesis(ctx, testGenesis) s.Require().NoError(err) @@ -53,34 +28,6 @@ func (s *KeeperTestSuite) TestInitAndExportGenesis() { } func TestInitGenesis(t *testing.T) { - generateState := func() *types.GenesisState { - testSwapRate, _ := sdk.NewDecFromStr("1234567890") - return &types.GenesisState{ - Swaps: []types.Swap{ - { - FromDenom: "aaa", - ToDenom: "bbb", - AmountCapForToDenom: sdk.NewInt(1234567890000), - SwapRate: testSwapRate, - }, - }, - SwapStats: types.SwapStats{ - SwapCount: 1, - }, - Swappeds: []types.Swapped{ - { - FromCoinAmount: sdk.Coin{ - Denom: "aaa", - Amount: sdk.ZeroInt(), - }, - ToCoinAmount: sdk.Coin{ - Denom: "bbb", - Amount: sdk.ZeroInt(), - }, - }, - }, - } - } checkTx := false app := simapp.Setup(checkTx) testdata.RegisterInterfaces(app.InterfaceRegistry()) @@ -95,13 +42,13 @@ func TestInitGenesis(t *testing.T) { }{ { name: "valid", - genState: generateState(), + genState: stubGenesisState(), expectedError: nil, }, { name: "invalid: swapCount", genState: func() *types.GenesisState { - state := generateState() + state := stubGenesisState() state.SwapStats.SwapCount = -1 return state }(), @@ -110,7 +57,7 @@ func TestInitGenesis(t *testing.T) { { name: "invalid: swaps count exceeds limit", genState: func() *types.GenesisState { - state := generateState() + state := stubGenesisState() state.Swaps = append(state.Swaps, state.Swaps[0]) state.Swappeds = append(state.Swappeds, state.Swappeds[0]) state.SwapStats.SwapCount = 2 @@ -126,3 +73,32 @@ func TestInitGenesis(t *testing.T) { }) } } + +func stubGenesisState() *types.GenesisState { + testSwapRate, _ := sdk.NewDecFromStr("1234567890") + return &types.GenesisState{ + Swaps: []types.Swap{ + { + FromDenom: "aaa", + ToDenom: "bbb", + AmountCapForToDenom: sdk.NewInt(1234567890000), + SwapRate: testSwapRate, + }, + }, + SwapStats: types.SwapStats{ + SwapCount: 1, + }, + Swappeds: []types.Swapped{ + { + FromCoinAmount: sdk.Coin{ + Denom: "aaa", + Amount: sdk.ZeroInt(), + }, + ToCoinAmount: sdk.Coin{ + Denom: "bbb", + Amount: sdk.ZeroInt(), + }, + }, + }, + } +} From 6b6c5bf0d3519027c2f4534e44fea98fc8ec5cc2 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Wed, 12 Jun 2024 18:15:27 +0900 Subject: [PATCH 10/11] chore: remove unnecessary code --- x/fswap/keeper/grpc_query_test.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/x/fswap/keeper/grpc_query_test.go b/x/fswap/keeper/grpc_query_test.go index 089ce05bdd..f9499b1dc7 100644 --- a/x/fswap/keeper/grpc_query_test.go +++ b/x/fswap/keeper/grpc_query_test.go @@ -297,11 +297,9 @@ func (s *FSwapQueryTestSuite) TestQuerySwapsRequest() { name: "invalid request", request: &types.QuerySwapsRequest{ Pagination: &query.PageRequest{ - Key: []byte("invalid-key"), - Offset: 1, - Limit: 0, - CountTotal: false, - Reverse: false, + Key: []byte("invalid-key"), + Offset: 1, + Limit: 0, }, }, expectedResponse: nil, From 28b44ed3d5d56977355e19c6cea59ab6c9acd498 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Wed, 12 Jun 2024 19:20:49 +0900 Subject: [PATCH 11/11] chore: remove unnecessary code --- x/fswap/types/msgs_test.go | 55 -------------------------------------- 1 file changed, 55 deletions(-) diff --git a/x/fswap/types/msgs_test.go b/x/fswap/types/msgs_test.go index d4769b1666..d6091af476 100644 --- a/x/fswap/types/msgs_test.go +++ b/x/fswap/types/msgs_test.go @@ -5,8 +5,6 @@ import ( "testing" "github.com/stretchr/testify/require" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" "github.com/Finschia/finschia-sdk/crypto/keys/secp256k1" sdk "github.com/Finschia/finschia-sdk/types" @@ -89,59 +87,6 @@ func TestAminoJSON(t *testing.T) { } } -func TestQuerySwapRequestValidate(t *testing.T) { - tests := []struct { - name string - msg *fswaptypes.QuerySwapRequest - expectedGrpcCode codes.Code - }{ - { - name: "valid", - msg: &fswaptypes.QuerySwapRequest{ - FromDenom: "cony", - ToDenom: "kei", - }, - expectedGrpcCode: codes.OK, - }, - { - name: "invalid: nil request", - msg: nil, - expectedGrpcCode: codes.InvalidArgument, - }, - { - name: "invalid: empty fromDenom", - msg: &fswaptypes.QuerySwapRequest{ - FromDenom: "", - ToDenom: "kei", - }, - expectedGrpcCode: codes.InvalidArgument, - }, - { - name: "invalid: empty toDenom", - msg: &fswaptypes.QuerySwapRequest{ - FromDenom: "cony", - ToDenom: "", - }, - expectedGrpcCode: codes.InvalidArgument, - }, - { - name: "invalid: the same fromDenom and toDenom", - msg: &fswaptypes.QuerySwapRequest{ - FromDenom: "cony", - ToDenom: "cony", - }, - expectedGrpcCode: codes.InvalidArgument, - }, - } - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { - err := tc.msg.Validate() - actualGrpcCode := status.Code(err) - require.Equal(t, tc.expectedGrpcCode, actualGrpcCode) - }) - } -} - func TestMsgSwapValidate(t *testing.T) { pk := secp256k1.GenPrivKey().PubKey() address, err := sdk.Bech32ifyAddressBytes("link", pk.Address())