Skip to content

Commit

Permalink
cucumber logging
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Nov 19, 2024
1 parent 557732e commit 5c1e431
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 39 deletions.
2 changes: 1 addition & 1 deletion applications/minotari_merge_mining_proxy/log4rs_sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ appenders:

# root (to proxy)
root:
level: debug
level: trace
appenders:
- stdout
- proxy
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_merge_mining_proxy/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ mod test {
"id": "0",
"method": rpc_method,
"params": {
"wallet_address": "489r43gR8bDMJNBf4Q6sL9CNERvZQrTqjRCSESqgWQEWWq2UGAfj2voaw3zBtD7U8CQ391Nc1PDHUHiN85yhbZnCDasqzyX",
"wallet_address": "44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A",
}
}),
Method::GetVersion => json!({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ const LOG_TARGET: &str = "minotari_mm_proxy::proxy";

#[allow(clippy::too_many_lines)]
pub async fn start_merge_miner(cli: Cli) -> Result<(), anyhow::Error> {
trace!(target: LOG_TARGET, "{:?}", cli);
let config_path = cli.common.config_path();
let cfg = load_configuration(&config_path, true, cli.non_interactive_mode, &cli, cli.common.network)?;
trace!(target: LOG_TARGET, "{:?}", cfg);
let mut config = MergeMiningProxyConfig::load_from(&cfg)?;
config.set_base_path(cli.common.get_base_path());
trace!(target: LOG_TARGET, "{:?}", config);

// Get reputable monerod URLs
let mut assigned_dynamic_fail = false;
Expand Down
22 changes: 21 additions & 1 deletion integration_tests/log4rs/cucumber.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,22 @@ appenders:
pattern: "{{log_dir}}/log/libp2p.{}.log"
encoder:
pattern: "{d(%Y-%m-%d %H:%M:%S.%f)} {f}.{L} {i} [{t}] {l:5} {m}{n}"
# An appender named "cucumber_detail" that writes to a file with a custom pattern encoder
cucumber_detail:
kind: rolling_file
path: "{{log_dir}}/log/cucumber_detail.log"
policy:
kind: compound
trigger:
kind: size
limit: 100mb
roller:
kind: fixed_window
base: 1
count: 5
pattern: "{{log_dir}}/log/cucumber_detail.{}.log"
encoder:
pattern: "{d(%Y-%m-%d %H:%M:%S.%f)} {f}.{L} {i} [{t}] {l:5} {m}{n}"

# We don't want prints during cucumber test, everything useful will in logs.
# root:
Expand All @@ -167,6 +183,10 @@ loggers:
level: info # we have only single print, and it's info
appenders:
- stdout
cucumber_detail:
level: debug
appenders:
- cucumber_detail
c:
level: debug #trace #debug
appenders:
Expand Down Expand Up @@ -210,7 +230,7 @@ loggers:

# merge mining proxy
minotari_mm_proxy::proxy:
level: debug
level: debug #trace #debug
appenders:
- proxy
additive: false
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/src/base_node_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use tonic::transport::Channel;

use crate::{get_peer_seeds, get_port, wait_for_service, ServiceType, TariWorld};

const LOG_TARGET: &str = "cucumber::bas_node_process";
const LOG_TARGET: &str = "cucumber_detail::base_node_process";

#[derive(Clone)]
pub struct BaseNodeProcess {
Expand Down
69 changes: 35 additions & 34 deletions integration_tests/src/merge_mining_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

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

use log::*;
use minotari_app_utilities::common_cli_args::CommonCliArgs;
use minotari_merge_mining_proxy::{merge_miner, Cli};
use minotari_wallet_grpc_client::{grpc, WalletGrpcClient};
Expand All @@ -35,6 +36,8 @@ use tonic::transport::Channel;
use super::get_port;
use crate::TariWorld;

const LOG_TARGET: &str = "cucumber_detail::merge_mining_process";

#[derive(Clone, Debug)]
pub struct MergeMiningProxyProcess {
pub name: String,
Expand Down Expand Up @@ -104,20 +107,6 @@ impl MergeMiningProxyProcess {
"merge_mining_proxy.base_node_grpc_address".to_string(),
format!("/ip4/127.0.0.1/tcp/{}", base_node_grpc_port),
),
(
"merge_mining_proxy.monerod_url".to_string(),
[
"http://stagenet.xmr-tw.org:38081",
"http://node.monerodevs.org:38089",
"http://node3.monerodevs.org:38089",
"http://xmr-lux.boldsuck.org:38081",
"http://singapore.node.xmr.pm:38081",
]
.join(","),
),
("merge_mining_proxy.monerod_use_auth".to_string(), "false".to_string()),
("merge_mining_proxy.monerod_username".to_string(), "".to_string()),
("merge_mining_proxy.monerod_password".to_string(), "".to_string()),
(
"merge_mining_proxy.wait_for_initial_sync_at_startup".to_string(),
"false".to_string(),
Expand All @@ -138,22 +127,30 @@ impl MergeMiningProxyProcess {
},
non_interactive_mode: false,
};
debug!(target: LOG_TARGET, "{:?}", cli);
let rt = runtime::Builder::new_multi_thread().enable_all().build().unwrap();
if let Err(e) = rt.block_on(merge_miner(cli)) {
println!("Error running merge mining proxy : {:?}", e);
println!("Error running merge mining proxy : {}", e);
panic!("Error running merge mining proxy");
}
});
}

async fn get_response(&self, path: &str) -> Value {
let full_address = format!("http://127.0.0.1:{}", self.port);
reqwest::get(format!("{}/{}", full_address, path))
.await
.unwrap()
.json::<Value>()
.await
.unwrap()
match reqwest::get(format!("{}/{}", full_address, path)).await {
Ok(response) => match response.json::<Value>().await {
Ok(value) => value,
Err(err) => {
error!(target: LOG_TARGET, "response.json ({})", err);
panic!("Error parsing response ({})", err);
},
},
Err(err) => {
error!(target: LOG_TARGET, "reqwest::get ({})", err);
panic!("Error reqwest::get ({})", err);
},
}
}

async fn json_rpc_call(&mut self, method_name: &str, params: &Value) -> Value {
Expand All @@ -164,19 +161,24 @@ impl MergeMiningProxyProcess {
"params": params,
"id":self.id}
);
println!("json_rpc_call {}", method_name);
println!("json payload {}", json);
debug!(target: LOG_TARGET, "json_rpc_call {}", method_name);
debug!(target: LOG_TARGET, "json payload {}", json);
self.id += 1;
let full_address = format!("http://127.0.0.1:{}/json_rpc", self.port);
client
.post(full_address)
.json(&json)
.send()
.await
.unwrap()
.json()
.await
.unwrap()

match client.post(full_address).json(&json).send().await {
Ok(response) => match response.json().await {
Ok(value) => value,
Err(err) => {
error!(target: LOG_TARGET, "response.json() {}", err);
panic!("Error parsing response ({})", err);
},
},
Err(err) => {
error!(target: LOG_TARGET, "client.post ({})", err);
panic!("Error client.post ({})", err);
},
}
}

pub async fn get_height(&self) -> Value {
Expand All @@ -185,8 +187,7 @@ impl MergeMiningProxyProcess {

pub async fn get_block_template(&mut self) -> Value {
let params = json!({
"wallet_address":"5AUoj81i63cBUbiKY5jybsZXRDYb9CppmSjiZXC8ZYT6HZH6ebsQvBecYfRKDYoyzKF2uML9FKkTAc7nJvHKdoDYQEeteRW",
"reserve_size":60
"wallet_address": "44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A"
});
self.json_rpc_call("getblocktemplate", &params).await
}
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/tests/steps/wallet_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ use tari_utilities::hex::Hex;

use crate::steps::{mining_steps::create_miner, CONFIRMATION_PERIOD, HALF_SECOND, TWO_MINUTES_WITH_HALF_SECOND_SLEEP};

const LOG_TARGET: &str = "cucumber::wallet_steps";
const LOG_TARGET: &str = "cucumber_detail::wallet_steps";

#[given(expr = "a wallet {word} connected to base node {word}")]
async fn start_wallet(world: &mut TariWorld, wallet_name: String, node_name: String) {
Expand Down

0 comments on commit 5c1e431

Please sign in to comment.