fix: fix some test failures

This commit is contained in:
Raj 2022-01-15 01:57:12 +05:30 committed by GitHub
parent da7968efef
commit 5c8390bbe0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View File

@ -266,6 +266,7 @@ mod tests {
tags: vec![], tags: vec![],
content: "".to_owned(), content: "".to_owned(),
sig: "0".to_owned(), sig: "0".to_owned(),
tagidx: None,
} }
} }
@ -340,6 +341,7 @@ mod tests {
tags: vec![], tags: vec![],
content: "this is a test".to_owned(), content: "this is a test".to_owned(),
sig: "abcde".to_owned(), sig: "abcde".to_owned(),
tagidx: None,
}; };
let c = e.to_canonical(); let c = e.to_canonical();
let expected = Some(r#"[0,"012345",501234,1,[],"this is a test"]"#.to_owned()); let expected = Some(r#"[0,"012345",501234,1,[],"this is a test"]"#.to_owned());
@ -363,6 +365,7 @@ mod tests {
], ],
content: "this is a test".to_owned(), content: "this is a test".to_owned(),
sig: "abcde".to_owned(), sig: "abcde".to_owned(),
tagidx: None,
}; };
let c = e.to_canonical(); let c = e.to_canonical();
let expected_json = r###"[0,"012345",501234,1,[["#e","aoeu"],["#p","aaaa","ws://example.com"]],"this is a test"]"###; let expected_json = r###"[0,"012345",501234,1,[["#e","aoeu"],["#p","aaaa","ws://example.com"]],"this is a test"]"###;

View File

@ -216,19 +216,22 @@ mod tests {
#[test] #[test]
fn author_filter() -> Result<()> { fn author_filter() -> Result<()> {
let raw_json = "[\"REQ\",\"some-id\",{\"author\": \"test-author-id\"}]"; let raw_json = r#"["REQ","some-id",{"authors": ["test-author-id"]}]"#;
let s: Subscription = serde_json::from_str(raw_json)?; let s: Subscription = serde_json::from_str(raw_json)?;
assert_eq!(s.id, "some-id"); assert_eq!(s.id, "some-id");
assert_eq!(s.filters.len(), 1); assert_eq!(s.filters.len(), 1);
let first_filter = s.filters.get(0).unwrap(); let first_filter = s.filters.get(0).unwrap();
assert_eq!(first_filter.author, Some("test-author-id".to_owned())); assert_eq!(
first_filter.authors,
Some(vec!("test-author-id".to_owned()))
);
Ok(()) Ok(())
} }
#[test] #[test]
fn interest_id_nomatch() -> Result<()> { fn interest_id_nomatch() -> Result<()> {
// subscription with a filter for ID // subscription with a filter for ID
let s: Subscription = serde_json::from_str(r#"["REQ","xyz",{"id":"abc"}]"#)?; let s: Subscription = serde_json::from_str(r#"["REQ","xyz",{"ids": ["abc"]}]"#)?;
let e = Event { let e = Event {
id: "abcde".to_owned(), id: "abcde".to_owned(),
pubkey: "".to_owned(), pubkey: "".to_owned(),
@ -237,6 +240,7 @@ mod tests {
tags: Vec::new(), tags: Vec::new(),
content: "".to_owned(), content: "".to_owned(),
sig: "".to_owned(), sig: "".to_owned(),
tagidx: None,
}; };
assert_eq!(s.interested_in_event(&e), false); assert_eq!(s.interested_in_event(&e), false);
Ok(()) Ok(())
@ -245,7 +249,7 @@ mod tests {
#[test] #[test]
fn interest_time_and_id() -> Result<()> { fn interest_time_and_id() -> Result<()> {
// subscription with a filter for ID and time // subscription with a filter for ID and time
let s: Subscription = serde_json::from_str(r#"["REQ","xyz",{"id":"abc", "since": 1000}]"#)?; let s: Subscription = serde_json::from_str(r#"["REQ","xyz",{"ids": ["abc"], "since": 1000}]"#)?;
let e = Event { let e = Event {
id: "abc".to_owned(), id: "abc".to_owned(),
pubkey: "".to_owned(), pubkey: "".to_owned(),
@ -254,6 +258,7 @@ mod tests {
tags: Vec::new(), tags: Vec::new(),
content: "".to_owned(), content: "".to_owned(),
sig: "".to_owned(), sig: "".to_owned(),
tagidx: None,
}; };
assert_eq!(s.interested_in_event(&e), false); assert_eq!(s.interested_in_event(&e), false);
Ok(()) Ok(())
@ -271,6 +276,7 @@ mod tests {
tags: Vec::new(), tags: Vec::new(),
content: "".to_owned(), content: "".to_owned(),
sig: "".to_owned(), sig: "".to_owned(),
tagidx: None,
}; };
assert_eq!(s.interested_in_event(&e), true); assert_eq!(s.interested_in_event(&e), true);
Ok(()) Ok(())
@ -288,6 +294,7 @@ mod tests {
tags: Vec::new(), tags: Vec::new(),
content: "".to_owned(), content: "".to_owned(),
sig: "".to_owned(), sig: "".to_owned(),
tagidx: None,
}; };
assert_eq!(s.interested_in_event(&e), true); assert_eq!(s.interested_in_event(&e), true);
Ok(()) Ok(())
@ -305,6 +312,7 @@ mod tests {
tags: Vec::new(), tags: Vec::new(),
content: "".to_owned(), content: "".to_owned(),
sig: "".to_owned(), sig: "".to_owned(),
tagidx: None,
}; };
assert_eq!(s.interested_in_event(&e), true); assert_eq!(s.interested_in_event(&e), true);
Ok(()) Ok(())
@ -322,6 +330,7 @@ mod tests {
tags: Vec::new(), tags: Vec::new(),
content: "".to_owned(), content: "".to_owned(),
sig: "".to_owned(), sig: "".to_owned(),
tagidx: None,
}; };
assert_eq!(s.interested_in_event(&e), true); assert_eq!(s.interested_in_event(&e), true);
Ok(()) Ok(())
@ -339,6 +348,7 @@ mod tests {
tags: Vec::new(), tags: Vec::new(),
content: "".to_owned(), content: "".to_owned(),
sig: "".to_owned(), sig: "".to_owned(),
tagidx: None,
}; };
assert_eq!(s.interested_in_event(&e), false); assert_eq!(s.interested_in_event(&e), false);
Ok(()) Ok(())