From 31e40ff43b06e7ea104ddf77ac50c2a29a5419c1 Mon Sep 17 00:00:00 2001 From: bznein Date: Tue, 22 Oct 2024 11:25:35 +0100 Subject: [PATCH] chore: add tests for Channel.Validate --- .../core/04-channel/v2/types/channel_test.go | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 modules/core/04-channel/v2/types/channel_test.go diff --git a/modules/core/04-channel/v2/types/channel_test.go b/modules/core/04-channel/v2/types/channel_test.go new file mode 100644 index 00000000000..eda4953c04b --- /dev/null +++ b/modules/core/04-channel/v2/types/channel_test.go @@ -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) + } + }) + } +}