2018-03-05 22:33:44 +03:00
|
|
|
// Copyright 2018 The Grin Developers
|
2018-01-10 22:36:27 +03:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#[macro_use]
|
2018-10-21 23:30:56 +03:00
|
|
|
extern crate log;
|
2018-01-10 22:36:27 +03:00
|
|
|
|
|
|
|
extern crate grin_api as api;
|
|
|
|
extern crate grin_chain as chain;
|
2018-03-04 03:19:54 +03:00
|
|
|
extern crate grin_config as config;
|
2018-01-10 22:36:27 +03:00
|
|
|
extern crate grin_core as core;
|
|
|
|
extern crate grin_p2p as p2p;
|
2018-04-24 11:18:24 +03:00
|
|
|
extern crate grin_servers as servers;
|
2018-01-10 22:36:27 +03:00
|
|
|
extern crate grin_util as util;
|
|
|
|
extern crate grin_wallet as wallet;
|
|
|
|
|
|
|
|
mod framework;
|
|
|
|
|
2018-03-04 03:19:54 +03:00
|
|
|
use framework::{LocalServerContainer, LocalServerContainerConfig};
|
2018-10-20 03:13:07 +03:00
|
|
|
use std::sync::Arc;
|
2018-05-21 18:28:11 +03:00
|
|
|
use std::{thread, time};
|
2018-10-20 03:13:07 +03:00
|
|
|
use util::Mutex;
|
2018-01-10 22:36:27 +03:00
|
|
|
|
|
|
|
/// Start 1 node mining and two wallets, then send a few
|
|
|
|
/// transactions from one to the other
|
2018-05-21 19:01:05 +03:00
|
|
|
#[ignore]
|
2018-05-21 18:28:11 +03:00
|
|
|
#[test]
|
2018-01-10 22:36:27 +03:00
|
|
|
fn basic_wallet_transactions() {
|
|
|
|
let test_name_dir = "test_servers";
|
|
|
|
core::global::set_mining_mode(core::global::ChainTypes::AutomatedTesting);
|
|
|
|
framework::clean_all_output(test_name_dir);
|
|
|
|
let mut log_config = util::LoggingConfig::default();
|
|
|
|
//log_config.stdout_log_level = util::LogLevel::Trace;
|
|
|
|
log_config.stdout_log_level = util::LogLevel::Info;
|
|
|
|
//init_logger(Some(log_config));
|
|
|
|
util::init_test_logger();
|
|
|
|
|
|
|
|
// Run a separate coinbase wallet for coinbase transactions
|
|
|
|
let mut coinbase_config = LocalServerContainerConfig::default();
|
|
|
|
coinbase_config.name = String::from("coinbase_wallet");
|
2018-03-04 03:19:54 +03:00
|
|
|
coinbase_config.wallet_validating_node_url = String::from("http://127.0.0.1:30001");
|
2018-05-09 12:15:58 +03:00
|
|
|
coinbase_config.coinbase_wallet_address = String::from("http://127.0.0.1:13415");
|
2018-01-10 22:36:27 +03:00
|
|
|
coinbase_config.wallet_port = 10002;
|
2018-03-04 03:19:54 +03:00
|
|
|
let coinbase_wallet = Arc::new(Mutex::new(
|
|
|
|
LocalServerContainer::new(coinbase_config).unwrap(),
|
|
|
|
));
|
2018-10-20 03:13:07 +03:00
|
|
|
let coinbase_wallet_config = { coinbase_wallet.lock().wallet_config.clone() };
|
2018-01-10 22:36:27 +03:00
|
|
|
|
2018-02-06 14:42:26 +03:00
|
|
|
let coinbase_seed = LocalServerContainer::get_wallet_seed(&coinbase_wallet_config);
|
2018-01-10 22:36:27 +03:00
|
|
|
let _ = thread::spawn(move || {
|
2018-10-20 03:13:07 +03:00
|
|
|
let mut w = coinbase_wallet.lock();
|
2018-01-10 22:36:27 +03:00
|
|
|
w.run_wallet(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
let mut recp_config = LocalServerContainerConfig::default();
|
|
|
|
recp_config.name = String::from("target_wallet");
|
2018-03-04 03:19:54 +03:00
|
|
|
recp_config.wallet_validating_node_url = String::from("http://127.0.0.1:30001");
|
2018-01-10 22:36:27 +03:00
|
|
|
recp_config.wallet_port = 20002;
|
|
|
|
let target_wallet = Arc::new(Mutex::new(LocalServerContainer::new(recp_config).unwrap()));
|
|
|
|
let target_wallet_cloned = target_wallet.clone();
|
2018-10-20 03:13:07 +03:00
|
|
|
let recp_wallet_config = { target_wallet.lock().wallet_config.clone() };
|
2018-02-06 14:42:26 +03:00
|
|
|
let recp_seed = LocalServerContainer::get_wallet_seed(&recp_wallet_config);
|
2018-01-10 22:36:27 +03:00
|
|
|
//Start up a second wallet, to receive
|
|
|
|
let _ = thread::spawn(move || {
|
2018-10-20 03:13:07 +03:00
|
|
|
let mut w = target_wallet_cloned.lock();
|
2018-01-10 22:36:27 +03:00
|
|
|
w.run_wallet(0);
|
|
|
|
});
|
|
|
|
|
2018-08-01 12:44:07 +03:00
|
|
|
let mut server_config = LocalServerContainerConfig::default();
|
|
|
|
server_config.name = String::from("server_one");
|
|
|
|
server_config.p2p_server_port = 30000;
|
|
|
|
server_config.api_server_port = 30001;
|
|
|
|
server_config.start_miner = true;
|
|
|
|
server_config.start_wallet = false;
|
|
|
|
server_config.coinbase_wallet_address =
|
|
|
|
String::from(format!("http://{}:{}", server_config.base_addr, 10002));
|
2018-01-10 22:36:27 +03:00
|
|
|
// Spawn server and let it run for a bit
|
|
|
|
let _ = thread::spawn(move || {
|
|
|
|
let mut server_one = LocalServerContainer::new(server_config).unwrap();
|
|
|
|
server_one.run_server(120);
|
|
|
|
});
|
|
|
|
|
2018-02-06 14:42:26 +03:00
|
|
|
//Wait until we have some funds to send
|
2018-03-04 03:19:54 +03:00
|
|
|
let mut coinbase_info =
|
|
|
|
LocalServerContainer::get_wallet_info(&coinbase_wallet_config, &coinbase_seed);
|
2018-02-06 14:42:26 +03:00
|
|
|
let mut slept_time = 0;
|
2018-03-04 03:19:54 +03:00
|
|
|
while coinbase_info.amount_currently_spendable < 100000000000 {
|
2018-02-06 14:42:26 +03:00
|
|
|
thread::sleep(time::Duration::from_millis(500));
|
2018-03-04 03:19:54 +03:00
|
|
|
slept_time += 500;
|
2018-02-06 14:42:26 +03:00
|
|
|
if slept_time > 10000 {
|
|
|
|
panic!("Coinbase not confirming in time");
|
|
|
|
}
|
2018-03-04 03:19:54 +03:00
|
|
|
coinbase_info =
|
|
|
|
LocalServerContainer::get_wallet_info(&coinbase_wallet_config, &coinbase_seed);
|
2018-02-06 14:42:26 +03:00
|
|
|
}
|
2018-10-21 23:30:56 +03:00
|
|
|
warn!("Sending 50 Grins to recipient wallet");
|
2018-03-04 03:19:54 +03:00
|
|
|
LocalServerContainer::send_amount_to(
|
|
|
|
&coinbase_wallet_config,
|
|
|
|
"50.00",
|
|
|
|
1,
|
|
|
|
"not_all",
|
|
|
|
"http://127.0.0.1:20002",
|
2018-06-14 19:02:05 +03:00
|
|
|
false,
|
2018-03-04 03:19:54 +03:00
|
|
|
);
|
2018-01-10 22:36:27 +03:00
|
|
|
|
2018-02-06 14:42:26 +03:00
|
|
|
//Wait for a confirmation
|
|
|
|
thread::sleep(time::Duration::from_millis(3000));
|
2018-03-04 03:19:54 +03:00
|
|
|
let coinbase_info =
|
|
|
|
LocalServerContainer::get_wallet_info(&coinbase_wallet_config, &coinbase_seed);
|
2018-02-06 14:42:26 +03:00
|
|
|
println!("Coinbase wallet info: {:?}", coinbase_info);
|
|
|
|
|
|
|
|
let recipient_info = LocalServerContainer::get_wallet_info(&recp_wallet_config, &recp_seed);
|
|
|
|
println!("Recipient wallet info: {:?}", recipient_info);
|
2018-06-14 19:02:05 +03:00
|
|
|
assert!(recipient_info.amount_currently_spendable == 50000000000);
|
2018-01-10 22:36:27 +03:00
|
|
|
|
2018-10-21 23:30:56 +03:00
|
|
|
warn!("Sending many small transactions to recipient wallet");
|
2018-04-06 02:31:34 +03:00
|
|
|
for _i in 0..10 {
|
2018-03-04 03:19:54 +03:00
|
|
|
LocalServerContainer::send_amount_to(
|
|
|
|
&coinbase_wallet_config,
|
|
|
|
"1.00",
|
|
|
|
1,
|
|
|
|
"not_all",
|
|
|
|
"http://127.0.0.1:20002",
|
2018-06-14 19:02:05 +03:00
|
|
|
false,
|
2018-03-04 03:19:54 +03:00
|
|
|
);
|
2018-02-06 14:42:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
thread::sleep(time::Duration::from_millis(10000));
|
|
|
|
let recipient_info = LocalServerContainer::get_wallet_info(&recp_wallet_config, &recp_seed);
|
2018-03-04 03:19:54 +03:00
|
|
|
println!(
|
|
|
|
"Recipient wallet info post little sends: {:?}",
|
|
|
|
recipient_info
|
|
|
|
);
|
|
|
|
|
2018-06-14 19:02:05 +03:00
|
|
|
assert!(recipient_info.amount_currently_spendable == 60000000000);
|
2018-01-10 22:36:27 +03:00
|
|
|
//send some cash right back
|
2018-03-04 03:19:54 +03:00
|
|
|
LocalServerContainer::send_amount_to(
|
|
|
|
&recp_wallet_config,
|
|
|
|
"25.00",
|
|
|
|
1,
|
|
|
|
"all",
|
|
|
|
"http://127.0.0.1:10002",
|
2018-06-14 19:02:05 +03:00
|
|
|
false,
|
2018-03-04 03:19:54 +03:00
|
|
|
);
|
2018-02-06 14:42:26 +03:00
|
|
|
|
2018-01-10 22:36:27 +03:00
|
|
|
thread::sleep(time::Duration::from_millis(5000));
|
2018-02-06 14:42:26 +03:00
|
|
|
|
2018-03-04 03:19:54 +03:00
|
|
|
let coinbase_info =
|
|
|
|
LocalServerContainer::get_wallet_info(&coinbase_wallet_config, &coinbase_seed);
|
2018-02-06 14:42:26 +03:00
|
|
|
println!("Coinbase wallet info final: {:?}", coinbase_info);
|
2018-01-10 22:36:27 +03:00
|
|
|
}
|