Skip to content

Commit

Permalink
chore: add tests for Channel.Validate (#7504)
Browse files Browse the repository at this point in the history
* chore: add tests for Channel.Validate

* Update modules/core/04-channel/v2/types/channel_test.go

Co-authored-by: DimitrisJim <[email protected]>

* Update modules/core/04-channel/v2/types/channel_test.go

Co-authored-by: DimitrisJim <[email protected]>

---------

Co-authored-by: DimitrisJim <[email protected]>
  • Loading branch information
bznein and DimitrisJim authored Oct 22, 2024
1 parent 8b7889c commit 60f20f0
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) TestValidateChannel() {
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 channel id",
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 60f20f0

Please sign in to comment.