Skip to content

Commit

Permalink
added channel invariant check to msg_register_host_zone
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs committed Apr 21, 2023
1 parent 1b31e87 commit 0351d75
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions x/stakeibc/keeper/msg_server_register_host_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func (k msgServer) RegisterHostZone(goCtx context.Context, msg *types.MsgRegiste
k.Logger(ctx).Error(errMsg)
return nil, errorsmod.Wrapf(types.ErrFailedToRegisterHostZone, errMsg)
}
if hostZone.TransferChannelId == msg.TransferChannelId {
errMsg := fmt.Sprintf("transfer channel %s already registered", msg.TransferChannelId)
k.Logger(ctx).Error(errMsg)
return nil, errorsmod.Wrapf(types.ErrFailedToRegisterHostZone, errMsg)
}
if hostZone.Bech32Prefix == msg.Bech32Prefix {
errMsg := fmt.Sprintf("bech32prefix %s already registered", msg.Bech32Prefix)
k.Logger(ctx).Error(errMsg)
Expand Down
21 changes: 21 additions & 0 deletions x/stakeibc/keeper/msg_server_register_host_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,27 @@ func (s *KeeperTestSuite) TestRegisterHostZone_DuplicateHostDenom() {
s.Require().EqualError(err, expectedErrMsg, "registering host zone with duplicate host denom should fail")
}

func (s *KeeperTestSuite) TestRegisterHostZone_DuplicateTransferChannel() {
// tests for a failure if we register the same host zone twice (with a duplicate transfer)
tc := s.SetupRegisterHostZone()

// Register host zones successfully
_, err := s.GetMsgServer().RegisterHostZone(sdk.WrapSDKContext(s.Ctx), &tc.validMsg)
s.Require().NoError(err, "able to successfully register host zone once")

// Create the message for a brand new host zone
// (without modifications, you would expect this to be successful)
newHostZoneMsg := s.createNewHostZoneMessage("OSMO", "osmo", "osmo")

// Try to register with a duplicate transfer channel - it should fail
invalidMsg := newHostZoneMsg
invalidMsg.TransferChannelId = tc.validMsg.TransferChannelId

_, err = s.GetMsgServer().RegisterHostZone(sdk.WrapSDKContext(s.Ctx), &invalidMsg)
expectedErrMsg := "transfer channel channel-0 already registered: failed to register host zone"
s.Require().EqualError(err, expectedErrMsg, "registering host zone with duplicate host denom should fail")
}

func (s *KeeperTestSuite) TestRegisterHostZone_DuplicateBech32Prefix() {
// tests for a failure if we register the same host zone twice (with a duplicate bech32 prefix)
tc := s.SetupRegisterHostZone()
Expand Down

0 comments on commit 0351d75

Please sign in to comment.