Skip to content

Commit

Permalink
fix non deterministic tests (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram authored and thor314 committed Aug 3, 2022
1 parent ab9c743 commit fad25d6
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions crypto/signing-client/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#![allow(unused_imports)]
use super::rocket;
use crate::{ip_discovery::new_party, sign::*, store_share::User, Global};
use super::{rocket, IPs};
use crate::{
ip_discovery::{get_all_ips, IpAddresses},
sign::{
acknowledge_responsibility, convert_endpoint, does_have_key, get_api, get_author_endpoint,
get_block_author, get_block_number, get_whitelist, is_block_author, send_ip_address,
EntropyRuntime,
},
store_share::{store_keyshare, User},
Global,
};
use parity_scale_codec::Encode;
use rocket::{
http::{ContentType, Status},
local::asynchronous::Client,
Expand Down Expand Up @@ -30,6 +39,14 @@ fn get_path(extension: &str) -> String {
file_path
}

async fn wait_for_chain(api: &EntropyRuntime, block: u32) {
let mut result = get_block_number(&api).await;
while result.unwrap() < block {
sleep(Duration::from_secs(2u64)).await;
result = get_block_number(&api).await;
}
}

#[rocket::async_test]
#[serial]
async fn test_store_share() {
Expand Down Expand Up @@ -95,8 +112,9 @@ async fn test_store_share_fail_wrong_data() {
async fn test_sign() {
let cxt = test_context_stationary().await;
let now = time::Instant::now();
// sleep to make sure one block has been mined or else panic
sleep(Duration::from_secs(8u64)).await;
let api = get_api(&cxt.node_proc.ws_url).await.unwrap();

wait_for_chain(&api, 1).await;

let encoded_data = vec![
4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189,
Expand Down Expand Up @@ -180,9 +198,9 @@ async fn not_validator_block_author() {
#[rocket::async_test]
async fn test_get_block_author() {
let cxt = test_context().await;
sleep(Duration::from_secs(10u64)).await;
let api = get_api(&cxt.node_proc.ws_url).await;
let result = get_block_author(&api.unwrap()).await;
let api = get_api(&cxt.node_proc.ws_url).await.unwrap();
wait_for_chain(&api, 1).await;
let result = get_block_author(&api).await;
println!("result {:?}", result);
let alice_stash_id: subxt::sp_runtime::AccountId32 =
sr25519::Pair::from_string("//Alice//stash", None)
Expand Down Expand Up @@ -220,13 +238,13 @@ async fn test_get_author_endpoint() {
#[rocket::async_test]
async fn test_send_responsibility_message() {
let cxt = test_context().await;
let api = get_api(&cxt.node_proc.ws_url).await;
sleep(Duration::from_secs(25u64)).await;
let api = get_api(&cxt.node_proc.ws_url).await.unwrap();
wait_for_chain(&api, 3).await;
let mnemonic =
"alarm mutual concert decrease hurry invest culture survey diagram crash snap click"
.to_string();

let result = acknowledge_responsibility(&api.unwrap(), &mnemonic, 3u32).await;
let result = acknowledge_responsibility(&api, &mnemonic, 3u32).await;
assert_eq!(result.is_ok(), true);
}

Expand Down

0 comments on commit fad25d6

Please sign in to comment.