mirror of
https://github.com/RoboSats/taptrade-core.git
synced 2025-07-19 09:13:39 +00:00
update db tests
This commit is contained in:
@ -261,6 +261,9 @@ async fn test_fetch_suitable_offers() -> Result<()> {
|
|||||||
50, // bond_amount_sat
|
50, // bond_amount_sat
|
||||||
"signedBondHex".to_string(),
|
"signedBondHex".to_string(),
|
||||||
"1PayoutAddress".to_string(),
|
"1PayoutAddress".to_string(),
|
||||||
|
"1ChangeAddressMaker".to_string(),
|
||||||
|
"escrowInputsHexMakerCSV1,PSBT1,PSBT2".to_string(),
|
||||||
|
"taprootPubkeyHexMaker1".to_string(),
|
||||||
"musigPubNonceHex".to_string(),
|
"musigPubNonceHex".to_string(),
|
||||||
"musigPubkeyHex".to_string(),
|
"musigPubkeyHex".to_string(),
|
||||||
"1TakerBondAddress".to_string(),
|
"1TakerBondAddress".to_string(),
|
||||||
@ -275,6 +278,9 @@ async fn test_fetch_suitable_offers() -> Result<()> {
|
|||||||
100, // bond_amount_sat
|
100, // bond_amount_sat
|
||||||
"signedBondHex2".to_string(),
|
"signedBondHex2".to_string(),
|
||||||
"2PayoutAddress".to_string(),
|
"2PayoutAddress".to_string(),
|
||||||
|
"2ChangeAddressMaker".to_string(),
|
||||||
|
"escrowInputsHexMakerCSV2,PSBT3,PSBT4".to_string(),
|
||||||
|
"taprootPubkeyHexMaker2".to_string(),
|
||||||
"musigPubNonceHex2".to_string(),
|
"musigPubNonceHex2".to_string(),
|
||||||
"musigPubkeyHex2".to_string(),
|
"musigPubkeyHex2".to_string(),
|
||||||
"2TakerBondAddress".to_string(),
|
"2TakerBondAddress".to_string(),
|
||||||
@ -283,24 +289,28 @@ async fn test_fetch_suitable_offers() -> Result<()> {
|
|||||||
|
|
||||||
for offer in offers {
|
for offer in offers {
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
"INSERT INTO active_maker_offers (offer_id, robohash, is_buy_order, amount_sat, bond_ratio, offer_duration_ts, bond_address, bond_amount_sat, bond_tx_hex, payout_address, musig_pub_nonce_hex, musig_pubkey_hex, taker_bond_address)
|
"INSERT INTO active_maker_offers (offer_id, robohash, is_buy_order, amount_sat, bond_ratio, offer_duration_ts, bond_address, bond_amount_sat,
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
bond_tx_hex, payout_address, change_address_maker, escrow_inputs_hex_maker_csv, taproot_pubkey_hex_maker, musig_pub_nonce_hex, musig_pubkey_hex, taker_bond_address)
|
||||||
)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
.bind(offer.0)
|
)
|
||||||
.bind(hex::decode("a3f1f1f0e2f3f4f5").unwrap()) // Example robohash
|
.bind(offer.0)
|
||||||
.bind(offer.1)
|
.bind(hex::decode("a3f1f1f0e2f3f4f5").unwrap()) // Example robohash
|
||||||
.bind(offer.2)
|
.bind(offer.1)
|
||||||
.bind(offer.3)
|
.bind(offer.2)
|
||||||
.bind(offer.4)
|
.bind(offer.3)
|
||||||
.bind(offer.5.clone())
|
.bind(offer.4)
|
||||||
.bind(offer.6)
|
.bind(offer.5)
|
||||||
.bind(offer.7.clone())
|
.bind(offer.6)
|
||||||
.bind(offer.8.clone())
|
.bind(offer.7)
|
||||||
.bind(offer.9.clone())
|
.bind(offer.8)
|
||||||
.bind(offer.10.clone())
|
.bind(offer.9)
|
||||||
.bind(offer.11.clone())
|
.bind(offer.10)
|
||||||
.execute(&*database.db_pool)
|
.bind(offer.11)
|
||||||
.await?;
|
.bind(offer.12)
|
||||||
|
.bind(offer.13)
|
||||||
|
.bind(offer.14)
|
||||||
|
.execute(&*database.db_pool)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a sample OffersRequest
|
// Create a sample OffersRequest
|
||||||
@ -337,24 +347,28 @@ async fn test_fetch_taker_bond_requirements() -> Result<()> {
|
|||||||
let bond_amount_sat = 100;
|
let bond_amount_sat = 100;
|
||||||
|
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
"INSERT INTO active_maker_offers (offer_id, robohash, is_buy_order, amount_sat, bond_ratio, offer_duration_ts, bond_address, bond_amount_sat, bond_tx_hex, payout_address, musig_pub_nonce_hex, musig_pubkey_hex, taker_bond_address)
|
"INSERT INTO active_maker_offers (offer_id, robohash, is_buy_order, amount_sat, bond_ratio, offer_duration_ts, bond_address, bond_amount_sat,
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
bond_tx_hex, payout_address, change_address_maker, escrow_inputs_hex_maker_csv, taproot_pubkey_hex_maker, musig_pub_nonce_hex, musig_pubkey_hex, taker_bond_address)
|
||||||
)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
.bind(offer_id_hex)
|
)
|
||||||
.bind(hex::decode("a3f1f1f0e2f3f4f5").unwrap()) // Example robohash
|
.bind(offer_id_hex)
|
||||||
.bind(true) // is_buy_order
|
.bind(hex::decode("a3f1f1f0e2f3f4f5").unwrap()) // Example robohash
|
||||||
.bind(1500) // amount_sat
|
.bind(true) // is_buy_order
|
||||||
.bind(50) // bond_ratio
|
.bind(1500) // amount_sat
|
||||||
.bind(1234567890) // offer_duration_ts
|
.bind(50) // bond_ratio
|
||||||
.bind("1BondAddress")
|
.bind(1234567890) // offer_duration_ts
|
||||||
.bind(bond_amount_sat)
|
.bind("1BondAddress")
|
||||||
.bind("signedBondHex")
|
.bind(bond_amount_sat)
|
||||||
.bind("1PayoutAddress")
|
.bind("signedBondHex")
|
||||||
.bind("musigPubNonceHex")
|
.bind("1PayoutAddress")
|
||||||
.bind("musigPubkeyHex")
|
.bind("1ChangeAddressMaker")
|
||||||
.bind(taker_bond_address)
|
.bind("escrowInputsHexMakerCSV,PSBT1,PSBT2")
|
||||||
.execute(&*database.db_pool)
|
.bind("taprootPubkeyHexMaker")
|
||||||
.await?;
|
.bind("musigPubNonceHex")
|
||||||
|
.bind("musigPubkeyHex")
|
||||||
|
.bind(taker_bond_address)
|
||||||
|
.execute(&*database.db_pool)
|
||||||
|
.await?;
|
||||||
|
|
||||||
// Call the fetch_taker_bond_requirements function
|
// Call the fetch_taker_bond_requirements function
|
||||||
let result = database
|
let result = database
|
||||||
@ -383,28 +397,36 @@ async fn test_fetch_and_delete_offer_from_public_offers_table() -> Result<()> {
|
|||||||
let bond_amount_sat = 500;
|
let bond_amount_sat = 500;
|
||||||
let bond_tx_hex = "signedBondHex".to_string();
|
let bond_tx_hex = "signedBondHex".to_string();
|
||||||
let payout_address = "1PayoutAddress".to_string();
|
let payout_address = "1PayoutAddress".to_string();
|
||||||
|
let change_address_maker = "1ChangeAddressMaker".to_string();
|
||||||
|
let escrow_inputs_hex_maker_csv = "escrowInputsHexMakerCSV,PSBT1,PSBT2".to_string();
|
||||||
|
let taproot_pubkey_hex_maker = "taprootPubkeyHexMaker".to_string();
|
||||||
let musig_pub_nonce_hex = "musigPubNonceHex".to_string();
|
let musig_pub_nonce_hex = "musigPubNonceHex".to_string();
|
||||||
let musig_pubkey_hex = "musigPubkeyHex".to_string();
|
let musig_pubkey_hex = "musigPubkeyHex".to_string();
|
||||||
|
let taker_bond_address = "1TakerBondAddress".to_string();
|
||||||
|
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
"INSERT INTO active_maker_offers (offer_id, robohash, is_buy_order, amount_sat, bond_ratio, offer_duration_ts, bond_address, bond_amount_sat, bond_tx_hex, payout_address, musig_pub_nonce_hex, musig_pubkey_hex)
|
"INSERT INTO active_maker_offers (offer_id, robohash, is_buy_order, amount_sat, bond_ratio, offer_duration_ts, bond_address, bond_amount_sat,
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
bond_tx_hex, payout_address, change_address_maker, escrow_inputs_hex_maker_csv, taproot_pubkey_hex_maker, musig_pub_nonce_hex, musig_pubkey_hex, taker_bond_address)
|
||||||
)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
.bind(offer_id_hex)
|
)
|
||||||
.bind(robohash.clone())
|
.bind(offer_id_hex)
|
||||||
.bind(is_buy_order)
|
.bind(robohash.clone())
|
||||||
.bind(amount_sat)
|
.bind(is_buy_order)
|
||||||
.bind(bond_ratio)
|
.bind(amount_sat)
|
||||||
.bind(offer_duration_ts)
|
.bind(bond_ratio)
|
||||||
.bind(bond_address.clone())
|
.bind(offer_duration_ts)
|
||||||
.bind(bond_amount_sat)
|
.bind(bond_address.clone())
|
||||||
.bind(bond_tx_hex.clone())
|
.bind(bond_amount_sat)
|
||||||
.bind(payout_address.clone())
|
.bind(bond_tx_hex.clone())
|
||||||
.bind(musig_pub_nonce_hex.clone())
|
.bind(payout_address.clone())
|
||||||
.bind(musig_pubkey_hex.clone())
|
.bind(change_address_maker.clone())
|
||||||
.execute(&*database.db_pool)
|
.bind(escrow_inputs_hex_maker_csv.clone())
|
||||||
.await?;
|
.bind(taproot_pubkey_hex_maker.clone())
|
||||||
|
.bind(musig_pub_nonce_hex.clone())
|
||||||
|
.bind(musig_pubkey_hex.clone())
|
||||||
|
.bind(taker_bond_address.clone())
|
||||||
|
.execute(&*database.db_pool)
|
||||||
|
.await?;
|
||||||
// Call the fetch_and_delete_offer_from_public_offers_table function
|
// Call the fetch_and_delete_offer_from_public_offers_table function
|
||||||
let result = database
|
let result = database
|
||||||
.fetch_and_delete_offer_from_public_offers_table(offer_id_hex)
|
.fetch_and_delete_offer_from_public_offers_table(offer_id_hex)
|
||||||
|
@ -134,6 +134,7 @@ async fn test_transaction_without_signature() {
|
|||||||
.validate_bond_tx_hex(&bond_without_signature, &requirements)
|
.validate_bond_tx_hex(&bond_without_signature, &requirements)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
|
test_wallet.shutdown().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@ -151,6 +152,7 @@ async fn test_transaction_with_invalid_signature() {
|
|||||||
.validate_bond_tx_hex(&bond_with_invalid_signature, &requirements)
|
.validate_bond_tx_hex(&bond_with_invalid_signature, &requirements)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
|
test_wallet.shutdown().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@ -167,6 +169,7 @@ async fn test_bond_with_spent_input() {
|
|||||||
.validate_bond_tx_hex(&bond_with_spent_input, &requirements)
|
.validate_bond_tx_hex(&bond_with_spent_input, &requirements)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
|
test_wallet.shutdown().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@ -181,6 +184,7 @@ async fn test_valid_bond_tx() {
|
|||||||
|
|
||||||
let result = test_wallet.validate_bond_tx_hex(&bond, &requirements).await;
|
let result = test_wallet.validate_bond_tx_hex(&bond, &requirements).await;
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
|
test_wallet.shutdown().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@ -199,6 +203,7 @@ async fn test_invalid_bond_tx_low_input_sum() {
|
|||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
.to_string()
|
.to_string()
|
||||||
.contains("Bond input sum too small"));
|
.contains("Bond input sum too small"));
|
||||||
|
test_wallet.shutdown().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@ -212,6 +217,7 @@ async fn test_invalid_bond_tx_low_output_sum() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let result = test_wallet.validate_bond_tx_hex(&bond, &requirements).await;
|
let result = test_wallet.validate_bond_tx_hex(&bond, &requirements).await;
|
||||||
|
test_wallet.shutdown().await;
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
assert!(result
|
assert!(result
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
@ -230,6 +236,7 @@ async fn test_invalid_bond_tx_low_fee_rate() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let result = test_wallet.validate_bond_tx_hex(&bond, &requirements).await;
|
let result = test_wallet.validate_bond_tx_hex(&bond, &requirements).await;
|
||||||
|
test_wallet.shutdown().await;
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
assert!(result
|
assert!(result
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
|
Reference in New Issue
Block a user