use std::time::Duration;
use acceptxmr::{
storage::{
stores::{InMemory, Sled, Sqlite},
Storage,
},
PaymentGatewayBuilder, SubIndex,
};
use test_case::test_case;
use testing_utils::{init_logger, new_temp_dir, MockDaemon, PRIMARY_ADDRESS, PRIVATE_VIEW_KEY};
#[test_case(Sled::new(&new_temp_dir(), "invoices", "output keys", "height").unwrap(); "sled")]
#[test_case(InMemory::new(); "in-memory")]
#[test_case(Sqlite::new(":memory:", "invoices", "output keys", "height").unwrap(); "sqlite")]
#[tokio::test]
async fn reproducible_rand<S>(store: S)
where
S: Storage + 'static,
{
init_logger();
let mock_daemon = MockDaemon::new_mock_daemon().await;
let payment_gateway = PaymentGatewayBuilder::new(
PRIVATE_VIEW_KEY.to_string(),
PRIMARY_ADDRESS.to_string(),
store,
)
.scan_interval(Duration::from_millis(100))
.daemon_url(mock_daemon.url(""))
.account_index(1)
.seed(1)
.build()
.await
.expect("failed to build payment gateway");
payment_gateway
.run()
.await
.expect("failed to run payment gateway");
let invoice_id = payment_gateway
.new_invoice(1, 5, 10, "test invoice".to_string())
.await
.expect("failed to add new invoice to payment gateway for tracking");
let mut subscriber = payment_gateway
.subscribe(invoice_id)
.expect("invoice does not exist");
let update = subscriber
.recv_timeout(Duration::from_secs(120))
.await
.expect("timeout waiting for invoice update")
.expect("subscription channel is closed");
assert_eq!(update.index(), SubIndex::new(1, 97));
}