Skip to content

Commit

Permalink
test consistent packet commitment in cairo and rust
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed Feb 4, 2025
1 parent e1e9c15 commit aa5bc01
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions relayer/crates/starknet-integration-tests/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod erc20;
pub mod ics20;
pub mod light_client;
pub mod packet_commitment;
pub mod update_clients;
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use ibc::core::channel::types::commitment::compute_packet_commitment;
use ibc::core::channel::types::timeout::{TimeoutHeight, TimeoutTimestamp};
use ibc::core::client::types::Height;
use ibc::primitives::Timestamp;

#[test]
fn test_cairo_packet_commitment() {
// https://github.com/informalsystems/ibc-starknet/blob/7967c8045ed6b4453030e01d0df12c47c2d77b37/cairo-contracts/packages/apps/src/transfer/types.cairo#L307
// https://github.com/informalsystems/ibc-starknet/blob/7967c8045ed6b4453030e01d0df12c47c2d77b37/cairo-contracts/packages/core/src/tests/commitment.cairo#L52-L58

let timeout_height = TimeoutHeight::At(Height::new(0, 1000).expect("valid height"));
let timeout_timestamp = TimeoutTimestamp::At(Timestamp::from_nanoseconds(1000 * 1_000_000_000));

let packet_json_data: &str =
"{\"denom\":\"2087021424722619777119509474943472645767659996348769578120564519014510906823\",\"amount\":\"100\",\"sender\":\"1431520594\",\"receiver\":\"cosmos1wxeyh7zgn4tctjzs0vtqpc6p5cxq5t2muzl7ng\",\"memo\":\"\"}";

let expected: Vec<u32> = [
3458244073, 1576048754, 4210798310, 1002247062, 2365181318, 2763927782, 545147151,
944653547,
]
.to_vec();

let actual = compute_packet_commitment(
packet_json_data.as_ref(),
&timeout_height,
&timeout_timestamp,
)
.into_vec()
.chunks(4)
.map(|chunk| {
let mut bytes = [0u8; 4];
bytes.copy_from_slice(&chunk);
u32::from_be_bytes(bytes)
})
.collect::<Vec<_>>();

assert_eq!(expected, actual);
}

0 comments on commit aa5bc01

Please sign in to comment.