Skip to content

Commit

Permalink
fix: fix for comments
Browse files Browse the repository at this point in the history
Signed-off-by: 170210 <[email protected]>
  • Loading branch information
170210 committed May 17, 2024
1 parent 7e0df2c commit b5b105c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 23 deletions.
1 change: 0 additions & 1 deletion x/fswap/keeper/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type BankKeeper interface {
IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) error
GetDenomMetaData(ctx sdk.Context, denom string) (banktypes.Metadata, bool)
SetDenomMetaData(ctx sdk.Context, denomMetaData banktypes.Metadata)
HasSupply(ctx sdk.Context, denom string) bool
MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
}
2 changes: 1 addition & 1 deletion x/fswap/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (k Keeper) SetSwap(ctx sdk.Context, swap types.Swap, toDenomMetadata bank.M
return types.ErrCanNotHaveMoreSwap.Wrapf("cannot make more swaps, max swaps is %d", k.config.MaxSwaps)
}

if !k.HasSupply(ctx, swap.FromDenom) {
if _, ok := k.GetDenomMetaData(ctx, swap.FromDenom); !ok {
return sdkerrors.ErrInvalidRequest.Wrap("fromDenom should be existed in chain")
}

Expand Down
49 changes: 42 additions & 7 deletions x/fswap/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,12 @@ func (s *KeeperTestSuite) TestSwap() {
func (s *KeeperTestSuite) TestSetSwap() {
ctrl := gomock.NewController(s.T())
defer ctrl.Finish()

bankKeeper := testutil.NewMockBankKeeper(ctrl)
bankKeeper.EXPECT().HasSupply(gomock.Any(), "fromdenom").Return(true).AnyTimes()
bankKeeper.EXPECT().HasSupply(gomock.Any(), gomock.Any()).Return(false).AnyTimes()
bankKeeper.EXPECT().GetDenomMetaData(gomock.Any(), "todenom").Return(bank.Metadata{}, false).AnyTimes()
bankKeeper.EXPECT().GetDenomMetaData(gomock.Any(), gomock.Any()).Return(s.toDenomMetadata, true).AnyTimes()
bankKeeper.EXPECT().SetDenomMetaData(gomock.Any(), s.toDenomMetadata).Times(1)
s.keeper.BankKeeper = bankKeeper

testCases := map[string]struct {
swap types.Swap
toDenomMeta bank.Metadata
malleate func()
expectedError error
expectedEvents sdk.Events
}{
Expand All @@ -271,6 +265,11 @@ func (s *KeeperTestSuite) TestSetSwap() {
SwapRate: sdk.OneDec(),
},
s.toDenomMetadata,
func() {
bankKeeper.EXPECT().GetDenomMetaData(gomock.Any(), "fromdenom").Return(bank.Metadata{}, true).Times(1)
bankKeeper.EXPECT().GetDenomMetaData(gomock.Any(), "todenom").Return(bank.Metadata{}, false).Times(1)
bankKeeper.EXPECT().SetDenomMetaData(gomock.Any(), s.toDenomMetadata).Times(1)
},
nil,
sdk.Events{
sdk.Event{
Expand All @@ -295,6 +294,32 @@ func (s *KeeperTestSuite) TestSetSwap() {
},
},
},
"to-denom metadata has been stored": {
types.Swap{
FromDenom: "fromdenom",
ToDenom: "todenom",
AmountCapForToDenom: sdk.OneInt(),
SwapRate: sdk.OneDec(),
},
s.toDenomMetadata,
func() {
bankKeeper.EXPECT().GetDenomMetaData(gomock.Any(), "fromdenom").Return(bank.Metadata{}, true).Times(1)
bankKeeper.EXPECT().GetDenomMetaData(gomock.Any(), "todenom").Return(s.toDenomMetadata, true).Times(1)
},
nil,
sdk.Events{
sdk.Event{
Type: "lbm.fswap.v1.EventSetSwap",
Attributes: []abci.EventAttribute{
{
Key: []byte("swap"),
Value: []uint8{0x7b, 0x22, 0x66, 0x72, 0x6f, 0x6d, 0x5f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x66, 0x72, 0x6f, 0x6d, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x2c, 0x22, 0x74, 0x6f, 0x5f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x74, 0x6f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x2c, 0x22, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x63, 0x61, 0x70, 0x5f, 0x66, 0x6f, 0x72, 0x5f, 0x74, 0x6f, 0x5f, 0x64, 0x65, 0x6e, 0x6f, 0x6d, 0x22, 0x3a, 0x22, 0x31, 0x22, 0x2c, 0x22, 0x73, 0x77, 0x61, 0x70, 0x5f, 0x72, 0x61, 0x74, 0x65, 0x22, 0x3a, 0x22, 0x31, 0x2e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x22, 0x7d},
Index: false,
},
},
},
},
},
"from-denom does not exist": {
types.Swap{
FromDenom: "fakedenom",
Expand All @@ -303,6 +328,9 @@ func (s *KeeperTestSuite) TestSetSwap() {
SwapRate: sdk.OneDec(),
},
s.toDenomMetadata,
func() {
bankKeeper.EXPECT().GetDenomMetaData(gomock.Any(), "fakedenom").Return(bank.Metadata{}, false).Times(1)
},
sdkerrors.ErrInvalidRequest,
sdk.Events{},
},
Expand All @@ -321,13 +349,20 @@ func (s *KeeperTestSuite) TestSetSwap() {
Name: s.toDenomMetadata.Name,
Symbol: s.toDenomMetadata.Symbol,
},
func() {
bankKeeper.EXPECT().GetDenomMetaData(gomock.Any(), "fromdenom").Return(bank.Metadata{}, true).Times(1)
bankKeeper.EXPECT().GetDenomMetaData(gomock.Any(), "change").Return(s.toDenomMetadata, true).Times(1)
},
sdkerrors.ErrInvalidRequest,
sdk.Events{},
},
}
for name, tc := range testCases {
s.Run(name, func() {
ctx, _ := s.ctx.CacheContext()
tc.malleate()
s.keeper.BankKeeper = bankKeeper

err := s.keeper.SetSwap(ctx, tc.swap, tc.toDenomMeta)
if tc.expectedError != nil {
s.Require().ErrorIs(err, tc.expectedError)
Expand Down
14 changes: 0 additions & 14 deletions x/fswap/testutil/expected_keepers_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b5b105c

Please sign in to comment.