diff options
Diffstat (limited to 'test_utils')
| -rw-r--r-- | test_utils/Cargo.toml | 1 | ||||
| -rw-r--r-- | test_utils/src/lib.rs | 60 |
2 files changed, 53 insertions, 8 deletions
diff --git a/test_utils/Cargo.toml b/test_utils/Cargo.toml index 672dcdb..b354ff4 100644 --- a/test_utils/Cargo.toml +++ b/test_utils/Cargo.toml | |||
| @@ -21,3 +21,4 @@ simple-websockets = { git = "https://github.com/DanConwayDev/simple-websockets", | |||
| 21 | strip-ansi-escapes = "0.2.0" | 21 | strip-ansi-escapes = "0.2.0" |
| 22 | tokio = { version = "1.40.0", features = ["full"] } | 22 | tokio = { version = "1.40.0", features = ["full"] } |
| 23 | tungstenite = "0.20.1" | 23 | tungstenite = "0.20.1" |
| 24 | sha2 = "0.10" \ No newline at end of file | ||
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index 0c5de73..3ac171b 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs | |||
| @@ -10,6 +10,7 @@ use anyhow::{bail, ensure, Context, Result}; | |||
| 10 | use dialoguer::theme::{ColorfulTheme, Theme}; | 10 | use dialoguer::theme::{ColorfulTheme, Theme}; |
| 11 | use futures::executor::block_on; | 11 | use futures::executor::block_on; |
| 12 | use git::GitTestRepo; | 12 | use git::GitTestRepo; |
| 13 | use git2::{Signature, Time}; | ||
| 13 | use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag}; | 14 | use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag}; |
| 14 | use nostr_database::NostrEventsDatabase; | 15 | use nostr_database::NostrEventsDatabase; |
| 15 | use nostr_lmdb::NostrLMDB; | 16 | use nostr_lmdb::NostrLMDB; |
| @@ -1226,21 +1227,64 @@ pub fn create_and_populate_branch( | |||
| 1226 | test_repo.checkout("main")?; | 1227 | test_repo.checkout("main")?; |
| 1227 | test_repo.create_branch(branch_name)?; | 1228 | test_repo.create_branch(branch_name)?; |
| 1228 | test_repo.checkout(branch_name)?; | 1229 | test_repo.checkout(branch_name)?; |
| 1229 | std::fs::write( | 1230 | let file_name = format!("{}3.md", prefix); |
| 1230 | test_repo.dir.join(format!("{}3.md", prefix)), | 1231 | std::fs::write(test_repo.dir.join(&file_name), "some content")?; |
| 1231 | "some content", | 1232 | test_repo.stage_and_commit_custom_signature( |
| 1233 | &format!("add {}3.md", prefix), | ||
| 1234 | Some( | ||
| 1235 | &Signature::new( | ||
| 1236 | "Joe Bloggs", | ||
| 1237 | "joe.bloggs@pm.me", | ||
| 1238 | &Time::new(deterministic_timestamp(&file_name), 0), | ||
| 1239 | ) | ||
| 1240 | .unwrap(), | ||
| 1241 | ), | ||
| 1242 | None, | ||
| 1232 | )?; | 1243 | )?; |
| 1233 | test_repo.stage_and_commit(format!("add {}3.md", prefix).as_str())?; | ||
| 1234 | if !only_one_commit { | 1244 | if !only_one_commit { |
| 1235 | std::fs::write( | 1245 | let file_name = format!("{}4.md", prefix); |
| 1236 | test_repo.dir.join(format!("{}4.md", prefix)), | 1246 | std::fs::write(test_repo.dir.join(&file_name), "some content")?; |
| 1237 | "some content", | 1247 | test_repo.stage_and_commit_custom_signature( |
| 1248 | &format!("add {}4.md", prefix), | ||
| 1249 | Some( | ||
| 1250 | &Signature::new( | ||
| 1251 | "Joe Bloggs", | ||
| 1252 | "joe.bloggs@pm.me", | ||
| 1253 | &Time::new(deterministic_timestamp(&file_name), 0), | ||
| 1254 | ) | ||
| 1255 | .unwrap(), | ||
| 1256 | ), | ||
| 1257 | None, | ||
| 1238 | )?; | 1258 | )?; |
| 1239 | test_repo.stage_and_commit(format!("add {}4.md", prefix).as_str())?; | ||
| 1240 | } | 1259 | } |
| 1241 | Ok(()) | 1260 | Ok(()) |
| 1242 | } | 1261 | } |
| 1243 | 1262 | ||
| 1263 | use sha2::{Digest, Sha256}; | ||
| 1264 | |||
| 1265 | fn deterministic_timestamp(input: &str) -> i64 { | ||
| 1266 | // Create a SHA-256 hasher | ||
| 1267 | let mut hasher = Sha256::new(); | ||
| 1268 | |||
| 1269 | // Hash the input string | ||
| 1270 | hasher.update(input); | ||
| 1271 | |||
| 1272 | // Get the hash result | ||
| 1273 | let result = hasher.finalize(); | ||
| 1274 | |||
| 1275 | // Convert the first 8 bytes of the hash to an i64 | ||
| 1276 | let timestamp_bytes = &result[..8]; | ||
| 1277 | let timestamp = i64::from_be_bytes( | ||
| 1278 | timestamp_bytes | ||
| 1279 | .try_into() | ||
| 1280 | .expect("slice with incorrect length"), | ||
| 1281 | ); | ||
| 1282 | |||
| 1283 | // Normalize the timestamp to a valid Unix timestamp | ||
| 1284 | // You can adjust this to fit your needs, e.g., adding a base timestamp | ||
| 1285 | timestamp.abs() % 1_000_000_000 // Keep it within a reasonable range | ||
| 1286 | } | ||
| 1287 | |||
| 1244 | pub fn cli_tester_create_proposal( | 1288 | pub fn cli_tester_create_proposal( |
| 1245 | test_repo: &GitTestRepo, | 1289 | test_repo: &GitTestRepo, |
| 1246 | branch_name: &str, | 1290 | branch_name: &str, |