Skip to content

Commit

Permalink
imp(e2e): updated 'cw-ica-controller' types by using go-codegen (#86)
Browse files Browse the repository at this point in the history
* e2e: using go-codegen

* e2e: ran golangci-lint

* imp(e2e): fix issues

* fix(e2e): fix more

* fix: tests
  • Loading branch information
srdtrk authored Feb 14, 2024
1 parent bc30f22 commit ff13307
Show file tree
Hide file tree
Showing 10 changed files with 776 additions and 500 deletions.
214 changes: 107 additions & 107 deletions e2e/interchaintest/contract_test.go

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions e2e/interchaintest/owner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,31 +119,31 @@ func (s *OwnerTestSuite) TestOwnerCreateIcaContract() {
s.Require().Equal(channeltypes.OPEN.String(), simdChannel.State)

// Check contract's channel state
contractChannelState, err := types.QueryAnyMsg[icacontroller.ContractChannelState](ctx, &icaContract.Contract, icacontroller.GetChannelRequest)
contractChannelState, err := types.QueryAnyMsg[icacontroller.State](ctx, &icaContract.Contract, icacontroller.GetChannelRequest)
s.Require().NoError(err)

s.T().Logf("contract's channel store after handshake: %s", toJSONString(contractChannelState))

s.Require().Equal(wasmdChannel.State, contractChannelState.ChannelStatus)
s.Require().Equal(wasmdChannel.State, string(contractChannelState.ChannelStatus))
s.Require().Equal(wasmdChannel.Version, contractChannelState.Channel.Version)
s.Require().Equal(wasmdChannel.ConnectionHops[0], contractChannelState.Channel.ConnectionID)
s.Require().Equal(wasmdChannel.ChannelID, contractChannelState.Channel.Endpoint.ChannelID)
s.Require().Equal(wasmdChannel.PortID, contractChannelState.Channel.Endpoint.PortID)
s.Require().Equal(wasmdChannel.Counterparty.ChannelID, contractChannelState.Channel.CounterpartyEndpoint.ChannelID)
s.Require().Equal(wasmdChannel.Counterparty.PortID, contractChannelState.Channel.CounterpartyEndpoint.PortID)
s.Require().Equal(wasmdChannel.Ordering, contractChannelState.Channel.Order)
s.Require().Equal(wasmdChannel.ConnectionHops[0], contractChannelState.Channel.ConnectionId)
s.Require().Equal(wasmdChannel.ChannelID, contractChannelState.Channel.Endpoint.ChannelId)
s.Require().Equal(wasmdChannel.PortID, contractChannelState.Channel.Endpoint.PortId)
s.Require().Equal(wasmdChannel.Counterparty.ChannelID, contractChannelState.Channel.CounterpartyEndpoint.ChannelId)
s.Require().Equal(wasmdChannel.Counterparty.PortID, contractChannelState.Channel.CounterpartyEndpoint.PortId)
s.Require().Equal(wasmdChannel.Ordering, string(contractChannelState.Channel.Order))

// Check contract state
contractState, err := types.QueryAnyMsg[icacontroller.ContractState](
contractState, err := types.QueryAnyMsg[icacontroller.State_2](
ctx, &icaContract.Contract,
icacontroller.GetContractStateRequest,
)
s.Require().NoError(err)
s.Require().Equal(wasmdChannel.ChannelID, contractState.IcaInfo.ChannelID)
s.Require().Equal(wasmdChannel.ChannelID, contractState.IcaInfo.ChannelId)

ownershipResponse, err := types.QueryAnyMsg[icacontroller.OwnershipResponse](ctx, &icaContract.Contract, icacontroller.OwnershipRequest)
ownershipResponse, err := types.QueryAnyMsg[icacontroller.Ownership_for_String](ctx, &icaContract.Contract, icacontroller.OwnershipRequest)
s.Require().NoError(err)
s.Require().Equal(s.OwnerContract.Address, ownershipResponse.Owner)
s.Require().Equal(s.OwnerContract.Address, *ownershipResponse.Owner)
s.Require().Nil(ownershipResponse.PendingOwner)
s.Require().Nil(ownershipResponse.PendingExpiry)
})
Expand All @@ -165,7 +165,7 @@ func (s *OwnerTestSuite) TestOwnerPredefinedAction() {
icaContract := types.NewIcaContract(*types.NewContract(icaState.ContractAddr, strconv.FormatUint(s.IcaContractCodeId, 10), wasmd))

// Check contract state
contractState, err := types.QueryAnyMsg[icacontroller.ContractState](
contractState, err := types.QueryAnyMsg[icacontroller.State_2](
ctx, &icaContract.Contract,
icacontroller.GetContractStateRequest,
)
Expand Down
15 changes: 13 additions & 2 deletions e2e/interchaintest/types/ica_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"context"
"encoding/json"

"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"

Expand All @@ -22,11 +23,11 @@ func (c *IcaContract) SetIcaAddress(icaAddress string) {
}

func (c *IcaContract) Execute(ctx context.Context, callerKeyName string, msg icacontroller.ExecuteMsg, extraExecTxArgs ...string) error {
return c.Contract.ExecAnyMsg(ctx, callerKeyName, msg.ToString(), extraExecTxArgs...)
return c.Contract.ExecAnyMsg(ctx, callerKeyName, toString(msg), extraExecTxArgs...)
}

func (c *IcaContract) Instantiate(ctx context.Context, callerKeyName string, chain *cosmos.CosmosChain, codeId string, msg icacontroller.InstantiateMsg, extraExecTxArgs ...string) error {
contractAddr, err := chain.InstantiateContract(ctx, callerKeyName, codeId, msg.ToString(), true, extraExecTxArgs...)
contractAddr, err := chain.InstantiateContract(ctx, callerKeyName, codeId, toString(msg), true, extraExecTxArgs...)
if err != nil {
return err
}
Expand All @@ -36,3 +37,13 @@ func (c *IcaContract) Instantiate(ctx context.Context, callerKeyName string, cha
c.Chain = chain
return nil
}

// toString converts the message to a string using json
func toString(msg interface{}) string {
bz, err := json.Marshal(msg)
if err != nil {
panic(err)
}

return string(bz)
}
6 changes: 3 additions & 3 deletions e2e/interchaintest/types/icacontroller/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package icacontroller

var (
// Query request for contract state
GetContractStateRequest = QueryMsg{GetContractState: &struct{}{}}
GetContractStateRequest = QueryMsg{GetContractState: &QueryMsg_GetContractState{}}
// Query request for channel state
GetChannelRequest = QueryMsg{GetChannel: &struct{}{}}
GetChannelRequest = QueryMsg{GetChannel: &QueryMsg_GetChannel{}}
// Query request for contract ownership
OwnershipRequest = QueryMsg{Ownership: &struct{}{}}
OwnershipRequest = QueryMsg{Ownership: &QueryMsg_Ownership{}}
)
192 changes: 0 additions & 192 deletions e2e/interchaintest/types/icacontroller/cosmos_msg.go

This file was deleted.

14 changes: 7 additions & 7 deletions e2e/interchaintest/types/icacontroller/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

// NewExecuteMsg_SendCustomIcaMessages_FromProto creates a new ExecuteMsg_SendCustomIcaMessages.
func NewExecuteMsg_SendCustomIcaMessages_FromProto(cdc codec.Codec, msgs []proto.Message, encoding string, memo *string, timeout *uint64) ExecuteMsg {
func NewExecuteMsg_SendCustomIcaMessages_FromProto(cdc codec.Codec, msgs []proto.Message, encoding string, memo *string, timeout *int) ExecuteMsg {
bz, err := icatypes.SerializeCosmosTx(cdc, msgs, encoding)
if err != nil {
panic(err)
Expand All @@ -22,27 +22,27 @@ func NewExecuteMsg_SendCustomIcaMessages_FromProto(cdc codec.Codec, msgs []proto

return ExecuteMsg{
SendCustomIcaMessages: &ExecuteMsg_SendCustomIcaMessages{
Messages: messages,
Messages: Binary(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))
func NewExecuteMsg_SendCosmosMsgs_FromProto(msgs []proto.Message, memo *string, timeout *int) ExecuteMsg {
cosmosMsgs := make([]CosmosMsg_for_Empty, len(msgs))

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

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

Expand Down
Loading

0 comments on commit ff13307

Please sign in to comment.