Skip to content

Commit

Permalink
imp: add upgrade sequence to identified channel (#5436)
Browse files Browse the repository at this point in the history
* imp: add upgrade sequence to identified channel

* Add ValidateBasic tests for IdentifiedChannel.

---------

Co-authored-by: DimitrisJim <d.f.hilliard@gmail.com>
  • Loading branch information
crodriguezvega and DimitrisJim authored Dec 18, 2023
1 parent 7967cfd commit beb46ae
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 67 deletions.
42 changes: 42 additions & 0 deletions docs/client/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9107,6 +9107,15 @@ paths:
channel_id:
type: string
title: channel identifier
upgrade_sequence:
type: string
format: uint64
title: >-
upgrade sequence indicates the latest upgrade attempt
performed by this channel

the value of 0 indicates the channel has never been
upgraded
description: >-
IdentifiedChannel defines a channel with additional port and
channel
Expand Down Expand Up @@ -13970,6 +13979,15 @@ paths:
channel_id:
type: string
title: channel identifier
upgrade_sequence:
type: string
format: uint64
title: >-
upgrade sequence indicates the latest upgrade attempt
performed by this channel

the value of 0 indicates the channel has never been
upgraded
description: >-
IdentifiedChannel defines a channel with additional port and
channel
Expand Down Expand Up @@ -19088,6 +19106,14 @@ definitions:
channel_id:
type: string
title: channel identifier
upgrade_sequence:
type: string
format: uint64
title: >-
upgrade sequence indicates the latest upgrade attempt performed by
this channel

the value of 0 indicates the channel has never been upgraded
description: |-
IdentifiedChannel defines a channel with additional port and channel
identifier fields.
Expand Down Expand Up @@ -19864,6 +19890,14 @@ definitions:
channel_id:
type: string
title: channel identifier
upgrade_sequence:
type: string
format: uint64
title: >-
upgrade sequence indicates the latest upgrade attempt performed
by this channel

the value of 0 indicates the channel has never been upgraded
description: |-
IdentifiedChannel defines a channel with additional port and channel
identifier fields.
Expand Down Expand Up @@ -20006,6 +20040,14 @@ definitions:
channel_id:
type: string
title: channel identifier
upgrade_sequence:
type: string
format: uint64
title: >-
upgrade sequence indicates the latest upgrade attempt performed
by this channel

the value of 0 indicates the channel has never been upgraded
description: |-
IdentifiedChannel defines a channel with additional port and channel
identifier fields.
Expand Down
15 changes: 8 additions & 7 deletions modules/core/04-channel/types/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,14 @@ func (c Counterparty) ValidateBasic() error {
// NewIdentifiedChannel creates a new IdentifiedChannel instance
func NewIdentifiedChannel(portID, channelID string, ch Channel) IdentifiedChannel {
return IdentifiedChannel{
State: ch.State,
Ordering: ch.Ordering,
Counterparty: ch.Counterparty,
ConnectionHops: ch.ConnectionHops,
Version: ch.Version,
PortId: portID,
ChannelId: channelID,
State: ch.State,
Ordering: ch.Ordering,
Counterparty: ch.Counterparty,
ConnectionHops: ch.ConnectionHops,
Version: ch.Version,
UpgradeSequence: ch.UpgradeSequence,
PortId: portID,
ChannelId: channelID,
}
}

Expand Down
150 changes: 90 additions & 60 deletions modules/core/04-channel/types/channel.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions modules/core/04-channel/types/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
host "github.com/cosmos/ibc-go/v8/modules/core/24-host"
)

func TestChannelValidateBasic(t *testing.T) {
Expand Down Expand Up @@ -57,3 +58,37 @@ func TestCounterpartyValidateBasic(t *testing.T) {
}
}
}

// TestIdentifiedChannelValidateBasic tests ValidateBasic for IdentifiedChannel.
func TestIdentifiedChannelValidateBasic(t *testing.T) {
channel := types.NewChannel(types.TRYOPEN, types.ORDERED, types.Counterparty{"portidone", "channelidone"}, connHops, version)

testCases := []struct {
name string
identifiedChannel types.IdentifiedChannel
expErr error
}{
{
"valid identified channel",
types.NewIdentifiedChannel("portidone", "channelidone", channel),
nil,
},
{
"invalid portID",
types.NewIdentifiedChannel("(InvalidPort)", "channelidone", channel),
host.ErrInvalidID,
},
{
"invalid channelID",
types.NewIdentifiedChannel("portidone", "(InvalidChannel)", channel),
host.ErrInvalidID,
},
}

for _, tc := range testCases {
tc := tc

err := tc.identifiedChannel.ValidateBasic()
require.ErrorIs(t, err, tc.expErr)
}
}
3 changes: 3 additions & 0 deletions proto/ibc/core/channel/v1/channel.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ message IdentifiedChannel {
string port_id = 6;
// channel identifier
string channel_id = 7;
// upgrade sequence indicates the latest upgrade attempt performed by this channel
// the value of 0 indicates the channel has never been upgraded
uint64 upgrade_sequence = 8;
}

// State defines if a channel is in one of the following states:
Expand Down

0 comments on commit beb46ae

Please sign in to comment.