Skip to content

Commit

Permalink
More credible test fixture for batch_messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mzabaluev committed Aug 22, 2022
1 parent f0e9c58 commit 4f90ce3
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions relayer/src/chain/cosmos/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,58 @@ fn batch_messages(
#[cfg(test)]
mod tests {
use super::batch_messages;
use crate::chain::cosmos::types::account::Account;
use crate::chain::cosmos::types::account::{Account, AccountNumber, AccountSequence};
use crate::chain::cosmos::types::config::TxConfig;
use crate::config;
use crate::config::types::{MaxMsgNum, MaxTxSize, Memo};
use crate::keyring::KeyEntry;
use bitcoin::network::constants::Network;
use bitcoin::util::bip32::{ExtendedPrivKey, ExtendedPubKey};
use bitcoin::util::key::Secp256k1;
use ibc::core::ics24_host::identifier::ChainId;
use ibc_proto::google::protobuf::Any;

fn decode_bech32(input: &str) -> Vec<u8> {
use bech32::FromBase32;

bech32::decode(input)
.and_then(|(_, data, _)| Vec::from_base32(&data))
.unwrap()
}

fn test_fixture() -> (TxConfig, KeyEntry, Account) {
todo!()
let path = concat!(
env!("CARGO_MANIFEST_DIR"),
"/tests/config/fixtures/relayer_conf_example.toml"
);
let config = config::load(path).expect("could not parse config");
let chain_config = config.find_chain(&ChainId::from_string("chain_A")).unwrap();

let tx_config = TxConfig::try_from(chain_config).expect("could not obtain tx config");

let secp256k1 = Secp256k1::new();
let private_key = ExtendedPrivKey::new_master(
Network::Testnet,
b"the quick brown fox jumps over the lazy dog",
)
.unwrap();
// Derive a private subkey with a path?
let public_key = ExtendedPubKey::from_priv(&secp256k1, &private_key);
let account = String::from("cosmos1m2rdz42g8xwqa63r4s8tnsfwyvktcajpn93cvn");
let address = decode_bech32(&account);
let key_entry = KeyEntry {
public_key,
private_key,
account,
address,
};

let account = Account {
number: AccountNumber::new(0),
sequence: AccountSequence::new(0),
};

(tx_config, key_entry, account)
}

#[test]
Expand Down

0 comments on commit 4f90ce3

Please sign in to comment.