Skip to content

Commit

Permalink
test: updating setter + adding test
Browse files Browse the repository at this point in the history
  • Loading branch information
seantking committed Sep 13, 2021
1 parent e90d0e1 commit 3c5e568
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
4 changes: 2 additions & 2 deletions modules/apps/29-fee/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ func (k Keeper) SetPort(ctx sdk.Context, portID string) {

// SetCounterpartyAddress maps the destination chain relayer address to the source relayer address
// The receiving chain must store the mapping from: address -> counterpartyAddress for the given channel
func (k Keeper) SetCounterpartyAddress(ctx sdk.Context, address, counterpartyAddress string) {
func (k Keeper) SetCounterpartyAddress(ctx sdk.Context, address string, counterpartyAddress sdk.AccAddress) {
store := ctx.KVStore(k.storeKey)
store.Set(types.KeyRelayerAddress(address), []byte(counterpartyAddress))
store.Set(types.KeyRelayerAddress(address), counterpartyAddress)
}

// GetCounterpartyAddress gets the relayer counterparty address given a destination relayer address
Expand Down
7 changes: 6 additions & 1 deletion modules/apps/29-fee/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ var _ types.MsgServer = Keeper{}
func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.MsgRegisterCounterpartyAddress) (*types.MsgRegisterCounterpartyAddressResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

counterpartyAddress, err := sdk.AccAddressFromBech32(msg.CounterpartyAddress)
if err != nil {
return &types.MsgRegisterCounterpartyAddressResponse{}, err
}

k.SetCounterpartyAddress(
ctx, msg.Address, msg.CounterpartyAddress,
ctx, msg.Address, counterpartyAddress,
)

k.Logger(ctx).Info("Registering counterparty address for relayer.", "Address:", msg.Address, "Counterparty Address:", msg.CounterpartyAddress)
Expand Down
27 changes: 20 additions & 7 deletions modules/apps/29-fee/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,41 @@ import (
)

func (suite *KeeperTestSuite) TestRegisterCounterpartyAddress() {
validAddr := suite.chainA.SenderAccount.GetAddress().String()
validAddr2 := suite.chainB.SenderAccount.GetAddress().String()
var (
addr string
addr2 string
)

testCases := []struct {
msg *types.MsgRegisterCounterpartyAddress
expPass bool
name string
expPass bool
malleate func()
}{
{
types.NewMsgRegisterCounterpartyAddress(validAddr, validAddr2),
"CounterpartyAddress registered",
true,
func() {},
},
}

for _, tc := range testCases {
suite.SetupTest()
_, err := suite.chainA.SendMsgs(tc.msg)
ctx := suite.chainA.GetContext()

addr = suite.chainA.SenderAccount.GetAddress().String()
addr2 = suite.chainB.SenderAccount.GetAddress().String()
msg := types.NewMsgRegisterCounterpartyAddress(addr, addr2)
tc.malleate()

_, err := suite.chainA.SendMsgs(msg)

if tc.expPass {
suite.Require().NoError(err) // message committed

counterpartyAddress, _ := suite.chainA.GetSimApp().IBCFeeKeeper.GetCounterpartyAddress(ctx, suite.chainA.SenderAccount.GetAddress())
suite.Require().Equal(addr2, counterpartyAddress.String())
} else {
suite.Require().Error(err)
}

}
}

0 comments on commit 3c5e568

Please sign in to comment.