Skip to content

Commit

Permalink
release: Fix bug in test and retry release 1.0.3 (#467)
Browse files Browse the repository at this point in the history
* release: Fix a bug in the test for the proof_builder.rs

* Use random keypair in `test_get_proof_for_current_slot`

* Fix clippy
  • Loading branch information
ebma committed Dec 14, 2023
1 parent 335fc98 commit a5cc81e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
9 changes: 5 additions & 4 deletions clients/vault/src/oracle/agent.rs
Expand Up @@ -203,10 +203,9 @@ impl OracleAgent {

#[cfg(test)]
mod tests {

use crate::oracle::{
get_test_secret_key, get_test_stellar_relay_config, traits::ArchiveStorage,
ScpArchiveStorage, TransactionsArchiveStorage,
get_random_secret_key, get_test_secret_key, get_test_stellar_relay_config,
traits::ArchiveStorage, ScpArchiveStorage, TransactionsArchiveStorage,
};

use super::*;
Expand All @@ -217,9 +216,11 @@ mod tests {
#[serial]
async fn test_get_proof_for_current_slot() {
let shutdown_sender = ShutdownSender::new();

// We use a random secret key to avoid conflicts with other tests.
let agent = start_oracle_agent(
get_test_stellar_relay_config(true),
&get_test_secret_key(true),
&get_random_secret_key(),
shutdown_sender,
)
.await
Expand Down
16 changes: 13 additions & 3 deletions clients/vault/src/oracle/collector/proof_builder.rs
Expand Up @@ -358,7 +358,10 @@ impl ScpMessageCollector {

#[cfg(test)]
mod test {
use crate::oracle::collector::proof_builder::check_slot_still_recoverable_from_overlay;
use crate::oracle::{
collector::proof_builder::check_slot_still_recoverable_from_overlay,
types::constants::MAX_SLOTS_TO_REMEMBER,
};

#[test]
fn test_check_slot_position() {
Expand All @@ -367,7 +370,14 @@ mod test {
assert!(!check_slot_still_recoverable_from_overlay(last_slot, 50));
assert!(!check_slot_still_recoverable_from_overlay(last_slot, 100));
assert!(!check_slot_still_recoverable_from_overlay(last_slot, 30_000));
assert!(check_slot_still_recoverable_from_overlay(last_slot, 40_500));
assert!(check_slot_still_recoverable_from_overlay(last_slot, 49_500));
assert!(!check_slot_still_recoverable_from_overlay(
last_slot,
last_slot - MAX_SLOTS_TO_REMEMBER
));
assert!(check_slot_still_recoverable_from_overlay(last_slot, last_slot - 1));
assert!(check_slot_still_recoverable_from_overlay(
last_slot,
last_slot - MAX_SLOTS_TO_REMEMBER + 1
));
}
}
12 changes: 12 additions & 0 deletions clients/vault/src/oracle/testing_utils.rs
@@ -1,3 +1,5 @@
use stellar_relay_lib::sdk::SecretKey;

pub fn get_test_stellar_relay_config(is_mainnet: bool) -> stellar_relay_lib::StellarOverlayConfig {
use rand::seq::SliceRandom;

Expand All @@ -22,3 +24,13 @@ pub fn get_test_secret_key(is_mainnet: bool) -> String {
let path = format!("./resources/secretkey/stellar_secretkey_{file_name}");
std::fs::read_to_string(path).expect("should return a string")
}

pub fn get_random_secret_key() -> String {
// Generate a new random Stellar keypair
let secret = SecretKey::from_binary(rand::random());
let secret_encoded = secret.to_encoding();
// Convert the secret key to a string
let secret_string = std::str::from_utf8(&secret_encoded).expect("Failed to convert to string");

secret_string.to_string()
}

0 comments on commit a5cc81e

Please sign in to comment.