Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cosmwasm: add wormchain ibc receiver rust tests #80

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clients/js/src/consts/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Mainnet = {
key: getEnvVar("TERRA_MNEMONIC"),
},
Ethereum: {
rpc: `https://rpc.ankr.com/eth`,
rpc: `https://ethereum-rpc.publicnode.com`,
key: getEnvVar("ETH_KEY"),
chain_id: 1,
},
Expand Down
3 changes: 3 additions & 0 deletions cosmwasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions cosmwasm/contracts/wormchain-ibc-receiver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ thiserror = "1.0.31"
wormhole-bindings = "0.1.0"
wormhole-sdk = { workspace = true, features = ["schemars"] }
serde_wormhole.workspace = true

[dev-dependencies]
cw-multi-test = "0.13.2"
serde-json-wasm = "0.4"
wormhole-bindings = { version = "0.1.0", features=["fake"] }
serde = { version = "1.0.137", default-features = false, features = ["derive"] }
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn execute(
}
}

fn submit_vaas(
pub fn submit_vaas(
mut deps: DepsMut<WormholeQuery>,
info: MessageInfo,
vaas: Vec<Binary>,
Expand Down
3 changes: 3 additions & 0 deletions cosmwasm/contracts/wormchain-ibc-receiver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ pub mod error;
pub mod ibc;
pub mod msg;
pub mod state;

#[cfg(test)]
pub mod tests;
2 changes: 2 additions & 0 deletions cosmwasm/contracts/wormchain-ibc-receiver/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod test_utils;
pub mod tests;
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)
}
Loading
Loading