x/ibc: proto migration pt 1 (#6097)

* x/ibc: proto migration pt 1

* fix tests

* fixes and godoc

* yaml tags

* rm changelog

* address comments from review

* fix some tests

* fix tests

* add _UNSPECIFIED suffix for default enums

* Update app

* protobuf Any fixes

* use gogoproto

* fix tests

* wrap all messages

* address @alexanderbez comments

* update proto files

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <aleks.bezobchuk@gmail.com>
Co-authored-by: Aaron Craelius <aaron@regen.network>
This commit is contained in:
Federico Kunze 2020-05-06 11:17:50 -04:00 committed by GitHub
parent bb0a1edf8e
commit d7ebee74e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
84 changed files with 11012 additions and 1444 deletions

View File

@ -232,13 +232,15 @@ func NewSimApp(
)
// Create IBC Keeper
// TODO: remove amino codec dependency once Tendermint version is upgraded with
// protobuf changes
app.IBCKeeper = ibc.NewKeeper(
app.cdc, keys[ibc.StoreKey], app.StakingKeeper, scopedIBCKeeper,
app.cdc, appCodec, keys[ibc.StoreKey], app.StakingKeeper, scopedIBCKeeper,
)
// Create Transfer Keepers
app.TransferKeeper = transfer.NewKeeper(
app.cdc, keys[transfer.StoreKey],
appCodec, keys[transfer.StoreKey],
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.AccountKeeper, app.BankKeeper, scopedTransferKeeper,
)

View File

@ -282,8 +282,8 @@ func (m *MsgSubmitProposal) XXX_DiscardUnknown() {
var xxx_messageInfo_MsgSubmitProposal proto.InternalMessageInfo
// Proposal defines the application-level concrete proposal type used in governance
// proposals.
// Proposal defines the application-level concrete proposal type used in
// governance proposals.
type Proposal struct {
types3.ProposalBase `protobuf:"bytes,1,opt,name=base,proto3,embedded=base" json:"base"`
Content Content `protobuf:"bytes,2,opt,name=content,proto3" json:"content"`
@ -332,7 +332,8 @@ func (m *Proposal) GetContent() Content {
// Content defines the application-level allowed Content to be included in a
// governance proposal.
type Content struct {
// sum defines a set of all acceptable concrete governance proposal Content types.
// sum defines a set of all acceptable concrete governance proposal Content
// types.
//
// Types that are valid to be assigned to Sum:
// *Content_Text

View File

@ -52,8 +52,8 @@ message MsgSubmitProposal {
Content content = 2;
}
// Proposal defines the application-level concrete proposal type used in governance
// proposals.
// Proposal defines the application-level concrete proposal type used in
// governance proposals.
message Proposal {
option (gogoproto.equal) = true;
@ -67,7 +67,8 @@ message Content {
option (gogoproto.equal) = true;
option (cosmos_proto.interface_type) = "*github.com/cosmos/cosmos-sdk/x/gov/types.Content";
// sum defines a set of all acceptable concrete governance proposal Content types.
// sum defines a set of all acceptable concrete governance proposal Content
// types.
oneof sum {
cosmos_sdk.x.gov.v1.TextProposal text = 1;
cosmos_sdk.x.params.v1.ParameterChangeProposal parameter_change = 2;

View File

@ -3,10 +3,10 @@ package types
import (
"time"
"github.com/tendermint/tendermint/crypto"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported"
"github.com/tendermint/tendermint/crypto"
)
type (

View File

@ -35,7 +35,7 @@ type ClientState interface {
consensusState ConsensusState,
) error
VerifyConnectionState(
cdc *codec.Codec,
cdc codec.Marshaler,
height uint64,
prefix commitmentexported.Prefix,
proof commitmentexported.Proof,
@ -44,7 +44,7 @@ type ClientState interface {
consensusState ConsensusState,
) error
VerifyChannelState(
cdc *codec.Codec,
cdc codec.Marshaler,
height uint64,
prefix commitmentexported.Prefix,
proof commitmentexported.Proof,

View File

@ -28,6 +28,7 @@ var (
QuerierConnections = keeper.QuerierConnections
QuerierClientConnections = keeper.QuerierClientConnections
RegisterCodec = types.RegisterCodec
RegisterInterfaces = types.RegisterInterfaces
NewConnectionEnd = types.NewConnectionEnd
NewCounterparty = types.NewCounterparty
ErrConnectionExists = types.ErrConnectionExists

View File

@ -5,7 +5,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/types/rest"
commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
)
const (
@ -21,42 +21,42 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, queryRoute string)
// ConnectionOpenInitReq defines the properties of a connection open init request's body.
type ConnectionOpenInitReq struct {
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
ConnectionID string `json:"connection_id" yaml:"connection_id"`
ClientID string `json:"client_id" yaml:"client_id"`
CounterpartyClientID string `json:"counterparty_client_id" yaml:"counterparty_client_id"`
CounterpartyConnectionID string `json:"counterparty_connection_id" yaml:"counterparty_connection_id"`
CounterpartyPrefix commitmentexported.Prefix `json:"counterparty_prefix" yaml:"counterparty_prefix"`
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
ConnectionID string `json:"connection_id" yaml:"connection_id"`
ClientID string `json:"client_id" yaml:"client_id"`
CounterpartyClientID string `json:"counterparty_client_id" yaml:"counterparty_client_id"`
CounterpartyConnectionID string `json:"counterparty_connection_id" yaml:"counterparty_connection_id"`
CounterpartyPrefix commitmenttypes.MerklePrefix `json:"counterparty_prefix" yaml:"counterparty_prefix"`
}
// ConnectionOpenTryReq defines the properties of a connection open try request's body.
type ConnectionOpenTryReq struct {
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
ConnectionID string `json:"connection_id" yaml:"connection_id"`
ClientID string `json:"client_id" yaml:"client_id"`
CounterpartyClientID string `json:"counterparty_client_id" yaml:"counterparty_client_id"`
CounterpartyConnectionID string `json:"counterparty_connection_id" yaml:"counterparty_connection_id"`
CounterpartyPrefix commitmentexported.Prefix `json:"counterparty_prefix" yaml:"counterparty_prefix"`
CounterpartyVersions []string `json:"counterparty_versions" yaml:"counterparty_versions"`
ProofInit commitmentexported.Proof `json:"proof_init" yaml:"proof_init"`
ProofConsensus commitmentexported.Proof `json:"proof_consensus" yaml:"proof_consensus"`
ProofHeight uint64 `json:"proof_height" yaml:"proof_height"`
ConsensusHeight uint64 `json:"consensus_height" yaml:"consensus_height"`
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
ConnectionID string `json:"connection_id" yaml:"connection_id"`
ClientID string `json:"client_id" yaml:"client_id"`
CounterpartyClientID string `json:"counterparty_client_id" yaml:"counterparty_client_id"`
CounterpartyConnectionID string `json:"counterparty_connection_id" yaml:"counterparty_connection_id"`
CounterpartyPrefix commitmenttypes.MerklePrefix `json:"counterparty_prefix" yaml:"counterparty_prefix"`
CounterpartyVersions []string `json:"counterparty_versions" yaml:"counterparty_versions"`
ProofInit commitmenttypes.MerkleProof `json:"proof_init" yaml:"proof_init"`
ProofConsensus commitmenttypes.MerkleProof `json:"proof_consensus" yaml:"proof_consensus"`
ProofHeight uint64 `json:"proof_height" yaml:"proof_height"`
ConsensusHeight uint64 `json:"consensus_height" yaml:"consensus_height"`
}
// ConnectionOpenAckReq defines the properties of a connection open ack request's body.
type ConnectionOpenAckReq struct {
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
ProofTry commitmentexported.Proof `json:"proof_try" yaml:"proof_try"`
ProofConsensus commitmentexported.Proof `json:"proof_consensus" yaml:"proof_consensus"`
ProofHeight uint64 `json:"proof_height" yaml:"proof_height"`
ConsensusHeight uint64 `json:"consensus_height" yaml:"consensus_height"`
Version string `json:"version" yaml:"version"`
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
ProofTry commitmenttypes.MerkleProof `json:"proof_try" yaml:"proof_try"`
ProofConsensus commitmenttypes.MerkleProof `json:"proof_consensus" yaml:"proof_consensus"`
ProofHeight uint64 `json:"proof_height" yaml:"proof_height"`
ConsensusHeight uint64 `json:"consensus_height" yaml:"consensus_height"`
Version string `json:"version" yaml:"version"`
}
// ConnectionOpenConfirmReq defines the properties of a connection open confirm request's body.
type ConnectionOpenConfirmReq struct {
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
ProofAck commitmentexported.Proof `json:"proof_ack" yaml:"proof_ack"`
ProofHeight uint64 `json:"proof_height" yaml:"proof_height"`
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
ProofAck commitmenttypes.MerkleProof `json:"proof_ack" yaml:"proof_ack"`
ProofHeight uint64 `json:"proof_height" yaml:"proof_height"`
}

View File

@ -1,14 +1,13 @@
package exported
import (
"encoding/json"
commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
// ConnectionI describes the required methods for a connection.
type ConnectionI interface {
GetState() State
GetState() ibctypes.State
GetID() string
GetClientID() string
GetCounterparty() CounterpartyI
@ -23,68 +22,3 @@ type CounterpartyI interface {
GetPrefix() commitmentexported.Prefix
ValidateBasic() error
}
// State defines the state of a connection between two disctinct
// chains
type State byte
// available connection states
const (
UNINITIALIZED State = iota // default State
INIT
TRYOPEN
OPEN
)
// string representation of the connection states
const (
StateUninitialized string = "UNINITIALIZED"
StateInit string = "INIT"
StateTryOpen string = "TRYOPEN"
StateOpen string = "OPEN"
)
// String implements the Stringer interface
func (s State) String() string {
switch s {
case INIT:
return StateInit
case TRYOPEN:
return StateTryOpen
case OPEN:
return StateOpen
default:
return StateUninitialized
}
}
// StateFromString parses a string into a connection state
func StateFromString(state string) State {
switch state {
case StateInit:
return INIT
case StateTryOpen:
return TRYOPEN
case StateOpen:
return OPEN
default:
return UNINITIALIZED
}
}
// MarshalJSON marshal to JSON using string.
func (s State) MarshalJSON() ([]byte, error) {
return json.Marshal(s.String())
}
// UnmarshalJSON decodes from JSON assuming Bech32 encoding.
func (s *State) UnmarshalJSON(data []byte) error {
var str string
err := json.Unmarshal(data, &str)
if err != nil {
return err
}
*s = StateFromString(str)
return nil
}

View File

@ -1,46 +0,0 @@
package exported
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestConnectionStateString(t *testing.T) {
cases := []struct {
name string
state State
}{
{StateUninitialized, UNINITIALIZED},
{StateInit, INIT},
{StateTryOpen, TRYOPEN},
{StateOpen, OPEN},
}
for _, tt := range cases {
tt := tt
require.Equal(t, tt.state, StateFromString(tt.name))
require.Equal(t, tt.name, tt.state.String())
}
}
func TestConnectionlStateMarshalJSON(t *testing.T) {
cases := []struct {
name string
state State
}{
{StateUninitialized, UNINITIALIZED},
{StateInit, INIT},
{StateTryOpen, TRYOPEN},
{StateOpen, OPEN},
}
for _, tt := range cases {
tt := tt
bz, err := tt.state.MarshalJSON()
require.NoError(t, err)
var state State
require.NoError(t, state.UnmarshalJSON(bz))
require.Equal(t, tt.name, state.String())
}
}

View File

@ -7,9 +7,9 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
@ -28,7 +28,7 @@ func (k Keeper) ConnOpenInit(
}
// connection defines chain A's ConnectionEnd
connection := types.NewConnectionEnd(exported.INIT, connectionID, clientID, counterparty, types.GetCompatibleVersions())
connection := types.NewConnectionEnd(ibctypes.INIT, connectionID, clientID, counterparty, types.GetCompatibleVersions())
k.SetConnection(ctx, connectionID, connection)
if err := k.addConnectionToClient(ctx, clientID, connectionID); err != nil {
@ -68,15 +68,15 @@ func (k Keeper) ConnOpenTry(
// expectedConnection defines Chain A's ConnectionEnd
// NOTE: chain A's counterparty is chain B (i.e where this code is executed)
prefix := k.GetCommitmentPrefix()
expectedCounterparty := types.NewCounterparty(clientID, connectionID, prefix)
expectedConnection := types.NewConnectionEnd(exported.INIT, counterparty.ConnectionID, counterparty.ClientID, expectedCounterparty, counterpartyVersions)
expectedCounterparty := types.NewCounterparty(clientID, connectionID, commitmenttypes.NewMerklePrefix(prefix.Bytes()))
expectedConnection := types.NewConnectionEnd(ibctypes.INIT, counterparty.ConnectionID, counterparty.ClientID, expectedCounterparty, counterpartyVersions)
// chain B picks a version from Chain A's available versions that is compatible
// with the supported IBC versions
version := types.PickVersion(counterpartyVersions, types.GetCompatibleVersions())
// connection defines chain B's ConnectionEnd
connection := types.NewConnectionEnd(exported.UNINITIALIZED, connectionID, clientID, counterparty, []string{version})
connection := types.NewConnectionEnd(ibctypes.UNINITIALIZED, connectionID, clientID, counterparty, []string{version})
// Check that ChainA committed expectedConnectionEnd to its state
if err := k.VerifyConnectionState(
@ -97,7 +97,7 @@ func (k Keeper) ConnOpenTry(
// is chainA and connection is on INIT stage
// Check that existing connection version is on desired version of current handshake
previousConnection, found := k.GetConnection(ctx, connectionID)
if found && !(previousConnection.State == exported.INIT &&
if found && !(previousConnection.State == ibctypes.INIT &&
previousConnection.Counterparty.ConnectionID == counterparty.ConnectionID &&
bytes.Equal(previousConnection.Counterparty.Prefix.Bytes(), counterparty.Prefix.Bytes()) &&
previousConnection.ClientID == clientID &&
@ -107,7 +107,7 @@ func (k Keeper) ConnOpenTry(
}
// Set connection state to TRYOPEN and store in chainB state
connection.State = exported.TRYOPEN
connection.State = ibctypes.TRYOPEN
if err := k.addConnectionToClient(ctx, clientID, connectionID); err != nil {
return sdkerrors.Wrap(err, "cannot relay connection attempt")
}
@ -142,7 +142,7 @@ func (k Keeper) ConnOpenAck(
}
// Check connection on ChainA is on correct state: INIT
if connection.State != exported.INIT {
if connection.State != ibctypes.INIT {
return sdkerrors.Wrapf(
types.ErrInvalidConnectionState,
"connection state is not INIT (got %s)", connection.State.String(),
@ -164,8 +164,8 @@ func (k Keeper) ConnOpenAck(
}
prefix := k.GetCommitmentPrefix()
expectedCounterparty := types.NewCounterparty(connection.ClientID, connectionID, prefix)
expectedConnection := types.NewConnectionEnd(exported.TRYOPEN, connection.Counterparty.ConnectionID, connection.Counterparty.ClientID, expectedCounterparty, []string{version})
expectedCounterparty := types.NewCounterparty(connection.ClientID, connectionID, commitmenttypes.NewMerklePrefix(prefix.Bytes()))
expectedConnection := types.NewConnectionEnd(ibctypes.TRYOPEN, connection.Counterparty.ConnectionID, connection.Counterparty.ClientID, expectedCounterparty, []string{version})
// Ensure that ChainB stored expected connectionEnd in its state during ConnOpenTry
if err := k.VerifyConnectionState(
@ -183,7 +183,7 @@ func (k Keeper) ConnOpenAck(
}
// Update connection state to Open
connection.State = exported.OPEN
connection.State = ibctypes.OPEN
connection.Versions = []string{version}
k.SetConnection(ctx, connectionID, connection)
k.Logger(ctx).Info(fmt.Sprintf("connection %s state updated: INIT -> OPEN ", connectionID))
@ -207,7 +207,7 @@ func (k Keeper) ConnOpenConfirm(
}
// Check that connection state on ChainB is on state: TRYOPEN
if connection.State != exported.TRYOPEN {
if connection.State != ibctypes.TRYOPEN {
return sdkerrors.Wrapf(
types.ErrInvalidConnectionState,
"connection state is not TRYOPEN (got %s)", connection.State.String(),
@ -215,8 +215,8 @@ func (k Keeper) ConnOpenConfirm(
}
prefix := k.GetCommitmentPrefix()
expectedCounterparty := types.NewCounterparty(connection.ClientID, connectionID, prefix)
expectedConnection := types.NewConnectionEnd(exported.OPEN, connection.Counterparty.ConnectionID, connection.Counterparty.ClientID, expectedCounterparty, connection.Versions)
expectedCounterparty := types.NewCounterparty(connection.ClientID, connectionID, commitmenttypes.NewMerklePrefix(prefix.Bytes()))
expectedConnection := types.NewConnectionEnd(ibctypes.OPEN, connection.Counterparty.ConnectionID, connection.Counterparty.ClientID, expectedCounterparty, connection.Versions)
// Check that connection on ChainA is open
if err := k.VerifyConnectionState(
@ -227,7 +227,7 @@ func (k Keeper) ConnOpenConfirm(
}
// Update ChainB's connection to Open
connection.State = exported.OPEN
connection.State = ibctypes.OPEN
k.SetConnection(ctx, connectionID, connection)
k.Logger(ctx).Info(fmt.Sprintf("connection %s state updated: TRYOPEN -> OPEN ", connectionID))
return nil

View File

@ -4,7 +4,7 @@ import (
"fmt"
connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
@ -20,12 +20,12 @@ func (suite *KeeperTestSuite) TestConnOpenInit() {
suite.chainA.CreateClient(suite.chainB)
}, true},
{"connection already exists", func() {
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, exported.INIT)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.INIT)
}, false},
{"couldn't add connection to client", func() {}, false},
}
counterparty := connection.NewCounterparty(testClientIDB, testConnectionIDB, suite.chainA.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix())
counterparty := connection.NewCounterparty(testClientIDB, testConnectionIDB, commitmenttypes.NewMerklePrefix(suite.chainA.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes()))
for i, tc := range testCases {
tc := tc
@ -50,7 +50,7 @@ func (suite *KeeperTestSuite) TestConnOpenInit() {
func (suite *KeeperTestSuite) TestConnOpenTry() {
// counterparty for A on B
counterparty := connection.NewCounterparty(
testClientIDB, testConnectionIDA, suite.chainB.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix(),
testClientIDB, testConnectionIDA, commitmenttypes.NewMerklePrefix(suite.chainB.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes()),
)
testCases := []struct {
@ -61,12 +61,12 @@ func (suite *KeeperTestSuite) TestConnOpenTry() {
{"success", func() uint64 {
suite.chainB.CreateClient(suite.chainA)
suite.chainA.CreateClient(suite.chainB)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, exported.INIT)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.INIT)
suite.chainB.updateClient(suite.chainA)
suite.chainA.updateClient(suite.chainB)
suite.chainB.updateClient(suite.chainA)
suite.chainA.updateClient(suite.chainB)
return uint64(suite.chainB.Header.Height - 1)
return suite.chainB.Header.GetHeight() - 1
}, true},
{"consensus height > latest height", func() uint64 {
return 0
@ -78,29 +78,29 @@ func (suite *KeeperTestSuite) TestConnOpenTry() {
{"connection state verification invalid", func() uint64 {
suite.chainB.CreateClient(suite.chainA)
suite.chainA.CreateClient(suite.chainB)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, exported.UNINITIALIZED)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.UNINITIALIZED)
suite.chainB.updateClient(suite.chainA)
return 0
}, false},
{"consensus state verification invalid", func() uint64 {
suite.chainB.CreateClient(suite.chainA)
suite.chainA.CreateClient(suite.chainB)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, exported.INIT)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.INIT)
suite.chainB.updateClient(suite.chainA)
suite.chainA.updateClient(suite.chainB)
return uint64(suite.chainB.Header.Height)
return suite.chainB.Header.GetHeight()
}, false},
{"invalid previous connection", func() uint64 {
suite.chainB.CreateClient(suite.chainA)
suite.chainA.CreateClient(suite.chainB)
suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, exported.UNINITIALIZED)
suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, ibctypes.UNINITIALIZED)
suite.chainB.updateClient(suite.chainA)
suite.chainA.updateClient(suite.chainB)
return 0
}, false},
{"couldn't add connection to client", func() uint64 {
suite.chainB.CreateClient(suite.chainA)
suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, exported.UNINITIALIZED)
suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, ibctypes.UNINITIALIZED)
suite.chainB.updateClient(suite.chainA)
suite.chainA.updateClient(suite.chainB)
return 0
@ -150,11 +150,11 @@ func (suite *KeeperTestSuite) TestConnOpenAck() {
{"success", version, func() uint64 {
suite.chainA.CreateClient(suite.chainB)
suite.chainB.CreateClient(suite.chainA)
suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, exported.TRYOPEN)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, exported.INIT)
suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, ibctypes.TRYOPEN)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.INIT)
suite.chainB.updateClient(suite.chainA)
suite.chainA.updateClient(suite.chainB)
return uint64(suite.chainB.Header.Height)
return suite.chainB.Header.GetHeight()
}, true},
{"consensus height > latest height", version, func() uint64 {
return 10
@ -163,38 +163,38 @@ func (suite *KeeperTestSuite) TestConnOpenAck() {
return 2
}, false},
{"connection state is not INIT", version, func() uint64 {
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, exported.UNINITIALIZED)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.UNINITIALIZED)
suite.chainB.updateClient(suite.chainA)
return uint64(suite.chainB.Header.Height)
return suite.chainB.Header.GetHeight()
}, false},
{"incompatible IBC versions", "2.0", func() uint64 {
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, exported.INIT)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.INIT)
suite.chainB.updateClient(suite.chainA)
return uint64(suite.chainB.Header.Height)
return suite.chainB.Header.GetHeight()
}, false},
{"self consensus state not found", version, func() uint64 {
suite.chainB.CreateClient(suite.chainA)
suite.chainA.CreateClient(suite.chainB)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, exported.INIT)
suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, exported.TRYOPEN)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.INIT)
suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, ibctypes.TRYOPEN)
suite.chainB.updateClient(suite.chainA)
return uint64(suite.chainB.Header.Height)
return suite.chainB.Header.GetHeight()
}, false},
{"connection state verification failed", version, func() uint64 {
suite.chainB.CreateClient(suite.chainA)
suite.chainA.CreateClient(suite.chainB)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, exported.INIT)
suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, exported.UNINITIALIZED)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.INIT)
suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, ibctypes.UNINITIALIZED)
suite.chainB.updateClient(suite.chainA)
return uint64(suite.chainB.Header.Height)
return suite.chainB.Header.GetHeight()
}, false},
{"consensus state verification failed", version, func() uint64 {
suite.chainB.CreateClient(suite.chainA)
suite.chainA.CreateClient(suite.chainB)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, exported.INIT)
suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, exported.UNINITIALIZED)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.INIT)
suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, ibctypes.UNINITIALIZED)
suite.chainB.updateClient(suite.chainA)
return uint64(suite.chainB.Header.Height)
return suite.chainB.Header.GetHeight()
}, false},
}
@ -233,22 +233,22 @@ func (suite *KeeperTestSuite) TestConnOpenConfirm() {
{"success", func() {
suite.chainB.CreateClient(suite.chainA)
suite.chainA.CreateClient(suite.chainB)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, exported.OPEN)
suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, exported.TRYOPEN)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.OPEN)
suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, ibctypes.TRYOPEN)
suite.chainB.updateClient(suite.chainA)
}, true},
{"connection not found", func() {}, false},
{"chain B's connection state is not TRYOPEN", func() {
suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, exported.UNINITIALIZED)
suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, exported.OPEN)
suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB, ibctypes.UNINITIALIZED)
suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, ibctypes.OPEN)
suite.chainA.updateClient(suite.chainB)
}, false},
{"connection state verification failed", func() {
suite.chainB.CreateClient(suite.chainA)
suite.chainA.CreateClient(suite.chainB)
suite.chainB.updateClient(suite.chainA)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, exported.INIT)
suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, exported.TRYOPEN)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.INIT)
suite.chainB.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, ibctypes.TRYOPEN)
suite.chainA.updateClient(suite.chainA)
}, false},
}

View File

@ -20,14 +20,16 @@ import (
// Keeper defines the IBC connection keeper
type Keeper struct {
storeKey sdk.StoreKey
cdc *codec.Codec
aminoCdc *codec.Codec // amino codec. TODO: remove after clients have been migrated to proto
cdc codec.Marshaler // hybrid codec
clientKeeper types.ClientKeeper
}
// NewKeeper creates a new IBC connection Keeper instance
func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, ck types.ClientKeeper) Keeper {
func NewKeeper(aminoCdc *codec.Codec, cdc codec.Marshaler, key sdk.StoreKey, ck types.ClientKeeper) Keeper {
return Keeper{
storeKey: key,
aminoCdc: aminoCdc,
cdc: cdc,
clientKeeper: ck,
}
@ -54,13 +56,14 @@ func (k Keeper) GetConnection(ctx sdk.Context, connectionID string) (types.Conne
var connection types.ConnectionEnd
k.cdc.MustUnmarshalBinaryBare(bz, &connection)
return connection, true
}
// SetConnection sets a connection to the store
func (k Keeper) SetConnection(ctx sdk.Context, connectionID string, connection types.ConnectionEnd) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshalBinaryBare(connection)
bz := k.cdc.MustMarshalBinaryBare(&connection)
store.Set(ibctypes.KeyConnection(connectionID), bz)
}
@ -90,15 +93,16 @@ func (k Keeper) GetClientConnectionPaths(ctx sdk.Context, clientID string) ([]st
return nil, false
}
var paths []string
k.cdc.MustUnmarshalBinaryBare(bz, &paths)
return paths, true
var clientPaths types.ClientPaths
k.cdc.MustUnmarshalBinaryBare(bz, &clientPaths)
return clientPaths.Paths, true
}
// SetClientConnectionPaths sets the connections paths for client
func (k Keeper) SetClientConnectionPaths(ctx sdk.Context, clientID string, paths []string) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshalBinaryBare(paths)
clientPaths := types.ClientPaths{Paths: paths}
bz := k.cdc.MustMarshalBinaryBare(&clientPaths)
store.Set(ibctypes.KeyClientConnections(clientID), bz)
}

View File

