Skip to content

Commit

Permalink
feat: RecvPacket tests are passing with ibc-go (#4)
Browse files Browse the repository at this point in the history
* use new image

* deps: new branch

* imp: added correct prefix

* imp: started full test

* imp: all

* test: added more assertions

* imp: almost working send packet

* imp: improved commitments

* imp: test passing so far

* deps: ran 'go mod tidy'

* imp: passing tests

* fix: issues

* imp: RecvPacket test passing

* imp: fix test
  • Loading branch information
srdtrk authored Jun 28, 2024
1 parent b6e630a commit 16727a8
Show file tree
Hide file tree
Showing 23 changed files with 324 additions and 134 deletions.
1 change: 1 addition & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
- TestWithICS07TendermintTestSuite/TestUpdateClient
- TestWithICS07TendermintTestSuite/TestVerifyMembership
- TestWithIBCLiteTestSuite/TestWasmProofs
- TestWithIBCLiteTestSuite/TestCW20Transfer
name: ${{ matrix.test }}
runs-on: ubuntu-latest
steps:
Expand Down
12 changes: 6 additions & 6 deletions contracts/ics02-client/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# CosmWasm IBC Lite Router Contract
# `CosmWasm` IBC Lite Router Contract

This contract is the core router for CosmWasm IBC Lite. It is responsible for handling:
This contract is the core router for `CosmWasm` IBC Lite. It is responsible for handling:

- SendPacket
- RecvPacket
- Acknowledgement
- Timeout
- `SendPacket`
- `RecvPacket`
- `Acknowledgement`
- `Timeout`

It also stores the following provable state as defined in [ICS-24 host requirements](https://github.com/cosmos/ibc/blob/main/spec/core/ics-024-host-requirements/README.md):

Expand Down
23 changes: 0 additions & 23 deletions contracts/ics02-client/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ pub fn execute(
#[cosmwasm_std::entry_point]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result<Binary, ContractError> {
match msg {
QueryMsg::QueryClient { client_id, query } => query::query_client(deps, client_id, query),
QueryMsg::ClientInfo { client_id } => query::client_info(deps, client_id),
QueryMsg::Counterparty { client_id } => query::counterparty(deps, client_id),
}
}

Expand Down Expand Up @@ -188,8 +186,6 @@ mod execute {
mod query {
use super::{state, Binary, ContractError, Deps};

use cw_ibc_lite_shared::types::clients::helpers;

use crate::types::msg::query_responses;

/// Returns the address of the client encoded as a JSON binary.
Expand All @@ -208,23 +204,4 @@ mod query {
},
)?)
}

#[allow(clippy::needless_pass_by_value, clippy::module_name_repetitions)]
pub fn query_client(
deps: Deps,
client_id: String,
query_msg: cw_ibc_lite_shared::types::clients::msg::QueryMsg,
) -> Result<Binary, ContractError> {
let client_address = state::CLIENTS.load(deps.storage, &client_id)?;
let client_contract = helpers::LightClientContract::new(client_address);

Ok(client_contract.query(&deps.querier).smart_raw(query_msg)?)
}

#[allow(clippy::needless_pass_by_value)]
pub fn counterparty(deps: Deps, client_id: String) -> Result<Binary, ContractError> {
let counterparty_info: state::CounterpartyInfo =
state::COUNTERPARTY.load(deps.storage, &client_id)?;
Ok(cosmwasm_std::to_json_binary(&counterparty_info)?)
}
}
36 changes: 1 addition & 35 deletions contracts/ics02-client/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use cosmwasm_std::{
StdResult, WasmMsg,
};

use crate::types::{msg, state::CounterpartyInfo};
use crate::types::msg;

/// `Ics02ClientContract` is a wrapper around Addr that provides helpers
/// for working with this contract.
Expand Down Expand Up @@ -206,38 +206,4 @@ impl<'a> Ics02ClientContractQuerier<'a> {
},
)
}

/// `query_client` sends a [`msg::QueryMsg::QueryClient`] query to this contract.
/// It returns the result of the query on the client contract with the given client id.
///
/// # Errors
///
/// This function returns an error if the query fails
pub fn query_client(
&self,
client_id: impl Into<String>,
query: impl Into<cw_ibc_lite_shared::types::clients::msg::QueryMsg>,
) -> StdResult<msg::query_responses::QueryClient> {
self.querier.query_wasm_smart(
&self.addr,
&msg::QueryMsg::QueryClient {
client_id: client_id.into(),
query: query.into(),
},
)
}

