crates/monetize-shop-pairing/src/test_fixtures.rs
//! **The Gunnar- and Holger-shaped TEST contracts** the shop pairing's tests pair on: each
//! read off the TEST facts (`monetize_server::testing::lifecycles`), which the signed guests are
//! held to (monetize-server `tests/the_signed_guests_answer_the_op_table.rs`). The shop's own
//! code names no product: these exist for the tests alone.
use std::collections::BTreeMap;
use std::path::Path;
use monetize_server::estate_order::{FirstDoor, LaidOrder, SaleCheckAt};
use nordisk_pairing::installer::Plan;
use crate::sale_check::Front;
use crate::ProductContract;
/// Gunnar's contract, from Gunnar's TEST facts.
pub fn gunnar() -> ProductContract {
ProductContract::of(&monetize_server::testing::lifecycles::gunnar_facts()).expect("Gunnar's TEST facts declare a contract")
}
/// Holger's contract, from Holger's TEST facts.
pub fn holger() -> ProductContract {
ProductContract::of(&monetize_server::testing::lifecycles::holger_facts()).expect("Holger's TEST facts declare a contract")
}
/// The routes of Gunnar's console its sale proof asks (gunnar-ui-server's router).
pub mod console {
pub const LOGIN_PATH: &str = "/login";
pub const LOGIN_PAGE_MARK: &str = "/auth/passkey/login/start";
pub const AUTH_STATUS_PATH: &str = "/auth/status";
pub const REGISTER_START_PATH: &str = "/auth/passkey/register/start";
pub const REPOS_PATH: &str = "/api/repos";
pub const REPOS_MAX: usize = 2000;
}
/// The routes of Holger's thin console its sale proof asks.
pub mod holger_console {
pub const LOGIN_PATH: &str = "/login";
pub const CONFIG_PATH: &str = "/-/auth/passkey/config";
pub const REGISTER_START_PATH: &str = "/-/auth/passkey/register/start";
pub const REPOS_PATH: &str = "/-/releases";
}
/// Gunnar's sale proof over `front`.
pub fn judge(front: &dyn Front, host: &str, account: &str, bearer: &str, invite: &str) -> Result<String, String> {
crate::sale_proof::prove(&gunnar().proof, front, host, account, bearer, invite)
}
/// `c`'s sale proof over `front`.
pub fn judge_for(c: &ProductContract, front: &dyn Front, host: &str, account: &str, bearer: &str, invite: &str) -> Result<String, String> {
crate::sale_proof::prove(&c.proof, front, host, account, bearer, invite)
}
/// `c`'s first-admin door over `front`.
pub fn first_door_for(c: &ProductContract, front: &dyn Front, host: &str, account: &str, invite: &str) -> Result<FirstDoor, String> {
crate::sale_proof::first_door(&c.proof, front, host, account, invite)
}
/// Gunnar's sale proof over the front `reach` finds, over HTTPS (the shop's minted pin trusted).
pub fn check_reaching(at: &SaleCheckAt<'_>, reach: &dyn Fn(&SaleCheckAt<'_>) -> Result<std::net::SocketAddr, String>) -> Result<String, String> {
let addr = reach(at)?;
let pin = std::fs::read(at.run_dir.join(crate::sale_check::FRONT_CERT)).ok();
let front = crate::sale_check::Https::new(at.host, addr, pin.as_deref())?;
judge(&front, at.host, at.account, at.console_token, at.first_login)
}
/// Gunnar's material.
pub fn mint_material(host: &str) -> Result<Vec<(String, String)>, String> {
crate::mint_material_for(&gunnar(), host)
}
/// Gunnar's shared feed.
pub fn shared_feed(order: &LaidOrder, account: &str, admin_pubkey: &str, invite: &str) -> Result<BTreeMap<String, String>, String> {
crate::shared_feed_for(&gunnar(), order, account, admin_pubkey, invite)
}
/// Gunnar's front feed.
pub fn front_feed(sale_feed: &BTreeMap<String, String>, order: &LaidOrder, handoff: &Path) -> Result<BTreeMap<String, String>, String> {
crate::front_feed_for(&gunnar(), sale_feed, order, handoff)
}
/// Gunnar's plan.
pub fn plan_of(order: &LaidOrder, feed: BTreeMap<String, String>, front_feed: BTreeMap<String, String>, relay: &BTreeMap<String, String>, budget_s: u64) -> Result<Plan, String> {
crate::plan_of_for(&gunnar(), order, feed, front_feed, relay, budget_s)
}