Skip to content

Commit

Permalink
Update test_packet_clearing (#328)
Browse files Browse the repository at this point in the history
* Use auto_bi_relay in test_packet_clearing

* Assert acks have been relayed on Cosmos side

* Fix test_packet_clearing following merge

* use unshashed packet_ack

* add comment

* Fix test_packet_clearing using query packet commitment

* starknet-devnet with full state archive capacity

forgot in #332

---------

Co-authored-by: Ranadeep Biswas <[email protected]>
Co-authored-by: Rano | Ranadeep <[email protected]>
  • Loading branch information
3 people authored Mar 4, 2025
1 parent 792086d commit 6751a12
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ use crate::types::membership_proof_signer::MembershipVerifierContainer;
use crate::types::messages::ibc::channel::PortId as CairoPortId;
use crate::types::messages::ibc::packet::Sequence;
use crate::types::status::StarknetChainStatus;

const SUCCESS_ACK: &[u8] = br#"{"result":"AQ=="}"#;

pub struct QueryStarknetAckCommitment;

#[cgp_provider(PacketAcknowledgementQuerierComponent)]
Expand Down Expand Up @@ -117,6 +120,14 @@ where
proof_bytes: signed_bytes,
};

Ok((ack_bytes, dummy_proof))
// assert sha256 hash of SUCCESS_ACK is stored ack_bytes
// asset_eq!(ack_bytes, SUCCESS_ACK);

// FIXME: we can't send `ack_bytes` as it is stored after hashing.
// We should query block event to get the original ack_bytes.
//
// For now, we just return the SUCCESS_ACK as ack_bytes.

Ok((SUCCESS_ACK.to_vec(), dummy_proof))
}
}
119 changes: 100 additions & 19 deletions relayer/crates/starknet-integration-tests/src/tests/clear_packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ use flate2::Compression;
use hermes_chain_components::traits::packet::fields::{
HasPacketTimeoutHeight, HasPacketTimeoutTimestamp,
};
use hermes_chain_components::traits::queries::chain_status::CanQueryChainStatus;
use hermes_chain_components::traits::queries::chain_status::{
CanQueryChainHeight, CanQueryChainStatus,
};
use hermes_chain_components::traits::queries::client_state::CanQueryClientStateWithLatestHeight;
use hermes_chain_components::traits::queries::packet_commitment::CanQueryPacketCommitment;
use hermes_chain_components::traits::types::chain_id::HasChainId;
use hermes_chain_components::traits::types::timestamp::HasTimeoutType;
use hermes_cosmos_chain_components::types::channel::CosmosInitChannelOptions;
use hermes_cosmos_chain_components::types::config::gas::dynamic_gas_config::DynamicGasConfig;
use hermes_cosmos_chain_components::types::config::gas::eip_type::EipQueryType;
Expand Down Expand Up @@ -84,7 +86,7 @@ use crate::contexts::bootstrap::StarknetBootstrap;
use crate::contexts::osmosis_bootstrap::OsmosisBootstrap;