/// `counterparty` sends a [`msg::QueryMsg::Counterparty`] query to this contract.
/// It returns the counterparty of the client contract with the given client id.
///
/// # Errors
/// This function returns an error if the query fails
pub fn counterparty(&self, client_id: impl Into<String>) -> StdResult<CounterpartyInfo> {
self.querier.query_wasm_smart(
&self.addr,
&msg::QueryMsg::Counterparty {
client_id: client_id.into(),
},
)
}
}
18 changes: 0 additions & 18 deletions contracts/ics02-client/src/types/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,12 @@ pub enum ExecuteMsg {
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
/// Execute a query on a client.
/// Instead of using this message from external contracts, it is recommended to use
/// [`crate::helpers::Ics02ClientContractQuerier::client_querier`] to query the client.
#[returns(query_responses::QueryClient)]
QueryClient {
/// The client id of the client to execute the query on.
client_id: String,
/// The query to execute on the client.
query: cw_ibc_lite_shared::types::clients::msg::QueryMsg,
},
/// Get the contract address of a client. Returns an error if the client does not exist.
#[returns(query_responses::ClientInfo)]
ClientInfo {
/// The client id of the client to get the address of.
client_id: String,
},
/// Get the counterparty of a client. Returns an error if the client does not have a
/// counterparty or the client does not exist.
// TODO: Delete
#[returns(super::state::CounterpartyInfo)]
Counterparty {
/// The client id of the client to get the counterparty of.
client_id: String,
},
}

/// Contains the query responses supported by the contract.
Expand Down
12 changes: 6 additions & 6 deletions contracts/ics07-tendermint/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# CosmWasm IBC Lite Router Contract
# `CosmWasm` IBC Lite Router Contract

This contract is the core router for CosmWasm IBC Lite. It is responsible for handling:
This contract is the core router for `CosmWasm` IBC Lite. It is responsible for handling:

- SendPacket
- RecvPacket
- Acknowledgement
- Timeout
- `SendPacket`
- `RecvPacket`
- `Acknowledgement`
- `Timeout`

