Skip to content

Commit

Permalink
fixing cucumber tests ..(2)
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Nov 20, 2023
1 parent dbe1ceb commit 318285d
Show file tree
Hide file tree
Showing 24 changed files with 280 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ impl<'a> BlockTemplateProtocol<'a> {
let miner_node_script_key_id = key_manager.import_key(wallet_private_key).await?;
let wallet_payment_address = TariAddress::from_str(&config.wallet_payment_address)
.map_err(|err| MmProxyError::ConversionError(err.to_string()))?;
if wallet_payment_address == TariAddress::default() {
return Err(MmProxyError::PaymentWalletAddressMissing(
"Has default value".to_string(),
));
}
let consensus_manager = ConsensusManager::builder(config.network).build()?;
Ok(Self {
config,
Expand Down
13 changes: 0 additions & 13 deletions applications/minotari_merge_mining_proxy/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ pub struct MergeMiningProxyConfig {
pub base_node_grpc_address: Option<Multiaddr>,
/// GRPC authentication for base node
pub base_node_grpc_authentication: GrpcAuthentication,
/// The Minotari wallet's GRPC address
pub console_wallet_grpc_address: Option<Multiaddr>,
/// Address of the minotari_merge_mining_proxy application
pub listener_address: Multiaddr,
/// In sole merged mining, the block solution is usually submitted to the Monero blockchain (monerod) as well as to
Expand Down Expand Up @@ -86,7 +84,6 @@ impl Default for MergeMiningProxyConfig {
monerod_use_auth: false,
base_node_grpc_address: None,
base_node_grpc_authentication: GrpcAuthentication::default(),
console_wallet_grpc_address: None,
listener_address: "/ip4/127.0.0.1/tcp/18081".parse().unwrap(),
submit_to_origin: true,
wait_for_initial_sync_at_startup: true,
Expand Down Expand Up @@ -121,12 +118,10 @@ mod test {
baz = "foo"
[merge_mining_proxy]
monerod_username = "cmot"
console_wallet_grpc_address = "/dns4/wallet/tcp/9000"
[config_a.merge_mining_proxy]
monerod_url = [ "http://network.a.org" ]
monerod_password = "password_igor"
base_node_grpc_address = "/dns4/base_node_a/tcp/8080"
console_wallet_grpc_address = "/dns4/wallet_a/tcp/9000"
[config_b.merge_mining_proxy]
submit_to_origin = false
monerod_url = [ "http://network.b.org" ]
Expand Down Expand Up @@ -154,10 +149,6 @@ mod test {
config.base_node_grpc_address,
Some(Multiaddr::from_str("/dns4/base_node_b/tcp/8080").unwrap())
);
assert_eq!(
config.console_wallet_grpc_address,
Some(Multiaddr::from_str("/dns4/wallet/tcp/9000").unwrap())
);

let cfg = get_config("config_a");
let config = MergeMiningProxyConfig::load_from(&cfg).expect("Failed to load config");
Expand All @@ -169,10 +160,6 @@ mod test {
config.base_node_grpc_address,
Some(Multiaddr::from_str("/dns4/base_node_a/tcp/8080").unwrap())
);
assert_eq!(
config.console_wallet_grpc_address,
Some(Multiaddr::from_str("/dns4/wallet_a/tcp/9000").unwrap())
);
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions applications/minotari_merge_mining_proxy/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ pub enum MmProxyError {
CoreKeyManagerError(#[from] CoreKeyManagerError),
#[error("Consensus build error: {0}")]
ConsensusBuilderError(#[from] ConsensusBuilderError),
#[error("Could not convert data:{0}")]
PaymentWalletAddressMissing(String),
}

impl From<tonic::Status> for MmProxyError {
Expand Down
11 changes: 0 additions & 11 deletions applications/minotari_merge_mining_proxy/src/run_merge_miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,4 @@ fn setup_grpc_config(config: &mut MergeMiningProxyConfig) {
.unwrap(),
);
}

if config.console_wallet_grpc_address.is_none() {
config.console_wallet_grpc_address = Some(
format!(
"/ip4/127.0.0.1/tcp/{}",
grpc_default_port(ApplicationType::ConsoleWallet, config.network)
)
.parse()
.unwrap(),
);
}
}
9 changes: 9 additions & 0 deletions applications/minotari_miner/src/run_miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ pub async fn start_miner(cli: Cli) -> Result<(), ExitError> {
.map_err(|err| ExitError::new(ExitCode::KeyManagerServiceError, err.to_string()))?;
let wallet_payment_address = TariAddress::from_str(&config.wallet_payment_address)
.map_err(|err| ExitError::new(ExitCode::ConversionError, err.to_string()))?;
debug!(target: LOG_TARGET_FILE, "wallet_payment_address: {}", wallet_payment_address);
if wallet_payment_address == TariAddress::default() {
return Err(ExitError::new(
ExitCode::PaymentWalletAddressMissing,
"Has default value".to_string(),
));
}
let consensus_manager = ConsensusManager::builder(config.network)
.build()
.map_err(|err| ExitError::new(ExitCode::ConsensusManagerBuilderError, err.to_string()))?;
Expand Down Expand Up @@ -283,6 +290,8 @@ async fn mining_cycle(
)
.await
.map_err(|e| MinerError::CoinbaseError(e.to_string()))?;
debug!(target: LOG_TARGET, "Coinbase kernel: {}", kernel);
debug!(target: LOG_TARGET, "Coinbase output: {}", output);

let body = block_template
.body
Expand Down
19 changes: 18 additions & 1 deletion base_layer/core/src/transactions/coinbase_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
//

use chacha20poly1305::aead::OsRng;
use log::*;
use tari_common_types::{
tari_address::TariAddress,
types::{Commitment, PrivateKey, PublicKey},
};
use tari_crypto::keys::PublicKey as PK;
use tari_key_manager::key_manager_service::{KeyManagerInterface, KeyManagerServiceError};
use tari_script::{one_sided_payment_script, stealth_payment_script, ExecutionStack, TariScript};
use tari_utilities::ByteArrayError;
use tari_utilities::{hex::Hex, ByteArrayError};
use thiserror::Error;

use crate::{
Expand Down Expand Up @@ -71,6 +72,8 @@ use crate::{
},
};

pub const LOG_TARGET: &str = "c::tx::coinbase_builder";

#[derive(Debug, Clone, Error, PartialEq, Eq)]
pub enum CoinbaseBuildError {
#[error("The block height for this coinbase transaction wasn't provided")]
Expand Down Expand Up @@ -255,6 +258,12 @@ where TKeyManagerInterface: TransactionKeyManagerInterface
let covenant = self.covenant;
let script = self.script.ok_or(CoinbaseBuildError::MissingScript)?;

debug!(target: LOG_TARGET,
"Getting coinbase - height: {}, reward: {}, spending_key_id: {}, script_key_id: {}, encryption_key_id: {}, \
sender_offset_key_id: {}, script: {}",
height, total_reward, spending_key_id, script_key_id, encryption_key_id, sender_offset_key_id, script
);

let kernel_features = KernelFeatures::create_coinbase();
let metadata = TransactionMetadata::new_with_features(0.into(), 0, kernel_features);
// generate kernel signature
Expand Down Expand Up @@ -389,7 +398,12 @@ pub async fn generate_coinbase(
let encryption_private_key = shared_secret_to_output_encryption_key(&shared_secret)?;
let encryption_key_id = key_manager.import_key(encryption_private_key).await?;

let spending_key_hex = spending_key.to_hex();
let spending_key_id = key_manager.import_key(spending_key).await?;
debug!(target: LOG_TARGET,
"generate coinbase - height: {}, spending_key: {}, spending_key_id: {}, sender_offset_key_id: {}, shared_secret: {}",
height, spending_key_hex, spending_key_id, sender_offset_key_id, shared_secret.as_bytes().to_vec().to_hex()
);

let script = if stealth_payment {
let (nonce_private_key, nonce_public_key) = PublicKey::random_keypair(&mut OsRng);
Expand Down Expand Up @@ -423,6 +437,9 @@ pub async fn generate_coinbase(
.first()
.ok_or(CoinbaseBuildError::BuildError("No kernel found".to_string()))?;

debug!(target: LOG_TARGET, "Coinbase kernel: {}", kernel.clone());
debug!(target: LOG_TARGET, "Coinbase output: {}", output.clone());
debug!(target: LOG_TARGET, "Coinbase wallet output: {:?}", wallet_output);
Ok((transaction.clone(), output.clone(), kernel.clone(), wallet_output))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub async fn check_faux_transactions<TBackend: 'static + TransactionBackend>(
.map_or(0, |mined_timestamp| mined_timestamp.timestamp() as u64),
num_confirmations,
is_confirmed,
is_valid,
true,
);
if let Err(e) = result {
error!(
Expand Down
3 changes: 0 additions & 3 deletions common/config/presets/f_merge_mining_proxy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ monerod_url = [# stagenet
# GRPC authentication for the base node (default = "none")
#base_node_grpc_authentication = { username = "miner", password = "xxxx" }

# The Minotari wallet's GRPC address. (default = "/ip4/127.0.0.1/tcp/18143")
#console_wallet_grpc_address = "/ip4/127.0.0.1/tcp/18143"

# Address of the minotari_merge_mining_proxy application. (default = "/ip4/127.0.0.1/tcp/18081")
#listener_address = "/ip4/127.0.0.1/tcp/18081"

Expand Down
2 changes: 2 additions & 0 deletions common/src/exit_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ pub enum ExitCode {
KeyManagerServiceError = 121,
#[error("Consensus manager builder error")]
ConsensusManagerBuilderError = 122,
#[error("Payment wallet address is not defined")]
PaymentWalletAddressMissing = 123,
}

impl From<super::ConfigError> for ExitError {
Expand Down
33 changes: 33 additions & 0 deletions integration_tests/log4rs/cucumber.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ appenders:
pattern: "{{log_dir}}/log/other.{}.log"
encoder:
pattern: "{d(%Y-%m-%d %H:%M:%S.%f)} [{X(grpc)}] {f}.{L} {i} [{t}] {l:5} {m}{n}"
# An appender named "base_layer" that writes to a file with a custom pattern encoder
miner:
kind: rolling_file
path: "{{log_dir}}/log/miner.log"
policy:
kind: compound
trigger:
kind: size
limit: 10mb
roller:
kind: fixed_window
base: 1
count: 5
pattern: "{{log_dir}}/log/miner/miner.{}.log"
encoder:
pattern: "{d(%Y-%m-%d %H:%M:%S.%f)} [{t}] [Thread:{I}] {l:5} {m}{n}"

# We don't want prints during cucumber test, everything useful will in logs.
# root:
Expand All @@ -108,6 +124,7 @@ loggers:
- network
- base_layer_wallet
- base_layer_base_node
- miner
additive: true
stdout:
level: info # we have only single print, and it's info
Expand Down Expand Up @@ -135,6 +152,22 @@ loggers:
level: debug
appenders:
- base_layer_wallet
# miner
minotari::application:
level: debug
appenders:
- miner
additive: false
minotari::miner:
level: debug
appenders:
- miner
additive: false
minotari_miner:
level: debug
appenders:
- miner
additive: false
# Route log events sent to the "comms" logger to the "network" appender
comms:
level: debug
Expand Down
42 changes: 37 additions & 5 deletions integration_tests/src/merge_mining_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@

use std::{convert::TryInto, thread};

use minotari_app_grpc::tari_rpc::GetIdentityRequest;
use minotari_app_utilities::common_cli_args::CommonCliArgs;
use minotari_merge_mining_proxy::{merge_miner, Cli};
use minotari_wallet_grpc_client::WalletGrpcClient;
use serde_json::{json, Value};
use tari_common::configuration::Network;
use tari_common_types::{tari_address::TariAddress, types::PublicKey};
use tari_utilities::ByteArray;
use tempfile::tempdir;
use tokio::runtime;
use tonic::transport::Channel;

use super::get_port;
use crate::TariWorld;
Expand All @@ -39,6 +45,7 @@ pub struct MergeMiningProxyProcess {
pub port: u64,
pub origin_submission: bool,
id: u64,
pub stealth: bool,
}

pub async fn register_merge_mining_proxy_process(
Expand All @@ -47,6 +54,7 @@ pub async fn register_merge_mining_proxy_process(
base_node_name: String,
wallet_name: String,
origin_submission: bool,
stealth: bool,
) {
let merge_mining_proxy = MergeMiningProxyProcess {
name: merge_mining_proxy_name.clone(),
Expand All @@ -55,6 +63,7 @@ pub async fn register_merge_mining_proxy_process(
port: get_port(18000..18499).unwrap(),
origin_submission,
id: 0,
stealth,
};

merge_mining_proxy.start(world).await;
Expand All @@ -70,10 +79,23 @@ impl MergeMiningProxyProcess {
let data_dir_str = data_dir.clone().into_os_string().into_string().unwrap();
let mut config_path = data_dir;
config_path.push("config.toml");
let wallet_grpc_port = world.get_wallet(&self.wallet_name).unwrap().grpc_port;
let base_node_grpc_port = world.get_node(&self.base_node_name).unwrap().grpc_port;
let proxy_full_address = format! {"/ip4/127.0.0.1/tcp/{}", self.port};
let origin_submission = self.origin_submission;
let mut wallet_client = create_wallet_client(world, self.wallet_name.clone())
.await
.expect("wallet grpc client");
let wallet_public_key = PublicKey::from_vec(
&wallet_client
.identify(GetIdentityRequest {})
.await
.unwrap()
.into_inner()
.public_key,
)
.unwrap();
let wallet_payment_address = TariAddress::new(wallet_public_key, Network::LocalNet);
let stealth = self.stealth;
thread::spawn(move || {
let cli = Cli {
common: CommonCliArgs {
Expand All @@ -84,10 +106,6 @@ impl MergeMiningProxyProcess {
network: Some("localnet".to_string().try_into().unwrap()),
config_property_overrides: vec![
("merge_mining_proxy.listener_address".to_string(), proxy_full_address),
(
"merge_mining_proxy.console_wallet_grpc_address".to_string(),
format!("/ip4/127.0.0.1/tcp/{}", wallet_grpc_port),
),
(
"merge_mining_proxy.base_node_grpc_address".to_string(),
format!("/ip4/127.0.0.1/tcp/{}", base_node_grpc_port),
Expand All @@ -114,6 +132,11 @@ impl MergeMiningProxyProcess {
"merge_mining_proxy.submit_to_origin".to_string(),
origin_submission.to_string(),
),
(
"miner.wallet_payment_address".to_string(),
wallet_payment_address.to_hex(),
),
("miner.stealth_payment".to_string(), stealth.to_string()),
],
},
};
Expand Down Expand Up @@ -192,3 +215,12 @@ impl MergeMiningProxyProcess {
self.submit_block(block).await
}
}

pub async fn create_wallet_client(world: &TariWorld, wallet_name: String) -> anyhow::Result<WalletGrpcClient<Channel>> {
let wallet_grpc_port = world.wallets.get(&wallet_name).unwrap().grpc_port;
let wallet_addr = format!("http://127.0.0.1:{}", wallet_grpc_port);

eprintln!("Wallet GRPC at {}", wallet_addr);

Ok(WalletGrpcClient::connect(wallet_addr.as_str()).await?)
}
Loading

0 comments on commit 318285d

Please sign in to comment.