-
Notifications
You must be signed in to change notification settings - Fork 673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add pluming necessary for testing CreateChannel #7406
Changes from 4 commits
63ebeed
a935bd1
5ad3aec
2323e18
e96a3dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" | ||
) | ||
|
||
// EmitCreateChannelEvent emits a channel create event. | ||
func EmitCreateChannelEvent(ctx context.Context, channelID string) { | ||
sdkCtx := sdk.UnwrapSDKContext(ctx) | ||
|
||
sdkCtx.EventManager().EmitEvents(sdk.Events{ | ||
sdk.NewEvent( | ||
types.EventTypeCreateChannel, | ||
sdk.NewAttribute(types.AttributeKeyChannelID, channelID), | ||
), | ||
sdk.NewEvent( | ||
sdk.EventTypeMessage, | ||
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), | ||
), | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
|
||
ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" | ||
) | ||
|
||
// IBC channel events | ||
const ( | ||
AttributeKeyChannelID = "channel_id" | ||
) | ||
|
||
// IBC channel events vars | ||
var ( | ||
EventTypeCreateChannel = "create_channel" | ||
|
||
AttributeValueCategory = fmt.Sprintf("%s_%s", ibcexported.ModuleName, SubModuleName) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,6 +188,24 @@ func (endpoint *Endpoint) ProvideCounterparty() (err error) { | |
return err | ||
} | ||
|
||
// CreateChannel will construct and execute a new MsgCreateChannel on the associated endpoint. | ||
func (endpoint *Endpoint) CreateChannel() (err error) { | ||
merklePath := commitmenttypes.NewMerklePath([]byte("ibc"), []byte("")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could probably make |
||
|
||
msg := packetservertypes.NewMsgCreateChannel(endpoint.ClientID, merklePath, endpoint.Chain.SenderAccount.GetAddress().String()) | ||
|
||
// create channel | ||
res, err := endpoint.Chain.SendMsgs(msg) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
endpoint.ChannelID, err = ParseChannelIDV2FromEvents(res.Events) | ||
require.NoError(endpoint.Chain.TB, err) | ||
|
||
return nil | ||
} | ||
|
||
// UpgradeChain will upgrade a chain's chainID to the next revision number. | ||
// It will also update the counterparty client. | ||
// TODO: implement actual upgrade chain functionality via scheduling an upgrade | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import ( | |
clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" | ||
connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" | ||
channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" | ||
packetservertypes "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" | ||
) | ||
|
||
// ParseClientIDFromEvents parses events emitted from a MsgCreateClient and returns the | ||
|
@@ -56,6 +57,19 @@ func ParseChannelIDFromEvents(events []abci.Event) (string, error) { | |
return "", errors.New("channel identifier event attribute not found") | ||
} | ||
|
||
// ParseChannelIDV2FromEvents parses events emitted from a CreateChannel | ||
// and returns the channel identifier. | ||
func ParseChannelIDV2FromEvents(events []abci.Event) (string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i guess I could also have done the parsing in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I'd prefer to not have the V2 suffix in func names and stuff, personally There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gotcha, will axe this and merge into other func |
||
for _, ev := range events { | ||
if ev.Type == packetservertypes.EventTypeCreateChannel { | ||
if attribute, found := attributeByKey(ev.Attributes, packetservertypes.AttributeKeyChannelID); found { | ||
return attribute.Value, nil | ||
} | ||
} | ||
} | ||
return "", errors.New("channel identifier event attribute not found") | ||
} | ||
|
||
// ParsePacketFromEvents parses events emitted from a send packet and returns | ||
// the first EventTypeSendPacket packet found. | ||
// Returns an error if no packet is found. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,6 +152,9 @@ func (path *Path) Setup() { | |
// This is all that is necessary for path setup with the Eureka (V2) protocol | ||
func (path *Path) SetupV2() { | ||
path.SetupClients() | ||
|
||
// path.CreateChannelsV2() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. leftover comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, no! Will wire this up in next PR that makes changes in core handlers (currently this would just fail spectacularly if uncommented!) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, it already does 😆 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I swear this linter adding a duplicate import is the bane of my existence |
||
|
||
path.SetupCounterparties() | ||
} | ||
|
||
|
@@ -252,6 +255,19 @@ func (path *Path) CreateChannels() { | |
} | ||
} | ||
|
||
// CreateChannelsV2 initializes two channel endpoints by executing CreateChannel on both chainA and chainB. | ||
func (path *Path) CreateChannelsV2() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess there's no room to get rid of V2 here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we already have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Grimacing emoji indeed |
||
err := path.EndpointA.CreateChannel() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = path.EndpointB.CreateChannel() | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
// EnableFeeOnPath enables fee on a channel given a path. | ||
func EnableFeeOnPath(path *Path) *Path { | ||
path.EndpointA.ChannelConfig.Version = ibcmock.MockFeeVersion | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason this is not a constant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just how we do it elsewhere. Intuition is this was for grouping relevant vars together. Will change if people feel it best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feel like a const makes more sense here, we can worry about it when we move stuff over to msg_server_v2_land anyway