Skip to content

Commit

Permalink
refactor wait_for_* methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dkijania committed Nov 22, 2021
1 parent 0199f70 commit de1e933
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
27 changes: 17 additions & 10 deletions testing/jormungandr-testing-utils/src/testing/node/time.rs
@@ -1,23 +1,30 @@
use super::JormungandrRest;
use chain_impl_mockchain::block::BlockDate as ChainBlockDate;
use jormungandr_lib::interfaces::BlockDate;
use std::str::FromStr;

pub fn wait_for_epoch(target_epoch_id: u32, mut rest: JormungandrRest) {
rest.enable_logger();

while get_current_date(&mut rest).epoch() < target_epoch_id {
std::thread::sleep(std::time::Duration::from_secs(1));
}
pub fn wait_for_epoch(epoch: u32, rest: JormungandrRest) {
wait_for_date(ChainBlockDate { epoch, slot_id: 0 }.into(), rest)
}

pub fn wait_for_date(target_block_date: BlockDate, mut rest: JormungandrRest) {
rest.enable_logger();

while get_current_date(&mut rest) < target_block_date {
std::thread::sleep(std::time::Duration::from_secs(1));
let settings = rest.settings().unwrap();
while is_it_due(get_current_date(&mut rest), target_block_date) {
std::thread::sleep(std::time::Duration::from_secs(settings.slot_duration));
}
}

fn is_it_due(current_block_date: BlockDate, target_block_date: BlockDate) -> bool {
println!(
"waiting for block date : {}.{}/{}.{}",
current_block_date.epoch(),
current_block_date.slot(),
target_block_date.epoch(),
target_block_date.slot()
);
current_block_date < target_block_date
}

pub fn get_current_date(rest: &mut JormungandrRest) -> BlockDate {
BlockDate::from_str(
rest.stats()
Expand Down
6 changes: 5 additions & 1 deletion testing/jormungandr-testing-utils/src/wallet/mod.rs
Expand Up @@ -11,7 +11,7 @@ use crate::{
};
use chain_addr::AddressReadable;
use chain_addr::Discrimination;
use chain_crypto::{Ed25519, Ed25519Extended, SecretKey, Signature};
use chain_crypto::{Ed25519, Ed25519Extended, PublicKey, SecretKey, Signature};
pub use chain_impl_mockchain::{
account::SpendingCounter,
block::Block,
Expand Down Expand Up @@ -191,6 +191,10 @@ impl Wallet {
}
}

pub fn public_key(&self) -> PublicKey<Ed25519> {
self.address().1.public_key().unwrap().clone()
}

pub fn address_bech32(&self, discrimination: Discrimination) -> String {
AddressReadable::from_address(&discrimination.into_prefix(), &self.address().into())
.to_string()
Expand Down

0 comments on commit de1e933

Please sign in to comment.