-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
226 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -4,8 +4,9 @@ members = [ | |
"crow", | ||
"graphql", | ||
"honey-badger", | ||
"squirrel", | ||
"parrot", | ||
"pigeon", | ||
"squirrel", | ||
] | ||
|
||
resolver = "2" |
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,14 @@ | ||
[package] | ||
name = "pigeon" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
graphql = { path = "../graphql" } | ||
honey-badger = { path = "../honey-badger" } | ||
|
||
[dev-dependencies] | ||
bitcoin = { version = "0.30.1" } | ||
ctor = "0.2.0" | ||
simplelog = { version ="0.12.0", features = ["test"] } | ||
tokio = { version = "1.32.0" } |
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,20 @@ | ||
use graphql::perro::OptionToError; | ||
use graphql::schema::{assign_lightning_address, AssignLightningAddress}; | ||
use graphql::{build_async_client, post}; | ||
use honey_badger::asynchronous::Auth; | ||
|
||
pub async fn assign_lightning_address(backend_url: &str, auth: &Auth) -> graphql::Result<String> { | ||
let token = auth.query_token().await?; | ||
let client = build_async_client(Some(&token))?; | ||
let data = post::<AssignLightningAddress>( | ||
&client, | ||
backend_url, | ||
assign_lightning_address::Variables {}, | ||
) | ||
.await?; | ||
let address = data | ||
.assign_lightning_address | ||
.ok_or_permanent_failure("Unexpected backend response: empty")? | ||
.address; | ||
Ok(address) | ||
} |
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,56 @@ | ||
use bitcoin::Network; | ||
use honey_badger::asynchronous::Auth; | ||
use honey_badger::secrets::{derive_keys, generate_keypair, generate_mnemonic}; | ||
use honey_badger::AuthLevel; | ||
use pigeon::assign_lightning_address; | ||
use simplelog::TestLogger; | ||
use std::env; | ||
use std::sync::Once; | ||
|
||
static INIT_LOGGER_ONCE: Once = Once::new(); | ||
|
||
#[cfg(test)] | ||
#[ctor::ctor] | ||
fn init() { | ||
INIT_LOGGER_ONCE.call_once(|| { | ||
TestLogger::init(simplelog::LevelFilter::Info, simplelog::Config::default()).unwrap(); | ||
}); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_assigning_lightning_address() { | ||
let (backend_url, auth) = build_client(); | ||
let address = assign_lightning_address(&backend_url, &auth).await.unwrap(); | ||
println!("Assigned address is: {address}"); | ||
assert!(!address.is_empty()); | ||
let address_from_another_call = assign_lightning_address(&backend_url, &auth).await.unwrap(); | ||
assert_eq!(address, address_from_another_call); | ||
|
||
let (backend_url, another_auth) = build_client(); | ||
let address_for_another_user = assign_lightning_address(&backend_url, &another_auth) | ||
.await | ||
.unwrap(); | ||
assert_ne!(address, address_for_another_user); | ||
} | ||
|
||
fn build_client() -> (String, Auth) { | ||
println!("Generating keys ..."); | ||
let mnemonic = generate_mnemonic(); | ||
println!("mnemonic: {mnemonic:?}"); | ||
let wallet_keys = derive_keys(Network::Testnet, mnemonic).wallet_keypair; | ||
let auth_keys = generate_keypair(); | ||
|
||
let auth = Auth::new( | ||
get_backend_url(), | ||
AuthLevel::Pseudonymous, | ||
wallet_keys, | ||
auth_keys, | ||
) | ||
.unwrap(); | ||
|
||
(get_backend_url(), auth) | ||
} | ||
|
||
fn get_backend_url() -> String { | ||
env::var("GRAPHQL_API_URL").expect("GRAPHQL_API_URL environment variable is not set") | ||
} |