forked from wormhole-foundation/wormhole
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cosmwasm: added rust tests to wormchain-ibc-receiver
- Loading branch information
Showing
7 changed files
with
392 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
|
@@ -3,3 +3,6 @@ pub mod error; | |
pub mod ibc; | ||
pub mod msg; | ||
pub mod state; | ||
|
||
#[cfg(test)] | ||
pub mod tests; |
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,2 @@ | ||
pub mod test_utils; | ||
pub mod tests; |
66 changes: 66 additions & 0 deletions
66
cosmwasm/contracts/wormchain-ibc-receiver/src/tests/test_utils.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,66 @@ | ||
use cosmwasm_std::{Binary, Uint256}; | ||
use serde::Serialize; | ||
use wormhole_bindings::fake::WormholeKeeper; | ||
use wormhole_sdk::{ | ||
ibc_receiver::{Action, GovernancePacket}, | ||
token::Message, | ||
vaa::{Body, Header, Vaa}, | ||
Address, Amount, Chain, GOVERNANCE_EMITTER, | ||
}; | ||
|
||
pub fn create_transfer_vaa_body(i: usize) -> Body<Message> { | ||
Body { | ||
timestamp: i as u32, | ||
nonce: i as u32, | ||
emitter_chain: (i as u16).into(), | ||
emitter_address: Address([(i as u8); 32]), | ||
sequence: i as u64, | ||
consistency_level: 32, | ||
payload: Message::Transfer { | ||
amount: Amount(Uint256::from(i as u128).to_be_bytes()), | ||
token_address: Address([(i + 1) as u8; 32]), | ||
token_chain: (i as u16).into(), | ||
recipient: Address([i as u8; 32]), | ||
recipient_chain: ((i + 2) as u16).into(), | ||
fee: Amount([0u8; 32]), | ||
}, | ||
} | ||
} | ||
|
||
pub fn create_gov_vaa_body( | ||
i: usize, | ||
chain_id: Chain, | ||
channel_id: [u8; 64], | ||
) -> Body<GovernancePacket> { | ||
Body { | ||
timestamp: i as u32, | ||
nonce: i as u32, | ||
emitter_chain: Chain::Solana, | ||
emitter_address: GOVERNANCE_EMITTER, | ||
sequence: i as u64, | ||
consistency_level: 0, | ||
payload: GovernancePacket { | ||
chain: Chain::Wormchain, | ||
action: Action::UpdateChannelChain { | ||
channel_id, | ||
chain_id, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
pub fn sign_vaa_body<P: Serialize>(wh: WormholeKeeper, body: Body<P>) -> (Vaa<P>, Binary) { | ||
let data = serde_wormhole::to_vec(&body).unwrap(); | ||
let signatures = WormholeKeeper::new().sign(&data); | ||
|
||
let header = Header { | ||
version: 1, | ||
guardian_set_index: wh.guardian_set_index(), | ||
signatures, | ||
}; | ||
|
||
let v = (header, body).into(); | ||
let data = serde_wormhole::to_vec(&v).map(From::from).unwrap(); | ||
|
||
(v, data) | ||
} |
Oops, something went wrong.