upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/test_utils/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'test_utils/src/lib.rs')
-rw-r--r--test_utils/src/lib.rs60
1 files changed, 52 insertions, 8 deletions
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};
10use dialoguer::theme::{ColorfulTheme, Theme}; 10use dialoguer::theme::{ColorfulTheme, Theme};
11use futures::executor::block_on; 11use futures::executor::block_on;
12use git::GitTestRepo; 12use git::GitTestRepo;
13use git2::{Signature, Time};
13use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag}; 14use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag};
14use nostr_database::NostrEventsDatabase; 15use nostr_database::NostrEventsDatabase;
15use nostr_lmdb::NostrLMDB; 16use 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
1263use sha2::{Digest, Sha256};
1264
1265fn 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
1244pub fn cli_tester_create_proposal( 1288pub fn cli_tester_create_proposal(
1245 test_repo: &GitTestRepo, 1289 test_repo: &GitTestRepo,
1246 branch_name: &str, 1290 branch_name: &str,