diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-06-11 16:21:44 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-06-13 09:09:00 +0100 |
| commit | f1b3fcc40ab666d8def97096d1942c274da9b279 (patch) | |
| tree | 05d6af0c5c1ad9baedb90ef652152fba6d46abf5 /test_utils | |
| parent | 7c6a5ab4c5e7a81c7442061029b9230748a6639d (diff) | |
chore: bump rust-nostr to v0.32.0
both nostr and nostr-sdk packages and also in test_utils
fix the many breaking changes
fix: ignore trailing slash when depuplicate relays for send events.
this was picked up as TagStandard::RelayMetadata has started adding
a traling slash.
refactor cli output test function `expect_send_with_progress` so that
relays can succeed / fail in a random order
Diffstat (limited to 'test_utils')
| -rw-r--r-- | test_utils/Cargo.toml | 4 | ||||
| -rw-r--r-- | test_utils/src/lib.rs | 69 | ||||
| -rw-r--r-- | test_utils/src/relay.rs | 26 |
3 files changed, 54 insertions, 45 deletions
diff --git a/test_utils/Cargo.toml b/test_utils/Cargo.toml index 0784b1a..43f3629 100644 --- a/test_utils/Cargo.toml +++ b/test_utils/Cargo.toml | |||
| @@ -9,8 +9,8 @@ assert_cmd = "2.0.12" | |||
| 9 | dialoguer = "0.10.4" | 9 | dialoguer = "0.10.4" |
| 10 | directories = "5.0.1" | 10 | directories = "5.0.1" |
| 11 | git2 = "0.18.1" | 11 | git2 = "0.18.1" |
| 12 | nostr = { git = "https://github.com/DanConwayDev/nostr", branch="expose-nip49-log-n" } | 12 | nostr = "0.32.0" |
| 13 | nostr-sdk = { git = "https://github.com/DanConwayDev/nostr", branch="expose-nip49-log-n" } | 13 | nostr-sdk = "0.32.0" |
| 14 | once_cell = "1.18.0" | 14 | once_cell = "1.18.0" |
| 15 | rand = "0.8" | 15 | rand = "0.8" |
| 16 | rexpect = { git = "https://github.com/rust-cli/rexpect.git", rev = "9eb61dd" } | 16 | rexpect = { git = "https://github.com/rust-cli/rexpect.git", rev = "9eb61dd" } |
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index daed8fa..1d881cf 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs | |||
| @@ -3,8 +3,8 @@ use std::{ffi::OsStr, path::PathBuf, str::FromStr}; | |||
| 3 | use anyhow::{bail, ensure, Context, Result}; | 3 | use anyhow::{bail, ensure, Context, Result}; |
| 4 | use dialoguer::theme::{ColorfulTheme, Theme}; | 4 | use dialoguer::theme::{ColorfulTheme, Theme}; |
| 5 | use directories::ProjectDirs; | 5 | use directories::ProjectDirs; |
| 6 | use nostr::{self, Kind, Tag}; | 6 | use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag}; |
| 7 | use nostr_sdk::serde_json; | 7 | use nostr_sdk::{serde_json, TagStandard}; |
| 8 | use once_cell::sync::Lazy; | 8 | use once_cell::sync::Lazy; |
| 9 | use rexpect::session::{Options, PtySession}; | 9 | use rexpect::session::{Options, PtySession}; |
| 10 | use strip_ansi_escapes::strip_str; | 10 | use strip_ansi_escapes::strip_str; |
| @@ -12,8 +12,8 @@ use strip_ansi_escapes::strip_str; | |||
| 12 | pub mod git; | 12 | pub mod git; |
| 13 | pub mod relay; | 13 | pub mod relay; |
| 14 | 14 | ||
| 15 | pub static PATCH_KIND: u64 = 1617; | 15 | pub static PATCH_KIND: u16 = 1617; |
| 16 | pub static REPOSITORY_KIND: u64 = 30617; | 16 | pub static REPOSITORY_KIND: u16 = 30617; |
| 17 | 17 | ||
| 18 | pub static TEST_KEY_1_NSEC: &str = | 18 | pub static TEST_KEY_1_NSEC: &str = |
| 19 | "nsec1ppsg5sm2aexq06juxmu9evtutr6jkwkhp98exxxvwamhru9lyx9s3rwseq"; | 19 | "nsec1ppsg5sm2aexq06juxmu9evtutr6jkwkhp98exxxvwamhru9lyx9s3rwseq"; |
| @@ -54,15 +54,18 @@ pub fn generate_test_key_1_relay_list_event() -> nostr::Event { | |||
| 54 | nostr::Kind::RelayList, | 54 | nostr::Kind::RelayList, |
| 55 | "", | 55 | "", |
| 56 | [ | 56 | [ |
| 57 | nostr::Tag::RelayMetadata( | 57 | nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata { |
| 58 | "ws://localhost:8053".into(), | 58 | relay_url: nostr::Url::from_str("ws://localhost:8053").unwrap(), |
| 59 | Some(nostr::RelayMetadata::Write), | 59 | metadata: Some(RelayMetadata::Write), |
| 60 | ), | 60 | }), |
| 61 | nostr::Tag::RelayMetadata( | 61 | nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata { |
| 62 | "ws://localhost:8054".into(), | 62 | relay_url: nostr::Url::from_str("ws://localhost:8054").unwrap(), |
| 63 | Some(nostr::RelayMetadata::Read), | 63 | metadata: Some(RelayMetadata::Read), |
| 64 | ), | 64 | }), |
| 65 | nostr::Tag::RelayMetadata("ws://localhost:8055".into(), None), | 65 | nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata { |
| 66 | relay_url: nostr::Url::from_str("ws://localhost:8055").unwrap(), | ||
| 67 | metadata: None, | ||
| 68 | }), | ||
| 66 | ], | 69 | ], |
| 67 | ) | 70 | ) |
| 68 | .to_event(&TEST_KEY_1_KEYS) | 71 | .to_event(&TEST_KEY_1_KEYS) |
| @@ -74,14 +77,14 @@ pub fn generate_test_key_1_relay_list_event_same_as_fallback() -> nostr::Event { | |||
| 74 | nostr::Kind::RelayList, | 77 | nostr::Kind::RelayList, |
| 75 | "", | 78 | "", |
| 76 | [ | 79 | [ |
| 77 | nostr::Tag::RelayMetadata( | 80 | nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata { |
| 78 | "ws://localhost:8051".into(), | 81 | relay_url: nostr::Url::from_str("ws://localhost:8051").unwrap(), |
| 79 | Some(nostr::RelayMetadata::Write), | 82 | metadata: Some(RelayMetadata::Write), |
| 80 | ), | 83 | }), |
| 81 | nostr::Tag::RelayMetadata( | 84 | nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata { |
| 82 | "ws://localhost:8052".into(), | 85 | relay_url: nostr::Url::from_str("ws://localhost:8052").unwrap(), |
| 83 | Some(nostr::RelayMetadata::Write), | 86 | metadata: Some(RelayMetadata::Write), |
| 84 | ), | 87 | }), |
| 85 | ], | 88 | ], |
| 86 | ) | 89 | ) |
| 87 | .to_event(&TEST_KEY_1_KEYS) | 90 | .to_event(&TEST_KEY_1_KEYS) |
| @@ -141,33 +144,33 @@ pub fn generate_repo_ref_event() -> nostr::Event { | |||
| 141 | nostr::Kind::Custom(REPOSITORY_KIND), | 144 | nostr::Kind::Custom(REPOSITORY_KIND), |
| 142 | "", | 145 | "", |
| 143 | [ | 146 | [ |
| 144 | Tag::Identifier( | 147 | Tag::identifier( |
| 145 | // root_commit.to_string() | 148 | // root_commit.to_string() |
| 146 | format!("{}-consider-it-random", root_commit), | 149 | format!("{}-consider-it-random", root_commit), |
| 147 | ), | 150 | ), |
| 148 | Tag::Reference(root_commit.into()), | 151 | Tag::from_standardized(TagStandard::Reference(root_commit.to_string())), |
| 149 | Tag::Name("example name".into()), | 152 | Tag::from_standardized(TagStandard::Name("example name".into())), |
| 150 | Tag::Description("example description".into()), | 153 | Tag::from_standardized(TagStandard::Description("example description".into())), |
| 151 | Tag::Generic( | 154 | Tag::custom( |
| 152 | nostr::TagKind::Custom("clone".to_string()), | 155 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("clone")), |
| 153 | vec!["git:://123.gitexample.com/test".to_string()], | 156 | vec!["git:://123.gitexample.com/test".to_string()], |
| 154 | ), | 157 | ), |
| 155 | Tag::Generic( | 158 | Tag::custom( |
| 156 | nostr::TagKind::Custom("web".to_string()), | 159 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("web")), |
| 157 | vec![ | 160 | vec![ |
| 158 | "https://exampleproject.xyz".to_string(), | 161 | "https://exampleproject.xyz".to_string(), |
| 159 | "https://gitworkshop.dev/123".to_string(), | 162 | "https://gitworkshop.dev/123".to_string(), |
| 160 | ], | 163 | ], |
| 161 | ), | 164 | ), |
| 162 | Tag::Generic( | 165 | Tag::custom( |
| 163 | nostr::TagKind::Custom("relays".to_string()), | 166 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("relays")), |
| 164 | vec![ | 167 | vec![ |
| 165 | "ws://localhost:8055".to_string(), | 168 | "ws://localhost:8055".to_string(), |
| 166 | "ws://localhost:8056".to_string(), | 169 | "ws://localhost:8056".to_string(), |
| 167 | ], | 170 | ], |
| 168 | ), | 171 | ), |
| 169 | Tag::Generic( | 172 | Tag::custom( |
| 170 | nostr::TagKind::Custom("maintainers".to_string()), | 173 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("maintainers")), |
| 171 | vec![ | 174 | vec![ |
| 172 | TEST_KEY_1_KEYS.public_key().to_string(), | 175 | TEST_KEY_1_KEYS.public_key().to_string(), |
| 173 | TEST_KEY_2_KEYS.public_key().to_string(), | 176 | TEST_KEY_2_KEYS.public_key().to_string(), |
diff --git a/test_utils/src/relay.rs b/test_utils/src/relay.rs index e47ab5d..82a8f8d 100644 --- a/test_utils/src/relay.rs +++ b/test_utils/src/relay.rs | |||
| @@ -255,21 +255,27 @@ pub fn expect_send_with_progress( | |||
| 255 | " - {} -------------------- 0/{event_count}", | 255 | " - {} -------------------- 0/{event_count}", |
| 256 | &relays[0].0 | 256 | &relays[0].0 |
| 257 | ))?; | 257 | ))?; |
| 258 | for relay in &relays { | 258 | let last_relay_outcome = outcome_message(relays.last().unwrap()); |
| 259 | // if successful | 259 | let mut s = String::new(); |
| 260 | if relay.1 { | 260 | loop { |
| 261 | p.expect_eventually(format!(" y {}", relay.0))?; | 261 | s.push_str(&p.expect_eventually(&last_relay_outcome)?); |
| 262 | } else { | 262 | s.push_str(&last_relay_outcome); |
| 263 | p.expect_eventually(format!(" x {} {}", relay.0, relay.2))?; | 263 | if relays.iter().all(|r| s.contains(&outcome_message(r))) { |
| 264 | // all responses have been received with correct outcome | ||
| 265 | break; | ||
| 264 | } | 266 | } |
| 265 | // could check that before only contains titles: | ||
| 266 | // - # y x n/n and whitespace | ||
| 267 | // let before = p.expect_eventually(format!(" â {title}"))?; | ||
| 268 | // assert_eq!("", before.trim()); | ||
| 269 | } | 267 | } |
| 270 | Ok(()) | 268 | Ok(()) |
| 271 | } | 269 | } |
| 272 | 270 | ||
| 271 | fn outcome_message(relay: &(&str, bool, &str)) -> String { | ||
| 272 | if relay.1 { | ||
| 273 | format!(" y {}", relay.0) | ||
| 274 | } else { | ||
| 275 | format!(" x {} {}", relay.0, relay.2) | ||
| 276 | } | ||
| 277 | } | ||
| 278 | |||
| 273 | pub fn expect_send_with_progress_exact_interaction( | 279 | pub fn expect_send_with_progress_exact_interaction( |
| 274 | p: &mut CliTester, | 280 | p: &mut CliTester, |
| 275 | titles: Vec<&str>, | 281 | titles: Vec<&str>, |