Skip to content

Commit

Permalink
Add v2 e2e test
Browse files Browse the repository at this point in the history
Remove payjoin-cli v2 CI builds because this tests v2 which also builds.
  • Loading branch information
DanGould committed Jun 26, 2024
1 parent 1c7bf1a commit 6945102
Show file tree
Hide file tree
Showing 7 changed files with 403 additions and 33 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,10 @@ jobs:
run: cargo test --package payjoin --verbose --features=send,receive --test integration
- name: test payjoin v2 integration
run: cargo test --package payjoin --verbose --features=send,receive,danger-local-https,v2 --test integration
- name: test payjoin-cli bin v2
run: cargo test --package payjoin-cli --verbose --features=danger-local-https,v2 --test e2e
- name: test payjoin-cli bin v1
run: cargo test --package payjoin-cli --verbose --features=danger-local-https
- name: build payjoin-cli bin v2
if: matrix.rust != '1.63.0'
run: cargo build --package payjoin-cli --verbose --features=v2
- name: build payjoin-cli bin v2 with danger-local-https
if: matrix.rust != '1.63.0'
run: cargo build --package payjoin-cli --verbose --features=danger-local-https,v2

rustfmt:
runs-on: ubuntu-latest
Expand Down
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions payjoin-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ url = { version = "2.3.1", features = ["serde"] }
bitcoind = { version = "0.31.1", features = ["0_21_2"] }
http = "1"
ohttp-relay = "0.0.8"
once_cell = "1"
payjoin-directory = { path = "../payjoin-directory", features = ["danger-local-https"] }
testcontainers = "0.15.0"
testcontainers-modules = { version = "0.1.3", features = ["redis"] }
tokio = { version = "1.12.0", features = ["full"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
11 changes: 8 additions & 3 deletions payjoin-cli/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,18 @@ fn http_agent_builder() -> Result<reqwest::ClientBuilder> {
use rustls::pki_types::CertificateDer;
use rustls::RootCertStore;

let mut local_cert_path = std::env::temp_dir();
local_cert_path.push(LOCAL_CERT_FILE);
let cert_der = std::fs::read(local_cert_path)?;
let cert_der = read_local_cert()?;
let mut root_cert_store = RootCertStore::empty();
root_cert_store.add(CertificateDer::from(cert_der.as_slice()))?;
Ok(reqwest::ClientBuilder::new()
.danger_accept_invalid_certs(true)
.use_rustls_tls()
.add_root_certificate(reqwest::tls::Certificate::from_der(cert_der.as_slice())?))
}

#[cfg(feature = "danger-local-https")]
fn read_local_cert() -> Result<Vec<u8>> {
let mut local_cert_path = std::env::temp_dir();
local_cert_path.push(LOCAL_CERT_FILE);
Ok(std::fs::read(local_cert_path)?)
}
9 changes: 2 additions & 7 deletions payjoin-cli/src/app/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ impl AppTrait for App {
.send()
.await
.map_err(map_reqwest_err)?;

let session = initializer
.process_res(ohttp_response.bytes().await?.to_vec().as_slice(), ctx)
.map_err(|_| anyhow!("Enrollment failed"))?;
.map_err(|e| anyhow!("Enrollment failed {}", e))?;
self.db.insert_recv_session(session.clone())?;
self.spawn_payjoin_receiver(session, Some(amount)).await
}
Expand Down Expand Up @@ -339,11 +338,7 @@ async fn unwrap_ohttp_keys_or_else_fetch(config: &AppConfig) -> Result<payjoin::
let ohttp_relay = config.ohttp_relay.clone();
let payjoin_directory = config.pj_directory.clone();
#[cfg(feature = "danger-local-https")]
let cert_der = rcgen::generate_simple_self_signed(vec![
"0.0.0.0".to_string(),
"localhost".to_string(),
])?
.serialize_der()?;
let cert_der = crate::app::read_local_cert()?;
Ok(payjoin::io::fetch_ohttp_keys(
ohttp_relay,
payjoin_directory,
Expand Down
Loading

0 comments on commit 6945102

Please sign in to comment.