@ -6,6 +6,7 @@ import (
"time"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
tmtypes "github.com/tendermint/tendermint/types"
@ -13,9 +14,7 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
@ -88,8 +87,8 @@ func (suite *KeeperTestSuite) TestSetAndGetConnection() {
_, existed := suite.chainA.App.IBCKeeper.ConnectionKeeper.GetConnection(suite.chainA.GetContext(), testConnectionIDA)
suite.Require().False(existed)
counterparty := types.NewCounterparty(testClientIDA, testConnectionIDA, suite.chainA.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix())
expConn := types.NewConnectionEnd(exported.INIT, testConnectionIDB, testClientIDB, counterparty, types.GetCompatibleVersions())
counterparty := types.NewCounterparty(testClientIDA, testConnectionIDA, commitmenttypes.NewMerklePrefix(suite.chainA.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes()))
expConn := types.NewConnectionEnd(ibctypes.INIT, testConnectionIDB, testClientIDB, counterparty, types.GetCompatibleVersions())
suite.chainA.App.IBCKeeper.ConnectionKeeper.SetConnection(suite.chainA.GetContext(), testConnectionIDA, expConn)
conn, existed := suite.chainA.App.IBCKeeper.ConnectionKeeper.GetConnection(suite.chainA.GetContext(), testConnectionIDA)
suite.Require().True(existed)
@ -108,13 +107,13 @@ func (suite *KeeperTestSuite) TestSetAndGetClientConnectionPaths() {
func (suite KeeperTestSuite) TestGetAllConnections() {
// Connection (Counterparty): A(C) -> C(B) -> B(A)
counterparty1 := types.NewCounterparty(testClientIDA, testConnectionIDA, suite.chainA.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix())
counterparty2 := types.NewCounterparty(testClientIDB, testConnectionIDB, suite.chainA.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix())
counterparty3 := types.NewCounterparty(testClientID3, testConnectionID3, suite.chainA.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix())
counterparty1 := types.NewCounterparty(testClientIDA, testConnectionIDA, commitmenttypes.NewMerklePrefix(suite.chainA.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes()))
counterparty2 := types.NewCounterparty(testClientIDB, testConnectionIDB, commitmenttypes.NewMerklePrefix(suite.chainA.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes()))
counterparty3 := types.NewCounterparty(testClientID3, testConnectionID3, commitmenttypes.NewMerklePrefix(suite.chainA.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes()))
conn1 := types.NewConnectionEnd(exported.INIT, testConnectionIDA, testClientIDA, counterparty3, types.GetCompatibleVersions())
conn2 := types.NewConnectionEnd(exported.INIT, testConnectionIDB, testClientIDB, counterparty1, types.GetCompatibleVersions())
conn3 := types.NewConnectionEnd(exported.UNINITIALIZED, testConnectionID3, testClientID3, counterparty2, types.GetCompatibleVersions())
conn1 := types.NewConnectionEnd(ibctypes.INIT, testConnectionIDA, testClientIDA, counterparty3, types.GetCompatibleVersions())
conn2 := types.NewConnectionEnd(ibctypes.INIT, testConnectionIDB, testClientIDB, counterparty1, types.GetCompatibleVersions())
conn3 := types.NewConnectionEnd(ibctypes.UNINITIALIZED, testConnectionID3, testClientID3, counterparty2, types.GetCompatibleVersions())
expConnections := []types.ConnectionEnd{conn1, conn2, conn3}
@ -124,7 +123,7 @@ func (suite KeeperTestSuite) TestGetAllConnections() {
connections := suite.chainA.App.IBCKeeper.ConnectionKeeper.GetAllConnections(suite.chainA.GetContext())
suite.Require().Len(connections, len(expConnections))
suite.Require().ElementsMatch(expConnections, connections)
suite.Require().Equal(expConnections, connections)
}
func (suite KeeperTestSuite) TestGetAllClientConnectionPaths() {
@ -172,7 +171,7 @@ func (suite *KeeperTestSuite) TestGetTimestampAtHeight() {
tc.malleate()
// create and store a connection to chainB on chainA
connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, exported.OPEN)
connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.OPEN)
actualTimestamp, err := suite.chainA.App.IBCKeeper.ConnectionKeeper.GetTimestampAtHeight(
suite.chainA.GetContext(), connection, uint64(suite.chainB.Header.Height),
@ -224,7 +223,7 @@ func NewTestChain(clientID string) *TestChain {
// Creates simple context for testing purposes
func (chain *TestChain) GetContext() sdk.Context {
return chain.App.BaseApp.NewContext(false, abci.Header{ChainID: chain.Header.ChainID, Height: chain.Header.Height})
return chain.App.BaseApp.NewContext(false, abci.Header{ChainID: chain.Header.SignedHeader.Header.ChainID, Height: chain.Header.SignedHeader.Header.Height})
}
// createClient will create a client for clientChain on targetChain
@ -233,7 +232,7 @@ func (chain *TestChain) CreateClient(client *TestChain) error {
// Commit and create a new block on appTarget to get a fresh CommitID
client.App.Commit()
commitID := client.App.LastCommitID()
client.App.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: client.Header.Height, Time: client.Header.Time}})
client.App.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: client.Header.SignedHeader.Header.Height, Time: client.Header.Time}})
// Set HistoricalInfo on client chain after Commit
ctxClient := client.GetContext()
@ -250,7 +249,7 @@ func (chain *TestChain) CreateClient(client *TestChain) error {
},
Valset: validators,
}
client.App.StakingKeeper.SetHistoricalInfo(ctxClient, client.Header.Height, histInfo)
client.App.StakingKeeper.SetHistoricalInfo(ctxClient, client.Header.SignedHeader.Header.Height, histInfo)
// also set staking params
stakingParams := staking.DefaultParams()
@ -307,7 +306,7 @@ func (chain *TestChain) updateClient(client *TestChain) {
}
*/
client.App.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: client.Header.Height, Time: client.Header.Time}})
client.App.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: client.Header.SignedHeader.Header.Height, Time: client.Header.Time}})
// Set HistoricalInfo on client chain after Commit
ctxClient := client.GetContext()
@ -324,17 +323,17 @@ func (chain *TestChain) updateClient(client *TestChain) {
},
Valset: validators,
}
client.App.StakingKeeper.SetHistoricalInfo(ctxClient, client.Header.Height, histInfo)
client.App.StakingKeeper.SetHistoricalInfo(ctxClient, client.Header.SignedHeader.Header.Height, histInfo)
consensusState := ibctmtypes.ConsensusState{
Height: uint64(client.Header.Height),
Height: client.Header.GetHeight(),
Timestamp: client.Header.Time,
Root: commitmenttypes.NewMerkleRoot(commitID.Hash),
ValidatorSet: client.Vals,
}
chain.App.IBCKeeper.ClientKeeper.SetClientConsensusState(
ctxTarget, client.ClientID, uint64(client.Header.Height), consensusState,
ctxTarget, client.ClientID, client.Header.GetHeight(), consensusState,
)
chain.App.IBCKeeper.ClientKeeper.SetClientState(
ctxTarget, ibctmtypes.NewClientState(client.ClientID, trustingPeriod, ubdPeriod, maxClockDrift, client.Header),
@ -355,9 +354,9 @@ func (chain *TestChain) updateClient(client *TestChain) {
func (chain *TestChain) createConnection(
connID, counterpartyConnID, clientID, counterpartyClientID string,
state exported.State,
state ibctypes.State,
) types.ConnectionEnd {
counterparty := types.NewCounterparty(counterpartyClientID, counterpartyConnID, chain.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix())
counterparty := types.NewCounterparty(counterpartyClientID, counterpartyConnID, commitmenttypes.NewMerklePrefix(chain.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes()))
connection := types.ConnectionEnd{
State: state,
ID: connID,
@ -372,20 +371,21 @@ func (chain *TestChain) createConnection(
func (chain *TestChain) createChannel(
portID, channelID, counterpartyPortID, counterpartyChannelID string,
state channelexported.State, order channelexported.Order, connectionID string,
state ibctypes.State, order ibctypes.Order, connectionID string,
) channeltypes.Channel {
counterparty := channeltypes.NewCounterparty(counterpartyPortID, counterpartyChannelID)
channel := channeltypes.NewChannel(state, order, counterparty,
[]string{connectionID}, "1.0",
)
channel := channeltypes.NewChannel(state, order, counterparty, []string{connectionID}, "1.0")
ctx := chain.GetContext()
chain.App.IBCKeeper.ChannelKeeper.SetChannel(ctx, portID, channelID, channel)
return channel
}
func nextHeader(chain *TestChain) ibctmtypes.Header {
return ibctmtypes.CreateTestHeader(chain.Header.ChainID, chain.Header.Height+1,
chain.Header.Time.Add(nextTimestamp), chain.Vals, chain.Signers)
return ibctmtypes.CreateTestHeader(
chain.Header.SignedHeader.Header.ChainID,
chain.Header.SignedHeader.Header.Height+1,
chain.Header.Time.Add(nextTimestamp), chain.Vals, chain.Signers,
)
}
func prefixedClientKey(clientID string, key []byte) []byte {

View File

@ -32,7 +32,7 @@ func (k Keeper) VerifyClientConsensusState(
}
return clientState.VerifyClientConsensusState(
k.cdc, targetConsState.GetRoot(), height, connection.GetCounterparty().GetClientID(), consensusHeight, connection.GetCounterparty().GetPrefix(), proof, consensusState,
k.aminoCdc, targetConsState.GetRoot(), height, connection.GetCounterparty().GetClientID(), consensusHeight, connection.GetCounterparty().GetPrefix(), proof, consensusState,
)
}

View File

@ -4,9 +4,7 @@ import (
"fmt"
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
@ -24,10 +22,10 @@ func (suite *KeeperTestSuite) TestVerifyClientConsensusState() {
// create connection on chainA to chainB
counterparty := types.NewCounterparty(
testClientIDA, testConnectionIDA,
suite.chainA.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix(),
commitmenttypes.NewMerklePrefix(suite.chainA.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes()),
)
connection1 := types.NewConnectionEnd(
exported.UNINITIALIZED, testConnectionIDB, testClientIDB, counterparty,
ibctypes.UNINITIALIZED, testConnectionIDB, testClientIDB, counterparty,
types.GetCompatibleVersions(),
)
@ -67,7 +65,7 @@ func (suite *KeeperTestSuite) TestVerifyClientConsensusState() {
suite.chainA.updateClient(suite.chainB)
// TODO: is this the right consensus height
consensusHeight := uint64(suite.chainA.Header.Height)
consensusHeight := suite.chainA.Header.GetHeight()
consensusKey := prefixedClientKey(testClientIDA, ibctypes.KeyConsensusState(consensusHeight))
// get proof that chainB stored chainA' consensus state
@ -119,11 +117,11 @@ func (suite *KeeperTestSuite) TestVerifyConnectionState() {
tc.malleate()
// create and store connection on chain A
expectedConnection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, exported.OPEN)
expectedConnection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.OPEN)
// // create expected connection
// TODO: why is this commented
// expectedConnection := types.NewConnectionEnd(exported.INIT, testClientIDB, counterparty, []string{"1.0.0"})
// expectedConnection := types.NewConnectionEnd(types.INIT, testClientIDB, counterparty, []string{"1.0.0"})
// perform a couple updates of chain A on chain B
suite.chainB.updateClient(suite.chainA)
@ -136,7 +134,7 @@ func (suite *KeeperTestSuite) TestVerifyConnectionState() {
// Create B's connection to A
counterparty := types.NewCounterparty(testClientIDB, testConnectionIDB, commitmenttypes.NewMerklePrefix([]byte("ibc")))
connection := types.NewConnectionEnd(exported.UNINITIALIZED, testConnectionIDA, testClientIDA, counterparty, []string{"1.0.0"})
connection := types.NewConnectionEnd(ibctypes.UNINITIALIZED, testConnectionIDA, testClientIDA, counterparty, []string{"1.0.0"})
// Ensure chain B can verify connection exists in chain A
err := suite.chainB.App.IBCKeeper.ConnectionKeeper.VerifyConnectionState(
suite.chainB.GetContext(), connection, proofHeight+1, proof, testConnectionIDA, expectedConnection,
@ -157,11 +155,11 @@ func (suite *KeeperTestSuite) TestVerifyChannelState() {
// create connection of chainB to pass into verify function
counterparty := types.NewCounterparty(
testClientIDB, testConnectionIDB,
suite.chainA.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix(),
commitmenttypes.NewMerklePrefix(suite.chainA.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes()),
)
connection := types.NewConnectionEnd(
exported.UNINITIALIZED, testConnectionIDA, testClientIDA, counterparty,
ibctypes.UNINITIALIZED, testConnectionIDA, testClientIDA, counterparty,
types.GetCompatibleVersions(),
)
@ -195,7 +193,7 @@ func (suite *KeeperTestSuite) TestVerifyChannelState() {
// Create and store channel on chain A
channel := suite.chainA.createChannel(
testPort1, testChannel1, testPort2, testChannel2,
channelexported.OPEN, channelexported.ORDERED, testConnectionIDA,
ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA,
)
// Update chainA client on chainB
@ -252,7 +250,7 @@ func (suite *KeeperTestSuite) TestVerifyPacketCommitment() {
tc.malleate()
// Set PacketCommitment on chainA
connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, exported.OPEN)
connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainA.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainA.GetContext(), testPort1, testChannel1, 1, commitmentBz)
// Update ChainA client on chainB
@ -305,7 +303,7 @@ func (suite *KeeperTestSuite) TestVerifyPacketAcknowledgement() {
suite.SetupTest() // reset
tc.malleate()
connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, exported.OPEN)
connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainA.App.IBCKeeper.ChannelKeeper.SetPacketAcknowledgement(suite.chainA.GetContext(), testPort1, testChannel1, 1, channeltypes.CommitAcknowledgement(ack))
suite.chainB.updateClient(suite.chainA)
@ -355,7 +353,7 @@ func (suite *KeeperTestSuite) TestVerifyPacketAcknowledgementAbsence() {
suite.SetupTest() // reset
tc.malleate()
connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, exported.OPEN)
connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.updateClient(suite.chainA)
proof, proofHeight := queryProof(suite.chainA, packetAckKey)
@ -403,7 +401,7 @@ func (suite *KeeperTestSuite) TestVerifyNextSequenceRecv() {
suite.SetupTest() // reset
tc.malleate()
connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, exported.OPEN)
connection := suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainA.GetContext(), testPort1, testChannel1, 1)
suite.chainB.updateClient(suite.chainA)

View File

@ -2,27 +2,49 @@ package types
import (
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
)
// SubModuleCdc defines the IBC connection codec.
var SubModuleCdc *codec.Codec
// RegisterCodec registers the IBC connection types
// RegisterCodec registers the necessary x/ibc/03-connection interfaces and concrete types
// on the provided Amino codec. These types are used for Amino JSON serialization.
func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterInterface((*exported.ConnectionI)(nil), nil)
cdc.RegisterInterface((*exported.CounterpartyI)(nil), nil)
cdc.RegisterConcrete(ConnectionEnd{}, "ibc/connection/ConnectionEnd", nil)
cdc.RegisterConcrete(ConnectionEnd{}, "ibc/connection/ConnectionEnd", nil)
cdc.RegisterConcrete(MsgConnectionOpenInit{}, "ibc/connection/MsgConnectionOpenInit", nil)
cdc.RegisterConcrete(MsgConnectionOpenTry{}, "ibc/connection/MsgConnectionOpenTry", nil)
cdc.RegisterConcrete(MsgConnectionOpenAck{}, "ibc/connection/MsgConnectionOpenAck", nil)
cdc.RegisterConcrete(MsgConnectionOpenConfirm{}, "ibc/connection/MsgConnectionOpenConfirm", nil)
SetSubModuleCodec(cdc)
}
// SetSubModuleCodec sets the ibc connection codec
func SetSubModuleCodec(cdc *codec.Codec) {
SubModuleCdc = cdc
// RegisterInterfaces register the ibc interfaces submodule implementations to protobuf
// Any.
func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgConnectionOpenInit{},
&MsgConnectionOpenTry{},
&MsgConnectionOpenAck{},
&MsgConnectionOpenConfirm{},
)
}
var (
amino = codec.New()
// SubModuleCdc references the global x/ibc/03-connectionl module codec. Note, the codec should
// ONLY be used in certain instances of tests and for JSON encoding as Amino is
// still used for that purpose.
//
// The actual codec used for serialization should be provided to x/ibc/03-connectionl and
// defined at the application level.
SubModuleCdc = codec.NewHybridCodec(amino, cdctypes.NewInterfaceRegistry())
)
func init() {
RegisterCodec(amino)
amino.Seal()
}

View File

@ -6,43 +6,26 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
var _ exported.ConnectionI = ConnectionEnd{}
// ICS03 - Connection Data Structures as defined in https://github.com/cosmos/ics/tree/master/spec/ics-003-connection-semantics#data-structures
// ConnectionEnd defines a stateful object on a chain connected to another separate
// one.
// NOTE: there must only be 2 defined ConnectionEnds to establish a connection
// between two chains.
type ConnectionEnd struct {
State exported.State `json:"state" yaml:"state"`
ID string `json:"id" yaml:"id"`
ClientID string `json:"client_id" yaml:"client_id"`
// Counterparty chain associated with this connection.
Counterparty Counterparty `json:"counterparty" yaml:"counterparty"`
// Version is utilised to determine encodings or protocols for channels or
// packets utilising this connection.
Versions []string `json:"versions" yaml:"versions"`
}
var _ exported.ConnectionI = (*ConnectionEnd)(nil)
// NewConnectionEnd creates a new ConnectionEnd instance.
func NewConnectionEnd(state exported.State, connectionID, clientID string, counterparty Counterparty, versions []string) ConnectionEnd {
func NewConnectionEnd(state ibctypes.State, connectionID, clientID string, counterparty Counterparty, versions []string) ConnectionEnd {
return ConnectionEnd{
State: state,
ID: connectionID,
ClientID: clientID,
Counterparty: counterparty,
Versions: versions,
State: state,
Counterparty: counterparty,
}
}
// GetState implements the Connection interface
func (c ConnectionEnd) GetState() exported.State {
func (c ConnectionEnd) GetState() ibctypes.State {
return c.State
}
@ -87,17 +70,10 @@ func (c ConnectionEnd) ValidateBasic() error {
return c.Counterparty.ValidateBasic()
}
var _ exported.CounterpartyI = Counterparty{}
// Counterparty defines the counterparty chain associated with a connection end.
type Counterparty struct {
ClientID string `json:"client_id" yaml:"client_id"`
ConnectionID string `json:"connection_id" yaml:"connection_id"`
Prefix commitmentexported.Prefix `json:"prefix" yaml:"prefix"`
}
var _ exported.CounterpartyI = (*Counterparty)(nil)
// NewCounterparty creates a new Counterparty instance.
func NewCounterparty(clientID, connectionID string, prefix commitmentexported.Prefix) Counterparty {
func NewCounterparty(clientID, connectionID string, prefix commitmenttypes.MerklePrefix) Counterparty {
return Counterparty{
ClientID: clientID,
ConnectionID: connectionID,
@ -117,7 +93,7 @@ func (c Counterparty) GetConnectionID() string {
// GetPrefix implements the CounterpartyI interface
func (c Counterparty) GetPrefix() commitmentexported.Prefix {
return c.Prefix
return &c.Prefix
}
// ValidateBasic performs a basic validation check of the identifiers and prefix
@ -138,7 +114,7 @@ func (c Counterparty) ValidateBasic() error {
).Error(),
)
}
if c.Prefix == nil || len(c.Prefix.Bytes()) == 0 {
if c.Prefix.IsEmpty() {
return sdkerrors.Wrap(ErrInvalidCounterparty, "invalid counterparty prefix")
}
return nil

View File

@ -5,8 +5,8 @@ import (
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
var (
@ -24,32 +24,32 @@ func TestConnectionValidateBasic(t *testing.T) {
}{
{
"valid connection",
ConnectionEnd{exported.INIT, connectionID, clientID, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}},
ConnectionEnd{connectionID, clientID, []string{"1.0.0"}, ibctypes.INIT, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}},
true,
},
{
"invalid connection id",
ConnectionEnd{exported.INIT, "connectionIDONE", clientID, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}},
ConnectionEnd{"connectionIDONE", clientID, []string{"1.0.0"}, ibctypes.INIT, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}},
false,
},
{
"invalid client id",
ConnectionEnd{exported.INIT, connectionID, "ClientIDTwo", Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}},
ConnectionEnd{connectionID, "clientID1", []string{"1.0.0"}, ibctypes.INIT, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}},
false,
},
{
"empty versions",
ConnectionEnd{exported.INIT, connectionID, clientID, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, nil},
ConnectionEnd{connectionID, clientID, nil, ibctypes.INIT, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}},
false,
},
{
"invalid version",
ConnectionEnd{exported.INIT, connectionID, clientID, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{""}},
ConnectionEnd{connectionID, clientID, []string{""}, ibctypes.INIT, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}},
false,
},
{
"invalid counterparty",
ConnectionEnd{exported.INIT, connectionID, clientID, Counterparty{clientID2, connectionID2, nil}, []string{"1.0.0"}},
ConnectionEnd{connectionID, clientID, []string{"1.0.0"}, ibctypes.INIT, Counterparty{clientID2, connectionID2, emptyPrefix}},
false,
},
}
@ -72,10 +72,10 @@ func TestCounterpartyValidateBasic(t *testing.T) {
counterparty Counterparty
expPass bool
}{
{"valid counterparty", Counterparty{"clientidone", connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, true},
{"valid counterparty", Counterparty{clientID, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, true},
{"invalid client id", Counterparty{"InvalidClient", "channelidone", commitmenttypes.NewMerklePrefix([]byte("prefix"))}, false},
{"invalid connection id", Counterparty{"clientidone", "InvalidConnection", commitmenttypes.NewMerklePrefix([]byte("prefix"))}, false},
{"invalid prefix", Counterparty{"clientidone", connectionID2, nil}, false},
{"invalid connection id", Counterparty{clientID, "InvalidConnection", commitmenttypes.NewMerklePrefix([]byte("prefix"))}, false},
{"invalid prefix", Counterparty{clientID, connectionID2, emptyPrefix}, false},
}
for i, tc := range testCases {

View File

@ -5,7 +5,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
@ -26,7 +25,7 @@ func TestValidateGenesis(t *testing.T) {
name: "valid genesis",
genState: NewGenesisState(
[]ConnectionEnd{
{exported.INIT, connectionID, clientID, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}},
NewConnectionEnd(ibctypes.INIT, connectionID, clientID, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}),
},
[]ConnectionPaths{
{clientID, []string{ibctypes.ConnectionPath(connectionID)}},
@ -38,7 +37,7 @@ func TestValidateGenesis(t *testing.T) {
name: "invalid connection",
genState: NewGenesisState(
[]ConnectionEnd{
NewConnectionEnd(exported.INIT, connectionID, "CLIENTIDONE", Counterparty{clientID, connectionID, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}),
NewConnectionEnd(ibctypes.INIT, connectionID, "CLIENTIDONE", Counterparty{clientID, connectionID, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}),
},
[]ConnectionPaths{
{clientID, []string{ibctypes.ConnectionPath(connectionID)}},
@ -50,7 +49,7 @@ func TestValidateGenesis(t *testing.T) {
name: "invalid client id",
genState: NewGenesisState(
[]ConnectionEnd{
{exported.INIT, connectionID, clientID, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}},
NewConnectionEnd(ibctypes.INIT, connectionID, clientID, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}),
},
[]ConnectionPaths{
{"CLIENTIDONE", []string{ibctypes.ConnectionPath(connectionID)}},
@ -62,7 +61,7 @@ func TestValidateGenesis(t *testing.T) {
name: "invalid path",
genState: NewGenesisState(
[]ConnectionEnd{
{exported.INIT, connectionID, clientID, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}},
NewConnectionEnd(ibctypes.INIT, connectionID, clientID, Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []string{"1.0.0"}),
},
[]ConnectionPaths{
{clientID, []string{connectionID}},

View File

@ -5,7 +5,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
@ -13,19 +12,10 @@ import (
var _ sdk.Msg = MsgConnectionOpenInit{}
// MsgConnectionOpenInit defines the msg sent by an account on Chain A to
// initialize a connection with Chain B.
type MsgConnectionOpenInit struct {
ConnectionID string `json:"connection_id"`
ClientID string `json:"client_id"`
Counterparty Counterparty `json:"counterparty"`
Signer sdk.AccAddress `json:"signer"`
}
// NewMsgConnectionOpenInit creates a new MsgConnectionOpenInit instance
func NewMsgConnectionOpenInit(
connectionID, clientID, counterpartyConnectionID,
counterpartyClientID string, counterpartyPrefix commitmentexported.Prefix,
counterpartyClientID string, counterpartyPrefix commitmenttypes.MerklePrefix,
signer sdk.AccAddress,
) MsgConnectionOpenInit {
counterparty := NewCounterparty(counterpartyClientID, counterpartyConnectionID, counterpartyPrefix)
@ -73,25 +63,11 @@ func (msg MsgConnectionOpenInit) GetSigners() []sdk.AccAddress {
var _ sdk.Msg = MsgConnectionOpenTry{}
// MsgConnectionOpenTry defines a msg sent by a Relayer to try to open a connection
// on Chain B.
type MsgConnectionOpenTry struct {
ConnectionID string `json:"connection_id"`
ClientID string `json:"client_id"`
Counterparty Counterparty `json:"counterparty"`
CounterpartyVersions []string `json:"counterparty_versions"`
ProofInit commitmentexported.Proof `json:"proof_init"` // proof of the initialization the connection on Chain A: `none -> INIT`
ProofConsensus commitmentexported.Proof `json:"proof_consensus"` // proof of client consensus state
ProofHeight uint64 `json:"proof_height"`
ConsensusHeight uint64 `json:"consensus_height"`
Signer sdk.AccAddress `json:"signer"`
}
// NewMsgConnectionOpenTry creates a new MsgConnectionOpenTry instance
func NewMsgConnectionOpenTry(
connectionID, clientID, counterpartyConnectionID,
counterpartyClientID string, counterpartyPrefix commitmentexported.Prefix,
counterpartyVersions []string, proofInit, proofConsensus commitmentexported.Proof,
counterpartyClientID string, counterpartyPrefix commitmenttypes.MerklePrefix,
counterpartyVersions []string, proofInit, proofConsensus commitmenttypes.MerkleProof,
proofHeight, consensusHeight uint64, signer sdk.AccAddress,
) MsgConnectionOpenTry {
counterparty := NewCounterparty(counterpartyClientID, counterpartyConnectionID, counterpartyPrefix)
@ -134,7 +110,7 @@ func (msg MsgConnectionOpenTry) ValidateBasic() error {
return sdkerrors.Wrap(ibctypes.ErrInvalidVersion, "version can't be blank")
}
}
if msg.ProofInit == nil || msg.ProofConsensus == nil {
if msg.ProofInit.IsEmpty() || msg.ProofConsensus.IsEmpty() {
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof")
}
if err := msg.ProofInit.ValidateBasic(); err != nil {
@ -167,21 +143,9 @@ func (msg MsgConnectionOpenTry) GetSigners() []sdk.AccAddress {
var _ sdk.Msg = MsgConnectionOpenAck{}
// MsgConnectionOpenAck defines a msg sent by a Relayer to Chain A to acknowledge
// the change of connection state to TRYOPEN on Chain B.
type MsgConnectionOpenAck struct {
ConnectionID string `json:"connection_id"`
ProofTry commitmentexported.Proof `json:"proof_try"` // proof for the change of the connection state on Chain B: `none -> TRYOPEN`
ProofConsensus commitmentexported.Proof `json:"proof_consensus"` // proof of client consensus state
ProofHeight uint64 `json:"proof_height"`
ConsensusHeight uint64 `json:"consensus_height"`
Version string `json:"version"`
Signer sdk.AccAddress `json:"signer"`
}
// NewMsgConnectionOpenAck creates a new MsgConnectionOpenAck instance
func NewMsgConnectionOpenAck(
connectionID string, proofTry, proofConsensus commitmentexported.Proof,
connectionID string, proofTry, proofConsensus commitmenttypes.MerkleProof,
proofHeight, consensusHeight uint64, version string,
signer sdk.AccAddress,
) MsgConnectionOpenAck {
@ -214,7 +178,7 @@ func (msg MsgConnectionOpenAck) ValidateBasic() error {
if strings.TrimSpace(msg.Version) == "" {
return sdkerrors.Wrap(ibctypes.ErrInvalidVersion, "version can't be blank")
}
if msg.ProofTry == nil || msg.ProofConsensus == nil {
if msg.ProofTry.IsEmpty() || msg.ProofConsensus.IsEmpty() {
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof")
}
if err := msg.ProofTry.ValidateBasic(); err != nil {
@ -247,18 +211,9 @@ func (msg MsgConnectionOpenAck) GetSigners() []sdk.AccAddress {
var _ sdk.Msg = MsgConnectionOpenConfirm{}
// MsgConnectionOpenConfirm defines a msg sent by a Relayer to Chain B to acknowledge
// the change of connection state to OPEN on Chain A.
type MsgConnectionOpenConfirm struct {
ConnectionID string `json:"connection_id"`
ProofAck commitmentexported.Proof `json:"proof_ack"` // proof for the change of the connection state on Chain A: `INIT -> OPEN`
ProofHeight uint64 `json:"proof_height"`
Signer sdk.AccAddress `json:"signer"`
}
// NewMsgConnectionOpenConfirm creates a new MsgConnectionOpenConfirm instance
func NewMsgConnectionOpenConfirm(
connectionID string, proofAck commitmentexported.Proof, proofHeight uint64,
connectionID string, proofAck commitmenttypes.MerkleProof, proofHeight uint64,
signer sdk.AccAddress,
) MsgConnectionOpenConfirm {
return MsgConnectionOpenConfirm{
@ -284,7 +239,7 @@ func (msg MsgConnectionOpenConfirm) ValidateBasic() error {
if err := host.DefaultConnectionIdentifierValidator(msg.ConnectionID); err != nil {
return sdkerrors.Wrap(err, "invalid connection ID")
}
if msg.ProofAck == nil {
if msg.ProofAck.IsEmpty() {
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof")
}
if err := msg.ProofAck.ValidateBasic(); err != nil {

View File

@ -16,6 +16,11 @@ import (
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
)
var (
emptyPrefix = commitmenttypes.MerklePrefix{}
emptyProof = commitmenttypes.MerkleProof{Proof: nil}
)
type MsgTestSuite struct {
suite.Suite
@ -56,7 +61,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenInit() {
NewMsgConnectionOpenInit("ibcconntest", "test/iris", "connectiontotest", "clienttotest", prefix, signer),
NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "test/conn1", "clienttotest", prefix, signer),
NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "connectiontotest", "test/conn1", prefix, signer),
NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "connectiontotest", "clienttotest", nil, signer),
NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "connectiontotest", "clienttotest", emptyPrefix, signer),
NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "connectiontotest", "clienttotest", prefix, nil),
NewMsgConnectionOpenInit("ibcconntest", "clienttotest", "connectiontotest", "clienttotest", prefix, signer),
}
@ -94,12 +99,10 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenTry() {
NewMsgConnectionOpenTry("ibcconntest", "test/iris", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer),
NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "ibc/test", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer),
NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "test/conn1", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer),
NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", nil, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer),
NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", emptyPrefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, signer),
NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{}, suite.proof, suite.proof, 10, 10, signer),
NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, nil, suite.proof, 10, 10, signer),
NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, commitmenttypes.MerkleProof{Proof: nil}, suite.proof, 10, 10, signer),
NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, nil, 10, 10, signer),
NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, commitmenttypes.MerkleProof{Proof: nil}, 10, 10, signer),
NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, emptyProof, suite.proof, 10, 10, signer),
NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, emptyProof, 10, 10, signer),
NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 0, 10, signer),
NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 0, signer),
NewMsgConnectionOpenTry("ibcconntest", "clienttotesta", "connectiontotest", "clienttotest", prefix, []string{"1.0.0"}, suite.proof, suite.proof, 10, 10, nil),
@ -118,13 +121,11 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenTry() {
{testMsgs[4], false, "empty counterparty prefix"},
{testMsgs[5], false, "empty counterpartyVersions"},
{testMsgs[6], false, "empty proofInit"},
{testMsgs[7], false, "empty proofInit"},
{testMsgs[8], false, "empty proofConsensus"},
{testMsgs[9], false, "empty proofConsensus"},
{testMsgs[10], false, "invalid proofHeight"},
{testMsgs[11], false, "invalid consensusHeight"},
{testMsgs[12], false, "empty singer"},
{testMsgs[13], true, "success"},
{testMsgs[7], false, "empty proofConsensus"},
{testMsgs[8], false, "invalid proofHeight"},
{testMsgs[9], false, "invalid consensusHeight"},
{testMsgs[10], false, "empty singer"},
{testMsgs[11], true, "success"},
}
for i, tc := range testCases {
@ -142,10 +143,8 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenAck() {
testMsgs := []MsgConnectionOpenAck{
NewMsgConnectionOpenAck("test/conn1", suite.proof, suite.proof, 10, 10, "1.0.0", signer),
NewMsgConnectionOpenAck("ibcconntest", nil, suite.proof, 10, 10, "1.0.0", signer),
NewMsgConnectionOpenAck("ibcconntest", commitmenttypes.MerkleProof{Proof: nil}, suite.proof, 10, 10, "1.0.0", signer),
NewMsgConnectionOpenAck("ibcconntest", suite.proof, nil, 10, 10, "1.0.0", signer),
NewMsgConnectionOpenAck("ibcconntest", suite.proof, commitmenttypes.MerkleProof{Proof: nil}, 10, 10, "1.0.0", signer),
NewMsgConnectionOpenAck("ibcconntest", emptyProof, suite.proof, 10, 10, "1.0.0", signer),
NewMsgConnectionOpenAck("ibcconntest", suite.proof, emptyProof, 10, 10, "1.0.0", signer),
NewMsgConnectionOpenAck("ibcconntest", suite.proof, suite.proof, 0, 10, "1.0.0", signer),
NewMsgConnectionOpenAck("ibcconntest", suite.proof, suite.proof, 10, 0, "1.0.0", signer),
NewMsgConnectionOpenAck("ibcconntest", suite.proof, suite.proof, 10, 10, "", signer),
@ -159,14 +158,12 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenAck() {
}{
{testMsgs[0], false, "invalid connection ID"},
{testMsgs[1], false, "empty proofTry"},
{testMsgs[2], false, "empty proofTry"},
{testMsgs[3], false, "empty proofConsensus"},
{testMsgs[4], false, "empty proofConsensus"},
{testMsgs[5], false, "invalid proofHeight"},
{testMsgs[6], false, "invalid consensusHeight"},
{testMsgs[7], false, "invalid version"},
{testMsgs[8], false, "empty signer"},
{testMsgs[9], true, "success"},
{testMsgs[2], false, "empty proofConsensus"},
{testMsgs[3], false, "invalid proofHeight"},
{testMsgs[4], false, "invalid consensusHeight"},
{testMsgs[5], false, "invalid version"},
{testMsgs[6], false, "empty signer"},
{testMsgs[7], true, "success"},
}
for i, tc := range testCases {
@ -184,8 +181,7 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenConfirm() {
testMsgs := []MsgConnectionOpenConfirm{
NewMsgConnectionOpenConfirm("test/conn1", suite.proof, 10, signer),
NewMsgConnectionOpenConfirm("ibcconntest", nil, 10, signer),
NewMsgConnectionOpenConfirm("ibcconntest", commitmenttypes.MerkleProof{Proof: nil}, 10, signer),
NewMsgConnectionOpenConfirm("ibcconntest", emptyProof, 10, signer),
NewMsgConnectionOpenConfirm("ibcconntest", suite.proof, 0, signer),
NewMsgConnectionOpenConfirm("ibcconntest", suite.proof, 10, nil),
NewMsgConnectionOpenConfirm("ibcconntest", suite.proof, 10, signer),
@ -198,10 +194,9 @@ func (suite *MsgTestSuite) TestNewMsgConnectionOpenConfirm() {
}{
{testMsgs[0], false, "invalid connection ID"},
{testMsgs[1], false, "empty proofTry"},
{testMsgs[2], false, "empty proofTry"},
{testMsgs[3], false, "invalid proofHeight"},
{testMsgs[4], false, "empty signer"},
{testMsgs[5], true, "success"},
{testMsgs[2], false, "invalid proofHeight"},
{testMsgs[3], false, "empty signer"},
{testMsgs[4], true, "success"},
}
for i, tc := range testCases {

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,101 @@
syntax = "proto3";
package cosmos_sdk.x.ibc.connection.v1;
option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types";
import "third_party/proto/gogoproto/gogo.proto";
import "x/ibc/23-commitment/types/types.proto";
import "x/ibc/types/types.proto";
// MsgConnectionOpenInit defines the msg sent by an account on Chain A to
// initialize a connection with Chain B.
message MsgConnectionOpenInit {
string client_id = 1 [(gogoproto.customname) = "ClientID", (gogoproto.moretags) = "yaml:\"client_id\""];
string connection_id = 2 [(gogoproto.customname) = "ConnectionID", (gogoproto.moretags) = "yaml:\"connection_id\""];
Counterparty counterparty = 3 [(gogoproto.nullable) = false];
bytes signer = 4 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}
// MsgConnectionOpenTry defines a msg sent by a Relayer to try to open a connection
// on Chain B.
message MsgConnectionOpenTry {
string client_id = 1 [(gogoproto.customname) = "ClientID", (gogoproto.moretags) = "yaml:\"client_id\""];
string connection_id = 2 [(gogoproto.customname) = "ConnectionID", (gogoproto.moretags) = "yaml:\"connection_id\""];
Counterparty counterparty = 3 [(gogoproto.nullable) = false];
repeated string counterparty_versions = 4 [(gogoproto.moretags) = "yaml:\"counterparty_versions\""];
// proof of the initialization the connection on Chain A: `UNITIALIZED -> INIT`
cosmos_sdk.x.ibc.commitment.v1.MerkleProof proof_init = 5
[(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"proof_init\""];
uint64 proof_height = 6;
// proof of client consensus state
cosmos_sdk.x.ibc.commitment.v1.MerkleProof proof_consensus = 7
[(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"proof_consensus\""];
uint64 consensus_height = 8 [(gogoproto.moretags) = "yaml:\"consensus_height\""];
bytes signer = 9 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}
// MsgConnectionOpenAck defines a msg sent by a Relayer to Chain A to acknowledge
// the change of connection state to TRYOPEN on Chain B.
message MsgConnectionOpenAck {
string connection_id = 1 [(gogoproto.customname) = "ConnectionID", (gogoproto.moretags) = "yaml:\"connection_id\""];
string version = 2;
// proof of the initialization the connection on Chain B: `UNITIALIZED -> TRYOPEN`
cosmos_sdk.x.ibc.commitment.v1.MerkleProof proof_try = 3
[(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"proof_try\""];
uint64 proof_height = 4 [(gogoproto.moretags) = "yaml:\"proof_height\""];
// proof of client consensus state
cosmos_sdk.x.ibc.commitment.v1.MerkleProof proof_consensus = 5
[(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"proof_consensus\""];
uint64 consensus_height = 6 [(gogoproto.moretags) = "yaml:\"consensus_height\""];
bytes signer = 7 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}
// MsgConnectionOpenConfirm defines a msg sent by a Relayer to Chain B to acknowledge
// the change of connection state to OPEN on Chain A.
message MsgConnectionOpenConfirm {
string connection_id = 1 [(gogoproto.customname) = "ConnectionID", (gogoproto.moretags) = "yaml:\"connection_id\""];
// proof for the change of the connection state on Chain A: `INIT -> OPEN`
cosmos_sdk.x.ibc.commitment.v1.MerkleProof proof_ack = 2
[(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"proof_ack\""];
uint64 proof_height = 3 [(gogoproto.moretags) = "yaml:\"proof_height\""];
bytes signer = 4 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}
// ICS03 - Connection Data Structures as defined in
// https://github.com/cosmos/ics/tree/master/spec/ics-003-connection-semantics#data-structures
// ConnectionEnd defines a stateful object on a chain connected to another separate
// one.
// NOTE: there must only be 2 defined ConnectionEnds to establish a connection
// between two chains.
message ConnectionEnd {
option (gogoproto.goproto_getters) = false;
// connection identifier.
string id = 1 [(gogoproto.customname) = "ID", (gogoproto.moretags) = "yaml:\"id\""];
// client associated with this connection.
string client_id = 2 [(gogoproto.customname) = "ClientID", (gogoproto.moretags) = "yaml:\"client_id\""];
// opaque string which can be utilised to determine encodings or protocols for
// channels or packets utilising this connection
repeated string versions = 3;
// current state of the connection end.
cosmos_sdk.x.ibc.v1.State state = 4;
// counterparty chain associated with this connection.
Counterparty counterparty = 5 [(gogoproto.nullable) = false];
}
// Counterparty defines the counterparty chain associated with a connection end.
message Counterparty {
option (gogoproto.goproto_getters) = false;
// identifies the client on the counterparty chain associated with a given connection.
string client_id = 1 [(gogoproto.customname) = "ClientID", (gogoproto.moretags) = "yaml:\"client_id\""];
// identifies the connection end on the counterparty chain associated with a given connection.
string connection_id = 2 [(gogoproto.customname) = "ConnectionID", (gogoproto.moretags) = "yaml:\"connection_id\""];
// commitment merkle prefix of the counterparty chain
cosmos_sdk.x.ibc.commitment.v1.MerklePrefix prefix = 3 [(gogoproto.nullable) = false];
}
// ClientPaths define all the connection paths for a client state.
message ClientPaths {
repeated string paths = 1;
}

View File

@ -30,6 +30,7 @@ var (
NewCounterparty = types.NewCounterparty
NewIdentifiedChannel = types.NewIdentifiedChannel
RegisterCodec = types.RegisterCodec
RegisterInterfaces = types.RegisterInterfaces
ErrChannelExists = types.ErrChannelExists
ErrChannelNotFound = types.ErrChannelNotFound
ErrInvalidCounterparty = types.ErrInvalidCounterparty

View File

@ -14,8 +14,8 @@ import (
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
connectionutils "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/client/utils"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
// IBC Channel flags
@ -243,9 +243,9 @@ func GetMsgChannelCloseConfirmCmd(storeKey string, cdc *codec.Codec) *cobra.Comm
}
}
func channelOrder() exported.Order {
func channelOrder() ibctypes.Order {
if viper.GetBool(FlagOrdered) {
return exported.ORDERED
return ibctypes.ORDERED
}
return exported.UNORDERED
return ibctypes.UNORDERED
}

View File

@ -5,9 +5,9 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
const (
@ -27,7 +27,7 @@ type ChannelOpenInitReq struct {
PortID string `json:"port_id" yaml:"port_id"`
ChannelID string `json:"channel_id" yaml:"channel_id"`
Version string `json:"version" yaml:"version"`
ChannelOrder exported.Order `json:"channel_order" yaml:"channel_order"`
ChannelOrder ibctypes.Order `json:"channel_order" yaml:"channel_order"`
ConnectionHops []string `json:"connection_hops" yaml:"connection_hops"`
CounterpartyPortID string `json:"counterparty_port_id" yaml:"counterparty_port_id"`
CounterpartyChannelID string `json:"counterparty_channel_id" yaml:"counterparty_channel_id"`
@ -35,32 +35,32 @@ type ChannelOpenInitReq struct {
// ChannelOpenTryReq defines the properties of a channel open try request's body.
type ChannelOpenTryReq struct {
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
PortID string `json:"port_id" yaml:"port_id"`
ChannelID string `json:"channel_id" yaml:"channel_id"`
Version string `json:"version" yaml:"version"`
ChannelOrder exported.Order `json:"channel_order" yaml:"channel_order"`
ConnectionHops []string `json:"connection_hops" yaml:"connection_hops"`
CounterpartyPortID string `json:"counterparty_port_id" yaml:"counterparty_port_id"`
CounterpartyChannelID string `json:"counterparty_channel_id" yaml:"counterparty_channel_id"`
CounterpartyVersion string `json:"counterparty_version" yaml:"counterparty_version"`
ProofInit commitmentexported.Proof `json:"proof_init" yaml:"proof_init"`
ProofHeight uint64 `json:"proof_height" yaml:"proof_height"`
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
PortID string `json:"port_id" yaml:"port_id"`
ChannelID string `json:"channel_id" yaml:"channel_id"`
Version string `json:"version" yaml:"version"`
ChannelOrder ibctypes.Order `json:"channel_order" yaml:"channel_order"`
ConnectionHops []string `json:"connection_hops" yaml:"connection_hops"`
CounterpartyPortID string `json:"counterparty_port_id" yaml:"counterparty_port_id"`
CounterpartyChannelID string `json:"counterparty_channel_id" yaml:"counterparty_channel_id"`
CounterpartyVersion string `json:"counterparty_version" yaml:"counterparty_version"`
ProofInit commitmenttypes.MerkleProof `json:"proof_init" yaml:"proof_init"`
ProofHeight uint64 `json:"proof_height" yaml:"proof_height"`
}
// ChannelOpenAckReq defines the properties of a channel open ack request's body.
type ChannelOpenAckReq struct {
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
CounterpartyVersion string `json:"counterparty_version" yaml:"counterparty_version"`
ProofTry commitmentexported.Proof `json:"proof_try" yaml:"proof_try"`
ProofHeight uint64 `json:"proof_height" yaml:"proof_height"`
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
CounterpartyVersion string `json:"counterparty_version" yaml:"counterparty_version"`
ProofTry commitmenttypes.MerkleProof `json:"proof_try" yaml:"proof_try"`
ProofHeight uint64 `json:"proof_height" yaml:"proof_height"`
}
// ChannelOpenConfirmReq defines the properties of a channel open confirm request's body.
type ChannelOpenConfirmReq struct {
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
ProofAck commitmentexported.Proof `json:"proof_ack" yaml:"proof_ack"`
ProofHeight uint64 `json:"proof_height" yaml:"proof_height"`
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
ProofAck commitmenttypes.MerkleProof `json:"proof_ack" yaml:"proof_ack"`
ProofHeight uint64 `json:"proof_height" yaml:"proof_height"`
}
// ConnectionOpenInitReq defines the properties of a channel close init request's body.
@ -70,15 +70,15 @@ type ChannelCloseInitReq struct {
// ChannelCloseConfirmReq defines the properties of a channel close confirm request's body.
type ChannelCloseConfirmReq struct {
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
ProofInit commitmentexported.Proof `json:"proof_init" yaml:"proof_init"`
ProofHeight uint64 `json:"proof_height" yaml:"proof_height"`
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
ProofInit commitmenttypes.MerkleProof `json:"proof_init" yaml:"proof_init"`
ProofHeight uint64 `json:"proof_height" yaml:"proof_height"`
}
// RecvPacketReq defines the properties of a receive packet request's body.
type RecvPacketReq struct {
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
Packet types.Packet `json:"packet" yaml:"packet"`
Proofs commitmentexported.Proof `json:"proofs" yaml:"proofs"`
Height uint64 `json:"height" yaml:"height"`
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
Packet types.Packet `json:"packet" yaml:"packet"`
Proofs commitmenttypes.MerkleProof `json:"proofs" yaml:"proofs"`
Height uint64 `json:"height" yaml:"height"`
}

View File

@ -1,14 +1,13 @@
package exported
import (
"encoding/json"
"fmt"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
// ChannelI defines the standard interface for a channel end.
type ChannelI interface {
GetState() State
GetOrdering() Order
GetState() ibctypes.State
GetOrdering() ibctypes.Order
GetCounterparty() CounterpartyI
GetConnectionHops() []string
GetVersion() string
@ -35,137 +34,3 @@ type PacketI interface {
GetData() []byte
ValidateBasic() error
}
// Order defines if a channel is ORDERED or UNORDERED
type Order byte
// string representation of the channel ordering
const (
NONE Order = iota // zero-value for channel ordering
UNORDERED // packets can be delivered in any order, which may differ from the order in which they were sent.
ORDERED // packets are delivered exactly in the order which they were sent
)
// channel order types
const (
OrderNone string = ""
OrderUnordered string = "UNORDERED"
OrderOrdered string = "ORDERED"
)
// String implements the Stringer interface
func (o Order) String() string {
switch o {
case UNORDERED:
return OrderUnordered
case ORDERED:
return OrderOrdered
default:
return OrderNone
}
}
// MarshalJSON marshal to JSON using string.
func (o Order) MarshalJSON() ([]byte, error) {
return json.Marshal(o.String())
}
// UnmarshalJSON decodes from JSON.
func (o *Order) UnmarshalJSON(data []byte) error {
var s string
err := json.Unmarshal(data, &s)
if err != nil {
return err
}
order := OrderFromString(s)
if order == 0 {
return fmt.Errorf("invalid order '%s'", s)
}
*o = order
return nil
}
// OrderFromString parses a string into a channel order byte
func OrderFromString(order string) Order {
switch order {
case OrderUnordered:
return UNORDERED
case OrderOrdered:
return ORDERED
default:
return NONE
}
}
// State defines if a channel is in one of the following states:
// CLOSED, INIT, OPENTRY or OPEN
type State byte
// channel state types
const (
UNINITIALIZED State = iota // Default State
INIT // A channel end has just started the opening handshake.
TRYOPEN // A channel end has acknowledged the handshake step on the counterparty chain.
OPEN // A channel end has completed the handshake and is ready to send and receive packets.
CLOSED // A channel end has been closed and can no longer be used to send or receive packets.
)
// string representation of the channel states
const (
StateUninitialized string = "UNINITIALIZED"
StateInit string = "INIT"
StateTryOpen string = "TRYOPEN"
StateOpen string = "OPEN"
StateClosed string = "CLOSED"
)
// String implements the Stringer interface
func (s State) String() string {
switch s {
case INIT:
return StateInit
case TRYOPEN:
return StateTryOpen
case OPEN:
return StateOpen
case CLOSED:
return StateClosed
default:
return StateUninitialized
}
}
// MarshalJSON marshal to JSON using string.
func (s State) MarshalJSON() ([]byte, error) {
return json.Marshal(s.String())
}
// UnmarshalJSON decodes from JSON.
func (s *State) UnmarshalJSON(data []byte) error {
var stateStr string
err := json.Unmarshal(data, &stateStr)
if err != nil {
return err
}
*s = StateFromString(stateStr)
return nil
}
// StateFromString parses a string into a channel state byte
func StateFromString(state string) State {
switch state {
case StateClosed:
return CLOSED
case StateInit:
return INIT
case StateTryOpen:
return TRYOPEN
case StateOpen:
return OPEN
default:
return UNINITIALIZED
}
}

View File

@ -1,91 +0,0 @@
package exported
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestChannelStateString(t *testing.T) {
cases := []struct {
name string
state State
}{
{StateUninitialized, UNINITIALIZED},
{StateInit, INIT},
{StateTryOpen, TRYOPEN},
{StateOpen, OPEN},
{StateClosed, CLOSED},
}
for _, tt := range cases {
tt := tt
require.Equal(t, tt.state, StateFromString(tt.name))
require.Equal(t, tt.name, tt.state.String())
}
}
func TestChannelStateMarshalJSON(t *testing.T) {
cases := []struct {
name string
state State
}{
{StateUninitialized, UNINITIALIZED},
{StateInit, INIT},
{StateTryOpen, TRYOPEN},
{StateOpen, OPEN},
{StateClosed, CLOSED},
}
for _, tt := range cases {
tt := tt
bz, err := tt.state.MarshalJSON()
require.NoError(t, err)
var state State
require.NoError(t, state.UnmarshalJSON(bz))
require.Equal(t, tt.name, state.String())
}
}
func TestOrderString(t *testing.T) {
cases := []struct {
name string
order Order
}{
{OrderNone, NONE},
{OrderUnordered, UNORDERED},
{OrderOrdered, ORDERED},
}
for _, tt := range cases {
tt := tt
require.Equal(t, tt.order, OrderFromString(tt.name))
require.Equal(t, tt.name, tt.order.String())
}
}
func TestOrderMarshalJSON(t *testing.T) {
cases := []struct {
msg string
name string
order Order
expectPass bool
}{
{"none ordering should have failed", OrderNone, NONE, false},
{"unordered should have passed", OrderUnordered, UNORDERED, true},
{"ordered should have passed", OrderOrdered, ORDERED, true},
}
for _, tt := range cases {
tt := tt
bz, err := tt.order.MarshalJSON()
require.NoError(t, err)
var order Order
if tt.expectPass {
require.NoError(t, order.UnmarshalJSON(bz), tt.msg)
require.Equal(t, tt.name, order.String(), tt.msg)
} else {
require.Error(t, order.UnmarshalJSON(bz), tt.msg)
}
}
}

View File

@ -5,9 +5,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/capability"
connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection"
connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
porttypes "github.com/cosmos/cosmos-sdk/x/ibc/05-port/types"
commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported"
@ -35,7 +33,7 @@ func (k Keeper) CounterpartyHops(ctx sdk.Context, ch types.Channel) ([]string, b
// a module on another chain.
func (k Keeper) ChanOpenInit(
ctx sdk.Context,
order exported.Order,
order ibctypes.Order,
connectionHops []string,
portID,
channelID string,
@ -54,7 +52,7 @@ func (k Keeper) ChanOpenInit(
return nil, sdkerrors.Wrap(connection.ErrConnectionNotFound, connectionHops[0])
}
if connectionEnd.GetState() == connectionexported.UNINITIALIZED {
if connectionEnd.GetState() == ibctypes.UNINITIALIZED {
return nil, sdkerrors.Wrap(
connection.ErrInvalidConnectionState,
"connection state cannot be UNINITIALIZED",
@ -65,7 +63,7 @@ func (k Keeper) ChanOpenInit(
return nil, sdkerrors.Wrap(porttypes.ErrInvalidPort, "caller does not own port capability")
}
channel := types.NewChannel(exported.INIT, order, counterparty, connectionHops, version)
channel := types.NewChannel(ibctypes.INIT, order, counterparty, connectionHops, version)
k.SetChannel(ctx, portID, channelID, channel)
capKey, err := k.scopedKeeper.NewCapability(ctx, ibctypes.ChannelCapabilityPath(portID, channelID))
@ -84,7 +82,7 @@ func (k Keeper) ChanOpenInit(
// handshake initiated by a module on another chain.
func (k Keeper) ChanOpenTry(
ctx sdk.Context,
order exported.Order,
order ibctypes.Order,
connectionHops []string,
portID,
channelID string,
@ -97,7 +95,7 @@ func (k Keeper) ChanOpenTry(
) (*capability.Capability, error) {
// channel identifier and connection hop length checked on msg.ValidateBasic()
previousChannel, found := k.GetChannel(ctx, portID, channelID)
if found && !(previousChannel.State == exported.INIT &&
if found && !(previousChannel.State == ibctypes.INIT &&
previousChannel.Ordering == order &&
previousChannel.Counterparty.PortID == counterparty.PortID &&
previousChannel.Counterparty.ChannelID == counterparty.ChannelID &&
@ -115,7 +113,7 @@ func (k Keeper) ChanOpenTry(
return nil, sdkerrors.Wrap(connection.ErrConnectionNotFound, connectionHops[0])
}
if connectionEnd.GetState() != connectionexported.OPEN {
if connectionEnd.GetState() != ibctypes.OPEN {
return nil, sdkerrors.Wrapf(
connection.ErrInvalidConnectionState,
"connection state is not OPEN (got %s)", connectionEnd.GetState().String(),
@ -124,7 +122,7 @@ func (k Keeper) ChanOpenTry(
// NOTE: this step has been switched with the one below to reverse the connection
// hops
channel := types.NewChannel(exported.TRYOPEN, order, counterparty, connectionHops, version)
channel := types.NewChannel(ibctypes.TRYOPEN, order, counterparty, connectionHops, version)
counterpartyHops, found := k.CounterpartyHops(ctx, channel)
if !found {
@ -136,7 +134,7 @@ func (k Keeper) ChanOpenTry(
// (i.e self)
expectedCounterparty := types.NewCounterparty(portID, channelID)
expectedChannel := types.NewChannel(
exported.INIT, channel.Ordering, expectedCounterparty,
ibctypes.INIT, channel.Ordering, expectedCounterparty,
counterpartyHops, counterpartyVersion,
)
@ -177,7 +175,7 @@ func (k Keeper) ChanOpenAck(
return sdkerrors.Wrap(types.ErrChannelNotFound, channelID)
}
if !(channel.State == exported.INIT || channel.State == exported.TRYOPEN) {
if !(channel.State == ibctypes.INIT || channel.State == ibctypes.TRYOPEN) {
return sdkerrors.Wrapf(
types.ErrInvalidChannelState,
"channel state should be INIT or TRYOPEN (got %s)", channel.State.String(),
@ -193,7 +191,7 @@ func (k Keeper) ChanOpenAck(
return sdkerrors.Wrap(connection.ErrConnectionNotFound, channel.ConnectionHops[0])
}
if connectionEnd.GetState() != connectionexported.OPEN {
if connectionEnd.GetState() != ibctypes.OPEN {
return sdkerrors.Wrapf(
connection.ErrInvalidConnectionState,
"connection state is not OPEN (got %s)", connectionEnd.GetState().String(),
@ -209,7 +207,7 @@ func (k Keeper) ChanOpenAck(
// counterparty of the counterparty channel end (i.e self)
expectedCounterparty := types.NewCounterparty(portID, channelID)
expectedChannel := types.NewChannel(
exported.TRYOPEN, channel.Ordering, expectedCounterparty,
ibctypes.TRYOPEN, channel.Ordering, expectedCounterparty,
counterpartyHops, counterpartyVersion,
)
@ -221,7 +219,7 @@ func (k Keeper) ChanOpenAck(
return err
}
channel.State = exported.OPEN
channel.State = ibctypes.OPEN
channel.Version = counterpartyVersion
k.SetChannel(ctx, portID, channelID, channel)
@ -244,7 +242,7 @@ func (k Keeper) ChanOpenConfirm(
return sdkerrors.Wrap(types.ErrChannelNotFound, channelID)
}
if channel.State != exported.TRYOPEN {
if channel.State != ibctypes.TRYOPEN {
return sdkerrors.Wrapf(
types.ErrInvalidChannelState,
"channel state is not TRYOPEN (got %s)", channel.State.String(),
@ -260,7 +258,7 @@ func (k Keeper) ChanOpenConfirm(
return sdkerrors.Wrap(connection.ErrConnectionNotFound, channel.ConnectionHops[0])
}
if connectionEnd.GetState() != connectionexported.OPEN {
if connectionEnd.GetState() != ibctypes.OPEN {
return sdkerrors.Wrapf(
connection.ErrInvalidConnectionState,
"connection state is not OPEN (got %s)", connectionEnd.GetState().String(),
@ -275,7 +273,7 @@ func (k Keeper) ChanOpenConfirm(
counterparty := types.NewCounterparty(portID, channelID)
expectedChannel := types.NewChannel(
exported.OPEN, channel.Ordering, counterparty,
ibctypes.OPEN, channel.Ordering, counterparty,
counterpartyHops, channel.Version,
)
@ -287,7 +285,7 @@ func (k Keeper) ChanOpenConfirm(
return err
}
channel.State = exported.OPEN
channel.State = ibctypes.OPEN
k.SetChannel(ctx, portID, channelID, channel)
k.Logger(ctx).Info("channel (port-id: %s, channel-id: %s) state updated: TRYOPEN -> OPEN", portID, channelID)
@ -316,7 +314,7 @@ func (k Keeper) ChanCloseInit(
return sdkerrors.Wrap(types.ErrChannelNotFound, channelID)
}
if channel.State == exported.CLOSED {
if channel.State == ibctypes.CLOSED {
return sdkerrors.Wrap(types.ErrInvalidChannelState, "channel is already CLOSED")
}
@ -325,7 +323,7 @@ func (k Keeper) ChanCloseInit(
return sdkerrors.Wrap(connection.ErrConnectionNotFound, channel.ConnectionHops[0])
}
if connectionEnd.GetState() != connectionexported.OPEN {
if connectionEnd.GetState() != ibctypes.OPEN {
return sdkerrors.Wrapf(
connection.ErrInvalidConnectionState,
"connection state is not OPEN (got %s)", connectionEnd.GetState().String(),
@ -334,7 +332,7 @@ func (k Keeper) ChanCloseInit(
k.Logger(ctx).Info("channel (port-id: %s, channel-id: %s) state updated: %s -> CLOSED", portID, channelID, channel.State)
channel.State = exported.CLOSED
channel.State = ibctypes.CLOSED
k.SetChannel(ctx, portID, channelID, channel)
return nil
@ -359,7 +357,7 @@ func (k Keeper) ChanCloseConfirm(
return sdkerrors.Wrap(types.ErrChannelNotFound, channelID)
}
if channel.State == exported.CLOSED {
if channel.State == ibctypes.CLOSED {
return sdkerrors.Wrap(types.ErrInvalidChannelState, "channel is already CLOSED")
}
@ -368,7 +366,7 @@ func (k Keeper) ChanCloseConfirm(
return sdkerrors.Wrap(connection.ErrConnectionNotFound, channel.ConnectionHops[0])
}
if connectionEnd.GetState() != connectionexported.OPEN {
if connectionEnd.GetState() != ibctypes.OPEN {
return sdkerrors.Wrapf(
connection.ErrInvalidConnectionState,
"connection state is not OPEN (got %s)", connectionEnd.GetState().String(),
@ -383,7 +381,7 @@ func (k Keeper) ChanCloseConfirm(
counterparty := types.NewCounterparty(portID, channelID)
expectedChannel := types.NewChannel(
exported.CLOSED, channel.Ordering, counterparty,
ibctypes.CLOSED, channel.Ordering, counterparty,
counterpartyHops, channel.Version,
)
@ -397,7 +395,7 @@ func (k Keeper) ChanCloseConfirm(
k.Logger(ctx).Info("channel (port-id: %s, channel-id: %s) state updated: %s -> CLOSED", portID, channelID, channel.State)
channel.State = exported.CLOSED
channel.State = ibctypes.CLOSED
k.SetChannel(ctx, portID, channelID, channel)
return nil

View File

@ -4,10 +4,7 @@ import (
"fmt"
"github.com/cosmos/cosmos-sdk/x/capability"
connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
porttypes "github.com/cosmos/cosmos-sdk/x/ibc/05-port/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
@ -19,26 +16,26 @@ func (suite *KeeperTestSuite) TestChanOpenInit() {
{"success", func() {
suite.chainA.createConnection(
testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA,
connectionexported.INIT,
ibctypes.INIT,
)
}, true},
{"channel already exists", func() {
suite.chainA.createChannel(
testPort1, testChannel1, testPort2, testChannel2, exported.INIT,
exported.ORDERED, testConnectionIDA,
testPort1, testChannel1, testPort2, testChannel2, ibctypes.INIT,
ibctypes.ORDERED, testConnectionIDA,
)
}, false},
{"connection doesn't exist", func() {}, false},
{"connection is UNINITIALIZED", func() {
suite.chainA.createConnection(
testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA,
connectionexported.UNINITIALIZED,
ibctypes.UNINITIALIZED,
)
}, false},
{"capability is incorrect", func() {
suite.chainA.createConnection(
testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA,
connectionexported.INIT,
ibctypes.INIT,
)
portCap = capability.NewCapability(3)
}, false},
@ -52,13 +49,13 @@ func (suite *KeeperTestSuite) TestChanOpenInit() {
var err error
portCap, err = suite.chainA.App.ScopedIBCKeeper.NewCapability(
suite.chainA.GetContext(), porttypes.PortPath(testPort1),
suite.chainA.GetContext(), ibctypes.PortPath(testPort1),
)
suite.Require().NoError(err, "could not create capability")
tc.malleate()
cap, err := suite.chainA.App.IBCKeeper.ChannelKeeper.ChanOpenInit(
suite.chainA.GetContext(), exported.ORDERED, []string{testConnectionIDA},
suite.chainA.GetContext(), ibctypes.ORDERED, []string{testConnectionIDA},
testPort1, testChannel1, portCap, counterparty, testChannelVersion,
)
@ -89,36 +86,36 @@ func (suite *KeeperTestSuite) TestChanOpenTry() {
suite.chainB.CreateClient(suite.chainA)
_ = suite.chainA.createConnection(
testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA,
connectionexported.OPEN,
ibctypes.OPEN,
)
suite.chainB.createConnection(
testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.INIT, exported.ORDERED, testConnectionIDA)
testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.INIT, ibctypes.ORDERED, testConnectionIDA)
}, true},
{"previous channel with invalid state", func() {
_ = suite.chainA.createChannel(
testPort2, testChannel2, testPort1, testChannel1, exported.UNINITIALIZED,
exported.ORDERED, testConnectionIDB,
testPort2, testChannel2, testPort1, testChannel1, ibctypes.UNINITIALIZED,
ibctypes.ORDERED, testConnectionIDB,
)
}, false},
{"connection doesn't exist", func() {}, false},
{"connection is not OPEN", func() {
_ = suite.chainA.createConnection(
testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA,
connectionexported.INIT,
ibctypes.INIT,
)
}, false},
{"consensus state not found", func() {
_ = suite.chainA.createConnection(
testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA,
connectionexported.OPEN,
ibctypes.OPEN,
)
}, false},
{"channel verification failed", func() {
suite.chainA.CreateClient(suite.chainB)
_ = suite.chainA.createConnection(
testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA,
connectionexported.OPEN,
ibctypes.OPEN,
)
}, false},
{"port capability not found", func() {
@ -126,11 +123,11 @@ func (suite *KeeperTestSuite) TestChanOpenTry() {
suite.chainB.CreateClient(suite.chainA)
_ = suite.chainA.createConnection(
testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA,
connectionexported.OPEN,
ibctypes.OPEN,
)
suite.chainB.createConnection(
testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.INIT, exported.ORDERED, testConnectionIDA)
testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.INIT, ibctypes.ORDERED, testConnectionIDA)
portCap = capability.NewCapability(3)
}, false},
}
@ -142,7 +139,7 @@ func (suite *KeeperTestSuite) TestChanOpenTry() {
suite.SetupTest() // reset
var err error
portCap, err = suite.chainA.App.ScopedIBCKeeper.NewCapability(suite.chainA.GetContext(), porttypes.PortPath(testPort2))
portCap, err = suite.chainA.App.ScopedIBCKeeper.NewCapability(suite.chainA.GetContext(), ibctypes.PortPath(testPort2))
suite.Require().NoError(err, "could not create capability")
tc.malleate()
@ -153,7 +150,7 @@ func (suite *KeeperTestSuite) TestChanOpenTry() {
if tc.expPass {
cap, err := suite.chainA.App.IBCKeeper.ChannelKeeper.ChanOpenTry(
suite.chainA.GetContext(), exported.ORDERED, []string{testConnectionIDB},
suite.chainA.GetContext(), ibctypes.ORDERED, []string{testConnectionIDB},
testPort2, testChannel2, portCap, counterparty, testChannelVersion, testChannelVersion,
proof, proofHeight+1,
)
@ -167,7 +164,7 @@ func (suite *KeeperTestSuite) TestChanOpenTry() {
suite.Require().Equal(chanCap.String(), cap.String(), "channel capability is not correct")
} else {
_, err := suite.chainA.App.IBCKeeper.ChannelKeeper.ChanOpenTry(
suite.chainA.GetContext(), exported.ORDERED, []string{testConnectionIDB},
suite.chainA.GetContext(), ibctypes.ORDERED, []string{testConnectionIDB},
testPort2, testChannel2, portCap, counterparty, testChannelVersion, testChannelVersion,
invalidProof{}, proofHeight,
)
@ -187,63 +184,63 @@ func (suite *KeeperTestSuite) TestChanOpenAck() {
suite.chainB.CreateClient(suite.chainA)
suite.chainA.createConnection(
testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA,
connectionexported.OPEN,
ibctypes.OPEN,
)
_ = suite.chainB.createConnection(
testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB,
connectionexported.OPEN,
ibctypes.OPEN,
)
_ = suite.chainA.createChannel(
testPort1, testChannel1, testPort2, testChannel2, exported.INIT,
exported.ORDERED, testConnectionIDB,
testPort1, testChannel1, testPort2, testChannel2, ibctypes.INIT,
ibctypes.ORDERED, testConnectionIDB,
)
suite.chainB.createChannel(
testPort2, testChannel2, testPort1, testChannel1, exported.TRYOPEN,
exported.ORDERED, testConnectionIDA,
testPort2, testChannel2, testPort1, testChannel1, ibctypes.TRYOPEN,
ibctypes.ORDERED, testConnectionIDA,
)
}, true},
{"channel doesn't exist", func() {}, false},
{"channel state is not INIT or TRYOPEN", func() {
_ = suite.chainB.createChannel(
testPort1, testChannel1, testPort2, testChannel2, exported.UNINITIALIZED,
exported.ORDERED, testConnectionIDA,
testPort1, testChannel1, testPort2, testChannel2, ibctypes.UNINITIALIZED,
ibctypes.ORDERED, testConnectionIDA,
)
}, false},
{"connection not found", func() {
_ = suite.chainB.createChannel(
testPort1, testChannel1, testPort2, testChannel2, exported.TRYOPEN,
exported.ORDERED, testConnectionIDA,
testPort1, testChannel1, testPort2, testChannel2, ibctypes.TRYOPEN,
ibctypes.ORDERED, testConnectionIDA,
)
}, false},
{"connection is not OPEN", func() {
_ = suite.chainB.createConnection(
testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB,
connectionexported.TRYOPEN,
ibctypes.TRYOPEN,
)
_ = suite.chainB.createChannel(
testPort1, testChannel1, testPort2, testChannel2, exported.TRYOPEN,
exported.ORDERED, testConnectionIDA,
testPort1, testChannel1, testPort2, testChannel2, ibctypes.TRYOPEN,
ibctypes.ORDERED, testConnectionIDA,
)
}, false},
{"consensus state not found", func() {
_ = suite.chainB.createConnection(
testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB,
connectionexported.OPEN,
ibctypes.OPEN,
)
_ = suite.chainB.createChannel(
testPort1, testChannel1, testPort2, testChannel2, exported.TRYOPEN,
exported.ORDERED, testConnectionIDA,
testPort1, testChannel1, testPort2, testChannel2, ibctypes.TRYOPEN,
ibctypes.ORDERED, testConnectionIDA,
)
}, false},
{"channel verification failed", func() {
suite.chainB.CreateClient(suite.chainA)
_ = suite.chainB.createConnection(
testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB,
connectionexported.OPEN,
ibctypes.OPEN,
)
_ = suite.chainB.createChannel(
testPort1, testChannel1, testPort2, testChannel2, exported.TRYOPEN,
exported.ORDERED, testConnectionIDA,
testPort1, testChannel1, testPort2, testChannel2, ibctypes.TRYOPEN,
ibctypes.ORDERED, testConnectionIDA,
)
}, false},
{"channel capability not found", func() {
@ -251,19 +248,19 @@ func (suite *KeeperTestSuite) TestChanOpenAck() {
suite.chainB.CreateClient(suite.chainA)
suite.chainA.createConnection(
testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA,
connectionexported.OPEN,
ibctypes.OPEN,
)
_ = suite.chainB.createConnection(
testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB,
connectionexported.OPEN,
ibctypes.OPEN,
)
_ = suite.chainA.createChannel(
testPort1, testChannel1, testPort2, testChannel2, exported.INIT,
exported.ORDERED, testConnectionIDB,
testPort1, testChannel1, testPort2, testChannel2, ibctypes.INIT,
ibctypes.ORDERED, testConnectionIDB,
)
suite.chainB.createChannel(
testPort2, testChannel2, testPort1, testChannel1, exported.TRYOPEN,
exported.ORDERED, testConnectionIDA,
testPort2, testChannel2, testPort1, testChannel1, ibctypes.TRYOPEN,
ibctypes.ORDERED, testConnectionIDA,
)
channelCap = capability.NewCapability(3)
}, false},
@ -312,61 +309,61 @@ func (suite *KeeperTestSuite) TestChanOpenConfirm() {
suite.chainB.CreateClient(suite.chainA)
_ = suite.chainA.createConnection(
testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA,
connectionexported.TRYOPEN,
ibctypes.TRYOPEN,
)
suite.chainB.createConnection(
_ = suite.chainB.createConnection(
testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB,
connectionexported.OPEN,
ibctypes.OPEN,
)
_ = suite.chainA.createChannel(
testPort2, testChannel2, testPort1, testChannel1, exported.OPEN,
exported.ORDERED, testConnectionIDB,
testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN,
ibctypes.ORDERED, testConnectionIDB,
)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2,
exported.TRYOPEN, exported.ORDERED, testConnectionIDA)
_ = suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2,
ibctypes.TRYOPEN, ibctypes.ORDERED, testConnectionIDA)
}, true},
{"channel doesn't exist", func() {}, false},
{"channel state is not TRYOPEN", func() {
_ = suite.chainA.createChannel(
testPort1, testChannel1, testPort2, testChannel2, exported.UNINITIALIZED,
exported.ORDERED, testConnectionIDB,
testPort1, testChannel1, testPort2, testChannel2, ibctypes.UNINITIALIZED,
ibctypes.ORDERED, testConnectionIDB,
)
}, false},
{"connection not found", func() {
_ = suite.chainA.createChannel(
testPort2, testChannel2, testPort1, testChannel1, exported.TRYOPEN,
exported.ORDERED, testConnectionIDB,
testPort2, testChannel2, testPort1, testChannel1, ibctypes.TRYOPEN,
ibctypes.ORDERED, testConnectionIDB,
)
}, false},
{"connection is not OPEN", func() {
_ = suite.chainA.createConnection(
testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA,
connectionexported.TRYOPEN,
ibctypes.TRYOPEN,
)
_ = suite.chainA.createChannel(
testPort2, testChannel2, testPort1, testChannel1, exported.TRYOPEN,
exported.ORDERED, testConnectionIDB,
testPort2, testChannel2, testPort1, testChannel1, ibctypes.TRYOPEN,
ibctypes.ORDERED, testConnectionIDB,
)
}, false},
{"consensus state not found", func() {
_ = suite.chainA.createConnection(
testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA,
connectionexported.OPEN,
ibctypes.OPEN,
)
_ = suite.chainA.createChannel(
testPort2, testChannel2, testPort1, testChannel1, exported.TRYOPEN,
exported.ORDERED, testConnectionIDB,
testPort2, testChannel2, testPort1, testChannel1, ibctypes.TRYOPEN,
ibctypes.ORDERED, testConnectionIDB,
)
}, false},
{"channel verification failed", func() {
suite.chainA.CreateClient(suite.chainB)
_ = suite.chainA.createConnection(
testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA,
connectionexported.OPEN,
ibctypes.OPEN,
)
_ = suite.chainA.createChannel(
testPort2, testChannel2, testPort1, testChannel1, exported.TRYOPEN,
exported.ORDERED, testConnectionIDB,
testPort2, testChannel2, testPort1, testChannel1, ibctypes.TRYOPEN,
ibctypes.ORDERED, testConnectionIDB,
)
}, false},
{"channel capability not found", func() {
@ -374,18 +371,18 @@ func (suite *KeeperTestSuite) TestChanOpenConfirm() {
suite.chainB.CreateClient(suite.chainA)
_ = suite.chainA.createConnection(
testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA,
connectionexported.TRYOPEN,
ibctypes.TRYOPEN,
)
suite.chainB.createConnection(
testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB,
connectionexported.OPEN,
ibctypes.OPEN,
)
_ = suite.chainA.createChannel(
testPort2, testChannel2, testPort1, testChannel1, exported.OPEN,
exported.ORDERED, testConnectionIDB,
testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN,
ibctypes.ORDERED, testConnectionIDB,
)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2,
exported.TRYOPEN, exported.ORDERED, testConnectionIDA)
ibctypes.TRYOPEN, ibctypes.ORDERED, testConnectionIDA)
channelCap = capability.NewCapability(3)
}, false},
}
@ -430,45 +427,45 @@ func (suite *KeeperTestSuite) TestChanCloseInit() {
suite.chainB.CreateClient(suite.chainA)
_ = suite.chainA.createConnection(
testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB,
connectionexported.OPEN,
ibctypes.OPEN,
)
_ = suite.chainA.createChannel(
testPort1, testChannel1, testPort2, testChannel2, exported.OPEN,
exported.ORDERED, testConnectionIDA,
testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN,
ibctypes.ORDERED, testConnectionIDA,
)
}, true},
{"channel doesn't exist", func() {}, false},
{"channel state is CLOSED", func() {
_ = suite.chainA.createChannel(
testPort1, testChannel1, testPort2, testChannel2, exported.CLOSED,
exported.ORDERED, testConnectionIDB,
testPort1, testChannel1, testPort2, testChannel2, ibctypes.CLOSED,
ibctypes.ORDERED, testConnectionIDB,
)
}, false},
{"connection not found", func() {
_ = suite.chainA.createChannel(
testPort1, testChannel1, testPort2, testChannel2, exported.OPEN,
exported.ORDERED, testConnectionIDA,
testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN,
ibctypes.ORDERED, testConnectionIDA,
)
}, false},
{"connection is not OPEN", func() {
_ = suite.chainA.createConnection(
testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB,
connectionexported.TRYOPEN,
ibctypes.TRYOPEN,
)
_ = suite.chainA.createChannel(
testPort1, testChannel1, testPort2, testChannel2, exported.UNINITIALIZED,
exported.ORDERED, testConnectionIDA,
testPort1, testChannel1, testPort2, testChannel2, ibctypes.UNINITIALIZED,
ibctypes.ORDERED, testConnectionIDA,
)
}, false},
{"channel capability not found", func() {
suite.chainB.CreateClient(suite.chainA)
_ = suite.chainA.createConnection(
testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB,
connectionexported.OPEN,
ibctypes.OPEN,
)
_ = suite.chainA.createChannel(
testPort1, testChannel1, testPort2, testChannel2, exported.OPEN,
exported.ORDERED, testConnectionIDA,
testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN,
ibctypes.ORDERED, testConnectionIDA,
)
channelCap = capability.NewCapability(3)
}, false},
@ -508,63 +505,63 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() {
suite.chainB.CreateClient(suite.chainA)
_ = suite.chainB.createConnection(
testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB,
connectionexported.OPEN,
ibctypes.OPEN,
)
suite.chainA.createConnection(
testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA,
connectionexported.OPEN,
ibctypes.OPEN,
)
_ = suite.chainB.createChannel(
testPort2, testChannel2, testPort1, testChannel1, exported.OPEN,
exported.ORDERED, testConnectionIDB,
testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN,
ibctypes.ORDERED, testConnectionIDB,
)
suite.chainA.createChannel(
testPort1, testChannel1, testPort2, testChannel2, exported.CLOSED,
exported.ORDERED, testConnectionIDA,
testPort1, testChannel1, testPort2, testChannel2, ibctypes.CLOSED,
ibctypes.ORDERED, testConnectionIDA,
)
}, true},
{"channel doesn't exist", func() {}, false},
{"channel state is CLOSED", func() {
_ = suite.chainB.createChannel(
testPort2, testChannel2, testPort1, testChannel1, exported.CLOSED,
exported.ORDERED, testConnectionIDB,
testPort2, testChannel2, testPort1, testChannel1, ibctypes.CLOSED,
ibctypes.ORDERED, testConnectionIDB,
)
}, false},
{"connection not found", func() {
_ = suite.chainB.createChannel(
testPort2, testChannel2, testPort1, testChannel1, exported.OPEN,
exported.ORDERED, testConnectionIDA,
testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN,
ibctypes.ORDERED, testConnectionIDA,
)
}, false},
{"connection is not OPEN", func() {
_ = suite.chainB.createConnection(
testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB,
connectionexported.TRYOPEN,
ibctypes.TRYOPEN,
)
_ = suite.chainB.createChannel(
testPort2, testChannel2, testPort1, testChannel1, exported.OPEN,
exported.ORDERED, testConnectionIDB,
testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN,
ibctypes.ORDERED, testConnectionIDB,
)
}, false},
{"consensus state not found", func() {
_ = suite.chainB.createConnection(
testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB,
connectionexported.OPEN,
ibctypes.OPEN,
)
_ = suite.chainB.createChannel(
testPort2, testChannel2, testPort1, testChannel1, exported.OPEN,
exported.ORDERED, testConnectionIDB,
testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN,
ibctypes.ORDERED, testConnectionIDB,
)
}, false},
{"channel verification failed", func() {
suite.chainB.CreateClient(suite.chainA)
_ = suite.chainB.createConnection(
testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB,
connectionexported.OPEN,
ibctypes.OPEN,
)
_ = suite.chainB.createChannel(
testPort2, testChannel2, testPort1, testChannel1, exported.OPEN,
exported.ORDERED, testConnectionIDB,
testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN,
ibctypes.ORDERED, testConnectionIDB,
)
}, false},
{"channel capability not found", func() {
@ -572,19 +569,19 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() {
suite.chainB.CreateClient(suite.chainA)
_ = suite.chainB.createConnection(
testConnectionIDB, testConnectionIDA, testClientIDA, testClientIDB,
connectionexported.OPEN,
ibctypes.OPEN,
)
suite.chainA.createConnection(
testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA,
connectionexported.OPEN,
ibctypes.OPEN,
)
_ = suite.chainB.createChannel(
testPort2, testChannel2, testPort1, testChannel1, exported.OPEN,
exported.ORDERED, testConnectionIDB,
testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN,
ibctypes.ORDERED, testConnectionIDB,
)
suite.chainA.createChannel(
testPort1, testChannel1, testPort2, testChannel2, exported.CLOSED,
exported.ORDERED, testConnectionIDA,
testPort1, testChannel1, testPort2, testChannel2, ibctypes.CLOSED,
ibctypes.ORDERED, testConnectionIDA,
)
}, false},
}

View File

@ -19,7 +19,7 @@ import (
// Keeper defines the IBC channel keeper
type Keeper struct {
storeKey sdk.StoreKey
cdc *codec.Codec
cdc codec.Marshaler
clientKeeper types.ClientKeeper
connectionKeeper types.ConnectionKeeper
portKeeper types.PortKeeper
@ -28,7 +28,7 @@ type Keeper struct {
// NewKeeper creates a new IBC channel Keeper instance
func NewKeeper(
cdc *codec.Codec, key sdk.StoreKey,
cdc codec.Marshaler, key sdk.StoreKey,
clientKeeper types.ClientKeeper, connectionKeeper types.ConnectionKeeper,
portKeeper types.PortKeeper, scopedKeeper capability.ScopedKeeper,
) Keeper {
@ -63,7 +63,7 @@ func (k Keeper) GetChannel(ctx sdk.Context, portID, channelID string) (types.Cha
// SetChannel sets a channel to the store
func (k Keeper) SetChannel(ctx sdk.Context, portID, channelID string, channel types.Channel) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshalBinaryBare(channel)
bz := k.cdc.MustMarshalBinaryBare(&channel)
store.Set(ibctypes.KeyChannel(portID, channelID), bz)
}

View File

@ -14,9 +14,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported"
@ -41,7 +39,7 @@ const (
testChannel2 = "secondchannel"
testChannel3 = "thirdchannel"
testChannelOrder = exported.ORDERED
testChannelOrder = ibctypes.ORDERED
testChannelVersion = "1.0"
trustingPeriod time.Duration = time.Hour * 24 * 7 * 2
@ -77,7 +75,7 @@ func (suite *KeeperTestSuite) TestSetChannel() {
counterparty2 := types.NewCounterparty(testPort2, testChannel2)
channel := types.NewChannel(
exported.INIT, testChannelOrder,
ibctypes.INIT, testChannelOrder,
counterparty2, []string{testConnectionIDA}, testChannelVersion,
)
suite.chainB.App.IBCKeeper.ChannelKeeper.SetChannel(ctx, testPort1, testChannel1, channel)
@ -94,15 +92,15 @@ func (suite KeeperTestSuite) TestGetAllChannels() {
counterparty3 := types.NewCounterparty(testPort3, testChannel3)
channel1 := types.NewChannel(
exported.INIT, testChannelOrder,
ibctypes.INIT, testChannelOrder,
counterparty3, []string{testConnectionIDA}, testChannelVersion,
)
channel2 := types.NewChannel(
exported.INIT, testChannelOrder,
ibctypes.INIT, testChannelOrder,
counterparty1, []string{testConnectionIDA}, testChannelVersion,
)
channel3 := types.NewChannel(
exported.CLOSED, testChannelOrder,
ibctypes.CLOSED, testChannelOrder,
counterparty2, []string{testConnectionIDA}, testChannelVersion,
)
@ -287,7 +285,7 @@ func NewTestChain(clientID string) *TestChain {
// Creates simple context for testing purposes
func (chain *TestChain) GetContext() sdk.Context {
return chain.App.BaseApp.NewContext(false, abci.Header{ChainID: chain.Header.ChainID, Height: chain.Header.Height})
return chain.App.BaseApp.NewContext(false, abci.Header{ChainID: chain.Header.SignedHeader.Header.ChainID, Height: int64(chain.Header.GetHeight())})
}
// createClient will create a client for clientChain on targetChain
@ -296,7 +294,7 @@ func (chain *TestChain) CreateClient(client *TestChain) error {
// Commit and create a new block on appTarget to get a fresh CommitID
client.App.Commit()
commitID := client.App.LastCommitID()
client.App.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: client.Header.Height, Time: client.Header.Time}})
client.App.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: int64(client.Header.GetHeight()), Time: client.Header.Time}})
// Set HistoricalInfo on client chain after Commit
ctxClient := client.GetContext()
@ -312,7 +310,7 @@ func (chain *TestChain) CreateClient(client *TestChain) error {
},
Valset: validators,
}
client.App.StakingKeeper.SetHistoricalInfo(ctxClient, client.Header.Height, histInfo)
client.App.StakingKeeper.SetHistoricalInfo(ctxClient, int64(client.Header.GetHeight()), histInfo)
// Create target ctx
ctxTarget := chain.GetContext()
@ -357,7 +355,7 @@ func (chain *TestChain) updateClient(client *TestChain) {
commitID := client.App.LastCommitID()
client.Header = nextHeader(client)
client.App.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: client.Header.Height, Time: client.Header.Time}})
client.App.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: int64(client.Header.GetHeight()), Time: client.Header.Time}})
// Set HistoricalInfo on client chain after Commit
ctxClient := client.GetContext()
@ -373,17 +371,17 @@ func (chain *TestChain) updateClient(client *TestChain) {
},
Valset: validators,
}
client.App.StakingKeeper.SetHistoricalInfo(ctxClient, client.Header.Height, histInfo)
client.App.StakingKeeper.SetHistoricalInfo(ctxClient, int64(client.Header.GetHeight()), histInfo)
consensusState := ibctmtypes.ConsensusState{
Height: uint64(client.Header.Height),
Height: client.Header.GetHeight(),
Timestamp: client.Header.Time,
Root: commitmenttypes.NewMerkleRoot(commitID.Hash),
ValidatorSet: client.Vals,
}
chain.App.IBCKeeper.ClientKeeper.SetClientConsensusState(
ctxTarget, client.ClientID, uint64(client.Header.Height), consensusState,
ctxTarget, client.ClientID, client.Header.GetHeight(), consensusState,
)
chain.App.IBCKeeper.ClientKeeper.SetClientState(
ctxTarget, ibctmtypes.NewClientState(client.ClientID, trustingPeriod, ubdPeriod, maxClockDrift, client.Header),
@ -404,9 +402,9 @@ func (chain *TestChain) updateClient(client *TestChain) {
func (chain *TestChain) createConnection(
connID, counterpartyConnID, clientID, counterpartyClientID string,
state connectionexported.State,
state ibctypes.State,
) connectiontypes.ConnectionEnd {
counterparty := connectiontypes.NewCounterparty(counterpartyClientID, counterpartyConnID, chain.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix())
counterparty := connectiontypes.NewCounterparty(counterpartyClientID, counterpartyConnID, commitmenttypes.NewMerklePrefix(chain.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes()))
connection := connectiontypes.ConnectionEnd{
State: state,
ClientID: clientID,
@ -420,7 +418,7 @@ func (chain *TestChain) createConnection(
func (chain *TestChain) createChannel(
portID, channelID, counterpartyPortID, counterpartyChannelID string,
state exported.State, order exported.Order, connectionID string,
state ibctypes.State, order ibctypes.Order, connectionID string,
) types.Channel {
counterparty := types.NewCounterparty(counterpartyPortID, counterpartyChannelID)
channel := types.NewChannel(state, order, counterparty,
@ -432,7 +430,7 @@ func (chain *TestChain) createChannel(
}
func nextHeader(chain *TestChain) ibctmtypes.Header {
return ibctmtypes.CreateTestHeader(chain.Header.ChainID, chain.Header.Height+1,
return ibctmtypes.CreateTestHeader(chain.Header.SignedHeader.Header.ChainID, int64(chain.Header.GetHeight())+1,
chain.Header.Time.Add(time.Minute), chain.Vals, chain.Signers)
}

View File

@ -10,7 +10,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/capability"
client "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection"
connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported"
@ -34,7 +33,7 @@ func (k Keeper) SendPacket(
return sdkerrors.Wrap(types.ErrChannelNotFound, packet.GetSourceChannel())
}
if channel.State == exported.CLOSED {
if channel.State == ibctypes.CLOSED {
return sdkerrors.Wrapf(
types.ErrInvalidChannelState,
"channel is CLOSED (got %s)", channel.State.String(),
@ -65,7 +64,7 @@ func (k Keeper) SendPacket(
}
// NOTE: assume UNINITIALIZED is a closed connection
if connectionEnd.GetState() == connectionexported.UNINITIALIZED {
if connectionEnd.GetState() == ibctypes.UNINITIALIZED {
return sdkerrors.Wrap(
connection.ErrInvalidConnectionState,
"connection is closed (i.e NONE)",
@ -147,7 +146,7 @@ func (k Keeper) RecvPacket(
return nil, sdkerrors.Wrap(types.ErrChannelNotFound, packet.GetDestChannel())
}
if channel.State != exported.OPEN {
if channel.State != ibctypes.OPEN {
return nil, sdkerrors.Wrapf(
types.ErrInvalidChannelState,
"channel state is not OPEN (got %s)", channel.State.String(),
@ -177,7 +176,7 @@ func (k Keeper) RecvPacket(
return nil, sdkerrors.Wrap(connection.ErrConnectionNotFound, channel.ConnectionHops[0])
}
if connectionEnd.GetState() != connectionexported.OPEN {
if connectionEnd.GetState() != ibctypes.OPEN {
return nil, sdkerrors.Wrapf(
connection.ErrInvalidConnectionState,
"connection state is not OPEN (got %s)", connectionEnd.GetState().String(),
@ -226,7 +225,7 @@ func (k Keeper) PacketExecuted(
}
// sanity check
if channel.State != exported.OPEN {
if channel.State != ibctypes.OPEN {
return sdkerrors.Wrapf(
types.ErrInvalidChannelState,
"channel state is not OPEN (got %s)", channel.State.String(),
@ -238,14 +237,14 @@ func (k Keeper) PacketExecuted(
return sdkerrors.Wrap(types.ErrInvalidChannelCapability, "channel capability failed authentication")
}
if acknowledgement != nil || channel.Ordering == exported.UNORDERED {
if acknowledgement != nil || channel.Ordering == ibctypes.UNORDERED {
k.SetPacketAcknowledgement(
ctx, packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(),
types.CommitAcknowledgement(acknowledgement),
)
}
if channel.Ordering == exported.ORDERED {
if channel.Ordering == ibctypes.ORDERED {
nextSequenceRecv, found := k.GetNextSequenceRecv(ctx, packet.GetDestPort(), packet.GetDestChannel())
if !found {
return types.ErrSequenceReceiveNotFound
@ -302,7 +301,7 @@ func (k Keeper) AcknowledgePacket(
return nil, sdkerrors.Wrap(types.ErrChannelNotFound, packet.GetSourceChannel())
}
if channel.State != exported.OPEN {
if channel.State != ibctypes.OPEN {
return nil, sdkerrors.Wrapf(
types.ErrInvalidChannelState,
"channel state is not OPEN (got %s)", channel.State.String(),
@ -332,7 +331,7 @@ func (k Keeper) AcknowledgePacket(
return nil, sdkerrors.Wrap(connection.ErrConnectionNotFound, channel.ConnectionHops[0])
}
if connectionEnd.GetState() != connectionexported.OPEN {
if connectionEnd.GetState() != ibctypes.OPEN {
return nil, sdkerrors.Wrapf(
connection.ErrInvalidConnectionState,
"connection state is not OPEN (got %s)", connectionEnd.GetState().String(),
@ -396,7 +395,7 @@ func (k Keeper) CleanupPacket(
return nil, sdkerrors.Wrap(types.ErrChannelNotFound, packet.GetSourceChannel())
}
if channel.State != exported.OPEN {
if channel.State != ibctypes.OPEN {
return nil, sdkerrors.Wrapf(
types.ErrInvalidChannelState,
"channel state is not OPEN (got %s)", channel.State.String(),
@ -447,13 +446,13 @@ func (k Keeper) CleanupPacket(
var err error
switch channel.Ordering {
case exported.ORDERED:
case ibctypes.ORDERED:
// check that the recv sequence is as claimed
err = k.connectionKeeper.VerifyNextSequenceRecv(
ctx, connectionEnd, proofHeight, proof,
packet.GetDestPort(), packet.GetDestChannel(), nextSequenceRecv,
)
case exported.UNORDERED:
case ibctypes.UNORDERED:
err = k.connectionKeeper.VerifyPacketAcknowledgement(
ctx, connectionEnd, proofHeight, proof,
packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(),

View File

@ -4,7 +4,6 @@ import (
"fmt"
"github.com/cosmos/cosmos-sdk/x/capability"
connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
@ -21,8 +20,8 @@ func (suite *KeeperTestSuite) TestSendPacket() {
{"success", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.CreateClient(suite.chainA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
suite.chainB.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainB.GetContext(), testPort1, testChannel1, 1)
}, true},
{"packet basic validation failed", func() {
@ -33,62 +32,62 @@ func (suite *KeeperTestSuite) TestSendPacket() {
}, false},
{"channel closed", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.CLOSED, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.CLOSED, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"packet dest port ≠ channel counterparty port", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, testPort3, counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"packet dest channel ID ≠ channel counterparty channel ID", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), testChannel3, timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"connection not found", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"connection is UNINITIALIZED", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.UNINITIALIZED)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.UNINITIALIZED)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"client state not found", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"timeout height passed", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
commitNBlocks(suite.chainB, 10)
suite.chainB.CreateClient(suite.chainA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"timeout timestamp passed", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), disabledTimeoutHeight, timeoutTimestamp)
commitBlockWithNewTimestamp(suite.chainB, timeoutTimestamp)
suite.chainB.CreateClient(suite.chainA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"next sequence send not found", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.CreateClient(suite.chainA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"next sequence wrong", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.CreateClient(suite.chainA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
suite.chainB.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainB.GetContext(), testPort1, testChannel1, 5)
}, false},
{"channel capability not found", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.CreateClient(suite.chainA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
suite.chainB.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainB.GetContext(), testPort1, testChannel1, 1)
channelCap = capability.NewCapability(3)
}, false},
@ -127,10 +126,10 @@ func (suite *KeeperTestSuite) TestRecvPacket() {
{"success", func() {
suite.chainB.CreateClient(suite.chainA)
suite.chainA.CreateClient(suite.chainB)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDB)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDB)
suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainA.GetContext(), testPort2, testChannel2, 1)
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort2, testChannel2, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainA.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainA.GetContext(), testPort2, testChannel2, 1, types.CommitPacket(packet))
@ -139,41 +138,35 @@ func (suite *KeeperTestSuite) TestRecvPacket() {
{"channel not found", func() {}, false},
{"channel not open", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.INIT, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.INIT, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"packet source port ≠ channel counterparty port", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort2, testChannel2, testPort3, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort2, testChannel2, testPort3, testChannel1, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"packet source channel ID ≠ channel counterparty channel ID", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel3, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel3, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"connection not found", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"connection not OPEN", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.INIT)
suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.INIT)
suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"timeout height passed", func() {
commitNBlocks(suite.chainB, 10)
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDA)
}, false},
{"timeout timestamp passed", func() {
commitBlockWithNewTimestamp(suite.chainB, timeoutTimestamp)
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), disabledTimeoutHeight, timeoutTimestamp)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"validation failed", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
}
@ -210,31 +203,31 @@ func (suite *KeeperTestSuite) TestPacketExecuted() {
testCases := []testCase{
{"success: UNORDERED", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.UNORDERED, testConnectionIDA)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDA)
suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainA.GetContext(), testPort2, testChannel2, 1)
}, true},
{"success: ORDERED", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainA.GetContext(), testPort2, testChannel2, 1)
}, true},
{"channel not found", func() {}, false},
{"channel not OPEN", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.CLOSED, exported.ORDERED, testConnectionIDA)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.CLOSED, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"next sequence receive not found", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"packet sequence ≠ next sequence receive", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainA.GetContext(), testPort2, testChannel2, 5)
}, false},
{"capability not found", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.UNORDERED, testConnectionIDA)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDA)
suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainA.GetContext(), testPort2, testChannel2, 1)
channelCap = capability.NewCapability(3)
}, false},
@ -276,44 +269,44 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.CreateClient(suite.chainA)
suite.chainA.CreateClient(suite.chainB)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.ORDERED, testConnectionIDB)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDB)
suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 1, types.CommitPacket(packet))
suite.chainA.App.IBCKeeper.ChannelKeeper.SetPacketAcknowledgement(suite.chainA.GetContext(), testPort2, testChannel2, 1, types.CommitAcknowledgement(ack))
}, true},
{"channel not found", func() {}, false},
{"channel not open", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.CLOSED, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.CLOSED, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"packet source port ≠ channel counterparty port", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort1, testChannel1, testPort3, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort1, testChannel1, testPort3, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"packet source channel ID ≠ channel counterparty channel ID", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel3, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel3, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"connection not found", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"connection not OPEN", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.INIT)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.INIT)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"packet hasn't been sent", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"packet ack verification failed", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 1, types.CommitPacket(packet))
}, false},
}
@ -358,58 +351,58 @@ func (suite *KeeperTestSuite) TestCleanupPacket() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainA.CreateClient(suite.chainB)
suite.chainB.CreateClient(suite.chainA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.UNORDERED, testConnectionIDA)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.UNORDERED, testConnectionIDB)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDA)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDB)
suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 1, types.CommitPacket(packet))
suite.chainA.App.IBCKeeper.ChannelKeeper.SetPacketAcknowledgement(suite.chainA.GetContext(), testPort2, testChannel2, 1, types.CommitAcknowledgement(ack))
}, true},
{"channel not found", func() {}, false},
{"channel not open", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.CLOSED, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.CLOSED, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"packet source port ≠ channel counterparty port", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort1, testChannel1, testPort3, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort1, testChannel1, testPort3, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"packet source channel ID ≠ channel counterparty channel ID", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel3, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel3, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"connection not found", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"connection not OPEN", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.INIT)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.INIT)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"packet already received ", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 10, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"packet hasn't been sent", func() {
nextSeqRecv = 10
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"next seq receive verification failed", func() {
nextSeqRecv = 10
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 1, types.CommitPacket(packet))
}, false},
{"packet ack verification failed", func() {
nextSeqRecv = 10
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.UNORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDA)
suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 1, types.CommitPacket(packet))
}, false},
}

View File

@ -34,7 +34,7 @@ func (k Keeper) TimeoutPacket(
)
}
if channel.State != exported.OPEN {
if channel.State != ibctypes.OPEN {
return nil, sdkerrors.Wrapf(
types.ErrInvalidChannelState,
"channel state is not OPEN (got %s)", channel.State.String(),
@ -85,7 +85,7 @@ func (k Keeper) TimeoutPacket(
}
switch channel.Ordering {
case exported.ORDERED:
case ibctypes.ORDERED:
// check that packet has not been received
if nextSequenceRecv > packet.GetSequence() {
return nil, sdkerrors.Wrap(types.ErrInvalidPacket, "packet already received")
@ -96,7 +96,7 @@ func (k Keeper) TimeoutPacket(
ctx, connectionEnd, proofHeight, proof,
packet.GetDestPort(), packet.GetDestChannel(), nextSequenceRecv,
)
case exported.UNORDERED:
case ibctypes.UNORDERED:
err = k.connectionKeeper.VerifyPacketAcknowledgementAbsence(
ctx, connectionEnd, proofHeight, proof,
packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(),
@ -142,8 +142,8 @@ func (k Keeper) TimeoutExecuted(ctx sdk.Context, chanCap *capability.Capability,
k.deletePacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
if channel.Ordering == exported.ORDERED {
channel.State = exported.CLOSED
if channel.Ordering == ibctypes.ORDERED {
channel.State = ibctypes.CLOSED
k.SetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), channel)
}
@ -212,7 +212,7 @@ func (k Keeper) TimeoutOnClose(
counterparty := types.NewCounterparty(packet.GetSourcePort(), packet.GetSourceChannel())
expectedChannel := types.NewChannel(
exported.CLOSED, channel.Ordering, counterparty, counterpartyHops, channel.Version,
ibctypes.CLOSED, channel.Ordering, counterparty, counterpartyHops, channel.Version,
)
// check that the opposing channel end has closed
@ -226,13 +226,13 @@ func (k Keeper) TimeoutOnClose(
var err error
switch channel.Ordering {
case exported.ORDERED:
case ibctypes.ORDERED:
// check that the recv sequence is as claimed
err = k.connectionKeeper.VerifyNextSequenceRecv(
ctx, connectionEnd, proofHeight, proof,
packet.GetDestPort(), packet.GetDestChannel(), nextSequenceRecv,
)
case exported.UNORDERED:
case ibctypes.UNORDERED:
err = k.connectionKeeper.VerifyPacketAcknowledgementAbsence(
ctx, connectionEnd, proofHeight, proof,
packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence(),

View File

@ -4,8 +4,6 @@ import (
"fmt"
"github.com/cosmos/cosmos-sdk/x/capability"
connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
@ -24,58 +22,58 @@ func (suite *KeeperTestSuite) TestTimeoutPacket() {
packet = types.NewPacket(newMockTimeoutPacket().GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), 1, disabledTimeoutTimestamp)
suite.chainB.CreateClient(suite.chainA)
suite.chainA.CreateClient(suite.chainB)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.UNORDERED, testConnectionIDA)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.OPEN, exported.UNORDERED, testConnectionIDB)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainA.createConnection(testConnectionIDA, testConnectionIDB, testClientIDB, testClientIDA, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDA)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDB)
suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 2, types.CommitPacket(packet))
}, true},
{"channel not found", func() {}, false},
{"channel not open", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.CLOSED, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.CLOSED, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"packet source port ≠ channel counterparty port", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort1, testChannel1, testPort3, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort1, testChannel1, testPort3, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"packet source channel ID ≠ channel counterparty channel ID", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel3, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel3, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"connection not found", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"timeout", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 10, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"packet already received ", func() {
nextSeqRecv = 2
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"packet hasn't been sent", func() {
nextSeqRecv = 1
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"next seq receive verification failed", func() {
nextSeqRecv = 1
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 2, types.CommitPacket(packet))
}, false},
{"packet ack verification failed", func() {
nextSeqRecv = 1
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.UNORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDA)
suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 2, types.CommitPacket(packet))
}, false},
}
@ -111,14 +109,14 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() {
var chanCap *capability.Capability
testCases := []testCase{
{"success ORDERED", func() {
packet = types.NewPacket(newMockTimeoutPacket().GetBytes(), 1, testPort1, testChannel1, testPort2, testChannel2, 3, disabledTimeoutTimestamp)
suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
packet = types.NewPacket(newMockTimeoutPacket().GetBytes(), 1, testPort1, testChannel1, testPort2, testChannel2, timeoutHeight, disabledTimeoutTimestamp)
suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, true},
{"channel not found", func() {}, false},
{"incorrect capability", func() {
packet = types.NewPacket(newMockTimeoutPacket().GetBytes(), 1, testPort1, testChannel1, testPort2, testChannel2, 3, disabledTimeoutTimestamp)
suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
chanCap = capability.NewCapability(1)
packet = types.NewPacket(newMockTimeoutPacket().GetBytes(), 1, testPort1, testChannel1, testPort2, testChannel2, timeoutHeight, disabledTimeoutTimestamp)
suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
chanCap = capability.NewCapability(100)
}, false},
}
@ -160,52 +158,52 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.CreateClient(suite.chainA)
suite.chainA.CreateClient(suite.chainB)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.UNORDERED, testConnectionIDA)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, exported.CLOSED, exported.UNORDERED, testConnectionIDB) // channel on chainA is closed
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainA.createConnection(testConnectionIDB, testConnectionIDA, testClientIDB, testClientIDA, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDA)
suite.chainA.createChannel(testPort2, testChannel2, testPort1, testChannel1, ibctypes.CLOSED, ibctypes.UNORDERED, testConnectionIDB) // channel on chainA is closed
suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 2, types.CommitPacket(packet))
suite.chainB.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainB.GetContext(), testPort1, testChannel1, nextSeqRecv)
}, true},
{"channel not found", func() {}, false},
{"packet dest port ≠ channel counterparty port", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort1, testChannel1, testPort3, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort1, testChannel1, testPort3, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"packet dest channel ID ≠ channel counterparty channel ID", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel3, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel3, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"connection not found", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 1, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"packet hasn't been sent", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
}, false},
{"channel verification failed", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.CreateClient(suite.chainA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.UNORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDA)
suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 2, types.CommitPacket(packet))
suite.chainB.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainB.GetContext(), testPort1, testChannel1, nextSeqRecv)
}, false},
{"next seq receive verification failed", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.CreateClient(suite.chainA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.ORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnectionIDA)
suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 2, types.CommitPacket(packet))
suite.chainB.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainB.GetContext(), testPort1, testChannel1, nextSeqRecv)
}, false},
{"packet ack verification failed", func() {
packet = types.NewPacket(mockSuccessPacket{}.GetBytes(), 2, testPort1, testChannel1, counterparty.GetPortID(), counterparty.GetChannelID(), timeoutHeight, disabledTimeoutTimestamp)
suite.chainB.CreateClient(suite.chainA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, exported.OPEN, exported.UNORDERED, testConnectionIDA)
suite.chainB.createConnection(testConnectionIDA, testConnectionIDB, testClientIDA, testClientIDB, ibctypes.OPEN)
suite.chainB.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.UNORDERED, testConnectionIDA)
suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), testPort1, testChannel1, 2, types.CommitPacket(packet))
suite.chainB.App.IBCKeeper.ChannelKeeper.SetNextSequenceRecv(suite.chainB.GetContext(), testPort1, testChannel1, nextSeqRecv)
}, false},

View File

@ -9,19 +9,15 @@ import (
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
// Channel defines...
type Channel struct {
State exported.State `json:"state" yaml:"state"`
Ordering exported.Order `json:"ordering" yaml:"ordering"`
Counterparty Counterparty `json:"counterparty" yaml:"counterparty"`
ConnectionHops []string `json:"connection_hops" yaml:"connection_hops"`
Version string `json:"version" yaml:"version "`
}
var (
_ exported.ChannelI = (*Channel)(nil)
_ exported.CounterpartyI = (*Counterparty)(nil)
)
// NewChannel creates a new Channel instance
func NewChannel(
state exported.State, ordering exported.Order,
counterparty Counterparty, hops []string, version string,
state ibctypes.State, ordering ibctypes.Order, counterparty Counterparty,
hops []string, version string,
) Channel {
return Channel{
State: state,
@ -33,12 +29,12 @@ func NewChannel(
}
// GetState implements Channel interface.
func (ch Channel) GetState() exported.State {
func (ch Channel) GetState() ibctypes.State {
return ch.State
}
// GetOrdering implements Channel interface.
func (ch Channel) GetOrdering() exported.Order {
func (ch Channel) GetOrdering() ibctypes.Order {
return ch.Ordering
}
@ -62,8 +58,8 @@ func (ch Channel) ValidateBasic() error {
if ch.State.String() == "" {
return sdkerrors.Wrap(ErrInvalidChannel, ErrInvalidChannelState.Error())
}
if ch.Ordering.String() == "" {
return sdkerrors.Wrap(ErrInvalidChannel, ErrInvalidChannelOrdering.Error())
if !(ch.Ordering == ibctypes.ORDERED || ch.Ordering == ibctypes.UNORDERED) {
return sdkerrors.Wrap(ErrInvalidChannelOrdering, ch.Ordering.String())
}
if len(ch.ConnectionHops) != 1 {
return sdkerrors.Wrap(
@ -86,12 +82,6 @@ func (ch Channel) ValidateBasic() error {
return ch.Counterparty.ValidateBasic()
}
// Counterparty defines the counterparty chain's channel and port identifiers
type Counterparty struct {
PortID string `json:"port_id" yaml:"port_id"`
ChannelID string `json:"channel_id" yaml:"channel_id"`
}
// NewCounterparty returns a new Counterparty instance
func NewCounterparty(portID, channelID string) Counterparty {
return Counterparty{
@ -132,8 +122,8 @@ func (c Counterparty) ValidateBasic() error {
type IdentifiedChannel struct {
ID string `json:"id" yaml:"id"`
PortID string `json:"port_id" yaml:"port_id"`
State exported.State `json:"state" yaml:"state"`
Ordering exported.Order `json:"ordering" yaml:"ordering"`
State ibctypes.State `json:"state" yaml:"state"`
Ordering ibctypes.Order `json:"ordering" yaml:"ordering"`
Counterparty Counterparty `json:"counterparty" yaml:"counterparty"`
ConnectionHops []string `json:"connection_hops" yaml:"connection_hops"`
Version string `json:"version" yaml:"version "`

View File

@ -2,23 +2,13 @@ package types
import (
"github.com/cosmos/cosmos-sdk/codec"
client "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
)
// SubModuleCdc defines the IBC channel codec.
var SubModuleCdc *codec.Codec
func init() {
SubModuleCdc = codec.New()
commitmenttypes.RegisterCodec(SubModuleCdc)
client.RegisterCodec(SubModuleCdc)
RegisterCodec(SubModuleCdc)
}
// RegisterCodec registers all the necessary types and interfaces for the
// IBC channel.
// RegisterCodec registers the necessary x/ibc/04-channel interfaces and concrete types
// on the provided Amino codec. These types are used for Amino JSON serialization.
func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterInterface((*exported.PacketI)(nil), nil)
cdc.RegisterConcrete(Channel{}, "ibc/channel/Channel", nil)
@ -30,15 +20,41 @@ func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterConcrete(MsgChannelOpenConfirm{}, "ibc/channel/MsgChannelOpenConfirm", nil)
cdc.RegisterConcrete(MsgChannelCloseInit{}, "ibc/channel/MsgChannelCloseInit", nil)
cdc.RegisterConcrete(MsgChannelCloseConfirm{}, "ibc/channel/MsgChannelCloseConfirm", nil)
cdc.RegisterConcrete(MsgPacket{}, "ibc/channel/MsgPacket", nil)
cdc.RegisterConcrete(MsgAcknowledgement{}, "ibc/channel/MsgAcknowledgement", nil)
cdc.RegisterConcrete(MsgTimeout{}, "ibc/channel/MsgTimeout", nil)
SetSubModuleCodec(cdc)
}
// SetSubModuleCodec sets the ibc channel codec
func SetSubModuleCodec(cdc *codec.Codec) {
SubModuleCdc = cdc
// RegisterInterfaces register the ibc channel submodule interfaces to protobuf
// Any.
func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgChannelOpenInit{},
&MsgChannelOpenTry{},
&MsgChannelOpenAck{},
&MsgChannelOpenConfirm{},
&MsgChannelCloseInit{},
&MsgChannelCloseConfirm{},
&MsgPacket{},
&MsgAcknowledgement{},
&MsgTimeout{},
)
}
var (
amino = codec.New()
// SubModuleCdc references the global x/ibc/04-channel module codec. Note, the codec should
// ONLY be used in certain instances of tests and for JSON encoding as Amino is
// still used for that purpose.
//
// The actual codec used for serialization should be provided to x/ibc/04-channel and
// defined at the application level.
SubModuleCdc = codec.NewHybridCodec(amino, cdctypes.NewInterfaceRegistry())
)
func init() {
RegisterCodec(amino)
amino.Seal()
}

View File

@ -5,7 +5,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
const (
@ -16,7 +16,7 @@ const (
testChannel1 = "firstchannel"
testChannel2 = "secondchannel"
testChannelOrder = exported.ORDERED
testChannelOrder = ibctypes.ORDERED
testChannelVersion = "1.0"
)
@ -39,12 +39,12 @@ func TestValidateGenesis(t *testing.T) {
[]IdentifiedChannel{
NewIdentifiedChannel(
testPort1, testChannel1, NewChannel(
exported.INIT, testChannelOrder, counterparty2, []string{testConnectionIDA}, testChannelVersion,
ibctypes.INIT, testChannelOrder, counterparty2, []string{testConnectionIDA}, testChannelVersion,
),
),
NewIdentifiedChannel(
testPort2, testChannel2, NewChannel(
exported.INIT, testChannelOrder, counterparty1, []string{testConnectionIDA}, testChannelVersion,
ibctypes.INIT, testChannelOrder, counterparty1, []string{testConnectionIDA}, testChannelVersion,
),
),
},
@ -69,7 +69,7 @@ func TestValidateGenesis(t *testing.T) {
Channels: []IdentifiedChannel{
NewIdentifiedChannel(
testPort1, "testChannel1", NewChannel(
exported.INIT, testChannelOrder, counterparty2, []string{testConnectionIDA}, testChannelVersion,
ibctypes.INIT, testChannelOrder, counterparty2, []string{testConnectionIDA}, testChannelVersion,
),
),
},

View File

@ -6,8 +6,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
@ -15,20 +13,13 @@ import (
var _ sdk.Msg = MsgChannelOpenInit{}
type MsgChannelOpenInit struct {
PortID string `json:"port_id"`
ChannelID string `json:"channel_id"`
Channel Channel `json:"channel"`
Signer sdk.AccAddress `json:"signer"`
}
// NewMsgChannelOpenInit creates a new MsgChannelCloseInit MsgChannelOpenInit
func NewMsgChannelOpenInit(
portID, channelID string, version string, channelOrder exported.Order, connectionHops []string,
portID, channelID string, version string, channelOrder ibctypes.Order, connectionHops []string,
counterpartyPortID, counterpartyChannelID string, signer sdk.AccAddress,
) MsgChannelOpenInit {
counterparty := NewCounterparty(counterpartyPortID, counterpartyChannelID)
channel := NewChannel(exported.INIT, channelOrder, counterparty, connectionHops, version)
channel := NewChannel(ibctypes.INIT, channelOrder, counterparty, connectionHops, version)
return MsgChannelOpenInit{
PortID: portID,
ChannelID: channelID,
@ -71,24 +62,14 @@ func (msg MsgChannelOpenInit) GetSigners() []sdk.AccAddress {
var _ sdk.Msg = MsgChannelOpenTry{}
type MsgChannelOpenTry struct {
PortID string `json:"port_id"`
ChannelID string `json:"channel_id"`
Channel Channel `json:"channel"`
CounterpartyVersion string `json:"counterparty_version"`
ProofInit commitmentexported.Proof `json:"proof_init"`
ProofHeight uint64 `json:"proof_height"`
Signer sdk.AccAddress `json:"signer"`
}
// NewMsgChannelOpenTry creates a new MsgChannelOpenTry instance
func NewMsgChannelOpenTry(
portID, channelID, version string, channelOrder exported.Order, connectionHops []string,
portID, channelID, version string, channelOrder ibctypes.Order, connectionHops []string,
counterpartyPortID, counterpartyChannelID, counterpartyVersion string,
proofInit commitmentexported.Proof, proofHeight uint64, signer sdk.AccAddress,
proofInit commitmenttypes.MerkleProof, proofHeight uint64, signer sdk.AccAddress,
) MsgChannelOpenTry {
counterparty := NewCounterparty(counterpartyPortID, counterpartyChannelID)
channel := NewChannel(exported.INIT, channelOrder, counterparty, connectionHops, version)
channel := NewChannel(ibctypes.INIT, channelOrder, counterparty, connectionHops, version)
return MsgChannelOpenTry{
PortID: portID,
ChannelID: channelID,
@ -121,7 +102,7 @@ func (msg MsgChannelOpenTry) ValidateBasic() error {
if strings.TrimSpace(msg.CounterpartyVersion) == "" {
return sdkerrors.Wrap(ErrInvalidCounterparty, "counterparty version cannot be blank")
}
if msg.ProofInit == nil {
if msg.ProofInit.IsEmpty() {
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof")
}
if err := msg.ProofInit.ValidateBasic(); err != nil {
@ -146,18 +127,9 @@ func (msg MsgChannelOpenTry) GetSigners() []sdk.AccAddress {
var _ sdk.Msg = MsgChannelOpenAck{}
type MsgChannelOpenAck struct {
PortID string `json:"port_id"`
ChannelID string `json:"channel_id"`
CounterpartyVersion string `json:"counterparty_version"`
ProofTry commitmentexported.Proof `json:"proof_try"`
ProofHeight uint64 `json:"proof_height"`
Signer sdk.AccAddress `json:"signer"`
}
// NewMsgChannelOpenAck creates a new MsgChannelOpenAck instance
func NewMsgChannelOpenAck(
portID, channelID string, cpv string, proofTry commitmentexported.Proof, proofHeight uint64,
portID, channelID string, cpv string, proofTry commitmenttypes.MerkleProof, proofHeight uint64,
signer sdk.AccAddress,
) MsgChannelOpenAck {
return MsgChannelOpenAck{
@ -191,7 +163,7 @@ func (msg MsgChannelOpenAck) ValidateBasic() error {
if strings.TrimSpace(msg.CounterpartyVersion) == "" {
return sdkerrors.Wrap(ErrInvalidCounterparty, "counterparty version cannot be blank")
}
if msg.ProofTry == nil {
if msg.ProofTry.IsEmpty() {
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof")
}
if err := msg.ProofTry.ValidateBasic(); err != nil {
@ -216,17 +188,9 @@ func (msg MsgChannelOpenAck) GetSigners() []sdk.AccAddress {
var _ sdk.Msg = MsgChannelOpenConfirm{}
type MsgChannelOpenConfirm struct {
PortID string `json:"port_id"`
ChannelID string `json:"channel_id"`
ProofAck commitmentexported.Proof `json:"proof_ack"`
ProofHeight uint64 `json:"proof_height"`
Signer sdk.AccAddress `json:"signer"`
}
// NewMsgChannelOpenConfirm creates a new MsgChannelOpenConfirm instance
func NewMsgChannelOpenConfirm(
portID, channelID string, proofAck commitmentexported.Proof, proofHeight uint64,
portID, channelID string, proofAck commitmenttypes.MerkleProof, proofHeight uint64,
signer sdk.AccAddress,
) MsgChannelOpenConfirm {
return MsgChannelOpenConfirm{
@ -256,7 +220,7 @@ func (msg MsgChannelOpenConfirm) ValidateBasic() error {
if err := host.DefaultChannelIdentifierValidator(msg.ChannelID); err != nil {
return sdkerrors.Wrap(err, "invalid channel ID")
}
if msg.ProofAck == nil {
if msg.ProofAck.IsEmpty() {
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof")
}
if err := msg.ProofAck.ValidateBasic(); err != nil {
@ -281,14 +245,10 @@ func (msg MsgChannelOpenConfirm) GetSigners() []sdk.AccAddress {
var _ sdk.Msg = MsgChannelCloseInit{}
type MsgChannelCloseInit struct {
PortID string `json:"port_id"`
ChannelID string `json:"channel_id"`
Signer sdk.AccAddress `json:"signer"`
}
// NewMsgChannelCloseInit creates a new MsgChannelCloseInit instance
func NewMsgChannelCloseInit(portID string, channelID string, signer sdk.AccAddress) MsgChannelCloseInit {
func NewMsgChannelCloseInit(
portID string, channelID string, signer sdk.AccAddress,
) MsgChannelCloseInit {
return MsgChannelCloseInit{
PortID: portID,
ChannelID: channelID,
@ -330,17 +290,9 @@ func (msg MsgChannelCloseInit) GetSigners() []sdk.AccAddress {
var _ sdk.Msg = MsgChannelCloseConfirm{}
type MsgChannelCloseConfirm struct {
PortID string `json:"port_id"`
ChannelID string `json:"channel_id"`
ProofInit commitmentexported.Proof `json:"proof_init"`
ProofHeight uint64 `json:"proof_height"`
Signer sdk.AccAddress `json:"signer"`
}
// NewMsgChannelCloseConfirm creates a new MsgChannelCloseConfirm instance
func NewMsgChannelCloseConfirm(
portID, channelID string, proofInit commitmentexported.Proof, proofHeight uint64,
portID, channelID string, proofInit commitmenttypes.MerkleProof, proofHeight uint64,
signer sdk.AccAddress,
) MsgChannelCloseConfirm {
return MsgChannelCloseConfirm{
@ -370,7 +322,7 @@ func (msg MsgChannelCloseConfirm) ValidateBasic() error {
if err := host.DefaultChannelIdentifierValidator(msg.ChannelID); err != nil {
return sdkerrors.Wrap(err, "invalid channel ID")
}
if msg.ProofInit == nil {
if msg.ProofInit.IsEmpty() {
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof")
}
if err := msg.ProofInit.ValidateBasic(); err != nil {
@ -393,18 +345,13 @@ func (msg MsgChannelCloseConfirm) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.Signer}
}
// MsgPacket receives incoming IBC packet
type MsgPacket struct {
Packet `json:"packet" yaml:"packet"`
Proof commitmentexported.Proof `json:"proof" yaml:"proof"`
ProofHeight uint64 `json:"proof_height" yaml:"proof_height"`
Signer sdk.AccAddress `json:"signer" yaml:"signer"`
}
var _ sdk.Msg = MsgPacket{}
// NewMsgPacket constructs new MsgPacket
func NewMsgPacket(packet Packet, proof commitmentexported.Proof, proofHeight uint64, signer sdk.AccAddress) MsgPacket {
func NewMsgPacket(
packet Packet, proof commitmenttypes.MerkleProof, proofHeight uint64,
signer sdk.AccAddress,
) MsgPacket {
return MsgPacket{
Packet: packet,
Proof: proof,
@ -420,7 +367,7 @@ func (msg MsgPacket) Route() string {
// ValidateBasic implements sdk.Msg
func (msg MsgPacket) ValidateBasic() error {
if msg.Proof == nil {
if msg.Proof.IsEmpty() {
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof")
}
if err := msg.Proof.ValidateBasic(); err != nil {
@ -444,7 +391,7 @@ func (msg MsgPacket) GetSignBytes() []byte {
// GetDataSignBytes returns the base64-encoded bytes used for the
// data field when signing the packet.
func (msg MsgPacket) GetDataSignBytes() []byte {
s := "\"" + base64.StdEncoding.EncodeToString(msg.Data) + "\""
s := "\"" + base64.StdEncoding.EncodeToString(msg.Packet.Data) + "\""
return []byte(s)
}
@ -460,17 +407,11 @@ func (msg MsgPacket) Type() string {
var _ sdk.Msg = MsgTimeout{}
// MsgTimeout receives timed-out packet
type MsgTimeout struct {
Packet `json:"packet" yaml:"packet"`
NextSequenceRecv uint64 `json:"next_sequence_recv" yaml:"next_sequence_recv"`
Proof commitmentexported.Proof `json:"proof" yaml:"proof"`
ProofHeight uint64 `json:"proof_height" yaml:"proof_height"`
Signer sdk.AccAddress `json:"signer" yaml:"signer"`
}
// NewMsgTimeout constructs new MsgTimeout
func NewMsgTimeout(packet Packet, nextSequenceRecv uint64, proof commitmentexported.Proof, proofHeight uint64, signer sdk.AccAddress) MsgTimeout {
func NewMsgTimeout(
packet Packet, nextSequenceRecv uint64, proof commitmenttypes.MerkleProof,
proofHeight uint64, signer sdk.AccAddress,
) MsgTimeout {
return MsgTimeout{
Packet: packet,
NextSequenceRecv: nextSequenceRecv,
@ -487,7 +428,7 @@ func (msg MsgTimeout) Route() string {
// ValidateBasic implements sdk.Msg
func (msg MsgTimeout) ValidateBasic() error {
if msg.Proof == nil {
if msg.Proof.IsEmpty() {
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof")
}
if err := msg.Proof.ValidateBasic(); err != nil {
@ -520,17 +461,9 @@ func (msg MsgTimeout) Type() string {
var _ sdk.Msg = MsgAcknowledgement{}
// MsgAcknowledgement receives incoming IBC acknowledgement
type MsgAcknowledgement struct {
Packet `json:"packet" yaml:"packet"`
Acknowledgement []byte `json:"acknowledgement" yaml:"acknowledgement"`
Proof commitmentexported.Proof `json:"proof" yaml:"proof"`
ProofHeight uint64 `json:"proof_height" yaml:"proof_height"`
Signer sdk.AccAddress `json:"signer" yaml:"signer"`
}
// NewMsgAcknowledgement constructs a new MsgAcknowledgement
func NewMsgAcknowledgement(packet Packet, ack []byte, proof commitmentexported.Proof, proofHeight uint64, signer sdk.AccAddress) MsgAcknowledgement {
func NewMsgAcknowledgement(
packet Packet, ack []byte, proof commitmenttypes.MerkleProof, proofHeight uint64, signer sdk.AccAddress) MsgAcknowledgement {
return MsgAcknowledgement{
Packet: packet,
Acknowledgement: ack,
@ -547,7 +480,7 @@ func (msg MsgAcknowledgement) Route() string {
// ValidateBasic implements sdk.Msg
func (msg MsgAcknowledgement) ValidateBasic() error {
if msg.Proof == nil {
if msg.Proof.IsEmpty() {
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "cannot submit an empty proof")
}
if err := msg.Proof.ValidateBasic(); err != nil {

View File

@ -15,9 +15,9 @@ import (
"github.com/cosmos/cosmos-sdk/store/rootmulti"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
// define constants used for testing
@ -42,7 +42,7 @@ var (
invalidShortConnHops = []string{invalidShortConnection}
invalidLongConnHops = []string{invalidLongConnection}
proof = commitmenttypes.MerkleProof{Proof: &merkle.Proof{}}
proof = commitmenttypes.MerkleProof{Proof: &merkle.Proof{Ops: []merkle.ProofOp{{Type: "proof", Key: []byte("key"), Data: []byte("data")}}}}
addr = sdk.AccAddress("testaddr")
)
@ -81,21 +81,21 @@ func TestMsgTestSuite(t *testing.T) {
// TestMsgChannelOpenInit tests ValidateBasic for MsgChannelOpenInit
func (suite *MsgTestSuite) TestMsgChannelOpenInit() {
testMsgs := []MsgChannelOpenInit{
NewMsgChannelOpenInit("testportid", "testchannel", "1.0", exported.ORDERED, connHops, "testcpport", "testcpchannel", addr), // valid msg
NewMsgChannelOpenInit(invalidShortPort, "testchannel", "1.0", exported.ORDERED, connHops, "testcpport", "testcpchannel", addr), // too short port id
NewMsgChannelOpenInit(invalidLongPort, "testchannel", "1.0", exported.ORDERED, connHops, "testcpport", "testcpchannel", addr), // too long port id
NewMsgChannelOpenInit(invalidPort, "testchannel", "1.0", exported.ORDERED, connHops, "testcpport", "testcpchannel", addr), // port id contains non-alpha
NewMsgChannelOpenInit("testportid", invalidShortChannel, "1.0", exported.ORDERED, connHops, "testcpport", "testcpchannel", addr), // too short channel id
NewMsgChannelOpenInit("testportid", invalidLongChannel, "1.0", exported.ORDERED, connHops, "testcpport", "testcpchannel", addr), // too long channel id
NewMsgChannelOpenInit("testportid", invalidChannel, "1.0", exported.ORDERED, connHops, "testcpport", "testcpchannel", addr), // channel id contains non-alpha
NewMsgChannelOpenInit("testportid", "testchannel", "1.0", exported.Order(3), connHops, "testcpport", "testcpchannel", addr), // invalid channel order
NewMsgChannelOpenInit("testportid", "testchannel", "1.0", exported.ORDERED, invalidConnHops, "testcpport", "testcpchannel", addr), // connection hops more than 1
NewMsgChannelOpenInit("testportid", "testchannel", "1.0", exported.UNORDERED, invalidShortConnHops, "testcpport", "testcpchannel", addr), // too short connection id
NewMsgChannelOpenInit("testportid", "testchannel", "1.0", exported.UNORDERED, invalidLongConnHops, "testcpport", "testcpchannel", addr), // too long connection id
NewMsgChannelOpenInit("testportid", "testchannel", "1.0", exported.UNORDERED, []string{invalidConnection}, "testcpport", "testcpchannel", addr), // connection id contains non-alpha
NewMsgChannelOpenInit("testportid", "testchannel", "", exported.UNORDERED, connHops, "testcpport", "testcpchannel", addr), // empty channel version
NewMsgChannelOpenInit("testportid", "testchannel", "1.0", exported.UNORDERED, connHops, invalidPort, "testcpchannel", addr), // invalid counterparty port id
NewMsgChannelOpenInit("testportid", "testchannel", "1.0", exported.UNORDERED, connHops, "testcpport", invalidChannel, addr), // invalid counterparty channel id
NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", addr), // valid msg
NewMsgChannelOpenInit(invalidShortPort, "testchannel", "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", addr), // too short port id
NewMsgChannelOpenInit(invalidLongPort, "testchannel", "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", addr), // too long port id
NewMsgChannelOpenInit(invalidPort, "testchannel", "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", addr), // port id contains non-alpha
NewMsgChannelOpenInit("testportid", invalidShortChannel, "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", addr), // too short channel id
NewMsgChannelOpenInit("testportid", invalidLongChannel, "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", addr), // too long channel id
NewMsgChannelOpenInit("testportid", invalidChannel, "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", addr), // channel id contains non-alpha
NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ibctypes.Order(3), connHops, "testcpport", "testcpchannel", addr), // invalid channel order
NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ibctypes.ORDERED, invalidConnHops, "testcpport", "testcpchannel", addr), // connection hops more than 1
NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ibctypes.UNORDERED, invalidShortConnHops, "testcpport", "testcpchannel", addr), // too short connection id
NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ibctypes.UNORDERED, invalidLongConnHops, "testcpport", "testcpchannel", addr), // too long connection id
NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ibctypes.UNORDERED, []string{invalidConnection}, "testcpport", "testcpchannel", addr), // connection id contains non-alpha
NewMsgChannelOpenInit("testportid", "testchannel", "", ibctypes.UNORDERED, connHops, "testcpport", "testcpchannel", addr), // empty channel version
NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ibctypes.UNORDERED, connHops, invalidPort, "testcpchannel", addr), // invalid counterparty port id
NewMsgChannelOpenInit("testportid", "testchannel", "1.0", ibctypes.UNORDERED, connHops, "testcpport", invalidChannel, addr), // invalid counterparty channel id
}
testCases := []struct {
@ -133,24 +133,23 @@ func (suite *MsgTestSuite) TestMsgChannelOpenInit() {
// TestMsgChannelOpenTry tests ValidateBasic for MsgChannelOpenTry
func (suite *MsgTestSuite) TestMsgChannelOpenTry() {
testMsgs := []MsgChannelOpenTry{
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", exported.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // valid msg
NewMsgChannelOpenTry(invalidShortPort, "testchannel", "1.0", exported.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too short port id
NewMsgChannelOpenTry(invalidLongPort, "testchannel", "1.0", exported.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too long port id
NewMsgChannelOpenTry(invalidPort, "testchannel", "1.0", exported.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // port id contains non-alpha
NewMsgChannelOpenTry("testportid", invalidShortChannel, "1.0", exported.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too short channel id
NewMsgChannelOpenTry("testportid", invalidLongChannel, "1.0", exported.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too long channel id
NewMsgChannelOpenTry("testportid", invalidChannel, "1.0", exported.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // channel id contains non-alpha
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", exported.ORDERED, connHops, "testcpport", "testcpchannel", "", suite.proof, 1, addr), // empty counterparty version
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", exported.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", nil, 1, addr), // empty suite.proof
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", exported.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 0, addr), // suite.proof height is zero
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", exported.Order(4), connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // invalid channel order
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", exported.UNORDERED, invalidConnHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // connection hops more than 1
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", exported.UNORDERED, invalidShortConnHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too short connection id
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", exported.UNORDERED, invalidLongConnHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too long connection id
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", exported.UNORDERED, []string{invalidConnection}, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // connection id contains non-alpha
NewMsgChannelOpenTry("testportid", "testchannel", "", exported.UNORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // empty channel version
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", exported.UNORDERED, connHops, invalidPort, "testcpchannel", "1.0", suite.proof, 1, addr), // invalid counterparty port id
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", exported.UNORDERED, connHops, "testcpport", invalidChannel, "1.0", suite.proof, 1, addr), // invalid counterparty channel id
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // valid msg
NewMsgChannelOpenTry(invalidShortPort, "testchannel", "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too short port id
NewMsgChannelOpenTry(invalidLongPort, "testchannel", "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too long port id
NewMsgChannelOpenTry(invalidPort, "testchannel", "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // port id contains non-alpha
NewMsgChannelOpenTry("testportid", invalidShortChannel, "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too short channel id
NewMsgChannelOpenTry("testportid", invalidLongChannel, "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too long channel id
NewMsgChannelOpenTry("testportid", invalidChannel, "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // channel id contains non-alpha
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", "", suite.proof, 1, addr), // empty counterparty version
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ibctypes.ORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 0, addr), // suite.proof height is zero
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ibctypes.Order(4), connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // invalid channel order
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ibctypes.UNORDERED, invalidConnHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // connection hops more than 1
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ibctypes.UNORDERED, invalidShortConnHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too short connection id
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ibctypes.UNORDERED, invalidLongConnHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // too long connection id
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ibctypes.UNORDERED, []string{invalidConnection}, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // connection id contains non-alpha
NewMsgChannelOpenTry("testportid", "testchannel", "", ibctypes.UNORDERED, connHops, "testcpport", "testcpchannel", "1.0", suite.proof, 1, addr), // empty channel version
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ibctypes.UNORDERED, connHops, invalidPort, "testcpchannel", "1.0", suite.proof, 1, addr), // invalid counterparty port id
NewMsgChannelOpenTry("testportid", "testchannel", "1.0", ibctypes.UNORDERED, connHops, "testcpport", invalidChannel, "1.0", suite.proof, 1, addr), // invalid counterparty channel id
}
testCases := []struct {
@ -166,16 +165,15 @@ func (suite *MsgTestSuite) TestMsgChannelOpenTry() {
{testMsgs[5], false, "too long channel id"},
{testMsgs[6], false, "channel id contains non-alpha"},
{testMsgs[7], false, "empty counterparty version"},
{testMsgs[8], false, "empty proof"},
{testMsgs[9], false, "proof height is zero"},
{testMsgs[10], false, "invalid channel order"},
{testMsgs[11], false, "connection hops more than 1 "},
{testMsgs[12], false, "too short connection id"},
{testMsgs[13], false, "too long connection id"},
{testMsgs[14], false, "connection id contains non-alpha"},
{testMsgs[15], false, "empty channel version"},
{testMsgs[16], false, "invalid counterparty port id"},
{testMsgs[17], false, "invalid counterparty channel id"},
{testMsgs[8], false, "proof height is zero"},
{testMsgs[9], false, "invalid channel order"},
{testMsgs[10], false, "connection hops more than 1 "},
{testMsgs[11], false, "too short connection id"},
{testMsgs[12], false, "too long connection id"},
{testMsgs[13], false, "connection id contains non-alpha"},
{testMsgs[14], false, "empty channel version"},
{testMsgs[15], false, "invalid counterparty port id"},
{testMsgs[16], false, "invalid counterparty channel id"},
}
for i, tc := range testCases {
@ -199,7 +197,6 @@ func (suite *MsgTestSuite) TestMsgChannelOpenAck() {
NewMsgChannelOpenAck("testportid", invalidLongChannel, "1.0", suite.proof, 1, addr), // too long channel id
NewMsgChannelOpenAck("testportid", invalidChannel, "1.0", suite.proof, 1, addr), // channel id contains non-alpha
NewMsgChannelOpenAck("testportid", "testchannel", "", suite.proof, 1, addr), // empty counterparty version
NewMsgChannelOpenAck("testportid", "testchannel", "1.0", nil, 1, addr), // empty proof
NewMsgChannelOpenAck("testportid", "testchannel", "1.0", commitmenttypes.MerkleProof{Proof: nil}, 1, addr), // empty proof
NewMsgChannelOpenAck("testportid", "testchannel", "1.0", suite.proof, 0, addr), // proof height is zero
}
@ -218,8 +215,7 @@ func (suite *MsgTestSuite) TestMsgChannelOpenAck() {
{testMsgs[6], false, "channel id contains non-alpha"},
{testMsgs[7], false, "empty counterparty version"},
{testMsgs[8], false, "empty proof"},
{testMsgs[9], false, "empty proof"},
{testMsgs[10], false, "proof height is zero"},
{testMsgs[9], false, "proof height is zero"},
}
for i, tc := range testCases {
@ -242,7 +238,6 @@ func (suite *MsgTestSuite) TestMsgChannelOpenConfirm() {
NewMsgChannelOpenConfirm("testportid", invalidShortChannel, suite.proof, 1, addr), // too short channel id
NewMsgChannelOpenConfirm("testportid", invalidLongChannel, suite.proof, 1, addr), // too long channel id
NewMsgChannelOpenConfirm("testportid", invalidChannel, suite.proof, 1, addr), // channel id contains non-alpha
NewMsgChannelOpenConfirm("testportid", "testchannel", nil, 1, addr), // empty proof
NewMsgChannelOpenConfirm("testportid", "testchannel", commitmenttypes.MerkleProof{Proof: nil}, 1, addr), // empty proof
NewMsgChannelOpenConfirm("testportid", "testchannel", suite.proof, 0, addr), // proof height is zero
}
@ -260,8 +255,7 @@ func (suite *MsgTestSuite) TestMsgChannelOpenConfirm() {
{testMsgs[5], false, "too long channel id"},
{testMsgs[6], false, "channel id contains non-alpha"},
{testMsgs[7], false, "empty proof"},
{testMsgs[8], false, "empty proof"},
{testMsgs[9], false, "proof height is zero"},
{testMsgs[8], false, "proof height is zero"},
}
for i, tc := range testCases {
@ -320,7 +314,6 @@ func (suite *MsgTestSuite) TestMsgChannelCloseConfirm() {
NewMsgChannelCloseConfirm("testportid", invalidShortChannel, suite.proof, 1, addr), // too short channel id
NewMsgChannelCloseConfirm("testportid", invalidLongChannel, suite.proof, 1, addr), // too long channel id
NewMsgChannelCloseConfirm("testportid", invalidChannel, suite.proof, 1, addr), // channel id contains non-alpha
NewMsgChannelCloseConfirm("testportid", "testchannel", nil, 1, addr), // empty proof
NewMsgChannelCloseConfirm("testportid", "testchannel", commitmenttypes.MerkleProof{Proof: nil}, 1, addr), // empty proof
NewMsgChannelCloseConfirm("testportid", "testchannel", suite.proof, 0, addr), // proof height is zero
}
@ -338,8 +331,7 @@ func (suite *MsgTestSuite) TestMsgChannelCloseConfirm() {
{testMsgs[5], false, "too long channel id"},
{testMsgs[6], false, "channel id contains non-alpha"},
{testMsgs[7], false, "empty proof"},
{testMsgs[8], false, "empty proof"},
{testMsgs[9], false, "proof height is zero"},
{testMsgs[8], false, "proof height is zero"},
}
for i, tc := range testCases {
@ -382,7 +374,7 @@ var (
func TestMsgPacketType(t *testing.T) {
msg := NewMsgPacket(packet, proof, 1, addr1)
require.Equal(t, []byte("testdata"), msg.GetData())
require.Equal(t, []byte("testdata"), msg.Packet.GetData())
}
// TestMsgPacketValidation tests ValidateBasic for MsgPacket
@ -390,8 +382,6 @@ func TestMsgPacketValidation(t *testing.T) {
testMsgs := []MsgPacket{
NewMsgPacket(packet, proof, 1, addr1), // valid msg
NewMsgPacket(packet, proof, 0, addr1), // proof height is zero
NewMsgPacket(packet, nil, 1, addr1), // missing proof
NewMsgPacket(packet, invalidProofs1, 1, addr1), // missing proof
NewMsgPacket(packet, invalidProofs2, 1, addr1), // proof contain empty proof
NewMsgPacket(packet, proof, 1, emptyAddr), // missing signer address
NewMsgPacket(unknownPacket, proof, 1, addr1), // unknown packet
@ -404,11 +394,9 @@ func TestMsgPacketValidation(t *testing.T) {
}{
{testMsgs[0], true, ""},
{testMsgs[1], false, "proof height is zero"},
{testMsgs[2], false, "missing proof"},
{testMsgs[3], false, "missing proof"},
{testMsgs[4], false, "proof contain empty proof"},
{testMsgs[5], false, "missing signer address"},
{testMsgs[6], false, "invalid packet"},
{testMsgs[2], false, "proof contain empty proof"},
{testMsgs[3], false, "missing signer address"},
{testMsgs[4], false, "invalid packet"},
}
for i, tc := range testCases {
@ -427,7 +415,7 @@ func TestMsgPacketGetSignBytes(t *testing.T) {
res := msg.GetSignBytes()
expected := fmt.Sprintf(
`{"type":"ibc/channel/MsgPacket","value":{"packet":{"data":%s,"destination_channel":"testcpchannel","destination_port":"testcpport","sequence":"1","source_channel":"testchannel","source_port":"testportid","timeout_height":"100","timeout_timestamp":"100"},"proof":{"type":"ibc/commitment/MerkleProof","value":{"proof":{"ops":[]}}},"proof_height":"1","signer":"cosmos1w3jhxarpv3j8yvg4ufs4x"}}`,
`{"type":"ibc/channel/MsgPacket","value":{"packet":{"data":%s,"destination_channel":"testcpchannel","destination_port":"testcpport","sequence":"1","source_channel":"testchannel","source_port":"testportid","timeout_height":"100","timeout_timestamp":"100"},"proof":{"proof":{"ops":[{"data":"ZGF0YQ==","key":"a2V5","type":"proof"}]}},"proof_height":"1","signer":"cosmos1w3jhxarpv3j8yvg4ufs4x"}}`,
string(msg.GetDataSignBytes()),
)
require.Equal(t, expected, string(res))
@ -445,12 +433,11 @@ func TestMsgPacketGetSigners(t *testing.T) {
// TestMsgTimeout tests ValidateBasic for MsgTimeout
func (suite *MsgTestSuite) TestMsgTimeout() {
testMsgs := []MsgTimeout{
NewMsgTimeout(packet, 0, proof, 1, addr),
NewMsgTimeout(packet, 0, proof, 0, addr),
NewMsgTimeout(packet, 0, proof, 1, emptyAddr),
NewMsgTimeout(packet, 0, emptyProof, 1, addr),
NewMsgTimeout(unknownPacket, 0, proof, 1, addr),
NewMsgTimeout(packet, 0, invalidProofs1, 1, addr),
NewMsgTimeout(packet, 1, proof, 1, addr),
NewMsgTimeout(packet, 1, proof, 0, addr),
NewMsgTimeout(packet, 1, proof, 1, emptyAddr),
NewMsgTimeout(packet, 1, emptyProof, 1, addr),
NewMsgTimeout(unknownPacket, 1, proof, 1, addr),
}
testCases := []struct {
@ -463,7 +450,6 @@ func (suite *MsgTestSuite) TestMsgTimeout() {
{testMsgs[2], false, "missing signer address"},
{testMsgs[3], false, "cannot submit an empty proof"},
{testMsgs[4], false, "invalid packet"},
{testMsgs[5], false, "cannot submit an invalid proof"},
}
for i, tc := range testCases {
@ -485,7 +471,6 @@ func (suite *MsgTestSuite) TestMsgAcknowledgement() {
NewMsgAcknowledgement(packet, packet.GetData(), emptyProof, 1, addr),
NewMsgAcknowledgement(unknownPacket, packet.GetData(), proof, 1, addr),
NewMsgAcknowledgement(packet, invalidAck, proof, 1, addr),
NewMsgAcknowledgement(packet, packet.GetData(), invalidProofs1, 1, addr),
}
testCases := []struct {
@ -499,7 +484,6 @@ func (suite *MsgTestSuite) TestMsgAcknowledgement() {
{testMsgs[3], false, "cannot submit an empty proof"},
{testMsgs[4], false, "invalid packet"},
{testMsgs[5], false, "invalid acknowledgement"},
{testMsgs[6], false, "cannot submit an invalid proof"},
}
for i, tc := range testCases {

View File

@ -23,22 +23,10 @@ func CommitAcknowledgement(data []byte) []byte {
return tmhash.Sum(data)
}
var _ exported.PacketI = Packet{}
var _ exported.PacketI = (*Packet)(nil)
// Packet defines a type that carries data across different chains through IBC
type Packet struct {
Data []byte `json:"data" yaml:"data"` // Actual opaque bytes transferred directly to the application module
Sequence uint64 `json:"sequence" yaml:"sequence"` // number corresponds to the order of sends and receives, where a Packet with an earlier sequence number must be sent and received before a Packet with a later sequence number.
SourcePort string `json:"source_port" yaml:"source_port"` // identifies the port on the sending chain.
SourceChannel string `json:"source_channel" yaml:"source_channel"` // identifies the channel end on the sending chain.
DestinationPort string `json:"destination_port" yaml:"destination_port"` // identifies the port on the receiving chain.
DestinationChannel string `json:"destination_channel" yaml:"destination_channel"` // identifies the channel end on the receiving chain.
TimeoutHeight uint64 `json:"timeout_height" yaml:"timeout_height"` // block height after which the packet times out
TimeoutTimestamp uint64 `json:"timeout_timestamp" yaml:"timeout_timestamp"` // block timestamp (in nanoseconds) after which the packet times out
}
// NewPacket creates a new Packet instance
// NewPacket creates a new Packet instance. It panics if the provided
// packet data interface is not registered.
func NewPacket(
data []byte,
sequence uint64, sourcePort, sourceChannel,

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,151 @@
syntax = "proto3";
package cosmos_sdk.x.ibc.channel.v1;
option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types";
import "third_party/proto/gogoproto/gogo.proto";
import "x/ibc/23-commitment/types/types.proto";
import "x/ibc/types/types.proto";
// MsgChannelOpenInit defines an sdk.Msg to initialize a channel handshake. It is
// called by a relayer on Chain A.
message MsgChannelOpenInit {
string port_id = 1 [(gogoproto.customname) = "PortID", (gogoproto.moretags) = "yaml:\"port_id\""];
string channel_id = 2 [(gogoproto.customname) = "ChannelID", (gogoproto.moretags) = "yaml:\"channel_id\""];
Channel channel = 3 [(gogoproto.nullable) = false];
bytes signer = 4 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}
// MsgChannelOpenInit defines a msg sent by a Relayer to try to open a channel
// on Chain B.
message MsgChannelOpenTry {
string port_id = 1 [(gogoproto.customname) = "PortID", (gogoproto.moretags) = "yaml:\"port_id\""];
string channel_id = 2 [(gogoproto.customname) = "ChannelID", (gogoproto.moretags) = "yaml:\"channel_id\""];
Channel channel = 3 [(gogoproto.nullable) = false];
string counterparty_version = 4 [(gogoproto.moretags) = "yaml:\"counterparty_version\""];
cosmos_sdk.x.ibc.commitment.v1.MerkleProof proof_init = 5
[(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"proof_init\""];
uint64 proof_height = 6 [(gogoproto.moretags) = "yaml:\"proof_height\""];
bytes signer = 7 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}
// MsgChannelOpenAck defines a msg sent by a Relayer to Chain A to acknowledge
// the change of channel state to TRYOPEN on Chain B.
message MsgChannelOpenAck {
string port_id = 1 [(gogoproto.customname) = "PortID", (gogoproto.moretags) = "yaml:\"port_id\""];
string channel_id = 2 [(gogoproto.customname) = "ChannelID", (gogoproto.moretags) = "yaml:\"channel_id\""];
string counterparty_version = 3 [(gogoproto.moretags) = "yaml:\"counterparty_version\""];
cosmos_sdk.x.ibc.commitment.v1.MerkleProof proof_try = 4
[(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"proof_try\""];
uint64 proof_height = 5 [(gogoproto.moretags) = "yaml:\"proof_height\""];
bytes signer = 6 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}
// MsgChannelOpenConfirm defines a msg sent by a Relayer to Chain B to acknowledge
// the change of channel state to OPEN on Chain A.
message MsgChannelOpenConfirm {
string port_id = 1 [(gogoproto.customname) = "PortID", (gogoproto.moretags) = "yaml:\"port_id\""];
string channel_id = 2 [(gogoproto.customname) = "ChannelID", (gogoproto.moretags) = "yaml:\"channel_id\""];
cosmos_sdk.x.ibc.commitment.v1.MerkleProof proof_ack = 3
[(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"proof_ack\""];
uint64 proof_height = 4 [(gogoproto.moretags) = "yaml:\"proof_height\""];
bytes signer = 5 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}
// MsgChannelOpenConfirm defines a msg sent by a Relayer to Chain A
// to close a channel with Chain B.
message MsgChannelCloseInit {
string port_id = 1 [(gogoproto.customname) = "PortID", (gogoproto.moretags) = "yaml:\"port_id\""];
string channel_id = 2 [(gogoproto.customname) = "ChannelID", (gogoproto.moretags) = "yaml:\"channel_id\""];
bytes signer = 3 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}
// MsgChannelCloseConfirm defines a msg sent by a Relayer to Chain B
// to acknowledge the change of channel state to CLOSED on Chain A.
message MsgChannelCloseConfirm {
string port_id = 1 [(gogoproto.customname) = "PortID", (gogoproto.moretags) = "yaml:\"port_id\""];
string channel_id = 2 [(gogoproto.customname) = "ChannelID", (gogoproto.moretags) = "yaml:\"channel_id\""];
cosmos_sdk.x.ibc.commitment.v1.MerkleProof proof_init = 3
[(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"proof_init\""];
uint64 proof_height = 4 [(gogoproto.moretags) = "yaml:\"proof_height\""];
bytes signer = 5 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}
// MsgPacket receives incoming IBC packet
message MsgPacket {
Packet packet = 1 [(gogoproto.nullable) = false];
cosmos_sdk.x.ibc.commitment.v1.MerkleProof proof = 2 [(gogoproto.nullable) = false];
uint64 proof_height = 3 [(gogoproto.moretags) = "yaml:\"proof_height\""];
bytes signer = 4 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}
// MsgTimeout receives timed-out packet
message MsgTimeout {
Packet packet = 1 [(gogoproto.nullable) = false];
cosmos_sdk.x.ibc.commitment.v1.MerkleProof proof = 2 [(gogoproto.nullable) = false];
uint64 proof_height = 3 [(gogoproto.moretags) = "yaml:\"proof_height\""];
uint64 next_sequence_recv = 4 [(gogoproto.moretags) = "yaml:\"next_sequence_recv\""];
bytes signer = 5 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}
// MsgAcknowledgement receives incoming IBC acknowledgement
message MsgAcknowledgement {
Packet packet = 1 [(gogoproto.nullable) = false];
bytes acknowledgement = 2;
cosmos_sdk.x.ibc.commitment.v1.MerkleProof proof = 3 [(gogoproto.nullable) = false];
uint64 proof_height = 4 [(gogoproto.moretags) = "yaml:\"proof_height\""];
bytes signer = 5 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}
// Channel defines pipeline for exactly-once packet delivery between specific
// modules on separate blockchains, which has at least one end capable of sending
// packets and one end capable of receiving packets.
message Channel {
option (gogoproto.goproto_getters) = false;
// current state of the channel end
cosmos_sdk.x.ibc.v1.State state = 1;
// whether the channel is ordered or unordered
cosmos_sdk.x.ibc.v1.Order ordering = 2;
// counterparty channel end
Counterparty counterparty = 3 [(gogoproto.nullable) = false];
// list of connection identifiers, in order, along which packets sent on this
// channel will travel
repeated string connection_hops = 4 [(gogoproto.moretags) = "yaml:\"connection_hops\""];
// opaque channel version, which is agreed upon during the handshake
string version = 5;
}
// Counterparty defines a channel end counterparty
message Counterparty {
option (gogoproto.goproto_getters) = false;
// port on the counterparty chain which owns the other end of the channel.
string port_id = 1 [(gogoproto.customname) = "PortID", (gogoproto.moretags) = "yaml:\"port_id\""];
// channel end on the counterparty chain
string channel_id = 2 [(gogoproto.customname) = "ChannelID", (gogoproto.moretags) = "yaml:\"channel_id\""];
}
// Packet defines a type that carries data across different chains through IBC
message Packet {
option (gogoproto.goproto_getters) = false;
// number corresponds to the order of sends and receives, where a Packet with
// an earlier sequence number must be sent and received before a Packet with a
// later sequence number.
uint64 sequence = 1;
// identifies the port on the sending chain.
string source_port = 2 [(gogoproto.moretags) = "yaml:\"source_port\""];
// identifies the channel end on the sending chain.
string source_channel = 3 [(gogoproto.moretags) = "yaml:\"source_channel\""];
// identifies the port on the receiving chain.
string destination_port = 4 [(gogoproto.moretags) = "yaml:\"destination_port\""];
// identifies the channel end on the receiving chain.
string destination_channel = 5 [(gogoproto.moretags) = "yaml:\"destination_channel\""];
// actual opaque bytes transferred directly to the application module
bytes data = 6;
// block height after which the packet times out
uint64 timeout_height = 7 [(gogoproto.moretags) = "yaml:\"timeout_height\""];
// block timestamp (in nanoseconds) after which the packet times out
uint64 timeout_timestamp = 8 [(gogoproto.moretags) = "yaml:\"timeout_timestamp\""];
}

View File

@ -26,8 +26,6 @@ var (
ErrPortNotFound = types.ErrPortNotFound
ErrInvalidPort = types.ErrInvalidPort
ErrInvalidRoute = types.ErrInvalidRoute
PortPath = types.PortPath
KeyPort = types.KeyPort
)
type (

View File

@ -31,7 +31,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
// isBounded checks a given port ID is already bounded.
func (k Keeper) isBound(ctx sdk.Context, portID string) bool {
_, ok := k.scopedKeeper.GetCapability(ctx, types.PortPath(portID))
_, ok := k.scopedKeeper.GetCapability(ctx, ibctypes.PortPath(portID))
return ok
}
@ -48,7 +48,7 @@ func (k *Keeper) BindPort(ctx sdk.Context, portID string) *capability.Capability
panic(fmt.Sprintf("port %s is already bound", portID))
}
key, err := k.scopedKeeper.NewCapability(ctx, types.PortPath(portID))
key, err := k.scopedKeeper.NewCapability(ctx, ibctypes.PortPath(portID))
if err != nil {
panic(err.Error())
}
@ -66,12 +66,12 @@ func (k Keeper) Authenticate(ctx sdk.Context, key *capability.Capability, portID
panic(err.Error())
}
return k.scopedKeeper.AuthenticateCapability(ctx, key, types.PortPath(portID))
return k.scopedKeeper.AuthenticateCapability(ctx, key, ibctypes.PortPath(portID))
}
// LookupModuleByPort will return the IBCModule along with the capability associated with a given portID
func (k Keeper) LookupModuleByPort(ctx sdk.Context, portID string) (string, *capability.Capability, bool) {
modules, cap, ok := k.scopedKeeper.LookupModules(ctx, types.PortPath(portID))
modules, cap, ok := k.scopedKeeper.LookupModules(ctx, ibctypes.PortPath(portID))
if !ok {
return "", nil, false
}

View File

@ -8,7 +8,6 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/ibc/05-port/keeper"
@ -22,7 +21,6 @@ var (
type KeeperTestSuite struct {
suite.Suite
cdc *codec.Codec
ctx sdk.Context
keeper *keeper.Keeper
}
@ -31,7 +29,6 @@ func (suite *KeeperTestSuite) SetupTest() {
isCheckTx := false
app := simapp.Setup(isCheckTx)
suite.cdc = app.Codec()
suite.ctx = app.BaseApp.NewContext(isCheckTx, abci.Header{})
suite.keeper = &app.IBCKeeper.PortKeeper
}

View File

@ -1,9 +1,5 @@
package types
import (
"fmt"
)
const (
// SubModuleName defines the IBC port name
SubModuleName = "port"
@ -17,15 +13,3 @@ const (
// QuerierRoute is the querier route for IBC ports
QuerierRoute = SubModuleName
)
// The following paths are the keys to the store as defined in https://github.com/cosmos/ics/tree/master/spec/ics-005-port-allocation#store-paths
// PortPath defines the path under which ports paths are stored
func PortPath(portID string) string {
return fmt.Sprintf("ports/%s", portID)
}
// KeyPort returns the store key for a particular port
func KeyPort(portID string) []byte {
return []byte(PortPath(portID))
}

View File

@ -4,8 +4,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/capability"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
// IBCModule defines an interface that implements all the callbacks
@ -13,7 +13,7 @@ import (
type IBCModule interface {
OnChanOpenInit(
ctx sdk.Context,
order channelexported.Order,
order ibctypes.Order,
connectionHops []string,
portID string,
channelID string,
@ -24,7 +24,7 @@ type IBCModule interface {
OnChanOpenTry(
ctx sdk.Context,
order channelexported.Order,
order ibctypes.Order,
connectionHops []string,
portID,
channelID string,

View File

@ -11,6 +11,7 @@ import (
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported"
@ -168,7 +169,7 @@ func (cs ClientState) VerifyClientConsensusState(
// VerifyConnectionState verifies a proof of the connection state of the
// specified connection end stored on the target machine.
func (cs ClientState) VerifyConnectionState(
cdc *codec.Codec,
cdc codec.Marshaler,
height uint64,
prefix commitmentexported.Prefix,
proof commitmentexported.Proof,
@ -185,7 +186,12 @@ func (cs ClientState) VerifyConnectionState(
return err
}
bz, err := cdc.MarshalBinaryBare(connectionEnd)
connection, ok := connectionEnd.(connectiontypes.ConnectionEnd)
if !ok {
return fmt.Errorf("invalid connection type %T", connectionEnd)
}
bz, err := cdc.MarshalBinaryBare(&connection)
if err != nil {
return err
}
@ -200,7 +206,7 @@ func (cs ClientState) VerifyConnectionState(
// VerifyChannelState verifies a proof of the channel state of the specified
// channel end, under the specified port, stored on the target machine.
func (cs ClientState) VerifyChannelState(
cdc *codec.Codec,
cdc codec.Marshaler,
height uint64,
prefix commitmentexported.Prefix,
proof commitmentexported.Proof,
@ -218,7 +224,12 @@ func (cs ClientState) VerifyChannelState(
return err
}
bz, err := cdc.MarshalBinaryBare(channel)
channelEnd, ok := channel.(channeltypes.Channel)
if !ok {
return fmt.Errorf("invalid channel type %T", channel)
}
bz, err := cdc.MarshalBinaryBare(&channelEnd)
if err != nil {
return err
}

View File

@ -2,12 +2,11 @@ package types_test
import (
connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection"
connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
const (
@ -129,7 +128,7 @@ func (suite *TendermintTestSuite) TestVerifyClientConsensusState() {
tc := tc
err := tc.clientState.VerifyClientConsensusState(
suite.cdc, tc.consensusState.Root, height, "chainA", tc.consensusState.GetHeight(), tc.prefix, tc.proof, tc.consensusState,
suite.aminoCdc, tc.consensusState.Root, height, "chainA", tc.consensusState.GetHeight(), tc.prefix, tc.proof, tc.consensusState,
)
if tc.expPass {
@ -142,7 +141,7 @@ func (suite *TendermintTestSuite) TestVerifyClientConsensusState() {
func (suite *TendermintTestSuite) TestVerifyConnectionState() {
counterparty := connection.NewCounterparty("clientB", testConnectionID, commitmenttypes.NewMerklePrefix([]byte("ibc")))
conn := connection.NewConnectionEnd(connectionexported.OPEN, testConnectionID, "clientA", counterparty, []string{"1.0.0"})
conn := connection.NewConnectionEnd(ibctypes.OPEN, testConnectionID, "clientA", counterparty, []string{"1.0.0"})
testCases := []struct {
name string
@ -225,7 +224,7 @@ func (suite *TendermintTestSuite) TestVerifyConnectionState() {
func (suite *TendermintTestSuite) TestVerifyChannelState() {
counterparty := channel.NewCounterparty(testPortID, testChannelID)
ch := channel.NewChannel(channelexported.OPEN, channelexported.ORDERED, counterparty, []string{testConnectionID}, "1.0.0")
ch := channel.NewChannel(ibctypes.OPEN, ibctypes.ORDERED, counterparty, []string{testConnectionID}, "1.0.0")
testCases := []struct {
name string
@ -295,7 +294,7 @@ func (suite *TendermintTestSuite) TestVerifyChannelState() {
tc := tc
err := tc.clientState.VerifyChannelState(
suite.cdc, height, tc.prefix, tc.proof, testPortID, testChannelID, tc.channel, tc.consensusState,
suite.cdc, height, tc.prefix, tc.proof, testPortID, testChannelID, &tc.channel, tc.consensusState,
)
if tc.expPass {

View File

@ -9,8 +9,8 @@ import (
tmtypes "github.com/tendermint/tendermint/types"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
)
const (
@ -24,18 +24,20 @@ const (
type TendermintTestSuite struct {
suite.Suite
cdc *codec.Codec
privVal tmtypes.PrivValidator
valSet *tmtypes.ValidatorSet
header ibctmtypes.Header
now time.Time
aminoCdc *codec.Codec
cdc codec.Marshaler
privVal tmtypes.PrivValidator
valSet *tmtypes.ValidatorSet
header ibctmtypes.Header
now time.Time
}
func (suite *TendermintTestSuite) SetupTest() {
suite.cdc = codec.New()
codec.RegisterCrypto(suite.cdc)
ibctmtypes.RegisterCodec(suite.cdc)
commitmenttypes.RegisterCodec(suite.cdc)
checkTx := false
app := simapp.Setup(checkTx)
suite.aminoCdc = app.Codec()
suite.cdc = app.AppCodec()
suite.now = time.Date(2020, 1, 2, 0, 0, 0, 0, time.UTC)
suite.privVal = tmtypes.NewMockPV()

View File

@ -14,7 +14,9 @@ import (
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
commitmentexported "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
@ -125,7 +127,7 @@ func (cs ClientState) VerifyClientConsensusState(
// VerifyConnectionState verifies a proof of the connection state of the
// specified connection end stored locally.
func (cs ClientState) VerifyConnectionState(
cdc *codec.Codec,
cdc codec.Marshaler,
_ uint64,
prefix commitmentexported.Prefix,
_ commitmentexported.Proof,
@ -143,12 +145,13 @@ func (cs ClientState) VerifyConnectionState(
return sdkerrors.Wrapf(clienttypes.ErrFailedConnectionStateVerification, "not found for path %s", path)
}
var prevConnection connectionexported.ConnectionI
if err := cdc.UnmarshalBinaryBare(bz, &prevConnection); err != nil {
var prevConnection connectiontypes.ConnectionEnd
err = cdc.UnmarshalBinaryBare(bz, &prevConnection)
if err != nil {
return err
}
if connectionEnd != prevConnection {
if connectionEnd != &prevConnection {
return sdkerrors.Wrapf(
clienttypes.ErrFailedConnectionStateVerification,
"connection end ≠ previous stored connection: \n%v\n≠\n%v", connectionEnd, prevConnection,
@ -161,7 +164,7 @@ func (cs ClientState) VerifyConnectionState(
// VerifyChannelState verifies a proof of the channel state of the specified
// channel end, under the specified port, stored on the local machine.
func (cs ClientState) VerifyChannelState(
cdc *codec.Codec,
cdc codec.Marshaler,
_ uint64,
prefix commitmentexported.Prefix,
_ commitmentexported.Proof,
@ -180,11 +183,13 @@ func (cs ClientState) VerifyChannelState(
return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "not found for path %s", path)
}
var prevChannel channelexported.ChannelI
if err := cdc.UnmarshalBinaryBare(bz, &prevChannel); err != nil {
var prevChannel channeltypes.Channel
err = cdc.UnmarshalBinaryBare(bz, &prevChannel)
if err != nil {
return err
}
if channel != prevChannel {
if channel != &prevChannel {
return sdkerrors.Wrapf(
clienttypes.ErrFailedChannelStateVerification,
"channel end ≠ previous stored channel: \n%v\n≠\n%v", channel, prevChannel,

View File

@ -2,11 +2,10 @@ package types_test
import (
connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection"
connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
const (
@ -81,7 +80,7 @@ func (suite *LocalhostTestSuite) TestVerifyClientConsensusState() {
tc := tc
err := tc.clientState.VerifyClientConsensusState(
suite.cdc, nil, height, "chainA", 0, tc.prefix, tc.proof, nil,
suite.aminoCdc, nil, height, "chainA", 0, tc.prefix, tc.proof, nil,
// suite.cdc, height, tc.prefix, tc.proof, nil,
)
@ -96,7 +95,7 @@ func (suite *LocalhostTestSuite) TestVerifyClientConsensusState() {
func (suite *LocalhostTestSuite) TestVerifyConnectionState() {
counterparty := connection.NewCounterparty("clientB", testConnectionID, commitmenttypes.NewMerklePrefix([]byte("ibc")))
conn := connection.NewConnectionEnd(connectionexported.OPEN, testConnectionID, "clientA", counterparty, []string{"1.0.0"})
conn := connection.NewConnectionEnd(ibctypes.OPEN, testConnectionID, "clientA", counterparty, []string{"1.0.0"})
testCases := []struct {
name string
@ -127,7 +126,7 @@ func (suite *LocalhostTestSuite) TestVerifyConnectionState() {
tc := tc
err := tc.clientState.VerifyConnectionState(
suite.cdc, height, tc.prefix, tc.proof, testConnectionID, tc.connection, nil,
suite.cdc, height, tc.prefix, tc.proof, testConnectionID, &tc.connection, nil,
)
if tc.expPass {
@ -140,7 +139,7 @@ func (suite *LocalhostTestSuite) TestVerifyConnectionState() {
func (suite *LocalhostTestSuite) TestVerifyChannelState() {
counterparty := channel.NewCounterparty(testPortID, testChannelID)
ch := channel.NewChannel(channelexported.OPEN, channelexported.ORDERED, counterparty, []string{testConnectionID}, "1.0.0")
ch := channel.NewChannel(ibctypes.OPEN, ibctypes.ORDERED, counterparty, []string{testConnectionID}, "1.0.0")
testCases := []struct {
name string
@ -178,7 +177,7 @@ func (suite *LocalhostTestSuite) TestVerifyChannelState() {
tc := tc
err := tc.clientState.VerifyChannelState(
suite.cdc, height, tc.prefix, tc.proof, testPortID, testChannelID, tc.channel, nil,
suite.cdc, height, tc.prefix, tc.proof, testPortID, testChannelID, &tc.channel, nil,
)
if tc.expPass {

View File

@ -8,9 +8,9 @@ import (
dbm "github.com/tendermint/tm-db"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/store/cachekv"
"github.com/cosmos/cosmos-sdk/store/dbadapter"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
)
const (
@ -20,14 +20,17 @@ const (
type LocalhostTestSuite struct {
suite.Suite
cdc *codec.Codec
store *cachekv.Store
aminoCdc *codec.Codec
cdc codec.Marshaler
store *cachekv.Store
}
func (suite *LocalhostTestSuite) SetupTest() {
suite.cdc = codec.New()
codec.RegisterCrypto(suite.cdc)
commitmenttypes.RegisterCodec(suite.cdc)
checkTx := false
app := simapp.Setup(checkTx)
suite.aminoCdc = app.Codec()
suite.cdc = app.AppCodec()
mem := dbadapter.Store{DB: dbm.NewMemDB()}
suite.store = cachekv.NewStore(mem)

View File

@ -37,6 +37,7 @@ var (
GetDenomPrefix = types.GetDenomPrefix
GetModuleAccountName = types.GetModuleAccountName
NewMsgTransfer = types.NewMsgTransfer
RegisterInterfaces = types.RegisterInterfaces
// variable aliases
ModuleCdc = types.ModuleCdc

View File

@ -20,7 +20,7 @@ func NewHandler(k Keeper) sdk.Handler {
// See createOutgoingPacket in spec:https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#packet-relay
func handleMsgTransfer(ctx sdk.Context, k Keeper, msg MsgTransfer) (*sdk.Result, error) {
if err := k.SendTransfer(
ctx, msg.SourcePort, msg.SourceChannel, msg.DestHeight, msg.Amount, msg.Sender, msg.Receiver,
ctx, msg.SourcePort, msg.SourceChannel, msg.DestinationHeight, msg.Amount, msg.Sender, msg.Receiver,
); err != nil {
return nil, err
}

View File

@ -6,6 +6,7 @@ import (
"time"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
tmtypes "github.com/tendermint/tendermint/types"
@ -13,9 +14,7 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
transfer "github.com/cosmos/cosmos-sdk/x/ibc/20-transfer"
@ -85,8 +84,8 @@ func (suite *HandlerTestSuite) TestHandleMsgTransfer() {
// Setup channel from A to B
suite.chainA.CreateClient(suite.chainB)
suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, connectionexported.OPEN)
suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, channelexported.OPEN, channelexported.ORDERED, testConnection)
suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, ibctypes.OPEN)
suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnection)
res, err = handler(ctx, msg)
suite.Require().Error(err)
@ -158,7 +157,7 @@ func NewTestChain(clientID string) *TestChain {
// Creates simple context for testing purposes
func (chain *TestChain) GetContext() sdk.Context {
return chain.App.BaseApp.NewContext(false, abci.Header{ChainID: chain.Header.ChainID, Height: chain.Header.Height})
return chain.App.BaseApp.NewContext(false, abci.Header{ChainID: chain.Header.SignedHeader.Header.ChainID, Height: chain.Header.SignedHeader.Header.Height})
}
// createClient will create a client for clientChain on targetChain
@ -167,7 +166,7 @@ func (chain *TestChain) CreateClient(client *TestChain) error {
// Commit and create a new block on appTarget to get a fresh CommitID
client.App.Commit()
commitID := client.App.LastCommitID()
client.App.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: client.Header.Height, Time: client.Header.Time}})
client.App.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: client.Header.SignedHeader.Header.Height, Time: client.Header.Time}})
// Set HistoricalInfo on client chain after Commit
ctxClient := client.GetContext()
@ -183,7 +182,7 @@ func (chain *TestChain) CreateClient(client *TestChain) error {
},
Valset: validators,
}
client.App.StakingKeeper.SetHistoricalInfo(ctxClient, client.Header.Height, histInfo)
client.App.StakingKeeper.SetHistoricalInfo(ctxClient, client.Header.SignedHeader.Header.Height, histInfo)
// Create target ctx
ctxTarget := chain.GetContext()
@ -229,7 +228,7 @@ func (chain *TestChain) updateClient(client *TestChain) {
commitID := client.App.LastCommitID()
client.Header = nextHeader(client)
client.App.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: client.Header.Height, Time: client.Header.Time}})
client.App.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: client.Header.SignedHeader.Header.Height, Time: client.Header.Time}})
// Set HistoricalInfo on client chain after Commit
ctxClient := client.GetContext()
@ -245,17 +244,17 @@ func (chain *TestChain) updateClient(client *TestChain) {
},
Valset: validators,
}
client.App.StakingKeeper.SetHistoricalInfo(ctxClient, client.Header.Height, histInfo)
client.App.StakingKeeper.SetHistoricalInfo(ctxClient, client.Header.SignedHeader.Header.Height, histInfo)
consensusState := ibctmtypes.ConsensusState{
Height: uint64(client.Header.Height),
Height: uint64(client.Header.SignedHeader.Header.Height),
Timestamp: client.Header.Time,
Root: commitmenttypes.NewMerkleRoot(commitID.Hash),
ValidatorSet: client.Vals,
}
chain.App.IBCKeeper.ClientKeeper.SetClientConsensusState(
ctxTarget, client.ClientID, uint64(client.Header.Height), consensusState,
ctxTarget, client.ClientID, uint64(client.Header.SignedHeader.Header.Height), consensusState,
)
chain.App.IBCKeeper.ClientKeeper.SetClientState(
ctxTarget, ibctmtypes.NewClientState(client.ClientID, trustingPeriod, ubdPeriod, maxClockDrift, client.Header),
@ -276,9 +275,9 @@ func (chain *TestChain) updateClient(client *TestChain) {
func (chain *TestChain) createConnection(
connID, counterpartyConnID, clientID, counterpartyClientID string,
state connectionexported.State,
state ibctypes.State,
) connectiontypes.ConnectionEnd {
counterparty := connectiontypes.NewCounterparty(counterpartyClientID, counterpartyConnID, chain.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix())
counterparty := connectiontypes.NewCounterparty(counterpartyClientID, counterpartyConnID, commitmenttypes.NewMerklePrefix(chain.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes()))
connection := connectiontypes.ConnectionEnd{
State: state,
ClientID: clientID,
@ -293,7 +292,7 @@ func (chain *TestChain) createConnection(
// nolint: unused
func (chain *TestChain) createChannel(
portID, channelID, counterpartyPortID, counterpartyChannelID string,
state channelexported.State, order channelexported.Order, connectionID string,
state ibctypes.State, order ibctypes.Order, connectionID string,
) channeltypes.Channel {
counterparty := channeltypes.NewCounterparty(counterpartyPortID, counterpartyChannelID)
channel := channeltypes.NewChannel(state, order, counterparty,
@ -305,6 +304,6 @@ func (chain *TestChain) createChannel(
}
func nextHeader(chain *TestChain) ibctmtypes.Header {
return ibctmtypes.CreateTestHeader(chain.Header.ChainID, chain.Header.Height+1,
return ibctmtypes.CreateTestHeader(chain.Header.SignedHeader.Header.ChainID, chain.Header.SignedHeader.Header.Height+1,
chain.Header.Time.Add(time.Minute), chain.Vals, chain.Signers)
}

View File

@ -12,7 +12,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/capability"
channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
porttypes "github.com/cosmos/cosmos-sdk/x/ibc/05-port/types"
"github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
@ -30,7 +29,7 @@ const (
// Keeper defines the IBC transfer keeper
type Keeper struct {
storeKey sdk.StoreKey
cdc *codec.Codec
cdc codec.Marshaler
channelKeeper types.ChannelKeeper
portKeeper types.PortKeeper
@ -41,7 +40,7 @@ type Keeper struct {
// NewKeeper creates a new IBC transfer Keeper instance
func NewKeeper(
cdc *codec.Codec, key sdk.StoreKey,
cdc codec.Marshaler, key sdk.StoreKey,
channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper,
authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, scopedKeeper capability.ScopedKeeper,
) Keeper {
@ -96,7 +95,7 @@ func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string) error {
// IsBound checks if the transfer module is already bound to the desired port
func (k Keeper) IsBound(ctx sdk.Context, portID string) bool {
_, ok := k.scopedKeeper.GetCapability(ctx, porttypes.PortPath(portID))
_, ok := k.scopedKeeper.GetCapability(ctx, ibctypes.PortPath(portID))
return ok
}
@ -108,7 +107,7 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) error {
store.Set([]byte(types.PortKey), []byte(portID))
cap := k.portKeeper.BindPort(ctx, portID)
return k.ClaimCapability(ctx, cap, porttypes.PortPath(portID))
return k.ClaimCapability(ctx, cap, ibctypes.PortPath(portID))
}
// GetPort returns the portID for the transfer module. Used in ExportGenesis

View File

@ -13,9 +13,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
"github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types"
@ -135,7 +133,7 @@ func NewTestChain(clientID string) *TestChain {
// Creates simple context for testing purposes
func (chain *TestChain) GetContext() sdk.Context {
return chain.App.BaseApp.NewContext(false, abci.Header{ChainID: chain.Header.ChainID, Height: chain.Header.Height})
return chain.App.BaseApp.NewContext(false, abci.Header{ChainID: chain.Header.SignedHeader.Header.ChainID, Height: chain.Header.SignedHeader.Header.Height})
}
// createClient will create a client for clientChain on targetChain
@ -144,7 +142,7 @@ func (chain *TestChain) CreateClient(client *TestChain) error {
// Commit and create a new block on appTarget to get a fresh CommitID
client.App.Commit()
commitID := client.App.LastCommitID()
client.App.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: client.Header.Height, Time: client.Header.Time}})
client.App.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: client.Header.SignedHeader.Header.Height, Time: client.Header.Time}})
// Set HistoricalInfo on client chain after Commit
ctxClient := client.GetContext()
@ -160,7 +158,7 @@ func (chain *TestChain) CreateClient(client *TestChain) error {
},
Valset: validators,
}
client.App.StakingKeeper.SetHistoricalInfo(ctxClient, client.Header.Height, histInfo)
client.App.StakingKeeper.SetHistoricalInfo(ctxClient, client.Header.SignedHeader.Header.Height, histInfo)
// Create target ctx
ctxTarget := chain.GetContext()
@ -206,7 +204,7 @@ func (chain *TestChain) updateClient(client *TestChain) {
commitID := client.App.LastCommitID()
client.Header = nextHeader(client)
client.App.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: client.Header.Height, Time: client.Header.Time}})
client.App.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: client.Header.SignedHeader.Header.Height, Time: client.Header.Time}})
// Set HistoricalInfo on client chain after Commit
ctxClient := client.GetContext()
@ -222,17 +220,17 @@ func (chain *TestChain) updateClient(client *TestChain) {
},
Valset: validators,
}
client.App.StakingKeeper.SetHistoricalInfo(ctxClient, client.Header.Height, histInfo)
client.App.StakingKeeper.SetHistoricalInfo(ctxClient, client.Header.SignedHeader.Header.Height, histInfo)
consensusState := ibctmtypes.ConsensusState{
Height: uint64(client.Header.Height),
Height: client.Header.GetHeight(),
Timestamp: client.Header.Time,
Root: commitmenttypes.NewMerkleRoot(commitID.Hash),
ValidatorSet: client.Vals,
}
chain.App.IBCKeeper.ClientKeeper.SetClientConsensusState(
ctxTarget, client.ClientID, uint64(client.Header.Height), consensusState,
ctxTarget, client.ClientID, client.Header.GetHeight(), consensusState,
)
chain.App.IBCKeeper.ClientKeeper.SetClientState(
ctxTarget, ibctmtypes.NewClientState(client.ClientID, trustingPeriod, ubdPeriod, maxClockDrift, client.Header),
@ -253,9 +251,9 @@ func (chain *TestChain) updateClient(client *TestChain) {
func (chain *TestChain) createConnection(
connID, counterpartyConnID, clientID, counterpartyClientID string,
state connectionexported.State,
state ibctypes.State,
) connectiontypes.ConnectionEnd {
counterparty := connectiontypes.NewCounterparty(counterpartyClientID, counterpartyConnID, chain.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix())
counterparty := connectiontypes.NewCounterparty(counterpartyClientID, counterpartyConnID, commitmenttypes.NewMerklePrefix(chain.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes()))
connection := connectiontypes.ConnectionEnd{
State: state,
ClientID: clientID,
@ -269,7 +267,7 @@ func (chain *TestChain) createConnection(
func (chain *TestChain) createChannel(
portID, channelID, counterpartyPortID, counterpartyChannelID string,
state channelexported.State, order channelexported.Order, connectionID string,
state ibctypes.State, order ibctypes.Order, connectionID string,
) channeltypes.Channel {
counterparty := channeltypes.NewCounterparty(counterpartyPortID, counterpartyChannelID)
channel := channeltypes.NewChannel(state, order, counterparty,
@ -281,6 +279,6 @@ func (chain *TestChain) createChannel(
}
func nextHeader(chain *TestChain) ibctmtypes.Header {
return ibctmtypes.CreateTestHeader(chain.Header.ChainID, chain.Header.Height+1,
return ibctmtypes.CreateTestHeader(chain.Header.SignedHeader.Header.ChainID, chain.Header.SignedHeader.Header.Height+1,
chain.Header.Time.Add(time.Minute), chain.Vals, chain.Signers)
}

View File

@ -5,7 +5,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
"github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
@ -31,16 +31,16 @@ func (k Keeper) SendTransfer(
) error {
sourceChannelEnd, found := k.channelKeeper.GetChannel(ctx, sourcePort, sourceChannel)
if !found {
return sdkerrors.Wrap(channel.ErrChannelNotFound, sourceChannel)
return sdkerrors.Wrap(channeltypes.ErrChannelNotFound, sourceChannel)
}
destinationPort := sourceChannelEnd.Counterparty.PortID
destinationChannel := sourceChannelEnd.Counterparty.ChannelID
destinationPort := sourceChannelEnd.GetCounterparty().GetPortID()
destinationChannel := sourceChannelEnd.GetCounterparty().GetChannelID()
// get the next sequence
sequence, found := k.channelKeeper.GetNextSequenceSend(ctx, sourcePort, sourceChannel)
if !found {
return channel.ErrSequenceSendNotFound
return channeltypes.ErrSequenceSendNotFound
}
return k.createOutgoingPacket(ctx, sequence, sourcePort, sourceChannel, destinationPort, destinationChannel, destHeight, amount, sender, receiver)
@ -59,7 +59,7 @@ func (k Keeper) createOutgoingPacket(
) error {
channelCap, ok := k.scopedKeeper.GetCapability(ctx, ibctypes.ChannelCapabilityPath(sourcePort, sourceChannel))
if !ok {
return sdkerrors.Wrap(channel.ErrChannelCapabilityNotFound, "module does not own channel capability")
return sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability")
}
// NOTE:
// - Coins transferred from the destination chain should have their denomination
@ -127,7 +127,7 @@ func (k Keeper) createOutgoingPacket(
amount, sender.String(), receiver,
)
packet := channel.NewPacket(
packet := channeltypes.NewPacket(
packetData.GetBytes(),
seq,
sourcePort,
@ -141,7 +141,7 @@ func (k Keeper) createOutgoingPacket(
return k.channelKeeper.SendPacket(ctx, channelCap, packet)
}
func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channel.Packet, data types.FungibleTokenPacketData) error {
func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data types.FungibleTokenPacketData) error {
// NOTE: packet data type already checked in handler.go
if len(data.Amount) != 1 {
@ -190,18 +190,18 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channel.Packet, data types.
return k.bankKeeper.SendCoins(ctx, escrowAddress, receiver, coins)
}
func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, packet channel.Packet, data types.FungibleTokenPacketData, ack types.FungibleTokenPacketAcknowledgement) error {
func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, packet channeltypes.Packet, data types.FungibleTokenPacketData, ack types.FungibleTokenPacketAcknowledgement) error {
if !ack.Success {
return k.refundPacketAmount(ctx, packet, data)
}
return nil
}
func (k Keeper) OnTimeoutPacket(ctx sdk.Context, packet channel.Packet, data types.FungibleTokenPacketData) error {
func (k Keeper) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet, data types.FungibleTokenPacketData) error {
return k.refundPacketAmount(ctx, packet, data)
}
func (k Keeper) refundPacketAmount(ctx sdk.Context, packet channel.Packet, data types.FungibleTokenPacketData) error {
func (k Keeper) refundPacketAmount(ctx sdk.Context, packet channeltypes.Packet, data types.FungibleTokenPacketData) error {
// NOTE: packet data type already checked in handler.go
if len(data.Amount) != 1 {

View File

@ -5,8 +5,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
"github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
@ -27,8 +25,8 @@ func (suite *KeeperTestSuite) TestSendTransfer() {
func() {
suite.chainA.App.BankKeeper.AddCoins(suite.chainA.GetContext(), testAddr1, testCoins)
suite.chainA.CreateClient(suite.chainB)
suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, connectionexported.OPEN)
suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, channelexported.OPEN, channelexported.ORDERED, testConnection)
suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, ibctypes.OPEN)
suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnection)
suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainA.GetContext(), testPort1, testChannel1, 1)
}, true, true},
{"successful transfer from external chain", prefixCoins,
@ -37,8 +35,8 @@ func (suite *KeeperTestSuite) TestSendTransfer() {
_, err := suite.chainA.App.BankKeeper.AddCoins(suite.chainA.GetContext(), testAddr1, prefixCoins)
suite.Require().NoError(err)
suite.chainA.CreateClient(suite.chainB)
suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, connectionexported.OPEN)
suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, channelexported.OPEN, channelexported.ORDERED, testConnection)
suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, ibctypes.OPEN)
suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnection)
suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainA.GetContext(), testPort1, testChannel1, 1)
}, false, true},
{"source channel not found", testCoins,
@ -46,32 +44,32 @@ func (suite *KeeperTestSuite) TestSendTransfer() {
{"next seq send not found", testCoins,
func() {
suite.chainA.CreateClient(suite.chainB)
suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, connectionexported.OPEN)
suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, channelexported.OPEN, channelexported.ORDERED, testConnection)
suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, ibctypes.OPEN)
suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnection)
}, true, false},
// createOutgoingPacket tests
// - source chain
{"send coins failed", testCoins,
func() {
suite.chainA.CreateClient(suite.chainB)
suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, connectionexported.OPEN)
suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, channelexported.OPEN, channelexported.ORDERED, testConnection)
suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, ibctypes.OPEN)
suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnection)
suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainA.GetContext(), testPort1, testChannel1, 1)
}, true, false},
// - receiving chain
{"send from module account failed", testCoins,
func() {
suite.chainA.CreateClient(suite.chainB)
suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, connectionexported.OPEN)
suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, channelexported.OPEN, channelexported.ORDERED, testConnection)
suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, ibctypes.OPEN)
suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnection)
suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainA.GetContext(), testPort1, testChannel1, 1)
}, false, false},
{"channel capability not found", testCoins,
func() {
suite.chainA.App.BankKeeper.AddCoins(suite.chainA.GetContext(), testAddr1, testCoins)
suite.chainA.CreateClient(suite.chainB)
suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, connectionexported.OPEN)
suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, channelexported.OPEN, channelexported.ORDERED, testConnection)
suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, ibctypes.OPEN)
suite.chainA.createChannel(testPort1, testChannel1, testPort2, testChannel2, ibctypes.OPEN, ibctypes.ORDERED, testConnection)
suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainA.GetContext(), testPort1, testChannel1, 1)
// Release channel capability
cap, _ := suite.chainA.App.ScopedTransferKeeper.GetCapability(suite.chainA.GetContext(), capName)

View File

@ -11,12 +11,12 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/capability"
channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
port "github.com/cosmos/cosmos-sdk/x/ibc/05-port"
porttypes "github.com/cosmos/cosmos-sdk/x/ibc/05-port/types"
@ -71,6 +71,11 @@ func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetQueryCmd(cdc, QuerierRoute)
}
// RegisterInterfaceTypes registers module concrete types into protobuf Any.
func (AppModuleBasic) RegisterInterfaceTypes(registry cdctypes.InterfaceRegistry) {
RegisterInterfaces(registry)
}
// AppModule represents the AppModule for this module
type AppModule struct {
AppModuleBasic
@ -138,7 +143,7 @@ func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.V
// Implement IBCModule callbacks
func (am AppModule) OnChanOpenInit(
ctx sdk.Context,
order channelexported.Order,
order ibctypes.Order,
connectionHops []string,
portID string,
channelID string,
@ -169,7 +174,7 @@ func (am AppModule) OnChanOpenInit(
func (am AppModule) OnChanOpenTry(
ctx sdk.Context,
order channelexported.Order,
order ibctypes.Order,
connectionHops []string,
portID,
channelID string,

View File

@ -2,21 +2,39 @@ package types
import (
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
)
// ModuleCdc defines the IBC transfer codec.
var ModuleCdc = codec.New()
// RegisterCodec registers the IBC transfer types
func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterConcrete(MsgTransfer{}, "ibc/transfer/MsgTransfer", nil)
cdc.RegisterConcrete(FungibleTokenPacketData{}, "ibc/transfer/PacketDataTransfer", nil)
}
func init() {
RegisterCodec(ModuleCdc)
channel.RegisterCodec(ModuleCdc)
commitmenttypes.RegisterCodec(ModuleCdc)
// RegisterInterfaces register the ibc transfer module interfaces to protobuf
// Any.
func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil), &MsgTransfer{})
}
var (
amino = codec.New()
// ModuleCdc references the global x/ibc/20-transfer module codec. Note, the codec
// should ONLY be used in certain instances of tests and for JSON encoding as Amino
// is still used for that purpose.
//
// The actual codec used for serialization should be provided to x/ibc/20-transfer and
// defined at the application level.
ModuleCdc = codec.NewHybridCodec(amino, cdctypes.NewInterfaceRegistry())
)
func init() {
RegisterCodec(amino)
channel.RegisterCodec(amino)
commitmenttypes.RegisterCodec(amino)
amino.Seal()
}

View File

@ -6,8 +6,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/capability"
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection"
channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
)
// AccountKeeper defines the contract required for account APIs.
@ -27,7 +27,7 @@ type BankKeeper interface {
// ChannelKeeper defines the expected IBC channel keeper
type ChannelKeeper interface {
GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channel.Channel, found bool)
GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool)
GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool)
SendPacket(ctx sdk.Context, channelCap *capability.Capability, packet channelexported.PacketI) error
PacketExecuted(ctx sdk.Context, chanCap *capability.Capability, packet channelexported.PacketI, acknowledgement []byte) error

View File

@ -6,28 +6,22 @@ import (
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
)
// MsgTransfer defines a msg to transfer fungible tokens (i.e Coins) between ICS20 enabled chains.
// See ICS Spec here: https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#data-structures
type MsgTransfer struct {
SourcePort string `json:"source_port" yaml:"source_port"` // the port on which the packet will be sent
SourceChannel string `json:"source_channel" yaml:"source_channel"` // the channel by which the packet will be sent
DestHeight uint64 `json:"dest_height" yaml:"dest_height"` // the current height of the destination chain
Amount sdk.Coins `json:"amount" yaml:"amount"` // the tokens to be transferred
Sender sdk.AccAddress `json:"sender" yaml:"sender"` // the sender address
Receiver string `json:"receiver" yaml:"receiver"` // the recipient address on the destination chain
}
// msg types
const (
TypeMsgTransfer = "transfer"
)
// NewMsgTransfer creates a new MsgTransfer instance
func NewMsgTransfer(
sourcePort, sourceChannel string, destHeight uint64, amount sdk.Coins, sender sdk.AccAddress, receiver string,
) MsgTransfer {
return MsgTransfer{
SourcePort: sourcePort,
SourceChannel: sourceChannel,
DestHeight: destHeight,
Amount: amount,
Sender: sender,
Receiver: receiver,
SourcePort: sourcePort,
SourceChannel: sourceChannel,
DestinationHeight: destHeight,
Amount: amount,
Sender: sender,
Receiver: receiver,
}
}
@ -38,7 +32,7 @@ func (MsgTransfer) Route() string {
// Type implements sdk.Msg
func (MsgTransfer) Type() string {
return "transfer"
return TypeMsgTransfer
}
// ValidateBasic implements sdk.Msg

View File

@ -96,7 +96,7 @@ func TestMsgTransferGetSignBytes(t *testing.T) {
msg := NewMsgTransfer(validPort, validChannel, 10, coins, addr1, addr2)
res := msg.GetSignBytes()
expected := `{"type":"ibc/transfer/MsgTransfer","value":{"amount":[{"amount":"100","denom":"atom"}],"dest_height":"10","receiver":"cosmos1w3jhxarpv3j8yvs7f9y7g","sender":"cosmos1w3jhxarpv3j8yvg4ufs4x","source_channel":"testchannel","source_port":"testportid"}}`
expected := `{"type":"ibc/transfer/MsgTransfer","value":{"amount":[{"amount":"100","denom":"atom"}],"destination_height":"10","receiver":"cosmos1w3jhxarpv3j8yvs7f9y7g","sender":"cosmos1w3jhxarpv3j8yvg4ufs4x","source_channel":"testchannel","source_port":"testportid"}}`
require.Equal(t, expected, string(res))
}

View File

@ -1,20 +1,10 @@
package types
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
// FungibleTokenPacketData defines a struct for the packet payload
// See FungibleTokenPacketData spec: https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#data-structures
type FungibleTokenPacketData struct {
Amount sdk.Coins `json:"amount" yaml:"amount"` // the tokens to be transferred
Sender string `json:"sender" yaml:"sender"` // the sender address
Receiver string `json:"receiver" yaml:"receiver"` // the recipient address on the destination chain
}
// NewFungibleTokenPacketData contructs a new FungibleTokenPacketData instance
func NewFungibleTokenPacketData(
amount sdk.Coins, sender, receiver string) FungibleTokenPacketData {
@ -25,18 +15,6 @@ func NewFungibleTokenPacketData(
}
}
// String returns a string representation of FungibleTokenPacketData
func (ftpd FungibleTokenPacketData) String() string {
return fmt.Sprintf(`FungibleTokenPacketData:
Amount: %s
Sender: %s
Receiver: %s`,
ftpd.Amount.String(),
ftpd.Sender,
ftpd.Receiver,
)
}
// ValidateBasic is used for validating the token transfer
func (ftpd FungibleTokenPacketData) ValidateBasic() error {
if !ftpd.Amount.IsAllPositive() {
@ -59,14 +37,6 @@ func (ftpd FungibleTokenPacketData) GetBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(ftpd))
}
// FungibleTokenPacketAcknowledgement contains a boolean success flag and an optional error msg
// error msg is empty string on success
// See spec for onAcknowledgePacket: https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#packet-relay
type FungibleTokenPacketAcknowledgement struct {
Success bool `json:"success" yaml:"success"`
Error string `json:"error" yaml:"error"`
}
// GetBytes is a helper for serialising
func (ack FungibleTokenPacketAcknowledgement) GetBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(ack))

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,57 @@
syntax = "proto3";
package cosmos_sdk.x.ibc.transfer.v1;
option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types";
import "third_party/proto/gogoproto/gogo.proto";
import "types/types.proto";
// MsgTransfer defines a msg to transfer fungible tokens (i.e Coins) between ICS20 enabled chains.
// See ICS Spec here: https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#data-structures
message MsgTransfer {
// the port on which the packet will be sent
string source_port = 1 [
(gogoproto.moretags) = "yaml:\"source_port\""
];
// the channel by which the packet will be sent
string source_channel = 2 [
(gogoproto.moretags) = "yaml:\"source_channel\""
];
// the current height of the destination chain
uint64 destination_height = 3 [
(gogoproto.moretags) = "yaml:\"destination_height\""
];
// the tokens to be transferred
repeated cosmos_sdk.v1.Coin amount = 4 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
// the sender address
bytes sender = 5 [
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"
];
// the recipient address on the destination chain
string receiver = 6;
}
// FungibleTokenPacketData defines a struct for the packet payload
// See FungibleTokenPacketData spec: https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#data-structures
message FungibleTokenPacketData {
// the tokens to be transferred
repeated cosmos_sdk.v1.Coin amount = 1 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
// the sender address
string sender = 2;
// the recipient address on the destination chain
string receiver = 3;
}
// FungibleTokenPacketAcknowledgement contains a boolean success flag and an optional error msg
// error msg is empty string on success
// See spec for onAcknowledgePacket: https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#packet-relay
message FungibleTokenPacketAcknowledgement {
bool success = 1;
string error = 2;
}

View File

@ -2,12 +2,12 @@ package types
import (
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported"
)
var SubModuleCdc *codec.Codec
// RegisterCodec registers types declared in this package
// RegisterCodec registers the necessary x/ibc/23-commitment interfaces and concrete types
// on the provided Amino codec. These types are used for Amino JSON serialization.
func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterInterface((*exported.Root)(nil), nil)
cdc.RegisterInterface((*exported.Prefix)(nil), nil)
@ -18,10 +18,21 @@ func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterConcrete(MerklePrefix{}, "ibc/commitment/MerklePrefix", nil)
cdc.RegisterConcrete(MerklePath{}, "ibc/commitment/MerklePath", nil)
cdc.RegisterConcrete(MerkleProof{}, "ibc/commitment/MerkleProof", nil)
SetSubModuleCodec(cdc)
}
func SetSubModuleCodec(cdc *codec.Codec) {
SubModuleCdc = cdc
var (
amino = codec.New()
// SubModuleCdc references the global x/ibc/23-commitmentl module codec. Note, the codec should
// ONLY be used in certain instances of tests and for JSON encoding as Amino is
// still used for that purpose.
//
// The actual codec used for serialization should be provided to x/ibc/23-commitmentl and
// defined at the application level.
SubModuleCdc = codec.NewHybridCodec(amino, cdctypes.NewInterfaceRegistry())
)
func init() {
RegisterCodec(amino)
amino.Seal()
}

View File

@ -0,0 +1,28 @@
package types
import (
fmt "fmt"
"net/url"
)
// AppendKey appends a new key to a KeyPath
func (pth KeyPath) AppendKey(key []byte, enc KeyEncoding) KeyPath {
pth.Keys = append(pth.Keys, &Key{name: key, enc: enc})
return pth
}
// String implements the fmt.Stringer interface
func (pth *KeyPath) String() string {
res := ""
for _, key := range pth.Keys {
switch key.enc {
case URL:
res += "/" + url.PathEscape(string(key.name))
case HEX:
res += "/x:" + fmt.Sprintf("%X", key.name)
default:
panic("unexpected key encoding type")
}
}
return res
}

View File

@ -4,11 +4,11 @@ import (
"errors"
"net/url"
"github.com/tendermint/tendermint/crypto/merkle"
"github.com/cosmos/cosmos-sdk/store/rootmulti"
"github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/exported"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
"github.com/tendermint/tendermint/crypto/merkle"
)
// ICS 023 Merkle Types Implementation
@ -17,13 +17,7 @@ import (
// Merkle proof implementation of the Proof interface
// Applied on SDK-based IBC implementation
var _ exported.Root = MerkleRoot{}
// MerkleRoot defines a merkle root hash.
// In the Cosmos SDK, the AppHash of a block header becomes the root.
type MerkleRoot struct {
Hash []byte `json:"hash" yaml:"hash"`
}
var _ exported.Root = (*MerkleRoot)(nil)
// NewMerkleRoot constructs a new MerkleRoot
func NewMerkleRoot(hash []byte) MerkleRoot {
@ -32,28 +26,22 @@ func NewMerkleRoot(hash []byte) MerkleRoot {
}
}
// GetCommitmentType implements RootI interface
func (MerkleRoot) GetCommitmentType() exported.Type {
return exported.Merkle
}
// GetHash implements RootI interface
func (mr MerkleRoot) GetHash() []byte {
return mr.Hash
}
// GetCommitmentType implements RootI interface
func (MerkleRoot) GetCommitmentType() exported.Type {
return exported.Merkle
}
// IsEmpty returns true if the root is empty
func (mr MerkleRoot) IsEmpty() bool {
return len(mr.GetHash()) == 0
}
var _ exported.Prefix = MerklePrefix{}
// MerklePrefix is merkle path prefixed to the key.
// The constructed key from the Path and the key will be append(Path.KeyPath, append(Path.KeyPrefix, key...))
type MerklePrefix struct {
KeyPrefix []byte `json:"key_prefix" yaml:"key_prefix"` // byte slice prefixed before the key
}
var _ exported.Prefix = (*MerklePrefix)(nil)
// NewMerklePrefix constructs new MerklePrefix instance
func NewMerklePrefix(keyPrefix []byte) MerklePrefix {
@ -77,19 +65,13 @@ func (mp MerklePrefix) IsEmpty() bool {
return len(mp.Bytes()) == 0
}
var _ exported.Path = MerklePath{}
// MerklePath is the path used to verify commitment proofs, which can be an arbitrary
// structured object (defined by a commitment type).
type MerklePath struct {
KeyPath merkle.KeyPath `json:"key_path" yaml:"key_path"` // byte slice prefixed before the key
}
var _ exported.Path = (*MerklePath)(nil)
// NewMerklePath creates a new MerklePath instance
func NewMerklePath(keyPathStr []string) MerklePath {
merkleKeyPath := merkle.KeyPath{}
merkleKeyPath := KeyPath{}
for _, keyStr := range keyPathStr {
merkleKeyPath = merkleKeyPath.AppendKey([]byte(keyStr), merkle.KeyEncodingURL)
merkleKeyPath = merkleKeyPath.AppendKey([]byte(keyStr), URL)
}
return MerklePath{
@ -118,7 +100,7 @@ func (mp MerklePath) Pretty() string {
// IsEmpty returns true if the path is empty
func (mp MerklePath) IsEmpty() bool {
return len(mp.KeyPath) == 0
return len(mp.KeyPath.Keys) == 0
}
// ApplyPrefix constructs a new commitment path from the arguments. It interprets
@ -138,15 +120,7 @@ func ApplyPrefix(prefix exported.Prefix, path string) (MerklePath, error) {
return NewMerklePath([]string{string(prefix.Bytes()), path}), nil
}
var _ exported.Proof = MerkleProof{}
// MerkleProof is a wrapper type that contains a merkle proof.
// It demonstrates membership or non-membership for an element or set of elements,
// verifiable in conjunction with a known commitment root. Proofs should be
// succinct.
type MerkleProof struct {
Proof *merkle.Proof `json:"proof" yaml:"proof"`
}
var _ exported.Proof = (*MerkleProof)(nil)
// GetCommitmentType implements ProofI
func (MerkleProof) GetCommitmentType() exported.Type {
@ -175,7 +149,7 @@ func (proof MerkleProof) VerifyNonMembership(root exported.Root, path exported.P
// IsEmpty returns true if the root is empty
func (proof MerkleProof) IsEmpty() bool {
return (proof == MerkleProof{}) || proof.Proof == nil
return proof.Proof.Equal(nil) || proof.Equal(MerkleProof{}) || proof.Proof.Equal(nil) || proof.Proof.Equal(merkle.Proof{})
}
// ValidateBasic checks if the proof is empty.

View File

@ -53,7 +53,7 @@ func (suite *MerkleTestSuite) TestVerifyMembership() {
root := types.NewMerkleRoot(tc.root)
path := types.NewMerklePath(tc.pathArr)
err := proof.VerifyMembership(root, path, tc.value)
err := proof.VerifyMembership(&root, path, tc.value)
if tc.shouldPass {
// nolint: scopelint
@ -108,7 +108,7 @@ func (suite *MerkleTestSuite) TestVerifyNonMembership() {
root := types.NewMerkleRoot(tc.root)
path := types.NewMerklePath(tc.pathArr)
err := proof.VerifyNonMembership(root, path)
err := proof.VerifyNonMembership(&root, path)
if tc.shouldPass {
// nolint: scopelint

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,69 @@
syntax = "proto3";
package cosmos_sdk.x.ibc.commitment.v1;
option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types";
import "third_party/proto/gogoproto/gogo.proto";
import "third_party/proto/tendermint/crypto/merkle/merkle.proto";
// MerkleRoot defines a merkle root hash.
// In the Cosmos SDK, the AppHash of a block header becomes the root.
message MerkleRoot {
option (gogoproto.goproto_getters) = false;
bytes hash = 1;
}
// MerklePrefix is merkle path prefixed to the key.
// The constructed key from the Path and the key will be append(Path.KeyPath, append(Path.KeyPrefix, key...))
message MerklePrefix {
bytes key_prefix = 1 [(gogoproto.moretags) = "yaml:\"key_prefix\""];
}
// MerklePath is the path used to verify commitment proofs, which can be an arbitrary
// structured object (defined by a commitment type).
message MerklePath {
option (gogoproto.goproto_stringer) = false;
KeyPath key_path = 1 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"key_path\""
];
}
// MerkleProof is a wrapper type that contains a merkle proof.
// It demonstrates membership or non-membership for an element or set of elements,
// verifiable in conjunction with a known commitment root. Proofs should be
// succinct.
message MerkleProof {
option (gogoproto.equal) = true;
tendermint.crypto.merkle.Proof proof = 1;
}
// KeyPath defines a slice of keys
message KeyPath {
option (gogoproto.goproto_stringer) = false;
option (gogoproto.goproto_getters) = false;
repeated Key keys = 1;
}
// Key defines a proof Key
message Key {
option (gogoproto.goproto_getters) = false;
bytes name = 1 [(gogoproto.customname) = "name"];
KeyEncoding enc = 2 [(gogoproto.customname) = "enc"];
}
// KeyEncoding defines the encoding format of a key's bytes.
enum KeyEncoding {
option (gogoproto.goproto_enum_stringer) = false;
option (gogoproto.goproto_enum_prefix) = false;
// URL encoding
KEY_ENCODING_URL_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "URL"];
// Hex encoding
KEY_ENCODING_HEX = 1 [(gogoproto.enumvalue_customname) = "HEX"];
}

View File

@ -9,7 +9,8 @@ import (
// CalculateRoot returns the application Hash at the curretn block height as a commitment
// root for proof verification.
func CalculateRoot(ctx sdk.Context) exported.Root {
return types.NewMerkleRoot(ctx.BlockHeader().AppHash)
root := types.NewMerkleRoot(ctx.BlockHeader().AppHash)
return &root
}
// BatchVerifyMembership verifies a proof that many paths have been set to

View File

@ -13,10 +13,8 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
"github.com/cosmos/cosmos-sdk/x/staking"
@ -56,8 +54,8 @@ func (suite *HandlerTestSuite) SetupTest() {
// create client and connection during setups
suite.chainA.CreateClient(suite.chainB)
suite.chainB.CreateClient(suite.chainA)
suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, connectionexported.OPEN)
suite.chainB.createConnection(testConnection, testConnection, testClientIDA, testClientIDB, connectionexported.OPEN)
suite.chainA.createConnection(testConnection, testConnection, testClientIDB, testClientIDA, ibctypes.OPEN)
suite.chainB.createConnection(testConnection, testConnection, testClientIDA, testClientIDB, ibctypes.OPEN)
}
func queryProof(chain *TestChain, key string) (proof commitmenttypes.MerkleProof, height int64) {
@ -93,12 +91,12 @@ func (suite *HandlerTestSuite) TestHandleMsgPacketOrdered() {
cctx, _ := ctx.CacheContext()
// suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(ctx, packet.SourcePort, packet.SourceChannel, 1)
suite.chainB.App.IBCKeeper.ChannelKeeper.SetPacketCommitment(suite.chainB.GetContext(), packet.SourcePort, packet.SourceChannel, packet.Sequence, channeltypes.CommitPacket(packet))
msg := channel.NewMsgPacket(packet, nil, 0, addr1)
msg := channel.NewMsgPacket(packet, commitmenttypes.MerkleProof{}, 0, addr1)
_, err := handler(cctx, suite.newTx(msg), false)
suite.Error(err, "%+v", err) // channel does not exist
suite.chainA.createChannel(cpportid, cpchanid, portid, chanid, channelexported.OPEN, channelexported.ORDERED, testConnection)
suite.chainB.createChannel(portid, chanid, cpportid, cpchanid, channelexported.OPEN, channelexported.ORDERED, testConnection)
suite.chainA.createChannel(cpportid, cpchanid, portid, chanid, ibctypes.OPEN, ibctypes.ORDERED, testConnection)
suite.chainB.createChannel(portid, chanid, cpportid, cpchanid, ibctypes.OPEN, ibctypes.ORDERED, testConnection)
ctx = suite.chainA.GetContext()
packetCommitmentPath := ibctypes.PacketCommitmentPath(packet.SourcePort, packet.SourceChannel, packet.Sequence)
proof, proofHeight := queryProof(suite.chainB, packetCommitmentPath)
@ -152,7 +150,7 @@ func (suite *HandlerTestSuite) TestHandleMsgPacketUnordered() {
// suite.chainA.App.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainA.GetContext(), packet.SourcePort, packet.SourceChannel, uint64(10))
suite.chainA.createChannel(cpportid, cpchanid, portid, chanid, channelexported.OPEN, channelexported.UNORDERED, testConnection)
suite.chainA.createChannel(cpportid, cpchanid, portid, chanid, ibctypes.OPEN, ibctypes.UNORDERED, testConnection)
suite.chainA.updateClient(suite.chainB)
@ -327,9 +325,9 @@ func (chain *TestChain) updateClient(client *TestChain) {
func (chain *TestChain) createConnection(
connID, counterpartyConnID, clientID, counterpartyClientID string,
state connectionexported.State,
state ibctypes.State,
) connectiontypes.ConnectionEnd {
counterparty := connectiontypes.NewCounterparty(counterpartyClientID, counterpartyConnID, chain.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix())
counterparty := connectiontypes.NewCounterparty(counterpartyClientID, counterpartyConnID, commitmenttypes.NewMerklePrefix(chain.App.IBCKeeper.ConnectionKeeper.GetCommitmentPrefix().Bytes()))
connection := connectiontypes.ConnectionEnd{
State: state,
ClientID: clientID,
@ -343,7 +341,7 @@ func (chain *TestChain) createConnection(
func (chain *TestChain) createChannel(
portID, channelID, counterpartyPortID, counterpartyChannelID string,
state channelexported.State, order channelexported.Order, connectionID string,
state ibctypes.State, order ibctypes.Order, connectionID string,
) channeltypes.Channel {
counterparty := channeltypes.NewCounterparty(counterpartyPortID, counterpartyChannelID)
channel := channeltypes.NewChannel(state, order, counterparty,

View File

@ -5,9 +5,7 @@ import (
client "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection"
connectionexported "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported"
channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
localhosttypes "github.com/cosmos/cosmos-sdk/x/ibc/09-localhost/types"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
@ -46,7 +44,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
),
ConnectionGenesis: connection.NewGenesisState(
[]connection.ConnectionEnd{
connection.NewConnectionEnd(connectionexported.INIT, connectionID, clientID, connection.NewCounterparty(clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))), []string{"1.0.0"}),
connection.NewConnectionEnd(ibctypes.INIT, connectionID, clientID, connection.NewCounterparty(clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))), []string{"1.0.0"}),
},
[]connection.ConnectionPaths{
connection.NewConnectionPaths(clientID, []string{ibctypes.ConnectionPath(connectionID)}),
@ -56,7 +54,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
[]channel.IdentifiedChannel{
channel.NewIdentifiedChannel(
port1, channel1, channel.NewChannel(
channelexported.INIT, channelOrder,
ibctypes.INIT, channelOrder,
channel.NewCounterparty(port2, channel2), []string{connectionID}, channelVersion,
),
),
@ -97,7 +95,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
ClientGenesis: client.DefaultGenesisState(),
ConnectionGenesis: connection.NewGenesisState(
[]connection.ConnectionEnd{
connection.NewConnectionEnd(connectionexported.INIT, connectionID, "CLIENTIDONE", connection.NewCounterparty(clientID, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))), []string{"1.0.0"}),
connection.NewConnectionEnd(ibctypes.INIT, connectionID, "CLIENTIDONE", connection.NewCounterparty(clientID, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))), []string{"1.0.0"}),
},
[]connection.ConnectionPaths{
connection.NewConnectionPaths(clientID, []string{ibctypes.ConnectionPath(connectionID)}),

View File

@ -15,8 +15,8 @@ import (
"github.com/cosmos/cosmos-sdk/store/cachekv"
"github.com/cosmos/cosmos-sdk/store/dbadapter"
sdk "github.com/cosmos/cosmos-sdk/types"
channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
)
const (
@ -31,7 +31,7 @@ const (
channel1 = "firstchannel"
channel2 = "secondchannel"
channelOrder = channelexported.ORDERED
channelOrder = ibctypes.ORDERED
channelVersion = "1.0"
trustingPeriod time.Duration = time.Hour * 24 * 7 * 2

View File

@ -21,12 +21,12 @@ type Keeper struct {
// NewKeeper creates a new ibc Keeper
func NewKeeper(
cdc *codec.Codec, key sdk.StoreKey, stakingKeeper client.StakingKeeper, scopedKeeper capability.ScopedKeeper,
cdc *codec.Codec, appCodec codec.Marshaler, key sdk.StoreKey, stakingKeeper client.StakingKeeper, scopedKeeper capability.ScopedKeeper,
) *Keeper {
clientKeeper := client.NewKeeper(cdc, key, stakingKeeper)
connectionKeeper := connection.NewKeeper(cdc, key, clientKeeper)
connectionKeeper := connection.NewKeeper(cdc, appCodec, key, clientKeeper)
portKeeper := port.NewKeeper(scopedKeeper)
channelKeeper := channel.NewKeeper(cdc, key, clientKeeper, connectionKeeper, portKeeper, scopedKeeper)
channelKeeper := channel.NewKeeper(appCodec, key, clientKeeper, connectionKeeper, portKeeper, scopedKeeper)
return &Keeper{
ClientKeeper: clientKeeper,
@ -36,7 +36,8 @@ func NewKeeper(
}
}
// Set the Router in IBC Keeper and seal it
// SetRouter sets the Router in IBC Keeper and seals it. The method panics if
// there is an existing router that's already sealed.
func (k *Keeper) SetRouter(rtr *port.Router) {
if k.Router != nil && k.Router.Sealed() {
panic("cannot reset a sealed router")

View File

@ -11,6 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
client "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
@ -81,6 +82,12 @@ func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
return cli.GetQueryCmd(QuerierRoute, cdc)
}
// RegisterInterfaceTypes registers module concrete types into protobuf Any.
func (AppModuleBasic) RegisterInterfaceTypes(registry cdctypes.InterfaceRegistry) {
connection.RegisterInterfaces(registry)
channel.RegisterInterfaces(registry)
}
// AppModule implements an application module for the ibc module.
type AppModule struct {
AppModuleBasic

129
x/ibc/types/types.pb.go Normal file
View File

@ -0,0 +1,129 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: x/ibc/types/types.proto
package types
import (
fmt "fmt"
_ "github.com/gogo/protobuf/gogoproto"
proto "github.com/gogo/protobuf/proto"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
// Order defines if a channel is ORDERED or UNORDERED
type Order int32
const (
// zero-value for channel ordering
NONE Order = 0
// packets can be delivered in any order, which may differ from the order in which they were sent.
UNORDERED Order = 1
// packets are delivered exactly in the order which they were sent
ORDERED Order = 2
)
var Order_name = map[int32]string{
0: "ORDER_NONE_UNSPECIFIED",
1: "ORDER_UNORDERED",
2: "ORDER_ORDERED",
}
var Order_value = map[string]int32{
"ORDER_NONE_UNSPECIFIED": 0,
"ORDER_UNORDERED": 1,
"ORDER_ORDERED": 2,
}
func (x Order) String() string {
return proto.EnumName(Order_name, int32(x))
}
func (Order) EnumDescriptor() ([]byte, []int) {
return fileDescriptor_cc2eab1776b9fb6e, []int{0}
}
// State defines if a channel or connection is in one of the following states:
// CLOSED, INIT, TRYOPEN, OPEN or UNINITIALIZED.
type State int32
const (
// Default State
UNINITIALIZED State = 0
// A channel or connection end has just started the opening handshake.
INIT State = 1
// A channel or connection end has acknowledged the handshake step on the counterparty chain.
TRYOPEN State = 2
// A channel or connection end has completed the handshake. Open channels are
// ready to send and receive packets.
OPEN State = 3
// A channel end has been closed and can no longer be used to send or receive packets.
CLOSED State = 4
)
var State_name = map[int32]string{
0: "STATE_UNINITIALIZED_UNSPECIFIED",
1: "STATE_INIT",
2: "STATE_TRYOPEN",
3: "STATE_OPEN",
4: "STATE_CLOSED",
}
var State_value = map[string]int32{
"STATE_UNINITIALIZED_UNSPECIFIED": 0,
"STATE_INIT": 1,
"STATE_TRYOPEN": 2,
"STATE_OPEN": 3,
"STATE_CLOSED": 4,
}
func (x State) String() string {
return proto.EnumName(State_name, int32(x))
}
func (State) EnumDescriptor() ([]byte, []int) {
return fileDescriptor_cc2eab1776b9fb6e, []int{1}
}
func init() {
proto.RegisterEnum("cosmos_sdk.x.ibc.v1.Order", Order_name, Order_value)
proto.RegisterEnum("cosmos_sdk.x.ibc.v1.State", State_name, State_value)
}
func init() { proto.RegisterFile("x/ibc/types/types.proto", fileDescriptor_cc2eab1776b9fb6e) }
var fileDescriptor_cc2eab1776b9fb6e = []byte{
// 339 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xaf, 0xd0, 0xcf, 0x4c,
0x4a, 0xd6, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x86, 0x90, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42,
0xc2, 0xc9, 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x15, 0x7a, 0x99, 0x49,
0xc9, 0x7a, 0x65, 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29, 0xf1, 0x05, 0x89, 0x45, 0x25,
0x95, 0xfa, 0x60, 0x75, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, 0x44, 0xb3, 0x56, 0x39, 0x17,
0xab, 0x7f, 0x51, 0x4a, 0x6a, 0x91, 0x90, 0x0a, 0x97, 0x98, 0x7f, 0x90, 0x8b, 0x6b, 0x50, 0xbc,
0x9f, 0xbf, 0x9f, 0x6b, 0x7c, 0xa8, 0x5f, 0x70, 0x80, 0xab, 0xb3, 0xa7, 0x9b, 0xa7, 0xab, 0x8b,
0x00, 0x83, 0x14, 0x47, 0xd7, 0x5c, 0x05, 0x16, 0x90, 0xb8, 0x90, 0x12, 0x17, 0x3f, 0x44, 0x55,
0xa8, 0x1f, 0x98, 0x76, 0x75, 0x11, 0x60, 0x94, 0xe2, 0xed, 0x9a, 0xab, 0xc0, 0x09, 0x17, 0x10,
0x92, 0xe3, 0xe2, 0x85, 0xa8, 0x81, 0xa9, 0x60, 0x92, 0xe2, 0xee, 0x9a, 0xab, 0xc0, 0x0e, 0xe5,
0x4a, 0xb1, 0x74, 0x2c, 0x96, 0x63, 0xd0, 0xda, 0xce, 0xc8, 0xc5, 0x1a, 0x5c, 0x92, 0x58, 0x92,
0x2a, 0x64, 0xc6, 0x25, 0x1f, 0x1c, 0xe2, 0x18, 0x02, 0xb2, 0xd4, 0xd3, 0xcf, 0x33, 0xc4, 0xd3,
0xd1, 0xc7, 0x33, 0xca, 0xd5, 0x05, 0xcd, 0x09, 0x82, 0x5d, 0x73, 0x15, 0x78, 0x51, 0x14, 0x08,
0x49, 0x70, 0x71, 0x41, 0xf4, 0x81, 0x04, 0x05, 0x18, 0x21, 0xae, 0x04, 0xb1, 0x41, 0x2e, 0x80,
0xc8, 0x84, 0x04, 0x45, 0xfa, 0x07, 0xb8, 0xfa, 0xc1, 0x5c, 0x00, 0xe5, 0x22, 0x74, 0x82, 0x25,
0x99, 0x21, 0x3a, 0xc1, 0x32, 0x32, 0x5c, 0x3c, 0x10, 0x19, 0x67, 0x1f, 0xff, 0x60, 0x57, 0x17,
0x01, 0x16, 0x29, 0xae, 0xae, 0xb9, 0x0a, 0x6c, 0x10, 0x1e, 0xc4, 0xe5, 0x4e, 0x4e, 0x27, 0x1e,
0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17,
0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xa5, 0x91, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4,
0x97, 0x9c, 0x9f, 0xab, 0x0f, 0x89, 0x14, 0x28, 0xa5, 0x5b, 0x9c, 0x92, 0xad, 0x8f, 0x14, 0x7f,
0x49, 0x6c, 0xe0, 0xd0, 0x37, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xaa, 0x1c, 0xe7, 0x8b, 0xd5,
0x01, 0x00, 0x00,
}

36
x/ibc/types/types.proto Normal file
View File

@ -0,0 +1,36 @@
syntax = "proto3";
package cosmos_sdk.x.ibc.v1;
option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/types";
import "third_party/proto/gogoproto/gogo.proto";
// Order defines if a channel is ORDERED or UNORDERED
enum Order {
option (gogoproto.goproto_enum_prefix) = false;
// zero-value for channel ordering
ORDER_NONE_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "NONE"];
// packets can be delivered in any order, which may differ from the order in which they were sent.
ORDER_UNORDERED = 1 [(gogoproto.enumvalue_customname) = "UNORDERED"];
// packets are delivered exactly in the order which they were sent
ORDER_ORDERED = 2 [(gogoproto.enumvalue_customname) = "ORDERED"];
}
// State defines if a channel or connection is in one of the following states:
// CLOSED, INIT, TRYOPEN, OPEN or UNINITIALIZED.
enum State {
option (gogoproto.goproto_enum_prefix) = false;
// Default State
STATE_UNINITIALIZED_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "UNINITIALIZED"];
// A channel or connection end has just started the opening handshake.
STATE_INIT = 1 [(gogoproto.enumvalue_customname) = "INIT"];
// A channel or connection end has acknowledged the handshake step on the counterparty chain.
STATE_TRYOPEN = 2 [(gogoproto.enumvalue_customname) = "TRYOPEN"];
// A channel or connection end has completed the handshake. Open channels are
// ready to send and receive packets.
STATE_OPEN = 3 [(gogoproto.enumvalue_customname) = "OPEN"];
// A channel end has been closed and can no longer be used to send or receive packets.
STATE_CLOSED = 4 [(gogoproto.enumvalue_customname) = "CLOSED"];
}