Skip to content

Commit 5dbbdce

Browse files
committed
update cucumber mining code
1 parent 548258a commit 5dbbdce

File tree

4 files changed

+36
-70
lines changed

4 files changed

+36
-70
lines changed

integration_tests/src/miner.rs

Lines changed: 21 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222

2323
use minotari_app_grpc::{
2424
tari_rpc,
25-
tari_rpc::{pow_algo::PowAlgos, NewBlockTemplate, NewBlockTemplateRequest, PowAlgo},
25+
tari_rpc::{pow_algo::PowAlgos, GetIdentityRequest, NewBlockTemplate, NewBlockTemplateRequest, PowAlgo},
2626
};
2727
use minotari_node_grpc_client::BaseNodeGrpcClient;
28-
use tari_common_types::tari_address::TariAddress;
28+
use tari_common::configuration::Network;
29+
use tari_common_types::{tari_address::TariAddress, types::PublicKey};
2930
use tari_core::{
3031
consensus::ConsensusManager,
3132
transactions::{
@@ -35,6 +36,7 @@ use tari_core::{
3536
transaction_components::{RangeProofType, WalletOutput},
3637
},
3738
};
39+
use tari_crypto::tari_utilities::ByteArray;
3840

3941
use crate::TariWorld;
4042

@@ -57,14 +59,23 @@ pub fn register_miner_process(world: &mut TariWorld, miner_name: String, base_no
5759
}
5860

5961
pub async fn mine_blocks(world: &mut TariWorld, miner_name: String, num_blocks: u64) {
62+
let miner = world.get_miner(&miner_name);
6063
let mut base_client = create_base_node_client(world, &miner_name).await;
64+
let mut wallet_client = world.get_wallet(&miner.wallet_name).create_client().await;
65+
66+
let wallet_pk = PublicKey::from_canonical_bytes(
67+
&wallet_client
68+
.identify(GetIdentityRequest {})
69+
.await
70+
.unwrap()
71+
.into_inner()
72+
.public_key,
73+
)
74+
.unwrap();
75+
let payment_address = TariAddress::new(wallet_pk, Network::LocalNet);
6176

6277
for _ in 0..num_blocks {
63-
mine_block(world, &mut base_client).await;
64-
// Makes less likely that base layer will fail with
65-
// "Chain storage error: You tried to execute an invalid Database operation: UTXO 248a... was already marked as
66-
// deleted."
67-
// tokio::time::sleep(Duration::from_millis(100)).await;
78+
mine_block(world, &payment_address, &mut base_client).await;
6879
}
6980
}
7081

@@ -76,13 +87,13 @@ async fn create_base_node_client(world: &TariWorld, miner_name: &String) -> Base
7687
BaseNodeClient::connect(base_node_grpc_url).await.unwrap()
7788
}
7889

