damus
damus copied to clipboard
Integrate a controllable relay environment to expand test coverage
Several features and modules in Damus are directly or indirectly affected by relay behaviours. Having a controlled relay setup for testing could help us expand test coverage significantly.
The Rust Nostr SDK project will soon include their RelayBuilder in the Swift SDK, meaning that we will be able to spawn customized relays with custom content to test against, all programmatically. (See https://github.com/rust-nostr/nostr/discussions/1120)
Acceptance criteria:
- Integrate some library that can easily create local relays programmatically, such as https://github.com/rust-nostr/nostr-sdk-swift
- There is not a lot of documentation on the relay builder in Swift yet, but here are some examples in other languages (which use a very similar API):
- Python: https://github.com/rust-nostr/nostr-sdk-ffi/blob/v0.44.0/python/examples/relay_builder.py
- Rust: https://github.com/rust-nostr/nostr/blob/master/crates/nostr-relay-builder/examples
- There is not a lot of documentation on the relay builder in Swift yet, but here are some examples in other languages (which use a very similar API):
- In Damus, tweak the bootstrap relay list to change depending on an environment variable (or any other suitable mechanism) that indicates whether it should be in this new test mode or not. If on this test mode, make it connect to only our test relay in
localhost(Port number can be chosen at your discretion) - Build up mechanisms on the test target that allow tests to opt-in to this test mode, which will set the environment appropriately, spawn the relay locally.
- Make a sample small test using this test relay.
See also https://github.com/pippellia-btc/rely
I've put a lot of efforts in improving the performance while also improving the DX. Tests show it can handle easily 8000+ concurrent clients spamming it with random stuff