Skip to content

Commit

Permalink
e2e: test passing
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Jul 20, 2024
1 parent 7bfd922 commit 276f4ed
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 51 deletions.
52 changes: 26 additions & 26 deletions e2e/interchaintestv8/types/callbackcounter/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ type Uint128 string

// In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.
type IbcTimeout struct {
Block *IbcTimeoutBlock `json:"block,omitempty"`
Timestamp *Timestamp `json:"timestamp,omitempty"`
Block *IbcTimeoutBlock `json:"block,omitempty"`
Timestamp *Timestamp `json:"timestamp,omitempty"`
}

/*
Expand All @@ -66,9 +66,9 @@ type IbcChannel struct {
// Note: in ibcv3 this may be "", in the IbcOpenChannel handshake messages
Version string `json:"version"`
// The connection upon which this channel was created. If this is a multi-hop channel, we only expose the first hop.
ConnectionId string `json:"connection_id"`
ConnectionId string `json:"connection_id"`
CounterpartyEndpoint IbcEndpoint `json:"counterparty_endpoint"`
Endpoint IbcEndpoint `json:"endpoint"`
Endpoint IbcEndpoint `json:"endpoint"`
}

/*
Expand All @@ -92,9 +92,9 @@ type IbcTimeoutBlock struct {

// Replicates the cosmos-sdk bank module DenomUnit type
type DenomUnit struct {
Aliases []string `json:"aliases"`
Denom string `json:"denom"`
Exponent int `json:"exponent"`
Aliases []string `json:"aliases"`
Denom string `json:"denom"`
Exponent int `json:"exponent"`
}

// Instances are created in the querier.
Expand Down Expand Up @@ -134,7 +134,7 @@ The essential data from wasmd's [CodeInfo]/[CodeInfoResponse].
type CodeInfoResponse struct {
// The hash of the Wasm blob
Checksum HexBinary `json:"checksum"`
CodeId int `json:"code_id"`
CodeId int `json:"code_id"`
// The address that initially stored the code
Creator string `json:"creator"`
}
Expand All @@ -148,8 +148,8 @@ type ContractInfoResponse struct {
// if set, the contract is pinned to the cache, and thus uses less gas when called
Pinned bool `json:"pinned"`
// admin who can run migrations (if any)
Admin *string `json:"admin,omitempty"`
CodeId int `json:"code_id"`
Admin *string `json:"admin,omitempty"`
CodeId int `json:"code_id"`
// address that instantiated this contract
Creator string `json:"creator"`
// set if this contract has bound an IBC port
Expand Down Expand Up @@ -256,17 +256,17 @@ type IcaQueryResult struct {

type IbcEndpoint struct {
ChannelId string `json:"channel_id"`
PortId string `json:"port_id"`
PortId string `json:"port_id"`
}

// The response type for the [`cosmwasm_std::WasmQuery`] queries.
type WasmQueryResponse struct {
// Response for the [`cosmwasm_std::WasmQuery::ContractInfo`] query. Returns `None` if the contract does not exist. The `pinned` field is not supported.
ContractInfo *WasmQueryResponse_ContractInfo `json:"contract_info,omitempty"`
ContractInfo *ContractInfoResponse `json:"contract_info,omitempty"`
// Response for the [`cosmwasm_std::WasmQuery::CodeInfo`] query. Returns `None` if the code does not exist.
CodeInfo *WasmQueryResponse_CodeInfo `json:"code_info,omitempty"`
CodeInfo *CodeInfoResponse `json:"code_info,omitempty"`
// Response for the [`cosmwasm_std::WasmQuery::Raw`] query.
RawContractState *WasmQueryResponse_RawContractState `json:"raw_contract_state,omitempty"`
RawContractState *Binary `json:"raw_contract_state,omitempty"`
// Response for the [`cosmwasm_std::WasmQuery::Smart`] query.
SmartContractState *WasmQueryResponse_SmartContractState `json:"smart_contract_state,omitempty"`
}
Expand All @@ -279,8 +279,8 @@ type IbcPacket struct {
// The sequence number of the packet on the given channel
Sequence int `json:"sequence"`
// identifies the channel and port on the sending chain.
Src IbcEndpoint `json:"src"`
Timeout IbcTimeout `json:"timeout"`
Src IbcEndpoint `json:"src"`
Timeout IbcTimeout `json:"timeout"`
}
type ExecuteMsg_ReceiveIcaCallback IcaControllerCallbackMsg

Expand All @@ -306,7 +306,7 @@ type AllValidatorsResponse struct {
type AllDenomMetadataResponse struct {
// Always returns metadata for all token denoms on the base chain.
Metadata []DenomMetadata `json:"metadata"`
NextKey *Binary `json:"next_key,omitempty"`
NextKey *Binary `json:"next_key,omitempty"`
}

type BalanceResponse struct {
Expand All @@ -326,21 +326,21 @@ type IcaControllerCallbackMsg struct {

// Replicates the cosmos-sdk bank module Metadata type
type DenomMetadata struct {
Name string `json:"name"`
Symbol string `json:"symbol"`
Uri string `json:"uri"`
UriHash string `json:"uri_hash"`
Base string `json:"base"`
DenomUnits []DenomUnit `json:"denom_units"`
Description string `json:"description"`
Display string `json:"display"`
Name string `json:"name"`
Symbol string `json:"symbol"`
Uri string `json:"uri"`
UriHash string `json:"uri_hash"`
Base string `json:"base"`
DenomUnits []DenomUnit `json:"denom_units"`
Description string `json:"description"`
Display string `json:"display"`
}

type QueryMsg_GetCallbackCounter struct{}

type Coin struct {
Amount Uint128 `json:"amount"`
Denom string `json:"denom"`
Denom string `json:"denom"`
}

// `Data` is the response to an ibc packet. It either contains a result or an error.
Expand Down
43 changes: 18 additions & 25 deletions e2e/interchaintestv8/wasm_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ import (
"strconv"
"testing"

"github.com/cosmos/gogoproto/proto"
"github.com/stretchr/testify/suite"

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

icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
ibctesting "github.com/cosmos/ibc-go/v8/testing"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
Expand Down Expand Up @@ -356,31 +352,28 @@ func (s *WasmTestSuite) TestSendWasmQueries() {
expResp, err := s.CounterContract.QueryClient().GetCount(ctx, &simplecounter.QueryMsg_GetCount{})
s.Require().NoError(err)

icaAck := &sdk.TxMsgData{}
s.Require().True(s.Run("unmarshal ica response", func() {
err := proto.Unmarshal(callbackCounter.Success[0].OnAcknowledgementPacketCallback.IcaAcknowledgement.Result.Unwrap(), icaAck)
s.Require().NoError(err)
s.Require().Len(icaAck.GetMsgResponses(), 1)
}))

queryTxResp := &icahosttypes.MsgModuleQuerySafeResponse{}
s.Require().True(s.Run("unmarshal MsgModuleQuerySafeResponse", func() {
err := proto.Unmarshal(icaAck.MsgResponses[0].Value, queryTxResp)
s.Require().NoError(err)
s.Require().Len(queryTxResp.Responses, 1)
}))

contractResp := &simplecounter.GetCountResponse{}
s.Require().True(s.Run("unmarshal and verify bank query response", func() {
smartResp := &wasmtypes.QuerySmartContractStateResponse{}
s.Require().NoError(proto.Unmarshal(queryTxResp.Responses[0], smartResp))
s.Require().NoError(json.Unmarshal(smartResp.Data, contractResp))
s.Require().Equal(expResp.Count, contractResp.Count)
}))
s.Require().NotNil(callbackCounter.Success[1].OnAcknowledgementPacketCallback.QueryResult)
s.Require().Nil(callbackCounter.Success[1].OnAcknowledgementPacketCallback.QueryResult.Error)
s.Require().NotNil(callbackCounter.Success[1].OnAcknowledgementPacketCallback.QueryResult.Success)
s.Require().Len(callbackCounter.Success[1].OnAcknowledgementPacketCallback.QueryResult.Success.Responses, 1)

var countResp simplecounter.GetCountResponse
s.Require().NotNil(callbackCounter.Success[1].OnAcknowledgementPacketCallback.QueryResult.Success.Responses[0].Wasm.SmartContractState)
s.T().Logf("SmartContractState: %s", fromBase64(string(*callbackCounter.Success[1].OnAcknowledgementPacketCallback.QueryResult.Success.Responses[0].Wasm.SmartContractState)))
s.Require().NoError(json.Unmarshal(fromBase64(string(*callbackCounter.Success[1].OnAcknowledgementPacketCallback.QueryResult.Success.Responses[0].Wasm.SmartContractState)), &countResp))
s.Require().Equal(expResp.Count, countResp.Count)
}))
}))
}

func toBase64(msg string) string {
return base64.StdEncoding.EncodeToString([]byte(msg))
}

func fromBase64(data string) []byte {
b, err := base64.StdEncoding.DecodeString(data)
if err != nil {
panic(err)
}
return b
}

0 comments on commit 276f4ed

Please sign in to comment.