Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis committed Aug 30, 2024
1 parent ce56239 commit fc877bd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
28 changes: 15 additions & 13 deletions contracts/btc-staking/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,30 +277,26 @@ fn handle_end_block(
pub(crate) mod tests {
use super::*;

use hex::ToHex;

use babylon_apis::btc_staking_api::{
ActiveBtcDelegation, BtcUndelegationInfo, CovenantAdaptorSignatures,
FinalityProviderDescription, NewFinalityProvider, ProofOfPossessionBtc,
};
use babylon_apis::finality_api::PubRandCommit;
use babylon_proto::babylon::btcstaking::v1::BtcDelegation;
use cosmwasm_std::{
from_json,
testing::{message_info, mock_dependencies, mock_env},
Binary, Decimal,
};
use cw_controllers::AdminResponse;

use babylon_apis::btc_staking_api::{
ActiveBtcDelegation, BtcUndelegationInfo, CovenantAdaptorSignatures,
FinalityProviderDescription, NewFinalityProvider, ProofOfPossessionBtc,
};
use babylon_apis::finality_api::PubRandCommit;

use test_utils::{get_btc_delegation_and_params, get_pub_rand_commit};
use hex::ToHex;
use test_utils::{get_btc_delegation, get_pub_rand_commit};

pub(crate) const CREATOR: &str = "creator";
pub(crate) const INIT_ADMIN: &str = "initial_admin";
const NEW_ADMIN: &str = "new_admin";

/// Build an active BTC delegation from a BTC delegation
pub(crate) fn get_active_btc_delegation() -> ActiveBtcDelegation {
let (del, _) = get_btc_delegation_and_params();
fn new_active_btc_delegation(del: BtcDelegation) -> ActiveBtcDelegation {
let btc_undelegation = del.btc_undelegation.unwrap();

ActiveBtcDelegation {
Expand Down Expand Up @@ -347,6 +343,12 @@ pub(crate) mod tests {
}
}

/// Build an active BTC delegation from a BTC delegation
pub(crate) fn get_active_btc_delegation() -> ActiveBtcDelegation {
let del = get_btc_delegation();
new_active_btc_delegation(del)
}

// Build a derived active BTC delegation from the base (from testdata) BTC delegation
pub(crate) fn get_derived_btc_delegation(del_id: u8, fp_ids: &[u8]) -> ActiveBtcDelegation {
assert!(
Expand Down
14 changes: 9 additions & 5 deletions packages/btcstaking/src/tx_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,12 @@ mod tests {
use bitcoin::consensus::deserialize;
use bitcoin::secp256k1::schnorr::Signature;
use bitcoin::{Transaction, XOnlyPublicKey};
use test_utils::get_btc_delegation_and_params;
use test_utils::{get_btc_delegation, get_params};

#[test]
fn test_check_transactions() {
let (btc_del, params) = get_btc_delegation_and_params();
let btc_del = get_btc_delegation();
let params = get_params();

let staking_tx: Transaction = deserialize(&btc_del.staking_tx).unwrap();
let slashing_tx: Transaction = deserialize(&btc_del.slashing_tx).unwrap();
Expand Down Expand Up @@ -239,7 +240,8 @@ mod tests {

#[test]
fn test_verify_unbonding_tx_schnorr_sig() {
let (btc_del, params) = get_btc_delegation_and_params();
let btc_del = get_btc_delegation();
let params = get_params();

let staking_tx: Transaction = deserialize(&btc_del.staking_tx).unwrap();
let funding_out_idx: u32 = 0;
Expand Down Expand Up @@ -286,7 +288,8 @@ mod tests {

#[test]
fn test_verify_slashing_tx_adaptor_sig() {
let (btc_del, params) = get_btc_delegation_and_params();
let btc_del = get_btc_delegation();
let params = get_params();

let staking_tx: Transaction = deserialize(&btc_del.staking_tx).unwrap();
let slashing_tx: Transaction = deserialize(&btc_del.slashing_tx).unwrap();
Expand Down Expand Up @@ -334,7 +337,8 @@ mod tests {

#[test]
fn test_verify_unbonding_slashing_tx_adaptor_sig() {
let (btc_del, params) = get_btc_delegation_and_params();
let btc_del = get_btc_delegation();
let params = get_params();

let btc_undel = btc_del.btc_undelegation.unwrap();
let unbonding_tx: Transaction = deserialize(&btc_undel.unbonding_tx).unwrap();
Expand Down
14 changes: 7 additions & 7 deletions packages/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,16 @@ pub fn get_btc_timestamp_and_headers() -> (BtcTimestamp, HashMap<BlockHash, Bloc
(btc_ts, header_map)
}

pub fn get_btc_delegation_and_params() -> (BtcDelegation, BtcStakingParams) {
let btc_del_path = find_testdata_path().join(BTC_DELEGATION_DATA);
let btc_del_data: &[u8] = &fs::read(btc_del_path).unwrap();
let btc_del = BtcDelegation::decode(btc_del_data).unwrap();

pub fn get_params() -> BtcStakingParams {
let params_path = find_testdata_path().join(PARAMS_DATA);
let params_data: &[u8] = &fs::read(params_path).unwrap();
let params = BtcStakingParams::decode(params_data).unwrap();
BtcStakingParams::decode(params_data).unwrap()
}

(btc_del, params)
pub fn get_btc_delegation() -> BtcDelegation {
let btc_del_path = find_testdata_path().join(BTC_DELEGATION_DATA);
let btc_del_data: &[u8] = &fs::read(btc_del_path).unwrap();
BtcDelegation::decode(btc_del_data).unwrap()
}

pub fn get_pub_rand_commit() -> MsgCommitPubRandList {
Expand Down

0 comments on commit fc877bd

Please sign in to comment.