Skip to content

Commit

Permalink
chore: add tests for Channel.Validate
Browse files Browse the repository at this point in the history
  • Loading branch information
bznein committed Oct 22, 2024
1 parent e0a60a0 commit 31e40ff
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions modules/core/04-channel/v2/types/channel_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package types_test

import (
"github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
ibctesting "github.com/cosmos/ibc-go/v9/testing"
)

func (s *TypesTestSuite) TestValidate() {
var c types.Channel
testCases := []struct {
name string
malleate func()
expErr error
}{
{
name: "success",
malleate: func() {},
},
{
name: "failure: invalid ClientID",
malleate: func() {
c.ClientId = ""
},
expErr: host.ErrInvalidID,
},
{
name: "failure: invalid counterparty",
malleate: func() {
c.CounterpartyChannelId = ""
},
expErr: host.ErrInvalidID,
},
{
name: "failure: invalid Merkle Path Prefix",
malleate: func() {
c.MerklePathPrefix.KeyPath = [][]byte{}
},
expErr: types.ErrInvalidChannel,
},
}
for _, tc := range testCases {
s.Run(tc.name, func() {
c = types.NewChannel(ibctesting.FirstClientID, ibctesting.SecondClientID, ibctesting.MerklePath)

tc.malleate()

err := c.Validate()

expPass := tc.expErr == nil
if expPass {
s.Require().NoError(err)
} else {
ibctesting.RequireErrorIsOrContains(s.T(), err, tc.expErr)
}
})
}
}

0 comments on commit 31e40ff

Please sign in to comment.