#[test]
fn test_query_unreceived_packets() -> Result<(), Error> {
fn test_packet_clearing() -> Result<(), Error> {
// ### SETUP START ###
let runtime = init_test_runtime();

Expand Down Expand Up @@ -415,6 +417,7 @@ fn test_query_unreceived_packets() -> Result<(), Error> {
let wallet_starknet_b = &starknet_chain_driver.user_wallet_b;
let address_starknet_b = &wallet_starknet_b.account_address;
let transfer_quantity = 1_000u128;
let transfer_back_quantity = 310u128;
let denom_cosmos = &cosmos_chain_driver.genesis_config.transfer_denom;

let starknet_account_b = SingleOwnerAccount::new(
Expand Down Expand Up @@ -511,6 +514,16 @@ fn test_query_unreceived_packets() -> Result<(), Error> {
cairo_encoding.decode(&output)?
};

let birelay = StarknetCosmosBiRelay {
runtime: runtime.clone(),
relay_a_to_b: starknet_to_cosmos_relay,
relay_b_to_a: cosmos_to_starknet_relay.clone(),
};

birelay
.auto_bi_relay(Some(Duration::from_secs(10)), Some(Duration::from_secs(0)))
.await?;

info!("ics20 token address: {:?}", ics20_token_address);

let balance_cosmos_a_step_0 = cosmos_chain
Expand Down Expand Up @@ -560,7 +573,7 @@ fn test_query_unreceived_packets() -> Result<(), Error> {
{
let call_data = cairo_encoding.encode(&product![
ics20_contract_address,
U256::from(transfer_quantity)
U256::from(transfer_back_quantity)
])?;

let call = Call {
Expand Down Expand Up @@ -596,7 +609,7 @@ fn test_query_unreceived_packets() -> Result<(), Error> {
port_id_on_a: ics20_port.clone(),
chan_id_on_a: starknet_channel_id.clone(),
denom,
amount: transfer_quantity.into(),
amount: transfer_back_quantity.into(),
receiver: address_cosmos_a.clone(),
memo: String::new(),
timeout_height_on_b: Height {
Expand Down Expand Up @@ -643,17 +656,88 @@ fn test_query_unreceived_packets() -> Result<(), Error> {
)
.await?;

// assert_eq!(pending_packets_starknet, vec![Sequence::from(3)]);
// TODO: Currently, querying for unreceived packets using commitment sequences that were never sent
// will always return them as unreceived. This assertion must be updated once the correct commitment-
// querying logic has been implemented.
// assert_eq!(pending_packets_cosmos, vec![Sequence::from(1), Sequence::from(2), Sequence::from(3)]);
// assert_eq!(pending_acks_starknet, vec![Sequence::from(1)]);
// assert_eq!(pending_acks_cosmos, vec![Sequence::from(2), Sequence::from(3)]);
let eventual_cosmos_amount = &Amount::new(
balance_cosmos_a_step_0.quantity - (transfer_quantity * 2) + transfer_back_quantity,
denom_cosmos.clone(),
);

birelay
.auto_bi_relay(Some(Duration::from_secs(10)), Some(Duration::from_secs(0)))
.await?;

// TODO: Call packet clearing
// TODO: Assert there are no pending packets or pending acks
// TODO: Assert tokens have been correctly transferred
cosmos_chain
.assert_eventual_amount(address_cosmos_a, eventual_cosmos_amount)
.await?;

let balance_starknet_b_step_2 = starknet_chain
.query_token_balance(&ics20_token_address, address_starknet_b)
.await?;

assert_eq!(
balance_starknet_b_step_0.quantity + (transfer_quantity * 2).into()
- transfer_back_quantity.into(),
balance_starknet_b_step_2.quantity
);

let cosmos_latest_height = cosmos_chain.query_chain_height().await?;
let starknet_latest_height = starknet_chain.query_chain_height().await?;

let (cosmos_commitment1, _) =
<CosmosChain as CanQueryPacketCommitment<StarknetChain>>::query_packet_commitment(
cosmos_chain,
&cosmos_channel_id,
&IbcPortId::transfer(),
&Sequence::from(1),
&cosmos_latest_height,
)
.await?;

let (cosmos_commitment2, _) =
<CosmosChain as CanQueryPacketCommitment<StarknetChain>>::query_packet_commitment(
cosmos_chain,
&cosmos_channel_id,
&IbcPortId::transfer(),
&Sequence::from(2),
&cosmos_latest_height,
)
.await?;

let (cosmos_commitment3, _) =
<CosmosChain as CanQueryPacketCommitment<StarknetChain>>::query_packet_commitment(
cosmos_chain,
&cosmos_channel_id,
&IbcPortId::transfer(),
&Sequence::from(3),
&cosmos_latest_height,
)
.await?;

let (starknet_commitment1, _) =
<StarknetChain as CanQueryPacketCommitment<CosmosChain>>::query_packet_commitment(
&starknet_chain,
&starknet_channel_id,
&IbcPortId::transfer(),
&Sequence::from(1),
&starknet_latest_height,
)
.await?;

assert!(
cosmos_commitment1.is_none(),
"cosmos_commitment1 expected to be None"
);
assert!(
cosmos_commitment2.is_none(),
"cosmos_commitment2 expected to be None"
);
assert!(
cosmos_commitment3.is_none(),
"cosmos_commitment3 expected to be None"
);
assert!(
starknet_commitment1.is_none(),
"starknet_commitment1 expected to be None"
);

Ok(())
})
Expand Down Expand Up @@ -1274,10 +1358,7 @@ where
SrcChain: CanQueryChainStatus
+ HasPacketTimeoutHeight<DstChain>
+ HasPacketTimeoutTimestamp<DstChain>,
DstChain: CanQueryChainStatus
//+ HasChannelIdType<SrcChain>
//+ HasPortIdType<SrcChain>
+ HasTimeoutType,
DstChain: CanQueryChainStatus,
{
let src_chain = relay.src_chain();
let dst_chain = relay.dst_chain();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ where
&chain_node_config.rpc_port.to_string(),
"--block-generation-on",
"1",
"--state-archive-capacity",
"full",
"--dump-on",
"block",
"--dump-path",
Expand Down

0 comments on commit 6751a12

Please sign in to comment.