Skip to content

Commit

Permalink
Fund operators from the start for testing purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
ozankaymak committed Sep 2, 2024
1 parent 608cbf3 commit a260006
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
27 changes: 26 additions & 1 deletion core/src/servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
//! Utilities for operator and verifier servers.
use crate::mock::common;
use crate::traits::rpc::AggregatorServer;
use crate::{aggregator, create_extended_rpc};
use crate::traits::rpc::OperatorRpcClient;
use crate::{aggregator, create_extended_rpc, UTXO};
use crate::{
config::BridgeConfig,
create_test_config, create_test_config_with_thread_name,
Expand All @@ -14,6 +15,7 @@ use crate::{
traits::{self, rpc::VerifierRpcServer},
verifier::Verifier,
};
use bitcoin::Address;
use bitcoin_mock_rpc::RpcApiWrapper;
use errors::BridgeError;
use jsonrpsee::{
Expand Down Expand Up @@ -202,6 +204,29 @@ pub async fn create_verifiers_and_operators(
.await
.unwrap();

for (i, (operator_client, _, _)) in operator_endpoints.iter().enumerate() {
// Send operators some bitcoin so that they can afford the kickoff tx
let secp = bitcoin::secp256k1::Secp256k1::new();
let operator_internal_xonly_pk = config.operators_xonly_pks.get(i).unwrap();
let operator_address =
Address::p2tr(&secp, *operator_internal_xonly_pk, None, config.network);
let operator_funding_outpoint = rpc
.send_to_address(&operator_address, 2 * config.bridge_amount_sats)
.unwrap();
let operator_funding_txout = rpc
.get_txout_from_outpoint(&operator_funding_outpoint)
.unwrap();
let operator_funding_utxo = UTXO {
outpoint: operator_funding_outpoint,
txout: operator_funding_txout,
};

tracing::debug!("Operator {:?} funding utxo: {:?}", i, operator_funding_utxo);
operator_client
.set_funding_utxo_rpc(operator_funding_utxo)
.await
.unwrap();
}
let config = create_test_config_with_thread_name!(config_name);
let aggregator = create_aggregator_server(config.clone()).await.unwrap();

Expand Down
26 changes: 1 addition & 25 deletions core/tests/common.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// //! # Common utilities for tests

use bitcoin::Address;
use bitcoin::OutPoint;
use clementine_core::actor::Actor;
use clementine_core::config::BridgeConfig;
Expand All @@ -14,7 +13,6 @@ use clementine_core::traits::rpc::OperatorRpcClient;
use clementine_core::traits::rpc::VerifierRpcClient;
use clementine_core::user::User;
use clementine_core::EVMAddress;
use clementine_core::UTXO;
use clementine_core::{
create_extended_rpc, create_test_config, create_test_config_with_thread_name,
};
Expand Down Expand Up @@ -83,29 +81,7 @@ pub async fn run_single_deposit(
let mut kickoff_utxos = Vec::new();
let mut signatures = Vec::new();

for (i, (client, _, _)) in operators.iter().enumerate() {
// Send operators some bitcoin so that they can afford the kickoff tx
let secp = bitcoin::secp256k1::Secp256k1::new();
let operator_internal_xonly_pk = config.operators_xonly_pks.get(i).unwrap();
let operator_address =
Address::p2tr(&secp, *operator_internal_xonly_pk, None, config.network);
let operator_funding_outpoint = rpc
.send_to_address(&operator_address, 2 * config.bridge_amount_sats)
.unwrap();
let operator_funding_txout = rpc
.get_txout_from_outpoint(&operator_funding_outpoint)
.unwrap();
let operator_funding_utxo = UTXO {
outpoint: operator_funding_outpoint,
txout: operator_funding_txout,
};

// tracing::debug!("Operator {:?} funding utxo: {:?}", i, operator_funding_utxo);
client
.set_funding_utxo_rpc(operator_funding_utxo)
.await
.unwrap();

for (client, _, _) in operators.iter() {
// Create deposit kickoff transaction
let (kickoff_utxo, signature) = client
.new_deposit_rpc(deposit_outpoint, signer_address.clone(), evm_address)
Expand Down

0 comments on commit a260006

Please sign in to comment.