-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore(deps): bump pubky and refactor * Add testnet test * Fix testnet * Use hardcoded testnet config * Fix multi-signups wit same user in tests * Fix testnet * Add testnet singleton * Pin main branch on pubky deps * Add back init connector from client and use testnet::run * Use latest pkarr relay * Pin branches after merge
- Loading branch information
1 parent
53888c1
commit acc9596
Showing
13 changed files
with
504 additions
and
332 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use pkarr::Keypair; | ||
use pubky_testnet::Testnet; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
// Run a new testnet. | ||
let testnet = Testnet::run().await.unwrap(); | ||
|
||
// Optionally create and run a Homeserver. | ||
let server = testnet.run_homeserver().await.unwrap(); | ||
|
||
// Create a Pubky Client from the testnet. | ||
let client = testnet.client_builder().build().unwrap(); | ||
|
||
let keypair = Keypair::random(); | ||
|
||
client.signup(&keypair, &server.public_key()).await.unwrap(); | ||
client | ||
.put(format!( | ||
"pubky://{}/pub/pubky.app/object", | ||
keypair.public_key(), | ||
)) | ||
.body([0, 1, 2, 3].to_vec()) | ||
.send() | ||
.await | ||
.unwrap(); | ||
|
||
let response = client | ||
.get(format!( | ||
"https://{}/events/?cursor=0000000000000&limit=1000", | ||
server.public_key() | ||
)) | ||
.send() | ||
.await | ||
.unwrap(); | ||
|
||
println!("Event Lines: {}", response.text().await.unwrap()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
mod dht; | ||
pub mod testnet; | ||
pub mod watcher; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use anyhow::Error; | ||
use pubky_testnet::Testnet; | ||
use std::sync::Arc; | ||
use tokio::sync::OnceCell; | ||
|
||
static TESTNET_NETWORK: OnceCell<TestnetNetwork> = OnceCell::const_new(); | ||
|
||
/// Represents a test network for the Distributed Hash Table (DHT). | ||
pub struct TestnetNetwork { | ||
nodes: Arc<Testnet>, | ||
} | ||
|
||
impl TestnetNetwork { | ||
/// Returns the testnet. This method will initialize the testnet if it hasn't been | ||
/// already, and will wait for the initialization to complete if another task is doing it. | ||
pub async fn get() -> Result<Arc<Testnet>, Error> { | ||
let network = TESTNET_NETWORK | ||
.get_or_init(|| async { | ||
let testnet = Testnet::run() | ||
.await | ||
.expect("Failed to run testnet with hardcoded configurations"); | ||
TestnetNetwork { | ||
nodes: Arc::new(testnet), | ||
} | ||
}) | ||
.await; | ||
Ok(network.nodes.clone()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters