Skip to content

Commit

Permalink
Test slash or take signature is saved using database
Browse files Browse the repository at this point in the history
  • Loading branch information
lemonpartee committed Sep 4, 2024
1 parent e1d6ee8 commit ded8d26
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion core/src/database/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,47 @@ mod tests {
hashes::Hash, Address, Amount, OutPoint, ScriptBuf, TxOut, Txid, XOnlyPublicKey,
};
use crypto_bigint::rand_core::OsRng;
use secp256k1::Secp256k1;
use secp256k1::{constants::SCHNORR_SIGNATURE_SIZE, Secp256k1};
use std::thread;

#[tokio::test]
async fn test_database_gets_previously_saved_slash_or_take_signature() {
let config = create_test_config_with_thread_name!("test_config.toml");
let database = Database::new(config).await.unwrap();

let deposit_outpoint = OutPoint::null();
let outpoint = OutPoint {
txid: Txid::from_byte_array([1u8; 32]),
vout: 1,
};
let kickoff_utxo = UTXO {
outpoint,
txout: TxOut {
value: Amount::from_sat(100),
script_pubkey: ScriptBuf::from(vec![1u8]),
},
};
let signature = schnorr::Signature::from_slice(&[0u8; SCHNORR_SIGNATURE_SIZE]).unwrap();

database
.save_kickoff_utxos(deposit_outpoint, &[kickoff_utxo.clone()])
.await
.unwrap();

database
.save_slash_or_take_sigs(deposit_outpoint, [(kickoff_utxo.clone(), signature)])
.await
.unwrap();

let actual_sig = database
.get_slash_or_take_sig(deposit_outpoint, kickoff_utxo)
.await
.unwrap();
let expected_sig = Some(signature);

assert_eq!(actual_sig, expected_sig);
}

#[tokio::test]
#[should_panic]
async fn test_invalid_connection() {
Expand Down

0 comments on commit ded8d26

Please sign in to comment.