79-
async fn mine_block(world: &TariWorld, base_client: &mut BaseNodeClient) {
90+
async fn mine_block(world: &TariWorld, payment_address: &TariAddress, base_client: &mut BaseNodeClient) {
8091
let (block_template, _) = create_block_template_with_coinbase(
8192
base_client,
8293
0,
8394
&world.key_manager,
8495
&world.script_key_id().await,
85-
&world.default_payment_address,
96+
payment_address,
8697
false,
8798
&world.consensus_manager,
8899
)
@@ -96,65 +107,14 @@ async fn mine_block(world: &TariWorld, base_client: &mut BaseNodeClient) {
96107
.into_inner();
97108
let block = block_result.block.unwrap();
98109

99-
// We don't need to mine, as Localnet blocks have difficulty 1s
110+
// We don't need to mine, as Localnet blocks have difficulty target of 1s
100111
let submit_res = base_client.submit_block(block).await.unwrap().into_inner();
101112
log::info!(
102113
"Block {} successfully mined at height {:?}",
103114
tari_crypto::tari_utilities::hex::to_hex(&submit_res.block_hash),
104115
block_template.header.unwrap().height
105116
);
106117
}
107-
108-
// async fn create_block_template_with_coinbase(
109-
// base_client: &mut BaseNodeClient,
110-
// wallet_client: &mut WalletGrpcClient,
111-
// ) -> NewBlockTemplate {
112-
// // get the block template from the base node
113-
// let template_req = NewBlockTemplateRequest {
114-
// algo: Some(PowAlgo {
115-
// pow_algo: PowAlgos::Sha3x.into(),
116-
// }),
117-
// max_weight: 0,
118-
// };
119-
// let template_res = base_client
120-
// .get_new_block_template(template_req)
121-
// .await
122-
// .unwrap()
123-
// .into_inner();
124-
//
125-
// let NewBlockTemplateResponse {
126-
// new_block_template: Some(mut template),
127-
// miner_data: Some(miner_data),
128-
// ..
129-
// } = template_res
130-
// else {
131-
// panic!("Failed to get block template");
132-
// };
133-
//
134-
// let height = template.header.as_ref().unwrap().height;
135-
// let coinbase_res = wallet_client
136-
// .get_coinbase(GetCoinbaseRequest {
137-
// reward: miner_data.reward,
138-
// fee: miner_data.total_fees,
139-
// height,
140-
// extra: vec![],
141-
// })
142-
// .await
143-
// .unwrap()
144-
// .into_inner();
145-
//
146-
// let mut transaction_body = coinbase_res.transaction.unwrap().body.unwrap();
147-
// let tx_out = transaction_body.outputs.remove(0);
148-
// let tx_kernel = transaction_body.kernels.remove(0);
149-
//
150-
// // add the coinbase outputs and kernels to the block template
151-
// let body = template.body.as_mut().unwrap();
152-
// body.outputs.push(tx_out);
153-
// body.kernels.push(tx_kernel);
154-
//
155-
// template
156-
// }
157-
158118
async fn create_block_template_with_coinbase(
159119
base_client: &mut BaseNodeClient,
160120
weight: u64,

integration_tests/src/wallet.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,19 @@ pub async fn spawn_wallet(world: &mut TariWorld, wallet_name: String, base_node_
136136

137137
eprintln!("Using wallet temp_dir: {}", temp_dir.display());
138138

139+
wallet_config.wallet.set_base_path(temp_dir.clone());
139140
wallet_config.wallet.network = Network::LocalNet;
140141
wallet_config.wallet.password = Some("test".into());
141142
wallet_config.wallet.grpc_enabled = true;
142143
wallet_config.wallet.grpc_address =
143144
Some(Multiaddr::from_str(&format!("/ip4/127.0.0.1/tcp/{}", grpc_port)).unwrap());
144145
wallet_config.wallet.data_dir = temp_dir.join("data/wallet");
145146
wallet_config.wallet.db_file = temp_dir.join("db/console_wallet.db");
146-
147+
wallet_config.wallet.contacts_auto_ping_interval = Duration::from_secs(2);
148+
wallet_config
149+
.wallet
150+
.base_node_service_config
151+
.base_node_monitor_max_refresh_interval = Duration::from_secs(15);
147152
wallet_config.wallet.p2p.transport.transport_type = TransportType::Tcp;
148153
wallet_config.wallet.p2p.transport.tcp.listener_address =
149154
Multiaddr::from_str(&format!("/ip4/127.0.0.1/tcp/{}", port)).unwrap();

integration_tests/tests/log4rs/cucumber.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,21 @@ loggers:
135135

136136
# Route log events sent to the "core" logger to the "base_layer" appender
137137
c:
138-
level: info
138+
level: debug
139139
appenders:
140140
- base_layer
141141
# Route log events sent to the "wallet" logger to the "base_layer" appender
142142
wallet:
143-
level: info
143+
level: debug
144144
appenders:
145145
- console_wallet
146146
# Route log events sent to the "comms" logger to the "network" appender
147147
comms:
148-
level: info
148+
level: debug
149149
appenders:
150150
- network
151151
# Route log events sent to the "p2p" logger to the "network" appender
152152
p2p:
153-
level: info
153+
level: debug
154154
appenders:
155155
- network

integration_tests/tests/steps/wallet.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use std::time::Duration;
55

66
use cucumber::{given, when};
7-
use minotari_app_grpc::tari_rpc::GetBalanceRequest;
7+
use minotari_app_grpc::tari_rpc::{GetBalanceRequest, ValidateRequest};
88
use tari_common_types::types::{Commitment, PrivateKey, PublicKey};
99
use tari_crypto::{ristretto::RistrettoComSig, tari_utilities::ByteArray};
1010
use tokio::time::sleep;
@@ -86,6 +86,7 @@ async fn check_balance(world: &mut TariWorld, wallet_name: String, balance: u64,
8686
_ => panic!("Unknown unit {}", units),
8787
};
8888
loop {
89+
let _result = client.validate_all_transactions(ValidateRequest {}).await;
8990
let resp = client.get_balance(GetBalanceRequest {}).await.unwrap().into_inner();
9091
if resp.available_balance >= balance {
9192
break;
@@ -94,11 +95,11 @@ async fn check_balance(world: &mut TariWorld, wallet_name: String, balance: u64,
9495
"Waiting for wallet {} to have at least {} uT (balance: {} uT, pending: {} uT)",
9596
wallet_name, balance, resp.available_balance, resp.pending_incoming_balance
9697
);
97-
sleep(Duration::from_secs(1)).await;
98+
sleep(Duration::from_secs(5)).await;
9899

99-
if iterations == 40 {
100+
if iterations == 100 {
100101
panic!(
101-
"Wallet {} did not have at least {} uT after 40 seconds (balance: {} uT, pending: {} uT)",
102+
"Wallet {} did not have at least {} uT after 500 seconds (balance: {} uT, pending: {} uT)",
102103
wallet_name, balance, resp.available_balance, resp.pending_incoming_balance
103104
);
104105
}

0 commit comments

Comments
 (0)