Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sapling test download #95

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ rand_core = "0.6.4"
atomic_float = "1.1.0"

[dev-dependencies]
tokio = { version = "1.40.0", features = ["full"] }
tokio = { version = "1.40.0", features = ["full"] }
pivx_primitives = { git = "https://github.com/Duddino/librustpivx", default-features = false, features = ["transparent-inputs", "test-dependencies"] }
wasm-bindgen-test = "0.3.13"

[profile.release]
Expand Down
26 changes: 22 additions & 4 deletions src/prover.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
use pivx_primitives::sapling::prover::TxProver;

#[cfg(test)]
use pivx_primitives::sapling::prover::mock::MockTxProver;
#[cfg(not(test))]
use pivx_proofs::prover::LocalTxProver;

use reqwest::Client;
use std::error::Error;
use tokio::sync::OnceCell;
use wasm_bindgen::prelude::*;

static PROVER: OnceCell<LocalTxProver> = OnceCell::const_new();
#[cfg(not(test))]
type ImplTxProver = LocalTxProver;

#[cfg(test)]
type ImplTxProver = MockTxProver;

pub async fn get_prover() -> &'static LocalTxProver {
let default_urls = &["https://https://pivxla.bz", "https://duddino.com"];
static PROVER: OnceCell<ImplTxProver> = OnceCell::const_new();

pub async fn get_prover() -> &'static impl TxProver {
let default_urls = &["https://pivxla.bz", "https://duddino.com"];
for url in default_urls {
if let Ok(prover) = get_with_url(url).await {
return prover;
Expand All @@ -20,7 +32,8 @@ pub async fn get_prover() -> &'static LocalTxProver {
* gets prover using the specified url. If the prover has already been downloaded
* no request will be made
*/
pub async fn get_with_url(url: &str) -> Result<&'static LocalTxProver, Box<dyn Error>> {
#[cfg(not(test))]
pub async fn get_with_url(url: &str) -> Result<&'static impl TxProver, Box<dyn Error>> {
PROVER
.get_or_try_init(|| async {
let c = Client::new();
Expand Down Expand Up @@ -48,6 +61,11 @@ pub async fn get_with_url(url: &str) -> Result<&'static LocalTxProver, Box<dyn E
.await
}

#[cfg(test)]
pub async fn get_with_url(_url: &str) -> Result<&'static impl TxProver, Box<dyn Error>> {
Ok(PROVER.get_or_init(|| async { MockTxProver }).await)
}

#[wasm_bindgen]
pub async fn load_prover() -> bool {
get_prover().await;
Expand Down
4 changes: 2 additions & 2 deletions src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::keys::GenericAddress;
#[cfg(feature = "multicore")]
use atomic_float::AtomicF32;
pub use either::Either;
use pivx_primitives::sapling::prover::TxProver;
pub use pivx_primitives::sapling::{note::Note, Node, Nullifier};
pub use pivx_primitives::transaction::builder::Builder;
pub use pivx_primitives::transaction::components::Amount;
Expand All @@ -27,7 +28,6 @@ pub use pivx_primitives::zip32::AccountId;
use pivx_primitives::zip32::ExtendedFullViewingKey;
pub use pivx_primitives::zip32::ExtendedSpendingKey;
pub use pivx_primitives::zip32::Scope;
pub use pivx_proofs::prover::LocalTxProver;
use rand_core::OsRng;

use secp256k1::SecretKey;
Expand Down Expand Up @@ -550,7 +550,7 @@ fn prove_transaction(
builder: Builder<'_, Network, OsRng>,
nullifiers: Vec<String>,
fee: u64,
prover: &LocalTxProver,
prover: &impl TxProver,
) -> Result<JSTransaction, Box<dyn Error>> {
#[cfg(not(test))]
return {
Expand Down
Loading