Skip to content

Commit

Permalink
refactor: add types test and check for is fee enabled + fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
seantking committed May 4, 2022
1 parent cee78ba commit 248c4d6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
9 changes: 6 additions & 3 deletions modules/apps/29-fee/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ var _ types.MsgServer = Keeper{}
func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.MsgRegisterCounterpartyAddress) (*types.MsgRegisterCounterpartyAddressResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// only register counterparty address if the channel exists
_, found := k.channelKeeper.GetChannel(ctx, msg.PortId, msg.ChannelId)
if !found {
// only register counterparty address if the channel exists and is fee enabled
if _, found := k.channelKeeper.GetChannel(ctx, msg.PortId, msg.ChannelId); !found {
return nil, channeltypes.ErrChannelNotFound
}

if !k.IsFeeEnabled(ctx, msg.PortId, msg.ChannelId) {
return nil, types.ErrFeeNotEnabled
}

k.SetCounterpartyAddress(
ctx, msg.Address, msg.CounterpartyAddress, msg.ChannelId,
)
Expand Down
13 changes: 10 additions & 3 deletions modules/apps/29-fee/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func (suite *KeeperTestSuite) TestRegisterCounterpartyAddress() {
sender string
counterparty string
channelID string
ctx sdk.Context
)

testCases := []struct {
Expand All @@ -35,11 +36,18 @@ func (suite *KeeperTestSuite) TestRegisterCounterpartyAddress() {
false,
func() { channelID = "channel-22" },
},
{
"channel is not fee enabled",
false,
func() {
suite.chainA.GetSimApp().IBCFeeKeeper.DeleteFeeEnabled(ctx, suite.path.EndpointA.ChannelConfig.PortID, channelID)
},
},
}

for _, tc := range testCases {
suite.SetupTest()
ctx := suite.chainA.GetContext()
ctx = suite.chainA.GetContext()
suite.coordinator.Setup(suite.path) // setup channel

sender = suite.chainA.SenderAccount.GetAddress().String()
Expand All @@ -49,8 +57,7 @@ func (suite *KeeperTestSuite) TestRegisterCounterpartyAddress() {
tc.malleate()

msg := types.NewMsgRegisterCounterpartyAddress(sender, counterparty, suite.path.EndpointA.ChannelConfig.PortID, channelID)

_, err := suite.chainA.SendMsgs(msg)
_, err := suite.chainA.GetSimApp().IBCFeeKeeper.RegisterCounterpartyAddress(sdk.WrapSDKContext(ctx), msg)

if tc.expPass {
suite.Require().NoError(err) // message committed
Expand Down
7 changes: 7 additions & 0 deletions modules/apps/29-fee/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ func TestMsgRegisterCountepartyAddressValidation(t *testing.T) {
},
false,
},
{
"invalid portID",
func() {
msg.PortId = ""
},
false,
},
}

for i, tc := range testCases {
Expand Down

0 comments on commit 248c4d6

Please sign in to comment.