Skip to content

Commit

Permalink
lmdb: optimize vector initialization in unit tests
Browse files Browse the repository at this point in the history
Closes #636

Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
kasugamirai authored and yukibtc committed Nov 18, 2024
1 parent 04652b0 commit 2561d2b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
* pool: return error if relay not exists when removing it ([Yuki Kishimoto])
* sdk: cleanup `Client` methods
* relay-builder: port selection by using random port generation ([Yuki Kishimoto])
* lmdb: optimize vector initialization in unit tests ([Xiao Yu])
* nwc: increase default timeout to 60 secs ([Yuki Kishimoto])

### Added
Expand Down
23 changes: 3 additions & 20 deletions crates/nostr-lmdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,49 +207,32 @@ mod tests {
let keys_a = Keys::generate();
let keys_b = Keys::generate();

let mut events = Vec::new();

// Add some text notes
events.push(
let events = vec![
EventBuilder::text_note("Text Note A")
.sign_with_keys(&keys_a)
.unwrap(),
);
events.push(
EventBuilder::text_note("Text Note B")
.sign_with_keys(&keys_b)
.unwrap(),
);

// Add some replaceable events
events.push(
EventBuilder::metadata(
&Metadata::new().name("account-a").display_name("Account A"),
)
.sign_with_keys(&keys_a)
.unwrap(),
);
events.push(
EventBuilder::metadata(
&Metadata::new().name("account-b").display_name("Account B"),
)
.sign_with_keys(&keys_b)
.unwrap(),
);

// Add some param replaceable events
events.push(
EventBuilder::new(Kind::ParameterizedReplaceable(33_333), "")
.tag(Tag::identifier("my-id-a"))
.sign_with_keys(&keys_a)
.unwrap(),
);
events.push(
EventBuilder::new(Kind::ParameterizedReplaceable(33_333), "")
.tag(Tag::identifier("my-id-b"))
.sign_with_keys(&keys_b)
.unwrap(),
);
];

// Store
for event in events.iter() {
Expand All @@ -267,7 +250,7 @@ mod tests {
}

async fn add_event_with_keys(&self, builder: EventBuilder, keys: &Keys) -> (Event, bool) {
let event = builder.sign_with_keys(&keys).unwrap();
let event = builder.sign_with_keys(keys).unwrap();
let stored = self.db.save_event(&event).await.unwrap();
(event, stored)
}
Expand Down

0 comments on commit 2561d2b

Please sign in to comment.