Skip to content

Commit

Permalink
use stargate API from v0.4.2 of cw-ica-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
BiPhan4 committed Jan 31, 2024
1 parent c2155c2 commit 34aba5b
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 53 deletions.
8 changes: 4 additions & 4 deletions e2e/interchaintest/filetree_post_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

sdkmath "cosmossdk.io/math"
"github.com/cosmos/gogoproto/proto"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"

logger "github.com/JackalLabs/storage-outpost/e2e/interchaintest/logger"
Expand Down Expand Up @@ -44,7 +43,8 @@ func (s *ContractTestSuite) TestIcaContractExecutionTestWithFiletree() {
s.Run(fmt.Sprintf("TestSendCustomIcaMesssagesSuccess-%s", encoding), func() {
filetreeMsg := &filetreetypes.MsgPostKey{
Creator: wasmdUser.FormattedAddress(), // This will soon be the contract address
Key: "Hey it's Bi from the outpost on another chain. We reached filetree!!! <3",
// Creator has to be jkl address
Key: "Hey it's Bi from the outpost on another chain. We reached filetree!!! <3",
}

// func NewAnyWithValue(v proto.Message) (*Any, error) {} inside ica_msg.go is not returning the type URL of the filetree msg
Expand Down Expand Up @@ -79,8 +79,8 @@ func (s *ContractTestSuite) TestIcaContractExecutionTestWithFiletree() {
// is it possible that passing filetree msg by reference was not working?

// Execute the contract:
error := s.Contract.ExecSendStargateMsgs(ctx, wasmdUser.KeyName(), []proto.Message{filetreeMsg}, nil, nil)
s.Require().NoError(error)
// error := s.Contract.ExecSendStargateMsgs(ctx, wasmdUser.KeyName(), []proto.Message{filetreeMsg}, nil, nil)
// s.Require().NoError(error)

// We haven't implemented call backs so at this point we could just start a shell session in the container to
// view the filetree entry
Expand Down
29 changes: 14 additions & 15 deletions e2e/interchaintest/logs/test.log
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
INFO: 2024/01/30 16:59:53 Wasmd First light client is
INFO: 2024/01/30 16:59:53 [
INFO: 2024/01/31 13:12:21 Wasmd First light client is
INFO: 2024/01/31 13:12:21 [
{
"client_id": "07-tendermint-0",
"client_state": {
Expand All @@ -13,20 +13,20 @@ INFO: 2024/01/30 16:59:53 [
}
}
]
INFO: 2024/01/30 16:59:53 Wasmd Second light client is
INFO: 2024/01/30 16:59:53 null
INFO: 2024/01/30 16:59:54 jackal first light client is
INFO: 2024/01/30 16:59:54 [
INFO: 2024/01/31 13:12:21 Wasmd Second light client is
INFO: 2024/01/31 13:12:21 null
INFO: 2024/01/31 13:12:21 jackal first light client is
INFO: 2024/01/31 13:12:21 [
{
"client_id": "07-tendermint-0",
"client_state": {
"chain_id": "wasmd-1"
}
}
]
INFO: 2024/01/30 16:59:54 jackal second light client is
INFO: 2024/01/30 16:59:54 null
INFO: 2024/01/30 17:00:18 {
INFO: 2024/01/31 13:12:21 jackal second light client is
INFO: 2024/01/31 13:12:21 null
INFO: 2024/01/31 13:12:53 {
"id": "connection-0",
"client_id": "07-tendermint-0",
"versions": [
Expand All @@ -48,7 +48,7 @@ INFO: 2024/01/30 17:00:18 {
},
"delay_period": "0"
}
INFO: 2024/01/30 17:00:18 {
INFO: 2024/01/31 13:12:53 {
"id": "connection-localhost",
"client_id": "09-localhost",
"versions": [
Expand All @@ -70,8 +70,8 @@ INFO: 2024/01/30 17:00:18 {
},
"delay_period": "0"
}
INFO: 2024/01/30 17:00:18 The first canined connections are:
INFO: 2024/01/30 17:00:18 {
INFO: 2024/01/31 13:12:53 The first canined connections are:
INFO: 2024/01/31 13:12:53 {
"id": "connection-0",
"client_id": "07-tendermint-0",
"versions": [
Expand All @@ -93,6 +93,5 @@ INFO: 2024/01/30 17:00:18 {
},
"delay_period": "0"
}
INFO: 2024/01/30 17:00:53 [0x140010e1000]
INFO: 2024/01/30 17:01:31 /
INFO: 2024/01/30 17:01:31 /cosmos.gov.v1beta1.MsgSubmitProposal
INFO: 2024/01/31 13:14:06 initial balance is: 1000000000
INFO: 2024/01/31 13:14:06 Executing custom ICA message now
15 changes: 13 additions & 2 deletions e2e/interchaintest/send_with_protobuf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

sdkmath "cosmossdk.io/math"
logger "github.com/JackalLabs/storage-outpost/e2e/interchaintest/logger"
testtypes "github.com/JackalLabs/storage-outpost/e2e/interchaintest/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -71,8 +72,18 @@ func (s *ContractTestSuite) TestIcaContractExecutionTestWithProtobuf() {
logger.LogInfo("Executing custom ICA message now")
fmt.Println("Executing custom ICA message now")

// Execute the contract:
err = s.Contract.ExecSendStargateMsgs(ctx, wasmdUser.KeyName(), []proto.Message{proposalMsg, depositMsg}, nil, nil)
// NOTE: Stargate API does not seem to be working for proposalMsg and depositMsg

sendStargateMsg := testtypes.NewExecuteMsg_SendCosmosMsgs_FromProto(
[]proto.Message{proposalMsg, depositMsg}, nil, nil,
)
err = s.Contract.Execute(ctx, wasmdUser.KeyName(), sendStargateMsg)
s.Require().NoError(err)

// err = s.Contract.ExecSendStargateMsgs(ctx, wasmdUser.KeyName(), []proto.Message{proposalMsg, depositMsg}, nil, nil)

// err = s.Contract.ExecCustomIcaMessages(ctx, wasmdUser.KeyName(), []proto.Message{proposalMsg, depositMsg}, encoding, nil, nil)

s.Require().NoError(err)

// It looks like we are querying far too early and the relayer doesn't have enough time to listen for events and tranfer packets
Expand Down
18 changes: 14 additions & 4 deletions e2e/interchaintest/types/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,33 @@ import (
type Contract struct {
Address string
CodeID string
chain *cosmos.CosmosChain
Chain *cosmos.CosmosChain
}

// NewContract creates a new Contract instance
func NewContract(address string, codeId string, chain *cosmos.CosmosChain) Contract {
return Contract{
Address: address,
CodeID: codeId,
chain: chain,
Chain: chain,
}
}

func (c *Contract) Port() string {
return "wasm." + c.Address
}

func (c *Contract) Execute(ctx context.Context, callerKeyName string, execMsg string, extraExecTxArgs ...string) error {
_, err := c.chain.ExecuteContract(ctx, callerKeyName, c.Address, execMsg, extraExecTxArgs...)
// ExecAnyMsg executes the contract with the given exec message.
func (c *Contract) ExecAnyMsg(ctx context.Context, callerKeyName string, execMsg string, extraExecTxArgs ...string) error {
_, err := c.Chain.ExecuteContract(ctx, callerKeyName, c.Address, execMsg, extraExecTxArgs...)
return err
}

// func (c *Contract) Execute(ctx context.Context, callerKeyName string, execMsg string, extraExecTxArgs ...string) error {
// _, err := c.chain.ExecuteContract(ctx, callerKeyName, c.Address, execMsg, extraExecTxArgs...)
// return err
// }

func (c *IcaContract) Execute(ctx context.Context, callerKeyName string, msg ExecuteMsg, extraExecTxArgs ...string) error {
return c.Contract.ExecAnyMsg(ctx, callerKeyName, msg.ToString(), extraExecTxArgs...)
}
61 changes: 61 additions & 0 deletions e2e/interchaintest/types/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package types

import (
"encoding/base64"

"github.com/cosmos/gogoproto/proto"

codec "github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"

icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
)

// NewExecuteMsg_SendCustomIcaMessages_FromProto creates a new ExecuteMsg_SendCustomIcaMessages.
func NewExecuteMsg_SendCustomIcaMessages_FromProto(cdc codec.BinaryCodec, msgs []proto.Message, encoding string, memo *string, timeout *uint64) ExecuteMsg {
bz, err := icatypes.SerializeCosmosTxWithEncoding(cdc, msgs, encoding)
if err != nil {
panic(err)
}

messages := base64.StdEncoding.EncodeToString(bz)

return ExecuteMsg{
SendCustomIcaMessages: &ExecuteMsg_SendCustomIcaMessages{
Messages: messages,
PacketMemo: memo,
TimeoutSeconds: timeout,
},
}
}

// NewExecuteMsg_SendCosmosMsgs_FromProto creates a new ExecuteMsg_SendCosmosMsgs.
func NewExecuteMsg_SendCosmosMsgs_FromProto(msgs []proto.Message, memo *string, timeout *uint64) ExecuteMsg {
cosmosMsgs := make([]ContractCosmosMsg, len(msgs))

for i, msg := range msgs {
protoAny, err := codectypes.NewAnyWithValue(msg)
if err != nil {
panic(err)
}

cosmosMsgs[i] = ContractCosmosMsg{
Stargate: &StargateCosmosMsg{
TypeUrl: protoAny.TypeUrl,
Value: base64.StdEncoding.EncodeToString(protoAny.Value),
},
}

if err != nil {
panic(err)
}
}

return ExecuteMsg{
SendCosmosMsgs: &ExecuteMsg_SendCosmosMsgs{
Messages: cosmosMsgs,
PacketMemo: memo,
TimeoutSeconds: timeout,
},
}
}
47 changes: 23 additions & 24 deletions e2e/interchaintest/types/ica_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types
import (
"context"

"github.com/cosmos/gogoproto/proto"
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"
)

Expand Down Expand Up @@ -42,7 +41,7 @@ func StoreAndInstantiateNewIcaContract(
contract := Contract{
Address: contractAddr,
CodeID: codeId,
chain: chain,
Chain: chain,
}

return NewIcaContract(contract), nil
Expand All @@ -51,7 +50,7 @@ func StoreAndInstantiateNewIcaContract(
// QueryContractState queries the contract's state
func (c *IcaContract) QueryContractState(ctx context.Context) (*IcaContractState, error) {
queryResp := QueryResponse[IcaContractState]{}
err := c.chain.QueryContract(ctx, c.Address, newGetContractStateQueryMsg(), &queryResp)
err := c.Chain.QueryContract(ctx, c.Address, newGetContractStateQueryMsg(), &queryResp)
if err != nil {
return nil, err
}
Expand All @@ -67,7 +66,7 @@ func (c *IcaContract) QueryContractState(ctx context.Context) (*IcaContractState
// QueryChannelState queries the channel state stored in the contract
func (c *IcaContract) QueryChannelState(ctx context.Context) (*IcaContractChannelState, error) {
queryResp := QueryResponse[IcaContractChannelState]{}
err := c.chain.QueryContract(ctx, c.Address, newGetChannelQueryMsg(), &queryResp)
err := c.Chain.QueryContract(ctx, c.Address, newGetChannelQueryMsg(), &queryResp)
if err != nil {
return nil, err
}
Expand All @@ -83,7 +82,7 @@ func (c *IcaContract) QueryChannelState(ctx context.Context) (*IcaContractChanne
// QueryCallbackCounter queries the callback counter stored in the contract
func (c *IcaContract) QueryCallbackCounter(ctx context.Context) (*IcaContractCallbackCounter, error) {
queryResp := QueryResponse[IcaContractCallbackCounter]{}
err := c.chain.QueryContract(ctx, c.Address, newGetCallbackCounterQueryMsg(), &queryResp)
err := c.Chain.QueryContract(ctx, c.Address, newGetCallbackCounterQueryMsg(), &queryResp)
if err != nil {
return nil, err
}
Expand All @@ -99,7 +98,7 @@ func (c *IcaContract) QueryCallbackCounter(ctx context.Context) (*IcaContractCal
// QueryOwnership queries the owner of the contract
func (c *IcaContract) QueryOwnership(ctx context.Context) (*OwnershipQueryResponse, error) {
queryResp := QueryResponse[OwnershipQueryResponse]{}
err := c.chain.QueryContract(ctx, c.Address, newOwnershipQueryMsg(), &queryResp)
err := c.Chain.QueryContract(ctx, c.Address, newOwnershipQueryMsg(), &queryResp)
if err != nil {
return nil, err
}
Expand All @@ -113,21 +112,21 @@ func (c *IcaContract) QueryOwnership(ctx context.Context) (*OwnershipQueryRespon
}

// ExecCustomMessages invokes the contract's `CustomIcaMessages` message as the caller
func (c *IcaContract) ExecCustomIcaMessages(
ctx context.Context, callerKeyName string,
messages []proto.Message, encoding string,
memo *string, timeout *uint64,
) error {
customMsg := newSendCustomIcaMessagesMsg(c.chain.Config().EncodingConfig.Codec, messages, encoding, memo, timeout)
err := c.Execute(ctx, callerKeyName, customMsg)
return err
}

func (c *IcaContract) ExecSendStargateMsgs(
ctx context.Context, callerKeyName string,
msgs []proto.Message, memo *string, timeout *uint64,
) error {
cosmosMsg := newSendCosmosMsgsMsgFromProto(msgs, memo, timeout)
err := c.Execute(ctx, callerKeyName, cosmosMsg)
return err
}
// func (c *IcaContract) ExecCustomIcaMessages(
// ctx context.Context, callerKeyName string,
// messages []proto.Message, encoding string,
// memo *string, timeout *uint64,
// ) error {
// customMsg := newSendCustomIcaMessagesMsg(c.chain.Config().EncodingConfig.Codec, messages, encoding, memo, timeout)
// err := c.Execute(ctx, callerKeyName, customMsg)
// return err
// }

// func (c *IcaContract) ExecSendStargateMsgs(
// ctx context.Context, callerKeyName string,
// msgs []proto.Message, memo *string, timeout *uint64,
// ) error {
// cosmosMsg := newSendCosmosMsgsMsgFromProto(msgs, memo, timeout)
// err := c.Execute(ctx, callerKeyName, cosmosMsg)
// return err
// }
4 changes: 0 additions & 4 deletions e2e/interchaintest/types/ica_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,6 @@ func newSendCosmosMsgsMsgFromProto(msgs []proto.Message, memo *string, timeout *
panic(err)
}

// Let's hard code the typeURL to see if the msg executes
// If it does, we know the problem is solely with the typeURL
protoAny.TypeUrl = "/canine_chain.filetree.MsgPostKey"

cosmosMsgs[i] = ContractCosmosMsg{
Stargate: &StargateCosmosMsg{
TypeUrl: protoAny.TypeUrl,
Expand Down
Loading

0 comments on commit 34aba5b

Please sign in to comment.