Skip to content

Commit

Permalink
kairos-server/tests: move posgres into individual test case to avoid …
Browse files Browse the repository at this point in the history
…dropping
  • Loading branch information
marijanp committed Jul 12, 2024
1 parent a664f2c commit 46e804f
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions kairos-server/tests/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ use kairos_tx::asn::{SigningPayload, Transfer, Withdrawal};
static TEST_ENVIRONMENT: OnceLock<()> = OnceLock::new();

#[cfg(feature = "deposit-mock")]
async fn new_test_app() -> TestServer {
async fn new_test_app(#[cfg(feature = "database")] postgres_url: &Url) -> TestServer {
let dummy_url = Url::parse("http://0.0.0.0:0").unwrap();
#[cfg(feature = "database")]
let postgres = PostgresDB::run(None).unwrap();

new_test_app_with_casper_node(
&dummy_url,
&dummy_url,
#[cfg(feature = "database")]
&postgres.connection.clone().into(),
postgres_url,
)
.await
}
Expand Down Expand Up @@ -160,7 +158,14 @@ async fn test_signed_deploy_is_forwarded_if_sender_in_approvals() {
async fn test_deposit_withdraw() {
use kairos_circuit_logic::transactions::L1Deposit;

let server = new_test_app().await;
#[cfg(feature = "database")]
let postgres = PostgresDB::run(None).unwrap();

let server = new_test_app(
#[cfg(feature = "database")]
&postgres.connection.clone().into(),
)
.await;

let deposit = L1Deposit {
recipient: "alice_key".into(),
Expand All @@ -174,11 +179,13 @@ async fn test_deposit_withdraw() {
.assert_status_failure();

// deposit
server
let response = server
.post(MockDepositPath.to_uri().path())
.json(&deposit)
.await
.assert_status_success();
.await;

println!("{}", &response.text());
response.assert_status_success();

// wrong arguments
server
Expand Down Expand Up @@ -244,7 +251,14 @@ async fn test_deposit_withdraw() {
async fn test_deposit_transfer_withdraw() {
use kairos_circuit_logic::transactions::L1Deposit;

let server = new_test_app().await;
#[cfg(feature = "database")]
let postgres = PostgresDB::run(None).unwrap();

let server = new_test_app(
#[cfg(feature = "database")]
&postgres.connection.clone().into(),
)
.await;

// deposit
server
Expand Down Expand Up @@ -288,7 +302,14 @@ async fn test_deposit_transfer_withdraw() {
async fn test_deposit_transfer_to_self_withdraw() {
use kairos_circuit_logic::transactions::L1Deposit;

let server = new_test_app().await;
#[cfg(feature = "database")]
let postgres = PostgresDB::run(None).unwrap();

let server = new_test_app(
#[cfg(feature = "database")]
&postgres.connection.clone().into(),
)
.await;

// deposit
server
Expand Down

0 comments on commit 46e804f

Please sign in to comment.