It also stores the following provable state as defined in [ICS-24 host requirements](https://github.com/cosmos/ibc/blob/main/spec/core/ics-024-host-requirements/README.md):

Expand Down
5 changes: 2 additions & 3 deletions contracts/ics07-tendermint/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub fn instantiate(
}

/// Handles the execution of the contract by routing the messages to the respective handlers.
/// Can be called by anyone.
///
/// # Errors
/// Will return an error if the handler returns an error.
Expand All @@ -42,11 +43,9 @@ pub fn instantiate(
pub fn execute(
deps: DepsMut,
env: Env,
info: MessageInfo,
_info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, ContractError> {
state::owner::assert(deps.storage, info.sender.as_str())?;

let mut ctx = TendermintContext::new_mut(deps, env)?;
let data = ctx.sudo(msg.into())?;

Expand Down
2 changes: 1 addition & 1 deletion contracts/ics20-transfer/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# CosmWasm IBC Lite Transfer App
# `CosmWasm` IBC Lite Transfer App

This is a transfer application for `cw-ibc-lite`. It is based on [cw20-ics20](https://github.com/CosmWasm/cw-plus/tree/main/contracts/cw20-ics20) contract. It currently only works with cw20 tokens.
12 changes: 6 additions & 6 deletions contracts/ics26-router/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# CosmWasm IBC Lite Router Contract
# `CosmWasm` IBC Lite Router Contract

This contract is the core router for CosmWasm IBC Lite. It is responsible for handling:
This contract is the core router for `CosmWasm` IBC Lite. It is responsible for handling:

- SendPacket
- RecvPacket
- Acknowledgement
- Timeout
- `SendPacket`
- `RecvPacket`
- `Acknowledgement`
- `Timeout`

It also stores the following provable state as defined in [ICS-24 host requirements](https://github.com/cosmos/ibc/blob/main/spec/core/ics-024-host-requirements/README.md):

Expand Down
20 changes: 14 additions & 6 deletions contracts/ics26-router/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ mod execute {
// Ensure the counterparty is the destination channel.
let counterparty_id = ics02_contract
.query(&deps.querier)
.counterparty(msg.source_channel.as_str())?
.client_info(msg.source_channel.as_str())?
.counterparty_info
.ok_or(ContractError::CounterpartyNotFound)?
.client_id;
if let Some(dest_channel) = msg.dest_channel.as_ref() {
if counterparty_id != dest_channel.as_str() {
Expand Down Expand Up @@ -210,7 +212,9 @@ mod execute {
// Verify the counterparty.
let counterparty = ics02_contract
.query(&deps.querier)
.counterparty(packet.destination_channel.as_str())?;
.client_info(packet.destination_channel.as_str())?
.counterparty_info
.ok_or(ContractError::CounterpartyNotFound)?;
if counterparty.client_id != packet.source_channel.as_str() {
return Err(ContractError::invalid_counterparty(
counterparty.client_id,
Expand Down Expand Up @@ -277,7 +281,9 @@ mod execute {
// Verify the counterparty.
let counterparty = ics02_contract
.query(&deps.querier)
.counterparty(packet.source_channel.as_str())?;
.client_info(packet.source_channel.as_str())?
.counterparty_info
.ok_or(ContractError::CounterpartyNotFound)?;
if counterparty.client_id != packet.destination_channel.as_str() {
return Err(ContractError::invalid_counterparty(
counterparty.client_id,
Expand All @@ -303,6 +309,7 @@ mod execute {
}

// Verify the packet acknowledgement.
let packet_ack: ibc::Acknowledgement = msg.acknowledgement.try_into()?;
let packet_ack_path: ics24_host::MerklePath = ics24_host::PacketAcknowledgementPath {
port_id: packet.destination_port.clone(),
channel_id: packet.destination_channel.clone(),
Expand All @@ -315,7 +322,7 @@ mod execute {
.verify_membership(VerifyMembershipMsgRaw {
proof: msg.proof_acked.into(),
path: packet_ack_path,
value: msg.acknowledgement.to_vec(),
value: packet_ack.to_commitment_bytes(),
height: msg.proof_height.into(),
delay_time_period: 0,
delay_block_period: 0,
Expand All @@ -326,7 +333,7 @@ mod execute {
let event = events::acknowledge_packet::success(&packet);
let callback_msg = apps::callbacks::IbcAppCallbackMsg::OnAcknowledgementPacket {
packet,
acknowledgement: msg.acknowledgement,
acknowledgement: packet_ack.into(),
relayer: info.sender.into(),
};
let ack_callback = ibc_app_contract.call(callback_msg)?;
Expand Down Expand Up @@ -393,7 +400,8 @@ mod reply {
) -> Result<Response, ContractError> {
match result {
SubMsgResult::Ok(resp) => {
#[allow(warnings)] // TODO: remove this once we have working tests and then fix it.
// TODO: allow depracated until we have working tests and then change it.
#[allow(deprecated)]
let ack: ibc::Acknowledgement = resp
.data
.ok_or(ContractError::RecvPacketCallbackNoResponse)?
Expand Down
2 changes: 1 addition & 1 deletion contracts/ics26-router/src/types/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub mod helpers {
) -> StdResult<u64> {
let next_sequence = super::NEXT_SEQUENCE_SEND
.may_load(storage, (port_id, channel_id))?
.unwrap_or_default();
.unwrap_or(1);
super::NEXT_SEQUENCE_SEND.save(storage, (port_id, channel_id), &(next_sequence + 1))?;
Ok(next_sequence)
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/interchaintestv8/chainconfig/chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ var DefaultChainSpecs = []*interchaintest.ChainSpec{
ChainID: "simd-1",
Images: []ibc.DockerImage{
{
Repository: "ghcr.io/cosmos/ibc-go-simd", // FOR LOCAL IMAGE USE: Docker Image Name
Version: "serdar-xxx-lite-bytes-prefix", // FOR LOCAL IMAGE USE: Docker Image Tag
Repository: "ghcr.io/cosmos/ibc-go-simd", // FOR LOCAL IMAGE USE: Docker Image Name
Version: "serdar-xxx-ibc-lite-e2e-image", // FOR LOCAL IMAGE USE: Docker Image Tag
UidGid: "1025:1025",
},
},
Expand Down
4 changes: 3 additions & 1 deletion e2e/interchaintestv8/e2esuite/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"

abci "github.com/cometbft/cometbft/abci/types"

clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"

Expand Down Expand Up @@ -84,7 +86,7 @@ func (s *TestSuite) fundAddress(ctx context.Context, chain *cosmos.CosmosChain,
// ExtractValueFromEvents extracts the value of an attribute from a list of events.
// If the attribute is not found, the function returns an empty string and false.
// If the attribute is found, the function returns the value and true.
func (*TestSuite) ExtractValueFromEvents(events sdk.StringEvents, eventType, attrKey string) (string, bool) {
func (*TestSuite) ExtractValueFromEvents(events []abci.Event, eventType, attrKey string) (string, bool) {
for _, event := range events {
if event.Type != eventType {
continue
Expand Down
4 changes: 2 additions & 2 deletions e2e/interchaintestv8/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
cosmossdk.io/x/tx v0.13.3
cosmossdk.io/x/upgrade v0.1.2
github.com/CosmWasm/wasmd v0.51.0
github.com/cometbft/cometbft v0.38.7
github.com/cosmos/cosmos-sdk v0.50.6
github.com/cosmos/gogoproto v1.4.12
github.com/cosmos/ibc-go/v8 v8.3.0
Expand Down Expand Up @@ -69,7 +70,6 @@ require (
github.com/cockroachdb/pebble v1.1.0 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cometbft/cometbft v0.38.7 // indirect
github.com/cometbft/cometbft-db v0.10.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-db v1.0.2 // indirect
Expand Down Expand Up @@ -261,7 +261,7 @@ require (
sigs.k8s.io/yaml v1.4.0 // indirect
)

replace github.com/cosmos/ibc-go/v8 => github.com/cosmos/ibc-go/v8 v8.0.0-beta.1.0.20240626084404-83f90bbd2580
replace github.com/cosmos/ibc-go/v8 => github.com/cosmos/ibc-go/v8 v8.0.0-beta.1.0.20240626120620-1607d5969996

replace github.com/strangelove-ventures/interchaintest/v8 => github.com/DimitrisJim/interchaintest/v8 v8.0.0-20240419095404-2c9270423b9a

Expand Down
4 changes: 2 additions & 2 deletions e2e/interchaintestv8/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ github.com/cosmos/iavl v1.1.2 h1:zL9FK7C4L/P4IF1Dm5fIwz0WXCnn7Bp1M2FxH0ayM7Y=
github.com/cosmos/iavl v1.1.2/go.mod h1:jLeUvm6bGT1YutCaL2fIar/8vGUE8cPZvh/gXEWDaDM=
github.com/cosmos/ibc-go/modules/capability v1.0.0 h1:r/l++byFtn7jHYa09zlAdSeevo8ci1mVZNO9+V0xsLE=
github.com/cosmos/ibc-go/modules/capability v1.0.0/go.mod h1:D81ZxzjZAe0ZO5ambnvn1qedsFQ8lOwtqicG6liLBco=
github.com/cosmos/ibc-go/v8 v8.0.0-beta.1.0.20240626084404-83f90bbd2580 h1:CXYlFz54SeXghW2RbhVRz/3zOBtV4AXjomsQlLSLOFM=
github.com/cosmos/ibc-go/v8 v8.0.0-beta.1.0.20240626084404-83f90bbd2580/go.mod h1:1r6hWEhBg9a8bmWA3wtOeWhf86+9JkmXznLOoU0pCrY=
github.com/cosmos/ibc-go/v8 v8.0.0-beta.1.0.20240626120620-1607d5969996 h1:zIDq6vjhzYY+aAiQoA1N9MZYXmL4iawDdWVsKB1TkZE=
github.com/cosmos/ibc-go/v8 v8.0.0-beta.1.0.20240626120620-1607d5969996/go.mod h1:1r6hWEhBg9a8bmWA3wtOeWhf86+9JkmXznLOoU0pCrY=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0=
github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM=
Expand Down
Loading

0 comments on commit 16727a8

Please sign in to comment.