-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test consistent packet commitment in cairo and rust
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
38 changes: 38 additions & 0 deletions
38
relayer/crates/starknet-integration-tests/src/tests/packet_commitment.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |