mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-12-03 12:24:27 +01:00
merge staging
This commit is contained in:
+12
-12
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "grin_wallet_controller"
|
||||
version = "5.5.0"
|
||||
version = "5.5.1"
|
||||
authors = ["Grin Developers <mimblewimble@lists.launchpad.net>"]
|
||||
description = "Controllers for grin wallet instantiation"
|
||||
license = "Apache-2.0"
|
||||
@@ -25,21 +25,21 @@ lazy_static = "1"
|
||||
thiserror = "1"
|
||||
qr_code = "1.1.0"
|
||||
|
||||
grin_wallet_util = { path = "../util", version = "5.5.0" }
|
||||
grin_wallet_api = { path = "../api", version = "5.5.0" }
|
||||
grin_wallet_impls = { path = "../impls", version = "5.5.0" }
|
||||
grin_wallet_libwallet = { path = "../libwallet", version = "5.5.0" }
|
||||
grin_wallet_config = { path = "../config", version = "5.5.0" }
|
||||
grin_wallet_util = { path = "../util", version = "5.5.1" }
|
||||
grin_wallet_api = { path = "../api", version = "5.5.1" }
|
||||
grin_wallet_impls = { path = "../impls", version = "5.5.1" }
|
||||
grin_wallet_libwallet = { path = "../libwallet", version = "5.5.1" }
|
||||
grin_wallet_config = { path = "../config", version = "5.5.1" }
|
||||
|
||||
##### Grin Imports
|
||||
|
||||
grin_core = { path = "../grin/core"}
|
||||
grin_keychain = { path = "../grin/keychain"}
|
||||
grin_util = { path = "../grin/util"}
|
||||
grin_api = { path = "../grin/api"}
|
||||
grin_chain = { path = "../grin/chain"}
|
||||
grin_core = { workspace = true }
|
||||
grin_keychain = { workspace = true }
|
||||
grin_util = { workspace = true }
|
||||
grin_api = { workspace = true }
|
||||
grin_chain = { workspace = true }
|
||||
|
||||
#####
|
||||
|
||||
[dev-dependencies]
|
||||
ed25519-dalek = "2"
|
||||
ed25519-dalek = "2"
|
||||
|
||||
+319
-163
@@ -18,21 +18,28 @@ use crate::apiwallet::{try_slatepack_sync_workflow, Owner};
|
||||
use crate::config::{TorConfig, WalletConfig, WALLET_CONFIG_FILE_NAME};
|
||||
use crate::core::{core, global};
|
||||
use crate::error::Error;
|
||||
use crate::impls::PathToSlatepack;
|
||||
use crate::keychain;
|
||||
use crate::libwallet::api_impl::owner::{self, decrypt_slatepack};
|
||||
use crate::libwallet::api_impl::types::update_tx_slate_state;
|
||||
use crate::libwallet::contract::types::{
|
||||
ContractNewArgsAPI, ContractRevokeArgsAPI, ContractSetupArgsAPI, OutputSelectionArgs,
|
||||
PaymentMemo, ProofArgs, ProofType,
|
||||
};
|
||||
use crate::libwallet::contract::{can_finalize, initial_net_change};
|
||||
use crate::libwallet::mwixnet::MixnetReqCreationParams;
|
||||
use crate::libwallet::slatepack::get_slatepack_file_contents;
|
||||
use crate::libwallet::slatepack::SlatepackAddressIndex;
|
||||
use crate::libwallet::OutputCommitMapping;
|
||||
use crate::libwallet::{
|
||||
self, EarlyPaymentProof, InitTxArgs, IssueInvoiceTxArgs, NodeClient, PaymentProof, Slate,
|
||||
SlateState, SlatepackAddress, Slatepacker, SlatepackerArgs, WalletLCProvider,
|
||||
SlateState, Slatepack, SlatepackAddress, WalletLCProvider,
|
||||
};
|
||||
use crate::libwallet::{wallet_lock, WalletHandle};
|
||||
use crate::util::secp::key::SecretKey;
|
||||
use crate::util::{Mutex, ZeroingString};
|
||||
use crate::util::secp::pedersen::Commitment;
|
||||
use crate::util::{Mutex, ToHex, ZeroingString};
|
||||
use crate::{controller, display};
|
||||
use grin_wallet_util::OnionV3Address;
|
||||
|
||||
use qr_code::QrCode;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -59,7 +66,7 @@ fn show_recovery_phrase(phrase: ZeroingString) {
|
||||
/// Arguments common to all wallet commands
|
||||
#[derive(Clone)]
|
||||
pub struct GlobalArgs {
|
||||
pub account: String,
|
||||
pub account: Option<String>,
|
||||
pub api_secret: Option<String>,
|
||||
pub node_api_secret: Option<String>,
|
||||
pub show_spent: bool,
|
||||
@@ -126,7 +133,7 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn rewind_hash<'a, L, C, K>(
|
||||
pub fn rewind_hash<L, C, K>(
|
||||
owner_api: &mut Owner<L, C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
) -> Result<(), Error>
|
||||
@@ -165,7 +172,7 @@ where
|
||||
let tip_height = owner_api.node_height(None)?.height;
|
||||
let start_height = match args.backwards_from_tip {
|
||||
Some(b) => tip_height.saturating_sub(b),
|
||||
None => args.start_height.unwrap_or_else(|| 1),
|
||||
None => args.start_height.unwrap_or(1),
|
||||
};
|
||||
warn!(
|
||||
"Starting view wallet output scan from height {} ...",
|
||||
@@ -190,6 +197,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn listen<L, C, K>(
|
||||
owner_api: &mut Owner<L, C, K>,
|
||||
keychain_mask: Arc<Mutex<Option<SecretKey>>>,
|
||||
@@ -228,7 +236,7 @@ where
|
||||
if let Ok(t) = api_thread {
|
||||
if !cli_mode {
|
||||
let r = t.join();
|
||||
if let Err(_) = r {
|
||||
if r.is_err() {
|
||||
error!("Error starting listener");
|
||||
return Err(Error::ListenerError);
|
||||
}
|
||||
@@ -270,6 +278,8 @@ where
|
||||
/// Arguments for account command
|
||||
pub struct AccountArgs {
|
||||
pub create: Option<String>,
|
||||
pub minimum_confirmations: u64,
|
||||
pub active: Option<String>,
|
||||
}
|
||||
|
||||
pub fn account<L, C, K>(
|
||||
@@ -282,20 +292,7 @@ where
|
||||
C: NodeClient + 'static,
|
||||
K: keychain::Keychain + 'static,
|
||||
{
|
||||
if args.create.is_none() {
|
||||
let res = {
|
||||
let acct_mappings = owner_api.accounts(keychain_mask)?;
|
||||
// give logging thread a moment to catch up
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
display::accounts(acct_mappings);
|
||||
Ok(())
|
||||
};
|
||||
if let Err(e) = res {
|
||||
error!("Error listing accounts: {}", e);
|
||||
return Err(Error::LibWallet(e));
|
||||
}
|
||||
} else {
|
||||
let label = args.create.unwrap();
|
||||
if let Some(label) = args.create {
|
||||
let res = {
|
||||
owner_api.create_account_path(keychain_mask, &label)?;
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
@@ -307,6 +304,31 @@ where
|
||||
error!("Error creating account '{}': {}", label, e);
|
||||
return Err(Error::LibWallet(e));
|
||||
}
|
||||
} else if let Some(label) = args.active {
|
||||
let res = {
|
||||
owner_api.set_active_account(keychain_mask, &label)?;
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
info!("Account: '{}' set as active!", label);
|
||||
Ok(())
|
||||
};
|
||||
if let Err(e) = res {
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
error!("Error setting account '{}' as active: {}", label, e);
|
||||
return Err(Error::LibWallet(e));
|
||||
}
|
||||
} else {
|
||||
let res = {
|
||||
let acct_mappings =
|
||||
owner_api.accounts_info(keychain_mask, args.minimum_confirmations)?;
|
||||
// give logging thread a moment to catch up
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
display::accounts(acct_mappings);
|
||||
Ok(())
|
||||
};
|
||||
if let Err(e) = res {
|
||||
error!("Error listing accounts: {}", e);
|
||||
return Err(Error::LibWallet(e));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -332,6 +354,7 @@ pub struct SendArgs {
|
||||
pub outfile: Option<String>,
|
||||
pub bridge: Option<String>,
|
||||
pub slatepack_qr: bool,
|
||||
pub address_index: Option<SlatepackAddressIndex>,
|
||||
}
|
||||
|
||||
fn max_retry_args(mut init_args: InitTxArgs, amount: u64, max_inputs: u32) -> InitTxArgs {
|
||||
@@ -379,12 +402,15 @@ where
|
||||
true,
|
||||
args.minimum_confirmations,
|
||||
)?;
|
||||
if args.use_max_amount {
|
||||
amount = wallet_info.amount_currently_spendable;
|
||||
}
|
||||
if !info_updated && !update_skipped {
|
||||
warn!("Wallet info update failed: node connection error");
|
||||
}
|
||||
if args.use_max_amount {
|
||||
amount = wallet_info.amount_currently_spendable;
|
||||
if amount == 0 {
|
||||
return Err(Error::GenericError("No spendable funds".to_string()));
|
||||
}
|
||||
}
|
||||
if args.estimate_selection_strategies {
|
||||
let strategies = estimate_strategies(args.use_max_amount)
|
||||
.iter()
|
||||
@@ -400,6 +426,7 @@ where
|
||||
selection_strategy_is_use_all: strategy == "all",
|
||||
refresh_outputs_from_node: !info_updated,
|
||||
estimate_only: Some(true),
|
||||
address_index: args.address_index,
|
||||
..Default::default()
|
||||
};
|
||||
let result = owner_api.init_send_tx(keychain_mask, init_args.clone());
|
||||
@@ -413,11 +440,11 @@ where
|
||||
init_args = max_retry_args(init_args, amount, max_inputs);
|
||||
owner_api.init_send_tx(keychain_mask, init_args)?
|
||||
} else {
|
||||
return Err(grin_wallet_libwallet::Error::from(e));
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
return Err(grin_wallet_libwallet::Error::from(e));
|
||||
return Err(e);
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -443,26 +470,21 @@ where
|
||||
target_slate_version: args.target_slate_version,
|
||||
payment_proof_recipient_address,
|
||||
ttl_blocks: args.ttl_blocks,
|
||||
send_args: None,
|
||||
late_lock: Some(args.late_lock),
|
||||
address_index: args.address_index,
|
||||
..Default::default()
|
||||
};
|
||||
let init_send_tx = |init_args: InitTxArgs| -> Result<Slate, libwallet::Error> {
|
||||
let result = owner_api.init_send_tx(keychain_mask, init_args.clone());
|
||||
let slate = match result {
|
||||
Ok(s) => {
|
||||
info!(
|
||||
"Tx created: {} grin to {} (strategy '{}')",
|
||||
core::amount_to_hr_string(init_args.amount, false),
|
||||
dest.as_ref()
|
||||
.map(ToString::to_string)
|
||||
.unwrap_or_else(|| "no destination".to_string()),
|
||||
args.selection_strategy,
|
||||
);
|
||||
s
|
||||
}
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
let slate = result?;
|
||||
info!(
|
||||
"Tx created: {} grin to {} (strategy '{}')",
|
||||
core::amount_to_hr_string(init_args.amount, false),
|
||||
dest.as_ref()
|
||||
.map(ToString::to_string)
|
||||
.unwrap_or_else(|| "no destination".to_string()),
|
||||
args.selection_strategy,
|
||||
);
|
||||
Ok(slate)
|
||||
};
|
||||
slate = match init_send_tx(init_args.clone()) {
|
||||
@@ -498,22 +520,32 @@ where
|
||||
tor_config.bridge.bridge_line = Some(b);
|
||||
}
|
||||
|
||||
let output_sp = || -> Result<(), Error> {
|
||||
let output_sp = |owner_api: &mut Owner<L, C, K>, lock_outputs: bool| -> Result<(), Error> {
|
||||
let sender_index = {
|
||||
wallet_lock!(owner_api.wallet_inst, w);
|
||||
let context = w.get_private_context(keychain_mask, slate.id.as_bytes())?;
|
||||
context.payment_proof_derivation_index
|
||||
};
|
||||
Ok(output_slatepack(
|
||||
owner_api,
|
||||
keychain_mask,
|
||||
&slate,
|
||||
dest.clone(),
|
||||
args.outfile,
|
||||
true,
|
||||
lock_outputs,
|
||||
false,
|
||||
args.slatepack_qr,
|
||||
sender_index,
|
||||
)?)
|
||||
};
|
||||
|
||||
let can_send = tor_config.send_tor(args.skip_tor);
|
||||
if test_mode || !can_send || dest.is_none() {
|
||||
return output_sp();
|
||||
return output_sp(owner_api, !args.late_lock);
|
||||
}
|
||||
|
||||
if !args.late_lock {
|
||||
owner_api.tx_lock_outputs(keychain_mask, &slate)?;
|
||||
}
|
||||
|
||||
let dest = dest.as_ref().unwrap();
|
||||
@@ -521,7 +553,6 @@ where
|
||||
|
||||
match res {
|
||||
Ok(s) => {
|
||||
owner_api.tx_lock_outputs(keychain_mask, &s)?;
|
||||
let ret_slate = owner_api.finalize_tx(keychain_mask, &s)?;
|
||||
let result = owner_api.post_tx(keychain_mask, &ret_slate, args.fluff);
|
||||
match result {
|
||||
@@ -536,7 +567,13 @@ where
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Error sending slate sync: {}", e);
|
||||
output_sp()?;
|
||||
output_sp(owner_api, false)?;
|
||||
if !args.late_lock {
|
||||
println!(
|
||||
"Outputs are locked. To unlock them, cancel with `cancel -t {}`.",
|
||||
slate.id
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -548,6 +585,7 @@ fn slatepack_message<L, C, K>(
|
||||
slate: &Slate,
|
||||
dest: Option<SlatepackAddress>,
|
||||
out_file_override: Option<String>,
|
||||
sender_index: Option<SlatepackAddressIndex>,
|
||||
) -> Result<(String, String), libwallet::Error>
|
||||
where
|
||||
L: WalletLCProvider<'static, C, K> + 'static,
|
||||
@@ -555,7 +593,8 @@ where
|
||||
K: keychain::Keychain + 'static,
|
||||
{
|
||||
let recipients = dest.into_iter().collect();
|
||||
let message = owner_api.create_slatepack_message(keychain_mask, slate, Some(0), recipients)?;
|
||||
let message =
|
||||
owner_api.create_slatepack_message(keychain_mask, slate, sender_index, recipients)?;
|
||||
let tld = owner_api.get_top_level_directory()?;
|
||||
let slate_dir = format!("{}/{}", tld, "slatepack");
|
||||
let _ = std::fs::create_dir_all(&slate_dir);
|
||||
@@ -572,6 +611,7 @@ fn write_slatepack(message: &str, out_file: &str) -> io::Result<()> {
|
||||
output.sync_all()
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn output_slatepack<L, C, K>(
|
||||
owner_api: &mut Owner<L, C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
@@ -581,6 +621,7 @@ pub fn output_slatepack<L, C, K>(
|
||||
lock: bool,
|
||||
finalizing: bool,
|
||||
show_qr: bool,
|
||||
sender_index: Option<SlatepackAddressIndex>,
|
||||
) -> Result<(), libwallet::Error>
|
||||
where
|
||||
L: WalletLCProvider<'static, C, K> + 'static,
|
||||
@@ -593,6 +634,7 @@ where
|
||||
slate,
|
||||
dest.clone(),
|
||||
out_file_override,
|
||||
sender_index,
|
||||
)?;
|
||||
|
||||
if lock {
|
||||
@@ -604,7 +646,18 @@ where
|
||||
|
||||
println!();
|
||||
if !finalizing {
|
||||
println!("Slatepack data follows. Please provide this output to the other party");
|
||||
let cancel_hint = if lock {
|
||||
format!(
|
||||
" or cancel it manually with `cancel -t {}` command",
|
||||
slate.id
|
||||
)
|
||||
} else {
|
||||
"".to_string()
|
||||
};
|
||||
println!(
|
||||
"Slatepack data follows. Please provide this output to the other party{}.",
|
||||
cancel_hint
|
||||
);
|
||||
} else {
|
||||
println!("Slatepack data follows.");
|
||||
}
|
||||
@@ -725,6 +778,7 @@ where
|
||||
slate,
|
||||
dest.clone(),
|
||||
out_file_override,
|
||||
Some(SlatepackAddressIndex(0)),
|
||||
)?;
|
||||
message.truncate(message.trim_end().len());
|
||||
write_slatepack(&message, &out_file_name)?;
|
||||
@@ -753,28 +807,25 @@ where
|
||||
C: NodeClient + 'static,
|
||||
K: keychain::Keychain + 'static,
|
||||
{
|
||||
let packer = Slatepacker::new(SlatepackerArgs {
|
||||
sender: None,
|
||||
recipients: vec![],
|
||||
dec_key: None,
|
||||
});
|
||||
let mut slatepack = match filename {
|
||||
Some(f) => {
|
||||
let pts = PathToSlatepack::new(f.into(), &packer, true);
|
||||
pts.get_slatepack(false)?
|
||||
}
|
||||
None => match message {
|
||||
Some(message) => packer.deser_slatepack(message.trim_start().as_bytes(), false)?,
|
||||
None => {
|
||||
let msg = "No slate provided via file or direct input";
|
||||
return Err(Error::GenericError(msg.into()));
|
||||
}
|
||||
},
|
||||
let data = match filename {
|
||||
Some(f) => get_slatepack_file_contents(&f.into())?,
|
||||
None => message
|
||||
.ok_or_else(|| {
|
||||
Error::GenericError("No slate provided via file or direct input".into())
|
||||
})?
|
||||
.trim_start()
|
||||
.as_bytes()
|
||||
.to_vec(),
|
||||
};
|
||||
let mut slatepack = libwallet::api_impl::owner::parse_slatepack(&data)?;
|
||||
let was_encrypted = slatepack.is_encrypted();
|
||||
if was_encrypted {
|
||||
let dec_key = owner_api.get_slatepack_secret_key(keychain_mask, 0)?;
|
||||
if let Err(e) = slatepack.try_decrypt_payload(Some(&dec_key)) {
|
||||
if let Err(e) = decrypt_slatepack(
|
||||
&mut slatepack,
|
||||
owner_api.wallet_inst.clone(),
|
||||
keychain_mask,
|
||||
vec![SlatepackAddressIndex(0)],
|
||||
) {
|
||||
// tell the user which account can decrypt it
|
||||
let account = libwallet::api_impl::owner::slatepack_account(
|
||||
owner_api.wallet_inst.clone(),
|
||||
@@ -791,7 +842,7 @@ where
|
||||
});
|
||||
}
|
||||
}
|
||||
let slate = packer.get_slate(&slatepack)?;
|
||||
let slate = slatepack.get_slate()?;
|
||||
Ok((slate, slatepack.sender, was_encrypted))
|
||||
}
|
||||
|
||||
@@ -826,7 +877,6 @@ pub struct ReceiveArgs {
|
||||
pub fn receive<L, C, K>(
|
||||
owner_api: &mut Owner<L, C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
g_args: &GlobalArgs,
|
||||
args: ReceiveArgs,
|
||||
mut tor_config: TorConfig,
|
||||
test_mode: bool,
|
||||
@@ -862,10 +912,7 @@ where
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let km = match keychain_mask.as_ref() {
|
||||
None => None,
|
||||
Some(&m) => Some(m.to_owned()),
|
||||
};
|
||||
let km = keychain_mask.as_ref().map(|&m| m.to_owned());
|
||||
|
||||
if let Some(b) = args.bridge {
|
||||
tor_config.bridge.bridge_line = Some(b);
|
||||
@@ -876,7 +923,7 @@ where
|
||||
owner_api.config_path(),
|
||||
km,
|
||||
|api| {
|
||||
slate = api.receive_tx(&slate, Some(&g_args.account), None)?;
|
||||
slate = api.receive_tx(&slate, None, None)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
@@ -891,6 +938,7 @@ where
|
||||
false,
|
||||
false,
|
||||
args.slatepack_qr,
|
||||
None,
|
||||
)?)
|
||||
};
|
||||
|
||||
@@ -906,8 +954,7 @@ where
|
||||
Ok(s) => {
|
||||
// Update slate state.
|
||||
{
|
||||
let mut w_lock = owner_api.wallet_inst.lock();
|
||||
let w = w_lock.lc_provider()?.wallet_inst()?;
|
||||
wallet_lock!(owner_api.wallet_inst, w);
|
||||
let parent_key_id = w.parent_key_id();
|
||||
match update_tx_slate_state(w, keychain_mask, &parent_key_id, &s) {
|
||||
Ok(_) => {}
|
||||
@@ -929,65 +976,59 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn read_slatepack(args: ReceiveArgs) -> Result<Slatepack, Error> {
|
||||
let data = match args.input_file {
|
||||
Some(f) => get_slatepack_file_contents(&f.into())?,
|
||||
None => match args.input_slatepack_message {
|
||||
Some(message) => message.into_bytes(),
|
||||
None => return Err(Error::ArgumentError("Invalid Slatepack Input".into())),
|
||||
},
|
||||
};
|
||||
Ok(owner::parse_slatepack(&data)?)
|
||||
}
|
||||
|
||||
pub fn unpack<L, C, K>(
|
||||
owner_api: &mut Owner<L, C, K>,
|
||||
wallet_inst: WalletHandle<'static, L, C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
args: ReceiveArgs,
|
||||
mut slatepack: Slatepack,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
L: WalletLCProvider<'static, C, K> + 'static,
|
||||
C: NodeClient + 'static,
|
||||
K: keychain::Keychain + 'static,
|
||||
{
|
||||
let mut slatepack = match args.input_file {
|
||||
Some(f) => {
|
||||
let packer = Slatepacker::new(SlatepackerArgs {
|
||||
sender: None,
|
||||
recipients: vec![],
|
||||
dec_key: None,
|
||||
});
|
||||
PathToSlatepack::new(f.into(), &packer, true).get_slatepack(false)?
|
||||
}
|
||||
None => match args.input_slatepack_message {
|
||||
Some(mes) => owner_api.decode_slatepack_message(keychain_mask, mes, vec![])?,
|
||||
None => {
|
||||
return Err(Error::ArgumentError("Invalid Slatepack Input".into()).into());
|
||||
}
|
||||
},
|
||||
};
|
||||
println!();
|
||||
println!("SLATEPACK CONTENTS");
|
||||
println!("------------------");
|
||||
println!("{}", slatepack);
|
||||
println!("------------------");
|
||||
|
||||
let packer = Slatepacker::new(SlatepackerArgs {
|
||||
sender: None,
|
||||
recipients: vec![],
|
||||
dec_key: None,
|
||||
});
|
||||
|
||||
if slatepack.is_encrypted() {
|
||||
let dec_key = owner_api.get_slatepack_secret_key(keychain_mask, 0)?;
|
||||
match slatepack.try_decrypt_payload(Some(&dec_key)) {
|
||||
Ok(_) => {
|
||||
match decrypt_slatepack(
|
||||
&mut slatepack,
|
||||
wallet_inst,
|
||||
keychain_mask,
|
||||
vec![SlatepackAddressIndex(0)],
|
||||
)
|
||||
.and_then(|_| slatepack.get_slate())
|
||||
{
|
||||
Ok(s) => {
|
||||
println!("Slatepack is encrypted for this wallet");
|
||||
println!();
|
||||
println!("DECRYPTED SLATEPACK");
|
||||
println!("-------------------");
|
||||
println!("{}", slatepack);
|
||||
let slate = packer.get_slate(&slatepack)?;
|
||||
println!();
|
||||
println!("DECRYPTED SLATE");
|
||||
println!("---------------");
|
||||
println!("{}", slate);
|
||||
println!("{}", s);
|
||||
}
|
||||
Err(_) => {
|
||||
println!("Slatepack payload cannot be decrypted by this wallet");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let slate = packer.get_slate(&slatepack)?;
|
||||
let slate = slatepack.get_slate()?;
|
||||
println!("Slatepack is not encrypted");
|
||||
println!();
|
||||
println!("SLATE");
|
||||
@@ -1018,7 +1059,7 @@ where
|
||||
C: NodeClient + 'static,
|
||||
K: keychain::Keychain + 'static,
|
||||
{
|
||||
let (mut slate, _ret_address) = parse_slatepack(
|
||||
let (mut slate, _) = parse_slatepack(
|
||||
owner_api,
|
||||
keychain_mask,
|
||||
args.input_file.clone(),
|
||||
@@ -1050,10 +1091,7 @@ where
|
||||
let is_invoice = slate.state == SlateState::Invoice2;
|
||||
|
||||
if is_invoice {
|
||||
let km = match keychain_mask.as_ref() {
|
||||
None => None,
|
||||
Some(&m) => Some(m.to_owned()),
|
||||
};
|
||||
let km = keychain_mask.as_ref().map(|&m| m.to_owned());
|
||||
controller::foreign_single_use(
|
||||
owner_api.wallet_inst.clone(),
|
||||
owner_api.config_path(),
|
||||
@@ -1092,6 +1130,7 @@ where
|
||||
false,
|
||||
true,
|
||||
args.slatepack_qr,
|
||||
None,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
@@ -1101,11 +1140,11 @@ where
|
||||
pub struct IssueInvoiceArgs {
|
||||
/// Slatepack address
|
||||
pub dest: Option<String>,
|
||||
/// issue invoice tx args
|
||||
/// Issue invoice tx args
|
||||
pub issue_args: IssueInvoiceTxArgs,
|
||||
/// output file override
|
||||
/// Output file override
|
||||
pub outfile: Option<String>,
|
||||
/// show slatepack as QR code
|
||||
/// Show slatepack as QR code
|
||||
pub slatepack_qr: bool,
|
||||
}
|
||||
|
||||
@@ -1126,8 +1165,13 @@ where
|
||||
.transpose()?;
|
||||
let issue_args = args.issue_args.clone();
|
||||
|
||||
let slate = owner_api.issue_invoice_tx(keychain_mask, issue_args)?;
|
||||
let slate = owner_api.issue_invoice_tx(keychain_mask, issue_args.clone())?;
|
||||
|
||||
let sender_index = {
|
||||
wallet_lock!(owner_api.wallet_inst, w);
|
||||
let context = w.get_private_context(keychain_mask, slate.id.as_bytes())?;
|
||||
context.payment_proof_derivation_index
|
||||
};
|
||||
output_slatepack(
|
||||
owner_api,
|
||||
keychain_mask,
|
||||
@@ -1137,6 +1181,7 @@ where
|
||||
false,
|
||||
false,
|
||||
args.slatepack_qr,
|
||||
sender_index,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -1217,7 +1262,6 @@ where
|
||||
selection_strategy_is_use_all: args.selection_strategy == "all",
|
||||
refresh_outputs_from_node: !info_updated,
|
||||
ttl_blocks: args.ttl_blocks,
|
||||
send_args: None,
|
||||
..Default::default()
|
||||
};
|
||||
let result = owner_api.process_invoice_tx(keychain_mask, &slate, init_args);
|
||||
@@ -1251,6 +1295,7 @@ where
|
||||
true,
|
||||
false,
|
||||
args.slatepack_qr,
|
||||
None,
|
||||
)?)
|
||||
};
|
||||
|
||||
@@ -1297,7 +1342,6 @@ pub struct InfoArgs {
|
||||
pub fn info<L, C, K>(
|
||||
owner_api: &mut Owner<L, C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
g_args: &GlobalArgs,
|
||||
args: InfoArgs,
|
||||
dark_scheme: bool,
|
||||
) -> Result<(), Error>
|
||||
@@ -1309,8 +1353,9 @@ where
|
||||
let updater_running = owner_api.updater_running.load(Ordering::Relaxed);
|
||||
let (validated, wallet_info) =
|
||||
owner_api.retrieve_summary_info(keychain_mask, true, args.minimum_confirmations)?;
|
||||
let account = account_label(owner_api)?;
|
||||
display::info(
|
||||
&g_args.account,
|
||||
&account,
|
||||
&wallet_info,
|
||||
validated || updater_running,
|
||||
dark_scheme,
|
||||
@@ -1333,8 +1378,9 @@ where
|
||||
let res = owner_api.node_height(keychain_mask)?;
|
||||
let (validated, outputs) =
|
||||
owner_api.retrieve_outputs(keychain_mask, g_args.show_spent, true, None)?;
|
||||
let account = account_label(owner_api)?;
|
||||
display::outputs(
|
||||
&g_args.account,
|
||||
&account,
|
||||
res.height,
|
||||
validated || updater_running,
|
||||
outputs,
|
||||
@@ -1353,7 +1399,6 @@ pub struct TxsArgs {
|
||||
pub fn txs<L, C, K>(
|
||||
owner_api: &mut Owner<L, C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
g_args: &GlobalArgs,
|
||||
args: TxsArgs,
|
||||
dark_scheme: bool,
|
||||
) -> Result<(), Error>
|
||||
@@ -1367,13 +1412,14 @@ where
|
||||
// Note advanced query args not currently supported by command line client
|
||||
let (validated, txs) =
|
||||
owner_api.retrieve_txs(keychain_mask, true, args.id, args.tx_slate_id, None)?;
|
||||
let include_status = !args.id.is_some() && !args.tx_slate_id.is_some();
|
||||
let include_status = args.id.is_none() && args.tx_slate_id.is_none();
|
||||
// If view count is specified, restrict the TX list to `txs.len() - count`
|
||||
let first_tx = args
|
||||
.count
|
||||
.map_or(0, |c| txs.len().saturating_sub(c as usize));
|
||||
let account = account_label(owner_api)?;
|
||||
display::txs(
|
||||
&g_args.account,
|
||||
&account,
|
||||
res.height,
|
||||
validated || updater_running,
|
||||
&txs[first_tx..],
|
||||
@@ -1399,7 +1445,7 @@ where
|
||||
if id.is_some() {
|
||||
let (_, outputs) = owner_api.retrieve_outputs(keychain_mask, true, false, id)?;
|
||||
display::outputs(
|
||||
&g_args.account,
|
||||
&account,
|
||||
res.height,
|
||||
validated || updater_running,
|
||||
outputs,
|
||||
@@ -1431,7 +1477,7 @@ where
|
||||
C: NodeClient + 'static,
|
||||
K: keychain::Keychain + 'static,
|
||||
{
|
||||
let (slate, _ret_address) = parse_slatepack(
|
||||
let (slate, _) = parse_slatepack(
|
||||
owner_api,
|
||||
keychain_mask,
|
||||
args.input_file,
|
||||
@@ -1563,7 +1609,7 @@ where
|
||||
let tip_height = owner_api.node_height(keychain_mask)?.height;
|
||||
let start_height = match args.backwards_from_tip {
|
||||
Some(b) => tip_height.saturating_sub(b),
|
||||
None => args.start_height.unwrap_or_else(|| 1),
|
||||
None => args.start_height.unwrap_or(1),
|
||||
};
|
||||
warn!("Starting output scan from height {} ...", start_height);
|
||||
let result = owner_api.scan(keychain_mask, Some(start_height), args.delete_unconfirmed);
|
||||
@@ -1579,10 +1625,9 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Payment Proof Address
|
||||
/// Show wallet's slatepack address.
|
||||
pub fn address<L, C, K>(
|
||||
owner_api: &mut Owner<L, C, K>,
|
||||
g_args: &GlobalArgs,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
@@ -1590,16 +1635,30 @@ where
|
||||
C: NodeClient + 'static,
|
||||
K: keychain::Keychain + 'static,
|
||||
{
|
||||
// Just address at derivation index 0 for now
|
||||
let address = owner_api.get_slatepack_address(keychain_mask, 0)?;
|
||||
// Just address at derivation index 0 for now,
|
||||
// cause sender encrypts message for address,
|
||||
// and we don't know its derivation path index.
|
||||
let address = owner_api.get_slatepack_address(keychain_mask, SlatepackAddressIndex(0))?;
|
||||
let account = account_label(owner_api)?;
|
||||
println!();
|
||||
println!("Address for account - {}", g_args.account);
|
||||
println!("Address for account - {}", account);
|
||||
println!("-------------------------------------");
|
||||
println!("{}", address);
|
||||
println!();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get current account label.
|
||||
fn account_label<L, C, K>(owner_api: &mut Owner<L, C, K>) -> Result<String, Error>
|
||||
where
|
||||
L: WalletLCProvider<'static, C, K> + 'static,
|
||||
C: NodeClient + 'static,
|
||||
K: keychain::Keychain + 'static,
|
||||
{
|
||||
wallet_lock!(owner_api.wallet_inst, w);
|
||||
Ok(w.active_account().label)
|
||||
}
|
||||
|
||||
/// Proof Export Args
|
||||
pub struct ProofExportArgs {
|
||||
pub output_file: String,
|
||||
@@ -1765,7 +1824,9 @@ where
|
||||
error!("Proof not valid: {}", e);
|
||||
return Err(Error::from(e));
|
||||
}
|
||||
let my_address = owner_api.get_slatepack_address(keychain_mask, 0)?.pub_key;
|
||||
let my_address = owner_api
|
||||
.get_slatepack_address(keychain_mask, SlatepackAddressIndex(0))?
|
||||
.pub_key;
|
||||
print_proof_verified(
|
||||
file.proof.sender_address == my_address,
|
||||
file.recipient_address.pub_key == my_address,
|
||||
@@ -1982,7 +2043,7 @@ impl ContractSetupArgs {
|
||||
}
|
||||
}
|
||||
|
||||
fn read_slatepack(reader: &mut impl BufRead) -> io::Result<String> {
|
||||
fn read_contract_slatepack(reader: &mut impl BufRead) -> io::Result<String> {
|
||||
let mut message = String::new();
|
||||
let mut periods = 0;
|
||||
// Header, payload and footer each end with a period
|
||||
@@ -2019,7 +2080,7 @@ where
|
||||
{
|
||||
let recipient = slatepack_recipient(args.counterparty_addr.as_deref())?;
|
||||
display::print_status("Paste slatepack:", args.as_json);
|
||||
let slatepack_msg = read_slatepack(&mut io::stdin().lock())
|
||||
let slatepack_msg = read_contract_slatepack(&mut io::stdin().lock())
|
||||
.map_err(|e| libwallet::Error::GenericError(format!("Failed to read from stdin: {}", e)))?;
|
||||
let (slate, sender, _) =
|
||||
parse_slatepack_with_mode(owner_api, keychain_mask, None, Some(slatepack_msg))?;
|
||||
@@ -2155,11 +2216,6 @@ mod contract_tests {
|
||||
use libwallet::{Slatepack, SlatepackArmor};
|
||||
|
||||
global::set_local_chain_type(global::ChainTypes::AutomatedTesting);
|
||||
let packer = Slatepacker::new(SlatepackerArgs {
|
||||
sender: None,
|
||||
recipients: vec![],
|
||||
dec_key: None,
|
||||
});
|
||||
for size in [32, 4096] {
|
||||
let mut slatepack = Slatepack::default();
|
||||
slatepack.payload = vec![1; size];
|
||||
@@ -2173,10 +2229,10 @@ mod contract_tests {
|
||||
format!("{}\n", serde_json::to_string_pretty(&slatepack).unwrap()),
|
||||
] {
|
||||
let mut input = io::Cursor::new(format!("\n \t\n{}next input\n", encoded));
|
||||
let message = read_slatepack(&mut input).unwrap();
|
||||
let message = read_contract_slatepack(&mut input).unwrap();
|
||||
assert_eq!(message, encoded);
|
||||
assert_eq!(
|
||||
packer.deser_slatepack(message.as_bytes(), false).unwrap(),
|
||||
owner::parse_slatepack(message.as_bytes()).unwrap(),
|
||||
slatepack
|
||||
);
|
||||
let mut remaining = String::new();
|
||||
@@ -2186,15 +2242,15 @@ mod contract_tests {
|
||||
}
|
||||
|
||||
let mut input = io::Cursor::new("{invalid}\nnext input\n");
|
||||
assert_eq!(read_slatepack(&mut input).unwrap(), "{invalid}\n");
|
||||
assert_eq!(read_contract_slatepack(&mut input).unwrap(), "{invalid}\n");
|
||||
let incomplete_json = "{\n\"payload\":";
|
||||
assert_eq!(
|
||||
read_slatepack(&mut io::Cursor::new(incomplete_json)).unwrap(),
|
||||
read_contract_slatepack(&mut io::Cursor::new(incomplete_json)).unwrap(),
|
||||
incomplete_json
|
||||
);
|
||||
|
||||
let incomplete = "BEGINSLATEPACK.\nunfinished";
|
||||
let message = read_slatepack(&mut io::Cursor::new(incomplete)).unwrap();
|
||||
let message = read_contract_slatepack(&mut io::Cursor::new(incomplete)).unwrap();
|
||||
assert_eq!(message, incomplete);
|
||||
assert!(SlatepackArmor::decode(message.as_bytes()).is_err());
|
||||
}
|
||||
@@ -2226,34 +2282,17 @@ mod contract_tests {
|
||||
let address = SlatepackAddress::new(&VerifyingKey::from(&key));
|
||||
let slate = Slate::blank(2, false);
|
||||
|
||||
let plain = Slatepacker::new(SlatepackerArgs {
|
||||
sender: None,
|
||||
recipients: vec![],
|
||||
dec_key: None,
|
||||
})
|
||||
.create_slatepack(&slate)
|
||||
.unwrap();
|
||||
let plain = slate.create_slatepack(None, vec![]).unwrap();
|
||||
assert!(!plain.is_encrypted());
|
||||
|
||||
let encrypted = Slatepacker::new(SlatepackerArgs {
|
||||
sender: None,
|
||||
recipients: vec![address],
|
||||
dec_key: None,
|
||||
})
|
||||
.create_slatepack(&slate)
|
||||
.unwrap();
|
||||
let encrypted = slate.create_slatepack(None, vec![address]).unwrap();
|
||||
assert!(encrypted.is_encrypted());
|
||||
|
||||
let mut invalid = serde_json::to_value(&plain).unwrap();
|
||||
invalid["mode"] = serde_json::json!(2);
|
||||
let data = serde_json::to_vec(&invalid).unwrap();
|
||||
let packer = Slatepacker::new(SlatepackerArgs {
|
||||
sender: None,
|
||||
recipients: vec![],
|
||||
dec_key: None,
|
||||
});
|
||||
assert!(matches!(
|
||||
packer.deser_slatepack(&data, false),
|
||||
owner::parse_slatepack(&data),
|
||||
Err(libwallet::Error::SlatepackDeser(message))
|
||||
if message.contains("Unsupported Slatepack mode: 2")
|
||||
));
|
||||
@@ -2416,3 +2455,120 @@ mod contract_tests {
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MwixnetArgs {
|
||||
pub server: OnionV3Address,
|
||||
pub output: MwixnetOutput,
|
||||
pub minimum_confirmations: u64,
|
||||
pub params: MixnetReqCreationParams,
|
||||
}
|
||||
|
||||
pub enum MwixnetOutput {
|
||||
Commitment(Commitment),
|
||||
MinimumAmount(u64),
|
||||
Max,
|
||||
}
|
||||
|
||||
fn confirm_mwixnet_response(
|
||||
response: Result<Option<String>, libwallet::Error>,
|
||||
tx_id: u32,
|
||||
) -> Result<(), Error> {
|
||||
let message = match response {
|
||||
Ok(None) => {
|
||||
println!("MWixnet request accepted (transaction {})", tx_id);
|
||||
return Ok(());
|
||||
}
|
||||
Ok(Some(message)) => format!("MWixnet rejected the request: {}", message),
|
||||
Err(error) => error.to_string(),
|
||||
};
|
||||
// The server may already have accepted the request
|
||||
Err(Error::GenericError(format!(
|
||||
"{}. Output remains locked as transaction {}. The server may already have accepted \
|
||||
the request. To cancel manually, use `cancel -i {}`.",
|
||||
message, tx_id, tx_id
|
||||
)))
|
||||
}
|
||||
|
||||
pub fn mwixnet<L, C, K>(
|
||||
owner_api: &mut Owner<L, C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
args: MwixnetArgs,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
L: WalletLCProvider<'static, C, K> + 'static,
|
||||
C: NodeClient + 'static,
|
||||
K: keychain::Keychain + 'static,
|
||||
{
|
||||
let height = owner_api.node_height(keychain_mask)?.height;
|
||||
let (refreshed, outputs) = owner_api.retrieve_outputs(keychain_mask, false, true, None)?;
|
||||
if !refreshed {
|
||||
return Err(Error::GenericError(
|
||||
"Could not refresh wallet outputs. MWixnet request was not created".to_string(),
|
||||
));
|
||||
}
|
||||
let eligible = |output: &&OutputCommitMapping| {
|
||||
output
|
||||
.output
|
||||
.eligible_to_spend(height, args.minimum_confirmations.max(1))
|
||||
};
|
||||
let output = match &args.output {
|
||||
MwixnetOutput::Commitment(commitment) => outputs
|
||||
.iter()
|
||||
.find(|output| output.commit == *commitment && eligible(output)),
|
||||
MwixnetOutput::MinimumAmount(amount) => outputs
|
||||
.iter()
|
||||
.filter(eligible)
|
||||
.filter(|output| output.output.value >= *amount)
|
||||
.min_by_key(|output| output.output.value),
|
||||
MwixnetOutput::Max => outputs
|
||||
.iter()
|
||||
.filter(eligible)
|
||||
.max_by_key(|output| output.output.value),
|
||||
}
|
||||
.ok_or_else(|| Error::GenericError("No eligible MWixnet output was found".to_string()))?;
|
||||
let commitment = output.commit;
|
||||
println!(
|
||||
"Selected MWixnet output {} with value {}",
|
||||
commitment.to_hex(),
|
||||
core::amount_to_hr_string(output.output.value, false)
|
||||
);
|
||||
|
||||
let creation = owner_api.create_mwixnet_req(keychain_mask, &args.params, &commitment, true)?;
|
||||
match creation.tx_id {
|
||||
None => Err(Error::GenericError(
|
||||
"MWixnet request was created without locking its output".to_string(),
|
||||
)),
|
||||
Some(tx_id) => {
|
||||
let res = owner_api.send_mwixnet_req(&creation.request, args.server);
|
||||
confirm_mwixnet_response(res, tx_id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::confirm_mwixnet_response;
|
||||
|
||||
#[test]
|
||||
fn mwixnet_response_reports_uncertain_transactions_as_locked() {
|
||||
assert!(confirm_mwixnet_response(Ok(None), 3).is_ok());
|
||||
let error =
|
||||
confirm_mwixnet_response(Ok(Some("invalid response".to_string())), 3).unwrap_err();
|
||||
assert!(error
|
||||
.to_string()
|
||||
.contains("remains locked as transaction 3"));
|
||||
assert!(error.to_string().contains("cancel -i 3"));
|
||||
let error = confirm_mwixnet_response(
|
||||
Err(super::libwallet::Error::GenericError(
|
||||
"transport failed".into(),
|
||||
)),
|
||||
4,
|
||||
)
|
||||
.unwrap_err()
|
||||
.to_string();
|
||||
assert!(error.contains("transport failed"));
|
||||
assert!(error.contains("remains locked as transaction 4"));
|
||||
assert!(error.contains("cancel -i 4"));
|
||||
assert!(error.contains("may already have accepted"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ use crate::impls::tor::process as tor_process;
|
||||
use crate::impls::tor::{bridge as tor_bridge, proxy as tor_proxy};
|
||||
use crate::keychain::Keychain;
|
||||
use crate::libwallet::{
|
||||
address, Error, NodeClient, NodeVersionInfo, Slate, SlatepackAddress, WalletInst,
|
||||
WalletLCProvider, GRIN_BLOCK_HEADER_VERSION,
|
||||
address, Error, NodeClient, NodeVersionInfo, Slate, SlatepackAddress, WalletLCProvider,
|
||||
GRIN_BLOCK_HEADER_VERSION,
|
||||
};
|
||||
use crate::util::secp::key::SecretKey;
|
||||
use crate::util::{from_hex, static_secp_instance, to_base64, Mutex};
|
||||
@@ -55,6 +55,7 @@ use grin_wallet_config::config::{
|
||||
};
|
||||
use grin_wallet_impls::tor::arti::{start_tor_service, stop_tor_service};
|
||||
use grin_wallet_impls::tor::process::TorProcess;
|
||||
use grin_wallet_libwallet::slatepack::SlatepackAddressIndex;
|
||||
use http_body_util::{BodyExt, Full};
|
||||
use hyper::body::Incoming;
|
||||
use tokio::sync::mpsc;
|
||||
@@ -102,29 +103,23 @@ fn init_tor_listener(
|
||||
let mut hm_tor_bridge: HashMap<String, String> = HashMap::new();
|
||||
if tor_config.bridge.bridge_line.is_some() {
|
||||
let bridge_config = tor_bridge::TorBridge::try_from(tor_config.bridge)
|
||||
.map_err(|e| Error::TorConfig(format!("{}", e).into()))?;
|
||||
.map_err(|e| Error::TorConfig(format!("{}", e)))?;
|
||||
hm_tor_bridge = bridge_config
|
||||
.to_hashmap()
|
||||
.map_err(|e| Error::TorConfig(format!("{}", e).into()))?;
|
||||
.map_err(|e| Error::TorConfig(format!("{}", e)))?;
|
||||
}
|
||||
|
||||
let mut hm_tor_poxy: HashMap<String, String> = HashMap::new();
|
||||
if tor_config.proxy.transport.is_some() || tor_config.proxy.allowed_port.is_some() {
|
||||
let proxy_config = tor_proxy::TorProxy::try_from(tor_config.proxy)
|
||||
.map_err(|e| Error::TorConfig(format!("{}", e).into()))?;
|
||||
.map_err(|e| Error::TorConfig(format!("{}", e)))?;
|
||||
hm_tor_poxy = proxy_config
|
||||
.to_hashmap()
|
||||
.map_err(|e| Error::TorConfig(format!("{}", e).into()))?;
|
||||
.map_err(|e| Error::TorConfig(format!("{}", e)))?;
|
||||
}
|
||||
|
||||
tor_config::output_tor_listener_config(
|
||||
&tor_dir,
|
||||
addr,
|
||||
&vec![sec_key],
|
||||
hm_tor_bridge,
|
||||
hm_tor_poxy,
|
||||
)
|
||||
.map_err(|e| Error::TorConfig(format!("{:?}", e).into()))?;
|
||||
tor_config::output_tor_listener_config(&tor_dir, addr, &[sec_key], hm_tor_bridge, hm_tor_poxy)
|
||||
.map_err(|e| Error::TorConfig(format!("{:?}", e)))?;
|
||||
// Start TOR process
|
||||
process
|
||||
.torrc_path(&format!("{}/torrc", tor_dir))
|
||||
@@ -136,27 +131,10 @@ fn init_tor_listener(
|
||||
Ok(process)
|
||||
}
|
||||
|
||||
/// Instantiate wallet Owner API for a single-use (command line) call
|
||||
/// Return a function containing a loaded API context to call
|
||||
pub fn owner_single_use<L, F, C, K>(
|
||||
wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K>>>>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
config_path: PathBuf,
|
||||
f: F,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
L: WalletLCProvider<'static, C, K> + 'static,
|
||||
F: FnOnce(&mut Owner<L, C, K>, Option<&SecretKey>) -> Result<(), Error>,
|
||||
C: NodeClient + 'static,
|
||||
K: Keychain + 'static,
|
||||
{
|
||||
f(&mut Owner::new(wallet, None, config_path), keychain_mask)
|
||||
}
|
||||
|
||||
/// Instantiate wallet Foreign API for a single-use (command line) call
|
||||
/// Return a function containing a loaded API context to call
|
||||
pub fn foreign_single_use<'a, L, F, C, K>(
|
||||
wallet: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
|
||||
wallet: grin_wallet_libwallet::WalletHandle<'a, L, C, K>,
|
||||
config_path: PathBuf,
|
||||
keychain_mask: Option<SecretKey>,
|
||||
f: F,
|
||||
@@ -196,9 +174,9 @@ where
|
||||
K: Keychain + 'static,
|
||||
{
|
||||
let mut router = Router::new();
|
||||
if api_secret.is_some() {
|
||||
if let Some(api_secret) = api_secret {
|
||||
let api_basic_auth =
|
||||
"Basic ".to_string() + &to_base64(&("grin:".to_string() + &api_secret.unwrap()));
|
||||
"Basic ".to_string() + &to_base64(&("grin:".to_string() + &api_secret));
|
||||
let basic_auth_middleware = Arc::new(BasicAuthMiddleware::new(
|
||||
api_basic_auth,
|
||||
&GRIN_OWNER_BASIC_REALM,
|
||||
@@ -250,8 +228,9 @@ where
|
||||
|
||||
/// Listener version, providing same API but listening for requests on a
|
||||
/// port and wrapping the calls
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn foreign_listener<L, C, K>(
|
||||
wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K> + 'static>>>,
|
||||
wallet: grin_wallet_libwallet::WalletHandle<'static, L, C, K>,
|
||||
config_path: PathBuf,
|
||||
bridge: Option<String>,
|
||||
use_tor: Option<bool>,
|
||||
@@ -277,10 +256,11 @@ where
|
||||
let mut w_lock = wallet.lock();
|
||||
let lc = w_lock.lc_provider()?;
|
||||
let w_inst = lc.wallet_inst()?;
|
||||
let k = w_inst.keychain((&mask).as_ref())?;
|
||||
let k = w_inst.keychain(mask.as_ref())?;
|
||||
let parent_key_id = w_inst.parent_key_id();
|
||||
let sec_key = address::address_from_derivation_path(&k, &parent_key_id, 0)
|
||||
.map_err(|e| Error::TorConfig(format!("{:?}", e)))?;
|
||||
let sec_key =
|
||||
address::address_from_derivation_path(&k, &parent_key_id, SlatepackAddressIndex(0))
|
||||
.map_err(|e| Error::TorConfig(format!("{:?}", e)))?;
|
||||
let tor_dir = format!("{}/tor/listener", lc.get_top_level_directory()?);
|
||||
let onion_address = OnionV3Address::from_private(&sec_key.0)
|
||||
.map_err(|e| Error::TorConfig(format!("{:?}", e)))?;
|
||||
@@ -419,7 +399,7 @@ where
|
||||
K: Keychain + 'static,
|
||||
{
|
||||
/// Wallet instance
|
||||
pub wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K> + 'static>>>,
|
||||
pub wallet: grin_wallet_libwallet::WalletHandle<'static, L, C, K>,
|
||||
|
||||
/// Handle to Owner API
|
||||
owner_api: Arc<Owner<L, C, K>>,
|
||||
@@ -481,7 +461,7 @@ impl OwnerV3Helpers {
|
||||
val: &serde_json::Value,
|
||||
new_key: Option<SecretKey>,
|
||||
) {
|
||||
if let Some(_) = val["result"]["Ok"].as_str() {
|
||||
if val["result"]["Ok"].as_str().is_some() {
|
||||
let mut share_key_ref = key.lock();
|
||||
*share_key_ref = new_key;
|
||||
}
|
||||
@@ -522,7 +502,7 @@ impl OwnerV3Helpers {
|
||||
.as_json_value()
|
||||
})?;
|
||||
let id = enc_req.id.clone();
|
||||
let res = enc_req.decrypt(&shared_key).map_err(|e| {
|
||||
let res = enc_req.decrypt(shared_key).map_err(|e| {
|
||||
EncryptionErrorResponse::new(1, -32002, &format!("Decryption error: {}", e))
|
||||
.as_json_value()
|
||||
})?;
|
||||
@@ -537,7 +517,7 @@ impl OwnerV3Helpers {
|
||||
) -> Result<serde_json::Value, serde_json::Value> {
|
||||
let share_key_ref = key.lock();
|
||||
let shared_key = share_key_ref.as_ref().unwrap();
|
||||
let enc_res = EncryptedResponse::from_json(id, res, &shared_key).map_err(|e| {
|
||||
let enc_res = EncryptedResponse::from_json(id, res, shared_key).map_err(|e| {
|
||||
EncryptionErrorResponse::new(1, -32003, &format!("EncryptionError: {}", e))
|
||||
.as_json_value()
|
||||
})?;
|
||||
@@ -595,10 +575,7 @@ impl OwnerV3Helpers {
|
||||
retval
|
||||
} else if val["result"]["Err"].is_string() {
|
||||
let parsed = serde_json::from_value::<String>(val["result"]["Err"].clone());
|
||||
match parsed {
|
||||
Ok(p) => Some(p),
|
||||
Err(_) => None,
|
||||
}
|
||||
parsed.ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@@ -756,7 +733,7 @@ where
|
||||
K: Keychain + 'static,
|
||||
{
|
||||
/// Wallet instance.
|
||||
pub wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K> + 'static>>>,
|
||||
pub wallet: grin_wallet_libwallet::WalletHandle<'static, L, C, K>,
|
||||
/// Wallet configuration path.
|
||||
pub config_path: ConfigPath,
|
||||
/// Keychain mask
|
||||
@@ -773,7 +750,7 @@ where
|
||||
{
|
||||
/// Create a new foreign API handler for GET methods
|
||||
pub fn new(
|
||||
wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K> + 'static>>>,
|
||||
wallet: grin_wallet_libwallet::WalletHandle<'static, L, C, K>,
|
||||
config_path: ConfigPath,
|
||||
keychain_mask: Arc<Mutex<Option<SecretKey>>>,
|
||||
test_mode: bool,
|
||||
@@ -804,7 +781,7 @@ where
|
||||
async fn handle_post_request(
|
||||
req: Request<Incoming>,
|
||||
mask: Option<SecretKey>,
|
||||
wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K> + 'static>>>,
|
||||
wallet: grin_wallet_libwallet::WalletHandle<'static, L, C, K>,
|
||||
config_path: ConfigPath,
|
||||
test_mode: bool,
|
||||
) -> Result<Response<ApiBody>, Error> {
|
||||
|
||||
+163
-139
@@ -12,17 +12,20 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::core::core::amount_to_hr_string;
|
||||
use crate::core::core::FeeFields;
|
||||
use crate::core::core::{self, amount_to_hr_string, Inputs, OutputFeatures};
|
||||
use crate::core::core::{self, Inputs, OutputFeatures};
|
||||
use crate::core::global;
|
||||
use crate::libwallet::contract::types::{ContractView, OwnCommitmentStatus};
|
||||
use crate::libwallet::{
|
||||
AcctPathMapping, Error, OutputCommitMapping, OutputStatus, Slate, SlatepackAddress, TxLogEntry,
|
||||
ViewWallet, WalletInfo,
|
||||
address, AcctPathMapping, Error, OutputCommitMapping, OutputStatus, Slate, SlatepackAddress,
|
||||
TxLogEntry, TxLogEntryType, ViewWallet, WalletInfo,
|
||||
};
|
||||
use crate::util::secp::pedersen::Commitment;
|
||||
use crate::util::ToHex;
|
||||
use grin_wallet_libwallet::slatepack::SlatepackAddressIndex;
|
||||
use prettytable;
|
||||
use prettytable::format::{FormatBuilder, LinePosition, LineSeparator};
|
||||
use std::io::prelude::Write;
|
||||
use term;
|
||||
|
||||
@@ -53,9 +56,9 @@ pub fn outputs(
|
||||
return Ok(());
|
||||
}
|
||||
let mut t = term::stdout().unwrap();
|
||||
t.fg(term::color::MAGENTA).unwrap();
|
||||
writeln!(t, "{}", title).unwrap();
|
||||
t.reset().unwrap();
|
||||
let _ = t.fg(term::color::MAGENTA);
|
||||
writeln!(t, "{}", title)?;
|
||||
let _ = t.reset();
|
||||
|
||||
let mut table = table!();
|
||||
|
||||
@@ -72,7 +75,7 @@ pub fn outputs(
|
||||
]);
|
||||
|
||||
for m in outputs {
|
||||
let commit = format!("{}", m.commit.as_ref().to_hex());
|
||||
let commit = m.commit.as_ref().to_hex();
|
||||
let index = match m.output.mmr_index {
|
||||
None => "None".to_owned(),
|
||||
Some(t) => t.to_string(),
|
||||
@@ -88,7 +91,7 @@ pub fn outputs(
|
||||
};
|
||||
|
||||
let num_confirmations = format!("{}", m.output.num_confirmations(cur_height));
|
||||
let value = format!("{}", core::amount_to_hr_string(m.output.value, false));
|
||||
let value = amount_to_hr_string(m.output.value, false);
|
||||
let tx = match m.output.tx_log_entry {
|
||||
None => "".to_owned(),
|
||||
Some(t) => t.to_string(),
|
||||
@@ -128,7 +131,7 @@ pub fn outputs(
|
||||
if !validated {
|
||||
println!(
|
||||
"\nWARNING: Wallet failed to verify data. \
|
||||
The above is from local cache and possibly invalid! \
|
||||
The above is from local cache and possibly invalid! \
|
||||
(is your `grin server` offline or broken?)"
|
||||
);
|
||||
}
|
||||
@@ -154,73 +157,93 @@ pub fn txs(
|
||||
return Ok(());
|
||||
}
|
||||
let mut t = term::stdout().unwrap();
|
||||
t.fg(term::color::MAGENTA).unwrap();
|
||||
writeln!(t, "{}", title).unwrap();
|
||||
t.reset().unwrap();
|
||||
let _ = t.fg(term::color::MAGENTA);
|
||||
writeln!(t, "{}", title)?;
|
||||
let _ = t.reset();
|
||||
|
||||
let mut table = table!();
|
||||
|
||||
table.set_titles(row![
|
||||
bMG->"Id",
|
||||
bMG->"Type",
|
||||
bMG->"State",
|
||||
bMG->"Shared Transaction Id",
|
||||
bMG->"Creation Time",
|
||||
bMG->"TTL Cutoff Height",
|
||||
bMG->"Confirmed?",
|
||||
bMG->"Confirmation Time",
|
||||
bMG->"Num. \nInputs",
|
||||
bMG->"Num. \nOutputs",
|
||||
bMG->"Amount \nCredited",
|
||||
bMG->"Amount \nDebited",
|
||||
bMG->"Fee",
|
||||
bMG->"Net \nDifference",
|
||||
bMG->"Payment \nProof",
|
||||
bMG->"Kernel",
|
||||
bMG->"Tx \nData",
|
||||
]);
|
||||
table.set_titles(if dark_background_color_scheme {
|
||||
row![
|
||||
bMG->"Id",
|
||||
bMG->"Type (State)",
|
||||
bMG->"Shared Transaction Id \nKernel",
|
||||
bMG->"Creation Time \nConfirmation Time",
|
||||
bMG->"Payment Proof \nTTL Cutoff Height",
|
||||
bMG->"Inputs \nOutputs",
|
||||
bMG->"Credited \nDebited",
|
||||
bMG->"Fee \nDifference",
|
||||
]
|
||||
} else {
|
||||
row![
|
||||
bFD ->"Id",
|
||||
bFD->"Type (State)",
|
||||
bFD->"Shared Transaction Id \nKernel",
|
||||
bFD->"Creation Time \nConfirmation Time",
|
||||
bFD->"Payment Proof \nTTL Cutoff Height",
|
||||
bFD->"Inputs \nOutputs",
|
||||
bFD->"Credited \nDebited",
|
||||
bFD->"Fee \nDifference",
|
||||
]
|
||||
});
|
||||
|
||||
for t in txs {
|
||||
for (i, t) in txs.iter().enumerate() {
|
||||
let id = format!("{}", t.id);
|
||||
let slate_id = match t.tx_slate_id {
|
||||
Some(m) => format!("{}", m),
|
||||
None => "None".to_owned(),
|
||||
};
|
||||
let slate_state = match t.tx_slate_state.as_ref() {
|
||||
Some(m) => format!("{}", m),
|
||||
None => "None".to_owned(),
|
||||
|
||||
let entry_type = (match t.tx_type {
|
||||
TxLogEntryType::ConfirmedCoinbase => "Coinbase",
|
||||
TxLogEntryType::TxReceived => "Received Tx",
|
||||
TxLogEntryType::TxSent => "Sent Tx",
|
||||
TxLogEntryType::TxReceivedCancelled => "Received Tx",
|
||||
TxLogEntryType::TxSentCancelled => "Sent Tx",
|
||||
TxLogEntryType::TxReverted => "Received Tx",
|
||||
TxLogEntryType::TxSelfSpend | TxLogEntryType::TxSelfSpendCancelled => "Self Spend",
|
||||
})
|
||||
.to_string();
|
||||
let entry_type_state = match t.tx_slate_state.as_ref() {
|
||||
None => entry_type.to_string(),
|
||||
Some(s) => format!("{} ({})", entry_type, s),
|
||||
};
|
||||
let entry_type = format!("{}", t.tx_type);
|
||||
let entry_type_desc = (match t.tx_type {
|
||||
TxLogEntryType::ConfirmedCoinbase => "Confirmed",
|
||||
TxLogEntryType::TxReceived => "",
|
||||
TxLogEntryType::TxSent => "",
|
||||
TxLogEntryType::TxReceivedCancelled => "Cancelled",
|
||||
TxLogEntryType::TxSentCancelled => "Cancelled",
|
||||
TxLogEntryType::TxReverted => "Reverted",
|
||||
TxLogEntryType::TxSelfSpend => "",
|
||||
TxLogEntryType::TxSelfSpendCancelled => "Cancelled",
|
||||
})
|
||||
.to_string();
|
||||
let creation_ts = format!("{}", t.creation_ts.format("%Y-%m-%d %H:%M:%S"));
|
||||
let ttl_cutoff_height = match t.ttl_cutoff_height {
|
||||
Some(b) => format!("{}", b),
|
||||
Some(b) => b.to_string(),
|
||||
None => "None".to_owned(),
|
||||
};
|
||||
let confirmation_ts = match t.confirmation_ts {
|
||||
Some(m) => format!("{}", m.format("%Y-%m-%d %H:%M:%S")),
|
||||
None => "None".to_owned(),
|
||||
};
|
||||
let confirmed = format!("{}", t.confirmed);
|
||||
let num_inputs = format!("{}", t.num_inputs);
|
||||
let num_outputs = format!("{}", t.num_outputs);
|
||||
let amount_debited_str = core::amount_to_hr_string(t.amount_debited, true);
|
||||
let amount_credited_str = core::amount_to_hr_string(t.amount_credited, true);
|
||||
let amount_debited_str = amount_to_hr_string(t.amount_debited, true);
|
||||
let amount_credited_str = amount_to_hr_string(t.amount_credited, true);
|
||||
let fee = match t.fee {
|
||||
Some(f) => format!("{}", core::amount_to_hr_string(f.fee(), true)),
|
||||
Some(f) => amount_to_hr_string(f.fee(), true),
|
||||
None => "None".to_owned(),
|
||||
};
|
||||
let net_diff = if t.amount_credited >= t.amount_debited {
|
||||
core::amount_to_hr_string(t.amount_credited - t.amount_debited, true)
|
||||
amount_to_hr_string(t.amount_credited - t.amount_debited, true)
|
||||
} else {
|
||||
format!(
|
||||
"-{}",
|
||||
core::amount_to_hr_string(t.amount_debited - t.amount_credited, true)
|
||||
amount_to_hr_string(t.amount_debited - t.amount_credited, true)
|
||||
)
|
||||
};
|
||||
let tx_data = match t.stored_tx {
|
||||
Some(_) => "Yes".to_owned(),
|
||||
None => "None".to_owned(),
|
||||
};
|
||||
let kernel_excess = match t.kernel_excess {
|
||||
Some(e) => {
|
||||
let excess: &[u8] = e.0.as_ref();
|
||||
@@ -235,96 +258,76 @@ pub fn txs(
|
||||
if dark_background_color_scheme {
|
||||
table.add_row(row![
|
||||
bFC->id,
|
||||
bFC->entry_type,
|
||||
bFC->slate_state,
|
||||
bFC->entry_type_state,
|
||||
bFC->slate_id,
|
||||
bFB->creation_ts,
|
||||
bFB->ttl_cutoff_height,
|
||||
bFC->confirmed,
|
||||
bFB->confirmation_ts,
|
||||
bFC->payment_proof,
|
||||
bFC->num_inputs,
|
||||
bFC->num_outputs,
|
||||
bFG->amount_credited_str,
|
||||
bFR->amount_debited_str,
|
||||
bFR->fee,
|
||||
bFY->net_diff,
|
||||
bfG->payment_proof,
|
||||
]);
|
||||
table.add_row(row![
|
||||
bFD->"",
|
||||
bFC->entry_type_desc,
|
||||
bFB->kernel_excess,
|
||||
bFb->tx_data,
|
||||
bFB->confirmation_ts,
|
||||
bFB->ttl_cutoff_height,
|
||||
bFC->num_outputs,
|
||||
bFR->amount_debited_str,
|
||||
bFY->net_diff,
|
||||
]);
|
||||
} else {
|
||||
if t.confirmed {
|
||||
table.add_row(row![
|
||||
bFD->id,
|
||||
bFb->entry_type,
|
||||
bFD->slate_id,
|
||||
bFB->creation_ts,
|
||||
bFg->confirmed,
|
||||
bFB->confirmation_ts,
|
||||
bFD->num_inputs,
|
||||
bFD->num_outputs,
|
||||
bFG->amount_credited_str,
|
||||
bFD->amount_debited_str,
|
||||
bFD->fee,
|
||||
bFG->net_diff,
|
||||
bfG->payment_proof,
|
||||
bFB->kernel_excess,
|
||||
bFB->tx_data,
|
||||
]);
|
||||
} else {
|
||||
table.add_row(row![
|
||||
bFD->id,
|
||||
bFb->entry_type,
|
||||
bFD->slate_id,
|
||||
bFB->creation_ts,
|
||||
bFR->confirmed,
|
||||
bFB->confirmation_ts,
|
||||
bFD->num_inputs,
|
||||
bFD->num_outputs,
|
||||
bFG->amount_credited_str,
|
||||
bFD->amount_debited_str,
|
||||
bFD->fee,
|
||||
bFG->net_diff,
|
||||
bfG->payment_proof,
|
||||
bFB->kernel_excess,
|
||||
bFB->tx_data,
|
||||
]);
|
||||
}
|
||||
table.add_row(row![
|
||||
bFD->id,
|
||||
bFb->entry_type_state,
|
||||
bFD->slate_id,
|
||||
bFB->creation_ts,
|
||||
bFD->payment_proof,
|
||||
bFD->num_inputs,
|
||||
bFG->amount_credited_str,
|
||||
bFR->fee,
|
||||
]);
|
||||
table.add_row(row![
|
||||
bFD->"",
|
||||
bFb->entry_type_desc,
|
||||
bFB->kernel_excess,
|
||||
bFB->confirmation_ts,
|
||||
bFB->ttl_cutoff_height,
|
||||
bFD->num_outputs,
|
||||
bFR->amount_debited_str,
|
||||
bFG->net_diff,
|
||||
]);
|
||||
}
|
||||
if i != txs.len() - 1 {
|
||||
table.add_empty_row();
|
||||
}
|
||||
}
|
||||
|
||||
table.set_format(*prettytable::format::consts::FORMAT_NO_COLSEP);
|
||||
table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
|
||||
table.printstd();
|
||||
println!();
|
||||
|
||||
if !validated && include_status {
|
||||
println!(
|
||||
"\nWARNING: Wallet failed to verify data. \
|
||||
The above is from local cache and possibly invalid! \
|
||||
The above is from local cache and possibly invalid! \
|
||||
(is your `grin server` offline or broken?)"
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn view_wallet_balance(w: ViewWallet, cur_height: u64, dark_background_color_scheme: bool) {
|
||||
pub fn view_wallet_balance(w: ViewWallet, cur_height: u64, _dark_background_color_scheme: bool) {
|
||||
println!(
|
||||
"\n____ View Wallet Summary Info - Block Height: {} ____\n Rewind Hash - {}\n",
|
||||
cur_height, w.rewind_hash
|
||||
);
|
||||
let mut table = table!();
|
||||
|
||||
if dark_background_color_scheme {
|
||||
table.add_row(row![
|
||||
bFG->"Total Balance",
|
||||
FG->amount_to_hr_string(w.total_balance, false)
|
||||
]);
|
||||
} else {
|
||||
table.add_row(row![
|
||||
bFG->"Total Balance",
|
||||
FG->amount_to_hr_string(w.total_balance, false)
|
||||
]);
|
||||
};
|
||||
table.add_row(row![
|
||||
bFG->"Total Balance",
|
||||
FG->amount_to_hr_string(w.total_balance, false)
|
||||
]);
|
||||
table.set_format(*prettytable::format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR);
|
||||
table.printstd();
|
||||
println!();
|
||||
@@ -344,9 +347,9 @@ pub fn view_wallet_output(
|
||||
}
|
||||
|
||||
let mut t = term::stdout().unwrap();
|
||||
t.fg(term::color::MAGENTA).unwrap();
|
||||
writeln!(t, "{}", title).unwrap();
|
||||
t.reset().unwrap();
|
||||
let _ = t.fg(term::color::MAGENTA);
|
||||
writeln!(t, "{}", title)?;
|
||||
let _ = t.reset();
|
||||
|
||||
let mut table = table!();
|
||||
|
||||
@@ -361,13 +364,13 @@ pub fn view_wallet_output(
|
||||
]);
|
||||
|
||||
for m in view_wallet.output_result {
|
||||
let commit = format!("{}", m.commit);
|
||||
let commit = m.commit.as_str();
|
||||
let index = m.mmr_index;
|
||||
let height = format!("{}", m.height);
|
||||
let lock_height = format!("{}", m.lock_height);
|
||||
let is_coinbase = format!("{}", m.is_coinbase);
|
||||
let num_confirmations = format!("{}", m.num_confirmations(cur_height));
|
||||
let value = format!("{}", core::amount_to_hr_string(m.value, false));
|
||||
let value = amount_to_hr_string(m.value, false);
|
||||
|
||||
if dark_background_color_scheme {
|
||||
table.add_row(row![
|
||||
@@ -419,11 +422,11 @@ pub fn info(
|
||||
]);
|
||||
if wallet_info.amount_reverted > 0 {
|
||||
table.add_row(row![
|
||||
Fr->format!("Reverted"),
|
||||
Fr->"Reverted",
|
||||
Fr->amount_to_hr_string(wallet_info.amount_reverted, false)
|
||||
]);
|
||||
}
|
||||
// Only dispay "Immature Coinbase" if we have related outputs in the wallet.
|
||||
// Only display "Immature Coinbase" if we have related outputs in the wallet.
|
||||
// This row just introduces confusion if the wallet does not receive coinbase rewards.
|
||||
if wallet_info.amount_immature > 0 {
|
||||
table.add_row(row![
|
||||
@@ -436,7 +439,7 @@ pub fn info(
|
||||
FY->amount_to_hr_string(wallet_info.amount_awaiting_confirmation, false)
|
||||
]);
|
||||
table.add_row(row![
|
||||
bFB->format!("Awaiting Finalization"),
|
||||
bFB->"Awaiting Finalization",
|
||||
FB->amount_to_hr_string(wallet_info.amount_awaiting_finalization, false)
|
||||
]);
|
||||
table.add_row(row![
|
||||
@@ -458,11 +461,11 @@ pub fn info(
|
||||
]);
|
||||
if wallet_info.amount_reverted > 0 {
|
||||
table.add_row(row![
|
||||
Fr->format!("Reverted"),
|
||||
Fr->"Reverted",
|
||||
Fr->amount_to_hr_string(wallet_info.amount_reverted, false)
|
||||
]);
|
||||
}
|
||||
// Only dispay "Immature Coinbase" if we have related outputs in the wallet.
|
||||
// Only display "Immature Coinbase" if we have related outputs in the wallet.
|
||||
// This row just introduces confusion if the wallet does not receive coinbase rewards.
|
||||
if wallet_info.amount_immature > 0 {
|
||||
table.add_row(row![
|
||||
@@ -493,7 +496,7 @@ pub fn info(
|
||||
if !validated {
|
||||
println!(
|
||||
"\nWARNING: Wallet failed to verify data against a live chain. \
|
||||
The above is from local cache and only valid up to the given height! \
|
||||
The above is from local cache and only valid up to the given height! \
|
||||
(is your `grin server` offline or broken?)"
|
||||
);
|
||||
}
|
||||
@@ -543,48 +546,71 @@ pub fn estimate(
|
||||
|
||||
/// Display list of wallet accounts in a pretty way
|
||||
pub fn accounts(acct_mappings: Vec<AcctPathMapping>) {
|
||||
println!("\n____ Wallet Accounts ____\n",);
|
||||
println!("\n____ Wallet Accounts ____\n");
|
||||
let mut table = table!();
|
||||
|
||||
table.set_titles(row![
|
||||
mMG->"Name",
|
||||
bMG->"Parent BIP-32 Derivation Path",
|
||||
bMG->"Parent Output Key",
|
||||
bMG->"Slatepack Address (Index 0)",
|
||||
bMG->"Spendable balance",
|
||||
]);
|
||||
for m in acct_mappings {
|
||||
let slatepack_path =
|
||||
address::address_derivation_path(&m.path, SlatepackAddressIndex(0)).to_bip_32_string();
|
||||
let spendable = if let Some(info) = m.info {
|
||||
amount_to_hr_string(info.amount_currently_spendable, true)
|
||||
} else {
|
||||
"-".to_string()
|
||||
};
|
||||
table.add_row(row![
|
||||
bFC->m.label,
|
||||
bGC->m.path.to_bip_32_string(),
|
||||
bGC->slatepack_path,
|
||||
bGC->spendable,
|
||||
]);
|
||||
}
|
||||
table.set_format(*prettytable::format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR);
|
||||
table.set_format(
|
||||
FormatBuilder::new()
|
||||
.column_separator('|')
|
||||
.separators(
|
||||
&[LinePosition::Top, LinePosition::Title],
|
||||
LineSeparator::new('-', '+', '+', '+'),
|
||||
)
|
||||
.padding(1, 1)
|
||||
.build(),
|
||||
);
|
||||
let width = table.to_string().find('\n').unwrap_or(0);
|
||||
println!("{:^1$}", "BIP-32 Derivation Path", width);
|
||||
table.printstd();
|
||||
println!("Balances use local data and may be out of date.");
|
||||
println!();
|
||||
}
|
||||
|
||||
/// Display individual Payment Proof
|
||||
pub fn payment_proof(tx: &TxLogEntry) -> Result<(), Error> {
|
||||
let title = format!("Payment Proof - Transaction '{}'", tx.id,);
|
||||
let title = format!("Payment Proof - Transaction '{}'", tx.id);
|
||||
println!();
|
||||
if term::stdout().is_none() {
|
||||
println!("Could not open terminal");
|
||||
return Ok(());
|
||||
}
|
||||
let mut t = term::stdout().unwrap();
|
||||
t.fg(term::color::MAGENTA).unwrap();
|
||||
writeln!(t, "{}", title).unwrap();
|
||||
t.reset().unwrap();
|
||||
let _ = t.fg(term::color::MAGENTA);
|
||||
writeln!(t, "{}", title)?;
|
||||
let _ = t.reset();
|
||||
|
||||
let pp = match &tx.payment_proof {
|
||||
None => {
|
||||
writeln!(t, "None").unwrap();
|
||||
t.reset().unwrap();
|
||||
writeln!(t, "None")?;
|
||||
let _ = t.reset();
|
||||
return Ok(());
|
||||
}
|
||||
Some(p) => p.clone(),
|
||||
};
|
||||
|
||||
t.fg(term::color::WHITE).unwrap();
|
||||
writeln!(t).unwrap();
|
||||
let _ = t.fg(term::color::WHITE);
|
||||
writeln!(t)?;
|
||||
let receiver_signature = match pp.receiver_signature {
|
||||
Some(s) => {
|
||||
let sig_bytes = s.to_bytes();
|
||||
@@ -615,20 +641,18 @@ pub fn payment_proof(tx: &TxLogEntry) -> Result<(), Error> {
|
||||
t,
|
||||
"Receiver Address: {}",
|
||||
SlatepackAddress::new(&pp.receiver_address)
|
||||
)
|
||||
.unwrap();
|
||||
writeln!(t, "Receiver Signature: {}", receiver_signature).unwrap();
|
||||
writeln!(t, "Amount: {}", amount).unwrap();
|
||||
writeln!(t, "Kernel Excess: {}", kernel_excess).unwrap();
|
||||
)?;
|
||||
writeln!(t, "Receiver Signature: {}", receiver_signature)?;
|
||||
writeln!(t, "Amount: {}", amount)?;
|
||||
writeln!(t, "Kernel Excess: {}", kernel_excess)?;
|
||||
writeln!(
|
||||
t,
|
||||
"Sender Address: {}",
|
||||
SlatepackAddress::new(&pp.sender_address)
|
||||
)
|
||||
.unwrap();
|
||||
writeln!(t, "Sender Signature: {}", sender_signature).unwrap();
|
||||
)?;
|
||||
writeln!(t, "Sender Signature: {}", sender_signature)?;
|
||||
|
||||
t.reset().unwrap();
|
||||
let _ = t.reset();
|
||||
|
||||
println!();
|
||||
|
||||
|
||||
+185
-189
@@ -19,7 +19,6 @@ extern crate grin_wallet_impls as impls;
|
||||
|
||||
use grin_core as core;
|
||||
use grin_keychain as keychain;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use self::core::global;
|
||||
use self::keychain::{ExtKeychain, Keychain};
|
||||
@@ -49,10 +48,11 @@ fn accounts_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api1
|
||||
);
|
||||
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
@@ -62,10 +62,11 @@ fn accounts_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api2
|
||||
);
|
||||
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -79,183 +80,196 @@ fn accounts_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
let cm = global::coinbase_maturity(); // assume all testing precedes soft fork height
|
||||
|
||||
// test default accounts exist
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let accounts = api.accounts(m)?;
|
||||
assert_eq!(accounts[0].label, "default");
|
||||
assert_eq!(accounts[0].path, ExtKeychain::derive_key_id(2, 0, 0, 0, 0));
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
{
|
||||
let accounts = api1.accounts_info(mask1, 2)?;
|
||||
assert_eq!(accounts[0].label, "default");
|
||||
assert_eq!(accounts[0].path, ExtKeychain::derive_key_id(2, 0, 0, 0, 0));
|
||||
}
|
||||
|
||||
// add some accounts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let new_path = api.create_account_path(m, "account1").unwrap();
|
||||
assert_eq!(new_path, ExtKeychain::derive_key_id(2, 1, 0, 0, 0));
|
||||
let new_path = api.create_account_path(m, "account2").unwrap();
|
||||
assert_eq!(new_path, ExtKeychain::derive_key_id(2, 2, 0, 0, 0));
|
||||
let new_path = api.create_account_path(m, "account3").unwrap();
|
||||
assert_eq!(new_path, ExtKeychain::derive_key_id(2, 3, 0, 0, 0));
|
||||
// trying to add same label again should fail
|
||||
let res = api.create_account_path(m, "account1");
|
||||
assert!(res.is_err());
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
{
|
||||
let new_path = api1.create_account_path(mask1, "account1").unwrap();
|
||||
assert_eq!(new_path, ExtKeychain::derive_key_id(2, 1, 0, 0, 0));
|
||||
let new_path = api1.create_account_path(mask1, "account2").unwrap();
|
||||
assert_eq!(new_path, ExtKeychain::derive_key_id(2, 2, 0, 0, 0));
|
||||
let new_path = api1.create_account_path(mask1, "account3").unwrap();
|
||||
assert_eq!(new_path, ExtKeychain::derive_key_id(2, 3, 0, 0, 0));
|
||||
// trying to add same label again should fail
|
||||
let res = api1.create_account_path(mask1, "account1");
|
||||
assert!(res.is_err());
|
||||
// Check missing flags and temporary account changes
|
||||
for saved in [None, Some(true)] {
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
let mut account = w.get_acct_path("default".to_owned())?.unwrap();
|
||||
account.current = saved;
|
||||
let mut batch = w.batch(mask1)?;
|
||||
batch.save_acct_path(account)?;
|
||||
batch.commit()?;
|
||||
}
|
||||
for active in ["default", "account1"] {
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_account_by_name(active)?;
|
||||
}
|
||||
for accounts in [api1.accounts(mask1)?, api1.accounts_info(mask1, 2)?] {
|
||||
assert_eq!(accounts.len(), 4);
|
||||
assert_eq!(accounts[0].label, active);
|
||||
for account in accounts {
|
||||
assert_eq!(account.current, Some(account.label == active));
|
||||
}
|
||||
}
|
||||
// Keep the saved selection unchanged
|
||||
wallet_inst!(wallet1, w);
|
||||
for account in w.acct_path_iter()? {
|
||||
let expected = if account.label == "default" {
|
||||
saved
|
||||
} else {
|
||||
None
|
||||
};
|
||||
assert_eq!(account.current, expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Restore the saved account on reopen
|
||||
api1.set_active_account(mask1, "account1")?;
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_account_by_name("default")?;
|
||||
assert_eq!(w.active_account().label, "default");
|
||||
}
|
||||
api1.close_wallet(None)?;
|
||||
api1.open_wallet(None, "".into(), false)?;
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
assert_eq!(w.active_account().label, "account1");
|
||||
}
|
||||
}
|
||||
|
||||
// add account to wallet 2
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let new_path = api.create_account_path(m, "listener_account").unwrap();
|
||||
assert_eq!(new_path, ExtKeychain::derive_key_id(2, 1, 0, 0, 0));
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
{
|
||||
let new_path = api2.create_account_path(mask2, "listener_account").unwrap();
|
||||
assert_eq!(new_path, ExtKeychain::derive_key_id(2, 1, 0, 0, 0));
|
||||
}
|
||||
|
||||
// Default wallet 2 to listen on that account
|
||||
{
|
||||
wallet_inst!(wallet2, w);
|
||||
w.set_parent_key_id_by_name("listener_account")?;
|
||||
w.set_account_by_name("listener_account")?;
|
||||
}
|
||||
|
||||
// Mine into two different accounts in the same wallet
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account1")?;
|
||||
w.set_account_by_name("account1")?;
|
||||
assert_eq!(w.parent_key_id(), ExtKeychain::derive_key_id(2, 1, 0, 0, 0));
|
||||
}
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 7, false);
|
||||
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account2")?;
|
||||
w.set_account_by_name("account2")?;
|
||||
assert_eq!(w.parent_key_id(), ExtKeychain::derive_key_id(2, 2, 0, 0, 0));
|
||||
}
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 5, false);
|
||||
|
||||
// Should have 5 in account1 (5 spendable), 5 in account (2 spendable)
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 12);
|
||||
assert_eq!(wallet1_info.total, 5 * reward);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, (5 - cm) * reward);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 5);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
{
|
||||
let (wallet1_refreshed, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 12);
|
||||
assert_eq!(wallet1_info.total, 5 * reward);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, (5 - cm) * reward);
|
||||
// check tx log as well
|
||||
let (_, txs) = api1.retrieve_txs(mask1, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 5);
|
||||
}
|
||||
|
||||
// now check second account
|
||||
{
|
||||
// let mut w_lock = wallet1.lock();
|
||||
// let lc = w_lock.lc_provider()?;
|
||||
// let w = lc.wallet_inst()?;
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account1")?;
|
||||
w.set_account_by_name("account1")?;
|
||||
}
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
// check last confirmed height on this account is different from above (should be 0)
|
||||
let (_, wallet1_info) = api.retrieve_summary_info(m, false, 1)?;
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 0);
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 12);
|
||||
assert_eq!(wallet1_info.total, 7 * reward);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, 7 * reward);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 7);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
{
|
||||
let labels: Vec<_> = api1
|
||||
.accounts_info(mask1, 2)?
|
||||
.into_iter()
|
||||
.map(|a| a.label)
|
||||
.collect();
|
||||
assert_eq!(labels, ["account1", "default", "account2", "account3"]);
|
||||
assert!(api1.accounts(mask1)?.iter().all(|a| a.info.is_none()));
|
||||
for confirmations in [0, 1, 2, 10] {
|
||||
let accounts = api1.accounts_info(mask1, confirmations)?;
|
||||
assert_eq!(accounts[0].info.as_ref().unwrap().last_confirmed_height, 0);
|
||||
assert_eq!(accounts[2].info.as_ref().unwrap().last_confirmed_height, 12);
|
||||
for account in accounts {
|
||||
api1.set_active_account(mask1, &account.label)?;
|
||||
let (_, summary) = api1.retrieve_summary_info(mask1, false, confirmations)?;
|
||||
assert_eq!(account.info.unwrap(), summary);
|
||||
}
|
||||
api1.set_active_account(mask1, "account1")?;
|
||||
}
|
||||
// check last confirmed height on this account is different from above (should be 0)
|
||||
let (_, wallet1_info) = api1.retrieve_summary_info(mask1, false, 1)?;
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 0);
|
||||
let (wallet1_refreshed, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 12);
|
||||
assert_eq!(wallet1_info.total, 7 * reward);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, 7 * reward);
|
||||
// check tx log as well
|
||||
let (_, txs) = api1.retrieve_txs(mask1, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 7);
|
||||
}
|
||||
|
||||
// should be nothing in default account
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("default")?;
|
||||
w.set_account_by_name("default")?;
|
||||
}
|
||||
{
|
||||
let (_, wallet1_info) = api1.retrieve_summary_info(mask1, false, 1)?;
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 0);
|
||||
let (wallet1_refreshed, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 12);
|
||||
assert_eq!(wallet1_info.total, 0,);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, 0,);
|
||||
// check tx log as well
|
||||
let (_, txs) = api1.retrieve_txs(mask1, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 0);
|
||||
}
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, wallet1_info) = api.retrieve_summary_info(m, false, 1)?;
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 0);
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 12);
|
||||
assert_eq!(wallet1_info.total, 0,);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, 0,);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 0);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
// Send a tx to another wallet
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account1")?;
|
||||
w.set_account_by_name("account1")?;
|
||||
}
|
||||
{
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: reward,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
let mut slate = api1.init_send_tx(mask1, args)?;
|
||||
slate = client1.send_tx_slate_direct("wallet2", &slate)?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
slate = api1.finalize_tx(mask1, &slate)?;
|
||||
api1.post_tx(mask1, &slate, false)?;
|
||||
}
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: reward,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
let mut slate = api.init_send_tx(m, args)?;
|
||||
slate = client1.send_tx_slate_direct("wallet2", &slate)?;
|
||||
api.tx_lock_outputs(m, &slate)?;
|
||||
slate = api.finalize_tx(m, &slate)?;
|
||||
api.post_tx(m, &slate, false)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 13);
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 9);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
{
|
||||
let (wallet1_refreshed, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 13);
|
||||
let (_, txs) = api1.retrieve_txs(mask1, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 9);
|
||||
}
|
||||
// Use the requested account's stored height
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
@@ -268,61 +282,43 @@ fn accounts_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
// other account should be untouched
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account2")?;
|
||||
w.set_account_by_name("account2")?;
|
||||
}
|
||||
{
|
||||
let (_, wallet1_info) = api1.retrieve_summary_info(mask1, false, 1)?;
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 12);
|
||||
let (_, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 13);
|
||||
let (_, txs) = api1.retrieve_txs(mask1, true, None, None, None)?;
|
||||
println!("{:?}", txs);
|
||||
assert_eq!(txs.len(), 5);
|
||||
}
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, wallet1_info) = api.retrieve_summary_info(m, false, 1)?;
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 12);
|
||||
let (_, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 13);
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
println!("{:?}", txs);
|
||||
assert_eq!(txs.len(), 5);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
// wallet 2 should only have this tx on the listener account
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet2_refreshed);
|
||||
assert_eq!(wallet2_info.last_confirmed_height, 13);
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 1);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
{
|
||||
let (wallet2_refreshed, wallet2_info) = api2.retrieve_summary_info(mask2, true, 1)?;
|
||||
assert!(wallet2_refreshed);
|
||||
assert_eq!(wallet2_info.last_confirmed_height, 13);
|
||||
let (_, txs) = api2.retrieve_txs(mask2, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 1);
|
||||
}
|
||||
// Default account on wallet 2 should be untouched
|
||||
{
|
||||
wallet_inst!(wallet2, w);
|
||||
w.set_parent_key_id_by_name("default")?;
|
||||
w.set_account_by_name("default")?;
|
||||
}
|
||||
{
|
||||
let (_, wallet2_info) = api2.retrieve_summary_info(mask2, false, 1)?;
|
||||
assert_eq!(wallet2_info.last_confirmed_height, 0);
|
||||
let (wallet2_refreshed, wallet2_info) = api2.retrieve_summary_info(mask2, true, 1)?;
|
||||
assert!(wallet2_refreshed);
|
||||
assert_eq!(wallet2_info.last_confirmed_height, 13);
|
||||
assert_eq!(wallet2_info.total, 0,);
|
||||
assert_eq!(wallet2_info.amount_currently_spendable, 0,);
|
||||
// check tx log as well
|
||||
let (_, txs) = api2.retrieve_txs(mask2, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 0);
|
||||
}
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, wallet2_info) = api.retrieve_summary_info(m, false, 1)?;
|
||||
assert_eq!(wallet2_info.last_confirmed_height, 0);
|
||||
let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet2_refreshed);
|
||||
assert_eq!(wallet2_info.last_confirmed_height, 13);
|
||||
assert_eq!(wallet2_info.total, 0,);
|
||||
assert_eq!(wallet2_info.amount_currently_spendable, 0,);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 0);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
// let logging finish
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
|
||||
@@ -21,9 +21,8 @@ extern crate grin_wallet_impls as impls;
|
||||
extern crate grin_wallet_libwallet as libwallet;
|
||||
|
||||
use grin_core as core;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use self::libwallet::{InitTxArgs, Slate};
|
||||
use self::libwallet::InitTxArgs;
|
||||
use impls::test_framework::{self, LocalWalletClient};
|
||||
use rand::Rng;
|
||||
use std::sync::atomic::Ordering;
|
||||
@@ -48,9 +47,10 @@ fn build_chain(test_dir: &'static str, block_height: usize) -> Result<(), libwal
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
true
|
||||
true,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
debug!("Mask1: {:?}", mask1);
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
@@ -60,9 +60,10 @@ fn build_chain(test_dir: &'static str, block_height: usize) -> Result<(), libwal
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
debug!("Mask2: {:?}", mask2);
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
@@ -74,25 +75,8 @@ fn build_chain(test_dir: &'static str, block_height: usize) -> Result<(), libwal
|
||||
|
||||
// Stop the scanning updater threads because it extends the time needed to build the chain
|
||||
// exponentially
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, _m| {
|
||||
api.stop_updater()?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, _m| {
|
||||
api.stop_updater()?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api1.stop_updater()?;
|
||||
api2.stop_updater()?;
|
||||
|
||||
// few values to keep things shorter
|
||||
let reward = core::consensus::REWARD;
|
||||
@@ -105,22 +89,14 @@ fn build_chain(test_dir: &'static str, block_height: usize) -> Result<(), libwal
|
||||
let mut wallet_1_has_funds = false;
|
||||
|
||||
// Check wallet 1 contents
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
debug!(
|
||||
"Wallet 1 spendable - {}",
|
||||
wallet1_info.amount_currently_spendable
|
||||
);
|
||||
if wallet1_info.amount_currently_spendable > reward {
|
||||
wallet_1_has_funds = true;
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (_, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
debug!(
|
||||
"Wallet 1 spendable - {}",
|
||||
wallet1_info.amount_currently_spendable
|
||||
);
|
||||
if wallet1_info.amount_currently_spendable > reward {
|
||||
wallet_1_has_funds = true;
|
||||
}
|
||||
|
||||
// let's say 1 in every 3 blocks has a transaction (i.e. random 0 here and wallet1 has funds)
|
||||
let transact = rng.gen_range(0, 2) == 0;
|
||||
@@ -134,30 +110,21 @@ fn build_chain(test_dir: &'static str, block_height: usize) -> Result<(), libwal
|
||||
let num_txs = rng.gen_range(0, 3);
|
||||
for _ in 0..num_txs {
|
||||
let amount: u64 = rng.gen_range(1, 10_000_000_001);
|
||||
let mut slate = Slate::blank(1, false);
|
||||
debug!("Creating TX for {}", amount);
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|sender_api, m| {
|
||||
// note this will increment the block count as part of the transaction "Posting"
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount,
|
||||
minimum_confirmations: 1,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: false,
|
||||
..Default::default()
|
||||
};
|
||||
let slate_i = sender_api.init_send_tx(m, args)?;
|
||||
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
|
||||
sender_api.tx_lock_outputs(m, &slate)?;
|
||||
slate = sender_api.finalize_tx(m, &slate)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// note this will increment the block count as part of the transaction "Posting"
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount,
|
||||
minimum_confirmations: 1,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: false,
|
||||
..Default::default()
|
||||
};
|
||||
let slate_i = api1.init_send_tx(mask1, args)?;
|
||||
let slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
api1.finalize_tx(mask1, &slate)?;
|
||||
}
|
||||
}
|
||||
// let logging finish
|
||||
|
||||
@@ -25,7 +25,6 @@ use grin_util::{secp, ZeroingString};
|
||||
use grin_wallet_libwallet as libwallet;
|
||||
use impls::test_framework::LocalWalletClient;
|
||||
use rand::{thread_rng, Rng};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
@@ -37,7 +36,7 @@ use common::{clean_output_dir, create_wallet_proxy, setup};
|
||||
fn build_output_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
// Generate seed so we can verify the blinding factor is derived correctly
|
||||
let seed: [u8; 32] = thread_rng().gen();
|
||||
let keychain = ExtKeychain::from_seed(&seed, false).unwrap();
|
||||
let keychain = ExtKeychain::from_seed(&seed, false)?;
|
||||
let mnemonic = mnemonic::from_entropy(&seed).unwrap();
|
||||
|
||||
// Create a new proxy to simulate server and wallet responses
|
||||
@@ -52,10 +51,11 @@ fn build_output_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error
|
||||
"wallet1",
|
||||
Some(ZeroingString::from(mnemonic)),
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api1
|
||||
);
|
||||
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -67,28 +67,19 @@ fn build_output_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error
|
||||
let secp = secp::Secp256k1::with_caps(secp::ContextFlag::Commit);
|
||||
let features = OutputFeatures::Plain;
|
||||
let amount = 60_000_000_000;
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|sender_api, m| {
|
||||
let built_output = sender_api.build_output(m, features, amount)?;
|
||||
let built_output = api1.build_output(mask1, features, amount)?;
|
||||
|
||||
let key_id = built_output.key_id;
|
||||
assert_eq!(key_id.to_path(), ExtKeychainPath::new(3, 0, 0, 0, 0));
|
||||
let key_id = built_output.key_id;
|
||||
assert_eq!(key_id.to_path(), ExtKeychainPath::new(3, 0, 0, 0, 0));
|
||||
|
||||
let blind = built_output.blind;
|
||||
let key = keychain.derive_key(amount, &key_id, SwitchCommitmentType::Regular)?;
|
||||
assert_eq!(blind, BlindingFactor::from_secret_key(key.clone()));
|
||||
let blind = built_output.blind;
|
||||
let key = keychain.derive_key(amount, &key_id, SwitchCommitmentType::Regular)?;
|
||||
assert_eq!(blind, BlindingFactor::from_secret_key(key.clone()));
|
||||
|
||||
let output = built_output.output;
|
||||
assert_eq!(output.features(), features);
|
||||
assert_eq!(output.commitment(), secp.commit(amount, key)?);
|
||||
output.verify_proof()?;
|
||||
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let output = built_output.output;
|
||||
assert_eq!(output.features(), features);
|
||||
assert_eq!(output.commitment(), secp.commit(amount, key)?);
|
||||
output.verify_proof()?;
|
||||
|
||||
// let logging finish
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
|
||||
+221
-463
@@ -27,7 +27,6 @@ use impls::test_framework::{self, LocalWalletClient};
|
||||
use impls::{PathToSlate, SlatePutter as _};
|
||||
use libwallet::{InitTxArgs, NodeClient};
|
||||
use std::cmp;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
@@ -66,9 +65,10 @@ fn scan_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
@@ -77,9 +77,10 @@ fn scan_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -89,34 +90,22 @@ fn scan_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
});
|
||||
|
||||
// few values to keep things shorter
|
||||
let reward = core::consensus::REWARD;
|
||||
let cm = global::coinbase_maturity() as u64; // assume all testing precedes soft fork height
|
||||
let reward = consensus::REWARD;
|
||||
let cm = global::coinbase_maturity(); // assume all testing precedes soft fork height
|
||||
|
||||
// add some accounts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.create_account_path(m, "named_account_1")?;
|
||||
api.create_account_path(m, "account_2")?;
|
||||
api.create_account_path(m, "account_3")?;
|
||||
api.set_active_account(m, "named_account_1")?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
{
|
||||
api1.create_account_path(mask1, "named_account_1")?;
|
||||
api1.create_account_path(mask1, "account_2")?;
|
||||
api1.create_account_path(mask1, "account_3")?;
|
||||
api1.set_active_account(mask1, "named_account_1")?;
|
||||
}
|
||||
|
||||
// add account to wallet 2
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.create_account_path(m, "account_1")?;
|
||||
api.set_active_account(m, "account_1")?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
{
|
||||
api2.create_account_path(mask2, "account_1")?;
|
||||
api2.set_active_account(mask2, "account_1")?;
|
||||
}
|
||||
|
||||
// Do some mining
|
||||
let bh = 20u64;
|
||||
@@ -124,36 +113,21 @@ fn scan_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, bh as usize, false);
|
||||
|
||||
// Sanity check contents
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, (bh - cm) * reward);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
let (c, _) = libwallet::TxLogEntry::sum_confirmed(&txs);
|
||||
assert_eq!(wallet1_info.total, c);
|
||||
assert_eq!(txs.len(), bh as usize);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
{
|
||||
let (wallet1_refreshed, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, (bh - cm) * reward);
|
||||
// check tx log as well
|
||||
let (_, txs) = api1.retrieve_txs(mask1, true, None, None, None)?;
|
||||
let (c, _) = libwallet::TxLogEntry::sum_confirmed(&txs);
|
||||
assert_eq!(wallet1_info.total, c);
|
||||
assert_eq!(txs.len(), bh as usize);
|
||||
}
|
||||
|
||||
// Accidentally delete some outputs
|
||||
let mut w1_outputs_commits = vec![];
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
w1_outputs_commits = api.retrieve_outputs(m, false, true, None)?.1;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let w1_outputs_commits = api1.retrieve_outputs(mask1, false, true, None)?.1;
|
||||
let w1_outputs: Vec<libwallet::OutputData> =
|
||||
w1_outputs_commits.into_iter().map(|m| m.output).collect();
|
||||
{
|
||||
@@ -170,108 +144,54 @@ fn scan_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
}
|
||||
|
||||
// check we have a problem now
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
let (c, _) = libwallet::TxLogEntry::sum_confirmed(&txs);
|
||||
assert_ne!(wallet1_info.total, c);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (_, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
let (_, txs) = api1.retrieve_txs(mask1, true, None, None, None)?;
|
||||
let (c, _) = libwallet::TxLogEntry::sum_confirmed(&txs);
|
||||
assert_ne!(wallet1_info.total, c);
|
||||
|
||||
// this should restore our missing outputs
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.scan(m, None, true)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api1.scan(mask1, None, true)?;
|
||||
|
||||
// check our outputs match again
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.total, bh * reward);
|
||||
// And check account names haven't been splatted
|
||||
let accounts = api.accounts(m)?;
|
||||
assert_eq!(accounts.len(), 4);
|
||||
assert!(api.set_active_account(m, "account_1").is_err());
|
||||
assert!(api.set_active_account(m, "named_account_1").is_ok());
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
{
|
||||
let (wallet1_refreshed, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.total, bh * reward);
|
||||
// And check account names haven't been splatted
|
||||
let accounts = api1.accounts(mask1)?;
|
||||
assert_eq!(accounts.len(), 4);
|
||||
assert!(api1.set_active_account(mask1, "account_1").is_err());
|
||||
assert!(api1.set_active_account(mask1, "named_account_1").is_ok());
|
||||
}
|
||||
// perform a transaction, but don't let it finish
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
// send to send
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: reward * 2,
|
||||
minimum_confirmations: cm,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
let slate = api.init_send_tx(m, args)?;
|
||||
// output tx file
|
||||
let send_file = format!("{}/part_tx_1.tx", test_dir);
|
||||
PathToSlate(send_file.into()).put_tx(&slate, false)?;
|
||||
api.tx_lock_outputs(m, &slate)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
{
|
||||
// send to send
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: reward * 2,
|
||||
minimum_confirmations: cm,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
let slate = api1.init_send_tx(mask1, args)?;
|
||||
// output tx file
|
||||
let send_file = format!("{}/part_tx_1.tx", test_dir);
|
||||
PathToSlate(send_file.into()).put_tx(&slate, false)?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
}
|
||||
|
||||
// check we're all locked
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, 0);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
let (wallet1_refreshed, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, 0);
|
||||
// unlock/restore
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.scan(m, None, true)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api1.scan(mask1, None, true)?;
|
||||
|
||||
// check spendable amount again
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, (bh - cm) * reward);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (_, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, (bh - cm) * reward);
|
||||
|
||||
// let logging finish
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
@@ -300,9 +220,10 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
"miner",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
_m_api
|
||||
);
|
||||
let miner_mask = (&miner_mask_i).as_ref();
|
||||
let miner_mask = miner_mask_i.as_ref();
|
||||
|
||||
// non-mining recipient wallets
|
||||
create_wallet_and_add!(
|
||||
@@ -313,9 +234,10 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
"wallet1",
|
||||
seed_phrase,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
@@ -324,9 +246,10 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
"wallet2",
|
||||
seed_phrase,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
_api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
// we'll restore into here
|
||||
create_wallet_and_add!(
|
||||
client3,
|
||||
@@ -336,9 +259,10 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
"wallet3",
|
||||
seed_phrase,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api3
|
||||
);
|
||||
let mask3 = (&mask3_i).as_ref();
|
||||
let mask3 = mask3_i.as_ref();
|
||||
// also restore into here
|
||||
create_wallet_and_add!(
|
||||
client4,
|
||||
@@ -348,9 +272,10 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
"wallet4",
|
||||
seed_phrase,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api4
|
||||
);
|
||||
let mask4 = (&mask4_i).as_ref();
|
||||
let mask4 = mask4_i.as_ref();
|
||||
// Simulate a recover from seed without restore into here
|
||||
create_wallet_and_add!(
|
||||
client5,
|
||||
@@ -360,10 +285,11 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
"wallet5",
|
||||
seed_phrase,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api5
|
||||
);
|
||||
//simulate a recover from seed without restore into here
|
||||
let mask5 = (&mask5_i).as_ref();
|
||||
let mask5 = mask5_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client6,
|
||||
wallet6,
|
||||
@@ -372,9 +298,10 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
"wallet6",
|
||||
seed_phrase,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api6
|
||||
);
|
||||
let mask6 = (&mask6_i).as_ref();
|
||||
let mask6 = mask6_i.as_ref();
|
||||
|
||||
create_wallet_and_add!(
|
||||
client7,
|
||||
@@ -384,9 +311,10 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
"wallet7",
|
||||
seed_phrase,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api7
|
||||
);
|
||||
let mask7 = (&mask7_i).as_ref();
|
||||
let mask7 = mask7_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client8,
|
||||
wallet8,
|
||||
@@ -395,9 +323,10 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
"wallet8",
|
||||
seed_phrase,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api8
|
||||
);
|
||||
let mask8 = (&mask8_i).as_ref();
|
||||
let mask8 = mask8_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client9,
|
||||
wallet9,
|
||||
@@ -406,9 +335,10 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
"wallet9",
|
||||
seed_phrase,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api9
|
||||
);
|
||||
let mask9 = (&mask9_i).as_ref();
|
||||
let mask9 = mask9_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client10,
|
||||
wallet10,
|
||||
@@ -417,9 +347,10 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
"wallet10",
|
||||
seed_phrase,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api10
|
||||
);
|
||||
let mask10 = (&mask10_i).as_ref();
|
||||
let mask10 = mask10_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -449,7 +380,7 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
miner_mask,
|
||||
m_client.clone(),
|
||||
"wallet1",
|
||||
base_amount * 1
|
||||
base_amount
|
||||
)?;
|
||||
send_to_dest!(
|
||||
miner.clone(),
|
||||
@@ -468,18 +399,10 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
bh += 3;
|
||||
|
||||
// 0) Check repair when all is okay should leave wallet contents alone
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.scan(m, None, true)?;
|
||||
let info = wallet_info!(wallet1.clone(), m)?;
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 6);
|
||||
assert_eq!(info.total, base_amount * 6);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api1.scan(mask1, None, true)?;
|
||||
let info = wallet_info!(wallet1.clone(), mask1)?;
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 6);
|
||||
assert_eq!(info.total, base_amount * 6);
|
||||
|
||||
// send some funds to wallet 2
|
||||
send_to_dest!(
|
||||
@@ -523,53 +446,21 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
// seed + BIP32 path.
|
||||
|
||||
// 1) a full restore should recover all of them:
|
||||
wallet::controller::owner_single_use(
|
||||
wallet3.clone(),
|
||||
mask3,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.scan(m, None, false)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api3.scan(mask3, None, false)?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet3.clone(),
|
||||
mask3,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let info = wallet_info!(wallet3.clone(), m)?;
|
||||
let outputs = api.retrieve_outputs(m, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 6);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 21);
|
||||
assert_eq!(info.total, base_amount * 21);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let info = wallet_info!(wallet3.clone(), mask3)?;
|
||||
let outputs = api3.retrieve_outputs(mask3, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 6);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 21);
|
||||
assert_eq!(info.total, base_amount * 21);
|
||||
|
||||
// 2) scan should recover them into a single wallet
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.scan(m, None, true)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api1.scan(mask1, None, true)?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let info = wallet_info!(wallet1.clone(), m)?;
|
||||
let outputs = api.retrieve_outputs(m, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 6);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 21);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let info = wallet_info!(wallet1.clone(), mask1)?;
|
||||
let outputs = api1.retrieve_outputs(mask1, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 6);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 21);
|
||||
|
||||
// 3) If I recover from seed and start using the wallet without restoring,
|
||||
// scan should restore the older outputs
|
||||
@@ -601,41 +492,17 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, miner.clone(), miner_mask, cm, false);
|
||||
bh += cm as u64;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet4.clone(),
|
||||
mask4,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let info = wallet_info!(wallet4.clone(), m)?;
|
||||
let outputs = api.retrieve_outputs(m, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 9);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 45);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let info = wallet_info!(wallet4.clone(), mask4)?;
|
||||
let outputs = api4.retrieve_outputs(mask4, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 9);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 45);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet5.clone(),
|
||||
mask5,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.scan(m, None, false)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api5.scan(mask5, None, false)?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet5.clone(),
|
||||
mask5,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let info = wallet_info!(wallet5.clone(), m)?;
|
||||
let outputs = api.retrieve_outputs(m, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 9);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * (45));
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let info = wallet_info!(wallet5.clone(), mask5)?;
|
||||
let outputs = api5.retrieve_outputs(mask5, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 9);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * (45));
|
||||
|
||||
// 4) If I recover from seed and start using the wallet without restoring,
|
||||
// scan should restore the older outputs
|
||||
@@ -662,50 +529,20 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
)?;
|
||||
bh += 3;
|
||||
|
||||
let _ = test_framework::award_blocks_to_wallet(
|
||||
&chain,
|
||||
miner.clone(),
|
||||
miner_mask,
|
||||
cm as usize,
|
||||
false,
|
||||
);
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, miner.clone(), miner_mask, cm, false);
|
||||
bh += cm as u64;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet6.clone(),
|
||||
mask6,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let info = wallet_info!(wallet6.clone(), m)?;
|
||||
let outputs = api.retrieve_outputs(m, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 12);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 78);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let info = wallet_info!(wallet6.clone(), mask6)?;
|
||||
let outputs = api6.retrieve_outputs(mask6, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 12);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 78);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet6.clone(),
|
||||
mask6,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.scan(m, None, true)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api6.scan(mask6, None, true)?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet6.clone(),
|
||||
mask6,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let info = wallet_info!(wallet6.clone(), m)?;
|
||||
let outputs = api.retrieve_outputs(m, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 12);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * (78));
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let info = wallet_info!(wallet6.clone(), mask6)?;
|
||||
let outputs = api6.retrieve_outputs(mask6, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 12);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * (78));
|
||||
|
||||
// 5) Start using same seed with a different account, amounts should
|
||||
// be distinct and restore should return funds from other account
|
||||
@@ -734,23 +571,15 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
bh += 3;
|
||||
|
||||
// mix it up a bit
|
||||
wallet::controller::owner_single_use(
|
||||
wallet7.clone(),
|
||||
mask7,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.create_account_path(m, "account_1")?;
|
||||
api.set_active_account(m, "account_1")?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api7.create_account_path(mask7, "account_1")?;
|
||||
api7.set_active_account(mask7, "account_1")?;
|
||||
|
||||
send_to_dest!(
|
||||
miner.clone(),
|
||||
miner_mask,
|
||||
m_client.clone(),
|
||||
"wallet7",
|
||||
base_amount * 1
|
||||
base_amount
|
||||
)?;
|
||||
send_to_dest!(
|
||||
miner.clone(),
|
||||
@@ -772,57 +601,33 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, miner.clone(), miner_mask, cm, false);
|
||||
bh += cm as u64;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet7.clone(),
|
||||
mask7,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let info = wallet_info!(wallet7.clone(), m)?;
|
||||
let outputs = api.retrieve_outputs(m, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 3);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 6);
|
||||
api.set_active_account(m, "default")?;
|
||||
let info = wallet_info!(wallet7.clone(), m)?;
|
||||
let outputs = api.retrieve_outputs(m, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 15);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 120);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let info = wallet_info!(wallet7.clone(), mask7)?;
|
||||
let outputs = api7.retrieve_outputs(mask7, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 3);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 6);
|
||||
api7.set_active_account(mask7, "default")?;
|
||||
let info = wallet_info!(wallet7.clone(), mask7)?;
|
||||
let outputs = api7.retrieve_outputs(mask7, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 15);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 120);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet8.clone(),
|
||||
mask8,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.scan(m, None, false)?;
|
||||
let info = wallet_info!(wallet8.clone(), m)?;
|
||||
let outputs = api.retrieve_outputs(m, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 15);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 120);
|
||||
api.set_active_account(m, "account_1")?;
|
||||
let info = wallet_info!(wallet8.clone(), m)?;
|
||||
let outputs = api.retrieve_outputs(m, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 3);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 6);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api8.scan(mask8, None, false)?;
|
||||
let info = wallet_info!(wallet8.clone(), mask8)?;
|
||||
let outputs = api8.retrieve_outputs(mask8, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 15);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 120);
|
||||
api8.set_active_account(mask8, "account_1")?;
|
||||
let info = wallet_info!(wallet8.clone(), mask8)?;
|
||||
let outputs = api8.retrieve_outputs(mask8, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 3);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 6);
|
||||
|
||||
// 6) Start using same seed with a different account, now overwriting
|
||||
// ids on account 2 as well, scan should get all outputs created
|
||||
// to now into 2 accounts
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet9.clone(),
|
||||
mask9,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.create_account_path(m, "account_1")?;
|
||||
api.set_active_account(m, "account_1")?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api9.create_account_path(mask9, "account_1")?;
|
||||
api9.set_active_account(mask9, "account_1")?;
|
||||
|
||||
send_to_dest!(
|
||||
miner.clone(),
|
||||
@@ -848,53 +653,37 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
bh += 3;
|
||||
let _bh = bh;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet9.clone(),
|
||||
mask9,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let info = wallet_info!(wallet9.clone(), m)?;
|
||||
let outputs = api.retrieve_outputs(m, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 6);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 21);
|
||||
api.scan(m, None, true)?;
|
||||
let info = wallet_info!(wallet9.clone(), m)?;
|
||||
let outputs = api.retrieve_outputs(m, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 6);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 21);
|
||||
let info = wallet_info!(wallet9.clone(), mask9)?;
|
||||
let outputs = api9.retrieve_outputs(mask9, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 6);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 21);
|
||||
api9.scan(mask9, None, true)?;
|
||||
let info = wallet_info!(wallet9.clone(), mask9)?;
|
||||
let outputs = api9.retrieve_outputs(mask9, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 6);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 21);
|
||||
|
||||
api.set_active_account(m, "default")?;
|
||||
let info = wallet_info!(wallet9.clone(), m)?;
|
||||
let outputs = api.retrieve_outputs(m, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 15);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 120);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api9.set_active_account(mask9, "default")?;
|
||||
let info = wallet_info!(wallet9.clone(), mask9)?;
|
||||
let outputs = api9.retrieve_outputs(mask9, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 15);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 120);
|
||||
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, miner.clone(), miner_mask, cm, false);
|
||||
|
||||
// 7) Ensure scan creates missing accounts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet10.clone(),
|
||||
mask10,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.scan(m, None, true)?;
|
||||
api.set_active_account(m, "account_1")?;
|
||||
let info = wallet_info!(wallet10.clone(), m)?;
|
||||
let outputs = api.retrieve_outputs(m, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 6);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 21);
|
||||
api10.scan(mask10, None, true)?;
|
||||
api10.set_active_account(mask10, "account_1")?;
|
||||
let info = wallet_info!(wallet10.clone(), mask10)?;
|
||||
let outputs = api10.retrieve_outputs(mask10, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 6);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 21);
|
||||
|
||||
api.set_active_account(m, "default")?;
|
||||
let info = wallet_info!(wallet10.clone(), m)?;
|
||||
let outputs = api.retrieve_outputs(m, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 15);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 120);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api10.set_active_account(mask10, "default")?;
|
||||
let info = wallet_info!(wallet10.clone(), mask10)?;
|
||||
let outputs = api10.retrieve_outputs(mask10, true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 15);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 120);
|
||||
|
||||
// let logging finish
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
@@ -918,9 +707,10 @@ fn output_scanning_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
_api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
thread::spawn(move || {
|
||||
if let Err(e) = wallet_proxy.run() {
|
||||
error!("Wallet Proxy error: {}", e);
|
||||
@@ -952,7 +742,7 @@ fn output_scanning_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
);
|
||||
assert_eq!(outputs.2.len(), 14);
|
||||
|
||||
// mid range
|
||||
// mid-range
|
||||
let ranges = client1.height_range_to_pmmr_indices(5, Some(14))?;
|
||||
assert_eq!(ranges, (8, 25));
|
||||
let outputs = client1.get_outputs_by_pmmr_index(ranges.0, Some(ranges.1), 1000)?;
|
||||
@@ -1002,9 +792,10 @@ fn multi_batch_scan_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
thread::spawn(move || {
|
||||
if let Err(e) = wallet_proxy.run() {
|
||||
@@ -1017,19 +808,10 @@ fn multi_batch_scan_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
let _ =
|
||||
test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, bh as usize, false);
|
||||
|
||||
let mut output_commits = vec![];
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert_eq!(info.last_confirmed_height, bh);
|
||||
assert_eq!(info.total, bh * reward);
|
||||
output_commits = api.retrieve_outputs(m, false, true, None)?.1;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (_, info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert_eq!(info.last_confirmed_height, bh);
|
||||
assert_eq!(info.total, bh * reward);
|
||||
let output_commits = api1.retrieve_outputs(mask1, false, true, None)?.1;
|
||||
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
@@ -1076,18 +858,10 @@ fn multi_batch_scan_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
}
|
||||
assert!(batches > 1);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, restored_outputs) = api.retrieve_outputs(m, false, true, None)?;
|
||||
let (_, info) = api.retrieve_summary_info(m, false, 1)?;
|
||||
assert_eq!(info.total, bh * reward);
|
||||
assert_eq!(restored_outputs.len(), bh as usize);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (_, restored_outputs) = api1.retrieve_outputs(mask1, false, true, None)?;
|
||||
let (_, info) = api1.retrieve_summary_info(mask1, false, 1)?;
|
||||
assert_eq!(info.total, bh * reward);
|
||||
assert_eq!(restored_outputs.len(), bh as usize);
|
||||
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
@@ -1109,9 +883,10 @@ fn restore_corrupted_outputs_across_batches_impl(
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
thread::spawn(move || {
|
||||
if let Err(e) = wallet_proxy.run() {
|
||||
@@ -1124,18 +899,9 @@ fn restore_corrupted_outputs_across_batches_impl(
|
||||
let _ =
|
||||
test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, bh as usize, false);
|
||||
|
||||
let mut output_commits = vec![];
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert_eq!(info.total, bh * reward);
|
||||
output_commits = api.retrieve_outputs(m, false, true, None)?.1;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (_, info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert_eq!(info.total, bh * reward);
|
||||
let output_commits = api1.retrieve_outputs(mask1, false, true, None)?.1;
|
||||
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
@@ -1173,30 +939,22 @@ fn restore_corrupted_outputs_across_batches_impl(
|
||||
assert_eq!(last_scanned.hash, "");
|
||||
}
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, outputs_after_first_batch) = api.retrieve_outputs(m, false, false, None)?;
|
||||
assert_eq!(outputs_after_first_batch.len(), (bh - 1) as usize);
|
||||
let (_, outputs_after_first_batch) = api1.retrieve_outputs(mask1, false, false, None)?;
|
||||
assert_eq!(outputs_after_first_batch.len(), (bh - 1) as usize);
|
||||
|
||||
let (_, info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
let (_, restored_outputs) = api.retrieve_outputs(m, false, true, None)?;
|
||||
let unique_keys = restored_outputs
|
||||
.iter()
|
||||
.map(|o| o.output.key_id.clone())
|
||||
.collect::<std::collections::HashSet<_>>();
|
||||
let (_, info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
let (_, restored_outputs) = api1.retrieve_outputs(mask1, false, true, None)?;
|
||||
let unique_keys = restored_outputs
|
||||
.iter()
|
||||
.map(|o| o.output.key_id.clone())
|
||||
.collect::<std::collections::HashSet<_>>();
|
||||
|
||||
assert_eq!(info.total, bh * reward);
|
||||
assert_eq!(restored_outputs.len(), bh as usize);
|
||||
assert_eq!(unique_keys.len(), bh as usize);
|
||||
assert!(restored_outputs
|
||||
.iter()
|
||||
.all(|o| o.output.status == libwallet::OutputStatus::Unspent));
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
assert_eq!(info.total, bh * reward);
|
||||
assert_eq!(restored_outputs.len(), bh as usize);
|
||||
assert_eq!(unique_keys.len(), bh as usize);
|
||||
assert!(restored_outputs
|
||||
.iter()
|
||||
.all(|o| o.output.status == libwallet::OutputStatus::Unspent));
|
||||
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
|
||||
@@ -21,6 +21,7 @@ use grin_chain as chain;
|
||||
use grin_core as core;
|
||||
use grin_keychain as keychain;
|
||||
use grin_util as util;
|
||||
use std::env;
|
||||
|
||||
use self::core::core::{FeeFields, Inputs, KernelFeatures, OutputFeatures};
|
||||
use self::core::global;
|
||||
@@ -28,6 +29,8 @@ use self::core::global::ChainTypes;
|
||||
use self::keychain::{ExtKeychain, Keychain};
|
||||
use self::libwallet::WalletInst;
|
||||
use chain::Chain;
|
||||
use grin_wallet_api::Owner;
|
||||
use grin_wallet_config::{initial_setup_wallet, GRIN_WALLET_DIR};
|
||||
use grin_wallet_controller::Error;
|
||||
use impls::test_framework::{self, LocalWalletClient, WalletProxy};
|
||||
use impls::{DefaultLCProvider, DefaultWalletImpl};
|
||||
@@ -49,9 +52,9 @@ macro_rules! wallet_inst {
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! create_wallet_and_add {
|
||||
($client:ident, $wallet: ident, $mask: ident, $test_dir: expr, $name: expr, $seed_phrase: expr, $proxy: expr, $create_mask: expr) => {
|
||||
($client:ident, $wallet: ident, $mask: ident, $test_dir: expr, $name: expr, $seed_phrase: expr, $proxy: expr, $create_mask: expr, $owner_api: ident) => {
|
||||
let $client = LocalWalletClient::new($name, $proxy.tx.clone());
|
||||
let ($wallet, $mask) = common::create_local_wallet(
|
||||
let ($wallet, $mask, $owner_api) = common::create_local_wallet(
|
||||
$test_dir,
|
||||
$name,
|
||||
$seed_phrase.clone(),
|
||||
@@ -121,12 +124,7 @@ pub fn roundtrip_slate(
|
||||
slate: &libwallet::Slate,
|
||||
version: u16,
|
||||
) -> Result<libwallet::Slate, libwallet::Error> {
|
||||
let packer = libwallet::Slatepacker::new(libwallet::SlatepackerArgs {
|
||||
sender: None,
|
||||
recipients: vec![],
|
||||
dec_key: None,
|
||||
});
|
||||
let slate = packer.get_slate(&packer.create_slatepack(slate)?)?;
|
||||
let slate = slate.create_slatepack(None, vec![])?.get_slate()?;
|
||||
assert_eq!(slate.version_info.version, version);
|
||||
Ok(slate)
|
||||
}
|
||||
@@ -260,6 +258,7 @@ pub fn create_wallet_proxy(
|
||||
WalletProxy::new(test_dir)
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn create_local_wallet(
|
||||
test_dir: &str,
|
||||
name: &str,
|
||||
@@ -267,20 +266,25 @@ pub fn create_local_wallet(
|
||||
client: LocalWalletClient,
|
||||
create_mask: bool,
|
||||
) -> (
|
||||
Arc<
|
||||
Mutex<
|
||||
Box<
|
||||
dyn WalletInst<
|
||||
'static,
|
||||
DefaultLCProvider<LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
ExtKeychain,
|
||||
>,
|
||||
>,
|
||||
>,
|
||||
grin_wallet_libwallet::WalletHandle<
|
||||
'static,
|
||||
DefaultLCProvider<LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
ExtKeychain,
|
||||
>,
|
||||
Option<SecretKey>,
|
||||
Owner<DefaultLCProvider<LocalWalletClient, ExtKeychain>, LocalWalletClient, ExtKeychain>,
|
||||
) {
|
||||
let mut current_dir;
|
||||
current_dir = env::current_dir().unwrap_or_else(|e| {
|
||||
panic!("Error creating config file: {}", e);
|
||||
});
|
||||
current_dir.push(test_dir);
|
||||
current_dir.push(name);
|
||||
let config =
|
||||
initial_setup_wallet(&ChainTypes::AutomatedTesting, Some(current_dir), true).unwrap();
|
||||
let mut wallet_config = config.clone().members.wallet;
|
||||
|
||||
let mut wallet = Box::new(DefaultWalletImpl::<LocalWalletClient>::new(client).unwrap())
|
||||
as Box<
|
||||
dyn WalletInst<
|
||||
@@ -290,13 +294,25 @@ pub fn create_local_wallet(
|
||||
>,
|
||||
>;
|
||||
let lc = wallet.lc_provider().unwrap();
|
||||
let _ = lc.set_top_level_directory(&format!("{}/{}", test_dir, name));
|
||||
// legacy hack to avoid the need for changes in existing grin-wallet.toml files
|
||||
// remove `wallet_data` from end of path as
|
||||
// new lifecycle provider assumes grin_wallet.toml is in root of data directory
|
||||
let mut top_level_wallet_dir = PathBuf::from(wallet_config.clone().data_file_dir);
|
||||
if top_level_wallet_dir.ends_with(GRIN_WALLET_DIR) {
|
||||
top_level_wallet_dir.pop();
|
||||
wallet_config.data_file_dir = top_level_wallet_dir.to_str().unwrap().into();
|
||||
}
|
||||
let _ = lc.set_top_level_directory(&wallet_config.data_file_dir);
|
||||
lc.create_wallet(None, mnemonic, 32, ZeroingString::from(""), false)
|
||||
.unwrap();
|
||||
let mask = lc
|
||||
.open_wallet(None, ZeroingString::from(""), create_mask, false)
|
||||
.unwrap();
|
||||
(Arc::new(Mutex::new(wallet)), mask)
|
||||
|
||||
let wallet = Arc::new(Mutex::new(wallet));
|
||||
let owner_api = Owner::new(wallet.clone(), None, config.config_file_path.clone());
|
||||
|
||||
(wallet, mask, owner_api)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
@@ -306,17 +322,11 @@ pub fn open_local_wallet(
|
||||
client: LocalWalletClient,
|
||||
create_mask: bool,
|
||||
) -> (
|
||||
Arc<
|
||||
Mutex<
|
||||
Box<
|
||||
dyn WalletInst<
|
||||
'static,
|
||||
DefaultLCProvider<LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
ExtKeychain,
|
||||
>,
|
||||
>,
|
||||
>,
|
||||
grin_wallet_libwallet::WalletHandle<
|
||||
'static,
|
||||
DefaultLCProvider<LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
ExtKeychain,
|
||||
>,
|
||||
Option<SecretKey>,
|
||||
) {
|
||||
@@ -337,7 +347,7 @@ pub fn open_local_wallet(
|
||||
}
|
||||
|
||||
// Creates the given number of wallets and spawns a thread that runs the wallet proxy
|
||||
#[allow(dead_code)]
|
||||
#[allow(dead_code, clippy::type_complexity)]
|
||||
pub fn create_wallets(
|
||||
wallets_def: Vec<Vec<(&'static str, u64)>>, // a vector of boolean that represent whether we mine into a wallet
|
||||
test_dir: &'static str,
|
||||
@@ -373,7 +383,7 @@ pub fn create_wallets(
|
||||
for i in 0..wallets_def.len() {
|
||||
let name = format!("wallet{}", i + 1);
|
||||
let wclient = LocalWalletClient::new(&name, wallet_proxy.tx.clone());
|
||||
let (wallet1, mask1) = create_local_wallet(
|
||||
let (wallet1, mask1, _) = create_local_wallet(
|
||||
test_dir,
|
||||
&name,
|
||||
None,
|
||||
@@ -407,20 +417,15 @@ pub fn create_wallets(
|
||||
|
||||
for (acc_idx, (acc_name, num_mined_blocks)) in accs.iter().enumerate() {
|
||||
// create the account
|
||||
if acc_name.to_string() != "default" {
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let new_path = api.create_account_path(m, acc_name)?;
|
||||
assert_eq!(
|
||||
new_path,
|
||||
ExtKeychain::derive_key_id(2, acc_idx as u32, 0, 0, 0) // NOTE: default should always be at 0 and is already created
|
||||
);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
if *acc_name != "default" {
|
||||
owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let new_path = api.create_account_path(m, acc_name)?;
|
||||
assert_eq!(
|
||||
new_path,
|
||||
ExtKeychain::derive_key_id(2, acc_idx as u32, 0, 0, 0) // NOTE: default should always be at 0 and is already created
|
||||
);
|
||||
Ok(())
|
||||
})?;
|
||||
}
|
||||
|
||||
// Get some mining done
|
||||
@@ -429,7 +434,7 @@ pub fn create_wallets(
|
||||
}
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name(acc_name)?;
|
||||
w.set_account_by_name(acc_name)?;
|
||||
}
|
||||
let _ = test_framework::award_blocks_to_wallet(
|
||||
&chain,
|
||||
@@ -441,38 +446,43 @@ pub fn create_wallets(
|
||||
bh += num_mined_blocks;
|
||||
|
||||
// Sanity check wallet 1 contents
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) =
|
||||
api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, num_mined_blocks * reward);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, num_mined_blocks * reward);
|
||||
Ok(())
|
||||
})?;
|
||||
}
|
||||
|
||||
// Sanity check the number of accounts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let accounts = api.accounts(m)?;
|
||||
assert_eq!(accounts.len(), accs.len());
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let accounts = api.accounts(m)?;
|
||||
assert_eq!(accounts.len(), accs.len());
|
||||
Ok(())
|
||||
})?;
|
||||
// Set the account on the wallet to "default"
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("default")?;
|
||||
w.set_account_by_name("default")?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok((wallets, chain, stopper, bh))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn owner_single_use<L, F, C, K>(
|
||||
wallet: libwallet::WalletHandle<'static, L, C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
config_path: PathBuf,
|
||||
f: F,
|
||||
) -> Result<(), libwallet::Error>
|
||||
where
|
||||
L: libwallet::WalletLCProvider<'static, C, K> + 'static,
|
||||
F: FnOnce(&mut Owner<L, C, K>, Option<&SecretKey>) -> Result<(), libwallet::Error>,
|
||||
C: libwallet::NodeClient + 'static,
|
||||
K: Keychain + 'static,
|
||||
{
|
||||
f(&mut Owner::new(wallet, None, config_path), keychain_mask)
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ use config::config::{get_global_config, reload_global_config};
|
||||
use config::GlobalWalletConfig;
|
||||
use impls::test_framework::LocalWalletClient;
|
||||
use libwallet::{InitTxArgs, InitTxSendArgs};
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::{env, fs};
|
||||
|
||||
mod common;
|
||||
use common::{clean_output_dir, create_wallet_proxy, setup};
|
||||
@@ -63,7 +63,8 @@ fn tor_disable() {
|
||||
"wallet",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
_api
|
||||
);
|
||||
let path = PathBuf::from(test_dir).join("grin-wallet.toml");
|
||||
let mut config =
|
||||
@@ -94,6 +95,7 @@ fn tor_disable() {
|
||||
);
|
||||
assert_eq!(cached, stored);
|
||||
|
||||
drop(_api);
|
||||
drop(owner);
|
||||
drop(wallet);
|
||||
drop(wallet_proxy);
|
||||
@@ -113,7 +115,8 @@ fn send_preflight() {
|
||||
"wallet",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
_api
|
||||
);
|
||||
let owner = api::Owner::new(
|
||||
wallet.clone(),
|
||||
@@ -144,6 +147,7 @@ fn send_preflight() {
|
||||
assert!(after_txs.is_empty());
|
||||
assert_eq!(snapshot(&wallet_data), before_data);
|
||||
|
||||
drop(_api);
|
||||
drop(owner);
|
||||
drop(wallet);
|
||||
drop(wallet_proxy);
|
||||
@@ -163,9 +167,13 @@ fn directory_change() {
|
||||
"wallet",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
_api
|
||||
);
|
||||
let old_dir = PathBuf::from(test_dir).join("wallet");
|
||||
let old_dir = env::current_dir().unwrap_or_else(|e| {
|
||||
panic!("Error creating config file: {}", e);
|
||||
});
|
||||
let old_dir = old_dir.join(test_dir).join("wallet");
|
||||
let old_config = old_dir.join("grin-wallet.toml");
|
||||
let new_dir = PathBuf::from(test_dir).join("other");
|
||||
let owner = api::Owner::new(wallet.clone(), None, old_config.clone());
|
||||
|
||||
@@ -63,259 +63,210 @@ fn contract_accounts_impl(test_dir: &'static str) -> Result<(), libwallet::Error
|
||||
// Default wallet 2 to listen on that account
|
||||
{
|
||||
wallet_inst!(wallet2, w);
|
||||
w.set_parent_key_id_by_name("listener_account")?;
|
||||
w.set_account_by_name("listener_account")?;
|
||||
}
|
||||
|
||||
// Mine into two different accounts in the same wallet
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account1")?;
|
||||
w.set_account_by_name("account1")?;
|
||||
assert_eq!(w.parent_key_id(), ExtKeychain::derive_key_id(2, 1, 0, 0, 0));
|
||||
}
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 7, false);
|
||||
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account2")?;
|
||||
w.set_account_by_name("account2")?;
|
||||
assert_eq!(w.parent_key_id(), ExtKeychain::derive_key_id(2, 2, 0, 0, 0));
|
||||
}
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 5, false);
|
||||
|
||||
// Should have 5 in account1 (5 spendable), 5 in account (2 spendable)
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 12);
|
||||
assert_eq!(wallet1_info.total, 5 * reward);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, (5 - cm) * reward);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 5);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 12);
|
||||
assert_eq!(wallet1_info.total, 5 * reward);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, (5 - cm) * reward);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 5);
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// now check second account
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account1")?;
|
||||
w.set_account_by_name("account1")?;
|
||||
}
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
// check last confirmed height on this account is different from above (should be 0)
|
||||
let (_, wallet1_info) = api.retrieve_summary_info(m, false, 1)?;
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 0);
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 12);
|
||||
assert_eq!(wallet1_info.total, 7 * reward);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, 7 * reward);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 7);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
// check last confirmed height on this account is different from above (should be 0)
|
||||
let (_, wallet1_info) = api.retrieve_summary_info(m, false, 1)?;
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 0);
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 12);
|
||||
assert_eq!(wallet1_info.total, 7 * reward);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, 7 * reward);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 7);
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// should be nothing in default account
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("default")?;
|
||||
w.set_account_by_name("default")?;
|
||||
}
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, wallet1_info) = api.retrieve_summary_info(m, false, 1)?;
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 0);
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 12);
|
||||
assert_eq!(wallet1_info.total, 0,);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, 0,);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 0);
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let (_, wallet1_info) = api.retrieve_summary_info(m, false, 1)?;
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 0);
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 12);
|
||||
assert_eq!(wallet1_info.total, 0,);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, 0,);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 0);
|
||||
|
||||
// Do not fall back to another account when the active account has no funds
|
||||
let progress = common::wallet_progress(api, m)?;
|
||||
let err = api
|
||||
.contract_new(
|
||||
m,
|
||||
&ContractNewArgsAPI {
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
net_change: Some(-(reward as i64)),
|
||||
selection_args: common::contract_selection_args(),
|
||||
..Default::default()
|
||||
},
|
||||
// Do not fall back to another account when the active account has no funds
|
||||
let progress = common::wallet_progress(api, m)?;
|
||||
let err = api
|
||||
.contract_new(
|
||||
m,
|
||||
&ContractNewArgsAPI {
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
net_change: Some(-(reward as i64)),
|
||||
selection_args: common::contract_selection_args(),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap_err();
|
||||
assert!(matches!(err, libwallet::Error::NotEnoughFunds { .. }));
|
||||
assert_eq!(common::wallet_progress(api, m)?, progress);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap_err();
|
||||
assert!(matches!(err, libwallet::Error::NotEnoughFunds { .. }));
|
||||
assert_eq!(common::wallet_progress(api, m)?, progress);
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// Send a tx from wallet1::account1 -> wallet2::listener_account
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account1")?;
|
||||
w.set_account_by_name("account1")?;
|
||||
}
|
||||
|
||||
let mut slate = Slate::blank(0, true); // this gets overriden below
|
||||
|
||||
let mut sender_address = None;
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
// Send wallet inititates a standard transaction with --send=5
|
||||
let args = &ContractNewArgsAPI {
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(-5_000_000_000),
|
||||
..Default::default()
|
||||
},
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
// Send wallet inititates a standard transaction with --send=5
|
||||
let args = &ContractNewArgsAPI {
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(-5_000_000_000),
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.contract_new(m, args)?;
|
||||
sender_address = Some(api.get_slatepack_address(mask1, 0)?.pub_key);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.contract_new(m, args)?;
|
||||
sender_address = Some(
|
||||
api.get_slatepack_address(mask1, libwallet::slatepack::SlatepackAddressIndex(0))?
|
||||
.pub_key,
|
||||
);
|
||||
Ok(())
|
||||
})?;
|
||||
assert_eq!(slate.state, SlateState::Standard1);
|
||||
|
||||
let mut recipient_address = None;
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
// Receive wallet calls --receive=5
|
||||
let args = &mut ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(5_000_000_000),
|
||||
..Default::default()
|
||||
};
|
||||
// Proofs are opt-in; enable and supply the sender address.
|
||||
args.proof_args.suppress_proof = false;
|
||||
args.proof_args.sender_address = sender_address;
|
||||
slate = api.contract_sign(m, &slate, args)?;
|
||||
recipient_address = Some(api.get_slatepack_address(mask2, 0)?.pub_key);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet2.clone(), mask2, PathBuf::from(test_dir), |api, m| {
|
||||
// Receive wallet calls --receive=5
|
||||
let args = &mut ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(5_000_000_000),
|
||||
..Default::default()
|
||||
};
|
||||
// Proofs are opt-in; enable and supply the sender address.
|
||||
args.proof_args.suppress_proof = false;
|
||||
args.proof_args.sender_address = sender_address;
|
||||
slate = api.contract_sign(m, &slate, args)?;
|
||||
recipient_address = Some(
|
||||
api.get_slatepack_address(mask2, libwallet::slatepack::SlatepackAddressIndex(0))?
|
||||
.pub_key,
|
||||
);
|
||||
Ok(())
|
||||
})?;
|
||||
assert_eq!(slate.state, SlateState::Standard2);
|
||||
|
||||
// Send wallet finalizes and posts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let args = &ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.contract_sign(m, &slate, args)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let args = &ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.contract_sign(m, &slate, args)?;
|
||||
Ok(())
|
||||
})?;
|
||||
assert_eq!(slate.state, SlateState::Standard3);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.post_tx(m, &slate, false)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
api.post_tx(m, &slate, false)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 13);
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 9);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 13);
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 9);
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// other account should be untouched
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account2")?;
|
||||
w.set_account_by_name("account2")?;
|
||||
}
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, wallet1_info) = api.retrieve_summary_info(m, false, 1)?;
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 12);
|
||||
let (_, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 13);
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 5);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let (_, wallet1_info) = api.retrieve_summary_info(m, false, 1)?;
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 12);
|
||||
let (_, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 13);
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 5);
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// wallet 2 should only have this tx on the listener account
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet2_refreshed);
|
||||
assert_eq!(wallet2_info.last_confirmed_height, 13);
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 1);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet2.clone(), mask2, PathBuf::from(test_dir), |api, m| {
|
||||
let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet2_refreshed);
|
||||
assert_eq!(wallet2_info.last_confirmed_height, 13);
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 1);
|
||||
Ok(())
|
||||
})?;
|
||||
// Default account on wallet 2 should be untouched
|
||||
{
|
||||
wallet_inst!(wallet2, w);
|
||||
w.set_parent_key_id_by_name("default")?;
|
||||
w.set_account_by_name("default")?;
|
||||
}
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, wallet2_info) = api.retrieve_summary_info(m, false, 1)?;
|
||||
assert_eq!(wallet2_info.last_confirmed_height, 0);
|
||||
let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet2_refreshed);
|
||||
assert_eq!(wallet2_info.last_confirmed_height, 13);
|
||||
assert_eq!(wallet2_info.total, 0,);
|
||||
assert_eq!(wallet2_info.amount_currently_spendable, 0,);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 0);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet2.clone(), mask2, PathBuf::from(test_dir), |api, m| {
|
||||
let (_, wallet2_info) = api.retrieve_summary_info(m, false, 1)?;
|
||||
assert_eq!(wallet2_info.last_confirmed_height, 0);
|
||||
let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet2_refreshed);
|
||||
assert_eq!(wallet2_info.last_confirmed_height, 13);
|
||||
assert_eq!(wallet2_info.total, 0,);
|
||||
assert_eq!(wallet2_info.amount_currently_spendable, 0,);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 0);
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// let logging finish
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
@@ -341,11 +292,8 @@ fn contract_unknown_account_impl(test_dir: &'static str) -> Result<(), libwallet
|
||||
let wallet1 = wallets[0].0.clone();
|
||||
let mask1 = wallets[0].1.as_ref();
|
||||
|
||||
let res = wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let res =
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let args = &ContractNewArgsAPI {
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
@@ -357,8 +305,7 @@ fn contract_unknown_account_impl(test_dir: &'static str) -> Result<(), libwallet
|
||||
};
|
||||
api.contract_new(m, args)?;
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
});
|
||||
assert!(res.is_err(), "expected an error for an unknown account");
|
||||
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
@@ -383,11 +330,8 @@ fn contract_missing_net_change_impl(test_dir: &'static str) -> Result<(), libwal
|
||||
let wallet1 = wallets[0].0.clone();
|
||||
let mask1 = wallets[0].1.as_ref();
|
||||
|
||||
let res = wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let res =
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let args = &ContractNewArgsAPI {
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
@@ -398,8 +342,7 @@ fn contract_missing_net_change_impl(test_dir: &'static str) -> Result<(), libwal
|
||||
};
|
||||
api.contract_new(m, args)?;
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
});
|
||||
assert!(res.is_err(), "expected an error when net_change is missing");
|
||||
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
|
||||
@@ -52,210 +52,165 @@ fn contract_accounts_switch_impl(test_dir: &'static str) -> Result<(), libwallet
|
||||
// wallet1::account1 should have 1 in account1 (1 spendable)
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account1")?;
|
||||
w.set_account_by_name("account1")?;
|
||||
}
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 10);
|
||||
assert_eq!(wallet1_info.total, reward);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, reward);
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 1);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 10);
|
||||
assert_eq!(wallet1_info.total, reward);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, reward);
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 1);
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// wallet1::account2 should have 2 in account1 (2 spendable)
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account2")?;
|
||||
w.set_account_by_name("account2")?;
|
||||
}
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
// check last confirmed height on this account is different from above (should be 0)
|
||||
let (_, wallet1_info) = api.retrieve_summary_info(m, false, 1)?;
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 3);
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 10);
|
||||
assert_eq!(wallet1_info.total, 2 * reward);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, 2 * reward);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 2);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
// check last confirmed height on this account is different from above (should be 0)
|
||||
let (_, wallet1_info) = api.retrieve_summary_info(m, false, 1)?;
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 3);
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 10);
|
||||
assert_eq!(wallet1_info.total, 2 * reward);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, 2 * reward);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 2);
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// Make a transaction by sending 5 coins from wallet1::account1 -> wallet2::account2
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account1")?;
|
||||
w.set_account_by_name("account1")?;
|
||||
}
|
||||
|
||||
let mut slate = Slate::blank(0, true); // this gets overriden below
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
// Send wallet inititates a standard transaction with --send=5
|
||||
let args = &ContractNewArgsAPI {
|
||||
ttl_blocks: Some(20),
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(-5_000_000_000),
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
slate = api.contract_new(m, args)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
// Send wallet inititates a standard transaction with --send=5
|
||||
let args = &ContractNewArgsAPI {
|
||||
ttl_blocks: Some(20),
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(-5_000_000_000),
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
slate = api.contract_new(m, args)?;
|
||||
Ok(())
|
||||
})?;
|
||||
assert_eq!(slate.state, SlateState::Standard1);
|
||||
assert_eq!(slate.ttl_cutoff_height, bh + 20);
|
||||
|
||||
// Receiver gets their coins on account2 where they can payjoin
|
||||
{
|
||||
wallet_inst!(wallet2, w);
|
||||
w.set_parent_key_id_by_name("account2")?;
|
||||
w.set_account_by_name("account2")?;
|
||||
}
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
// Receive wallet calls --receive=5
|
||||
let args = &mut ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(5_000_000_000),
|
||||
..Default::default()
|
||||
};
|
||||
args.proof_args.suppress_proof = true;
|
||||
slate = api.contract_sign(m, &slate, args)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet2.clone(), mask2, PathBuf::from(test_dir), |api, m| {
|
||||
// Receive wallet calls --receive=5
|
||||
let args = &mut ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(5_000_000_000),
|
||||
..Default::default()
|
||||
};
|
||||
args.proof_args.suppress_proof = true;
|
||||
slate = api.contract_sign(m, &slate, args)?;
|
||||
Ok(())
|
||||
})?;
|
||||
assert_eq!(slate.state, SlateState::Standard2);
|
||||
|
||||
// Switch accounts and finish the transaction (should use account1 to complete)
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("default")?;
|
||||
w.set_account_by_name("default")?;
|
||||
}
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, wallet_info) = api.retrieve_summary_info(m, false, 1)?;
|
||||
assert_eq!(wallet_info.last_confirmed_height, 0);
|
||||
let mut expired = slate.clone();
|
||||
expired.ttl_cutoff_height = bh;
|
||||
assert!(matches!(
|
||||
api.contract_sign(m, &expired, &ContractSetupArgsAPI::default()),
|
||||
Err(libwallet::Error::TransactionExpired)
|
||||
));
|
||||
let args = &ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.contract_sign(m, &slate, args)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let (_, wallet_info) = api.retrieve_summary_info(m, false, 1)?;
|
||||
assert_eq!(wallet_info.last_confirmed_height, 0);
|
||||
let mut expired = slate.clone();
|
||||
expired.ttl_cutoff_height = bh;
|
||||
assert!(matches!(
|
||||
api.contract_sign(m, &expired, &ContractSetupArgsAPI::default()),
|
||||
Err(libwallet::Error::TransactionExpired)
|
||||
));
|
||||
let args = &ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.contract_sign(m, &slate, args)?;
|
||||
Ok(())
|
||||
})?;
|
||||
assert_eq!(slate.state, SlateState::Standard3);
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account2")?;
|
||||
w.set_account_by_name("account2")?;
|
||||
}
|
||||
|
||||
// post tx and mine a block to wallet1::account2
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.post_tx(m, &slate, false)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
api.post_tx(m, &slate, false)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// The currently set account (account2) should not be affected by this transaction because they weren't a part of it,
|
||||
// but it did mine a block and pick the transaction fees
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 11);
|
||||
assert_eq!(
|
||||
wallet1_info.total,
|
||||
3 * reward + core::libtx::tx_fee(2, 2, 1) // we have received a block reward and the tx fee (payjoin)
|
||||
);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, 2 * reward);
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 3);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 11);
|
||||
assert_eq!(
|
||||
wallet1_info.total,
|
||||
3 * reward + core::libtx::tx_fee(2, 2, 1) // we have received a block reward and the tx fee (payjoin)
|
||||
);
|
||||
assert_eq!(wallet1_info.amount_currently_spendable, 2 * reward);
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 3);
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// Switch to wallet1::account1 and check that it sent 5 coins
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account1")?;
|
||||
w.set_account_by_name("account1")?;
|
||||
}
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 11);
|
||||
assert_eq!(
|
||||
wallet1_info.total,
|
||||
reward - 5_000_000_000 - my_fee_contribution(1, 1, 1, 2)?.fee() // we subtract also our fee contribution
|
||||
);
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 2);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, 11);
|
||||
assert_eq!(
|
||||
wallet1_info.total,
|
||||
reward - 5_000_000_000 - my_fee_contribution(1, 1, 1, 2)?.fee() // we subtract also our fee contribution
|
||||
);
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 2);
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// Switch to wallet2::account2 and check that it received 5 coins
|
||||
{
|
||||
wallet_inst!(wallet2, w);
|
||||
w.set_parent_key_id_by_name("account2")?;
|
||||
w.set_account_by_name("account2")?;
|
||||
}
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet2_refreshed);
|
||||
assert_eq!(wallet2_info.last_confirmed_height, 11);
|
||||
assert_eq!(
|
||||
wallet2_info.total,
|
||||
4 * reward + 5_000_000_000 - my_fee_contribution(1, 1, 1, 2)?.fee() // we subtract also our fee contribution for a payjoin
|
||||
);
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 5);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet2.clone(), mask2, PathBuf::from(test_dir), |api, m| {
|
||||
let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet2_refreshed);
|
||||
assert_eq!(wallet2_info.last_confirmed_height, 11);
|
||||
assert_eq!(
|
||||
wallet2_info.total,
|
||||
4 * reward + 5_000_000_000 - my_fee_contribution(1, 1, 1, 2)?.fee() // we subtract also our fee contribution for a payjoin
|
||||
);
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 5);
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// let logging finish
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
|
||||
@@ -44,7 +44,7 @@ fn contract_early_lock_tx_impl(test_dir: &'static str) -> Result<(), libwallet::
|
||||
let recv_mask = wallets[1].1.as_ref();
|
||||
|
||||
// Confirm all our outputs are unspent
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -60,7 +60,7 @@ fn contract_early_lock_tx_impl(test_dir: &'static str) -> Result<(), libwallet::
|
||||
let mut slate = Slate::blank(0, false); // this gets overriden below
|
||||
|
||||
// Call contract 'new' with --add-outputs
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -83,7 +83,7 @@ fn contract_early_lock_tx_impl(test_dir: &'static str) -> Result<(), libwallet::
|
||||
assert_eq!(slate.state, SlateState::Standard1);
|
||||
|
||||
// Assert we locked 2 inputs and prepared an unconfirmed change output
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -107,7 +107,7 @@ fn contract_early_lock_tx_impl(test_dir: &'static str) -> Result<(), libwallet::
|
||||
)?;
|
||||
|
||||
// The receiver signs without seeing the sender's locked commitments.
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
recv_wallet.clone(),
|
||||
recv_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -127,7 +127,7 @@ fn contract_early_lock_tx_impl(test_dir: &'static str) -> Result<(), libwallet::
|
||||
assert_eq!(slate.state, SlateState::Standard2);
|
||||
|
||||
// Even a commitment reserved for this contract must not be present before we add it.
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -169,7 +169,7 @@ fn contract_early_lock_tx_impl(test_dir: &'static str) -> Result<(), libwallet::
|
||||
)?;
|
||||
|
||||
// The sender adds the reserved commitments and completes the contract.
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
|
||||
@@ -55,18 +55,24 @@ fn contract_early_proofs_rsr_test_impl(
|
||||
|
||||
let mut sender_address = None;
|
||||
// Get sender address explicitly
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
|api, _m| {
|
||||
sender_address = Some(api.get_slatepack_address(send_mask, 0)?.pub_key);
|
||||
sender_address = Some(
|
||||
api.get_slatepack_address(
|
||||
send_mask,
|
||||
libwallet::slatepack::SlatepackAddressIndex(0),
|
||||
)?
|
||||
.pub_key,
|
||||
);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
let mut recipient_address = None;
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
recv_wallet.clone(),
|
||||
recv_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -79,7 +85,13 @@ fn contract_early_proofs_rsr_test_impl(
|
||||
args.setup_args.proof_args.memo = Some(PaymentMemo::new("RSR payment".into())?);
|
||||
args.setup_args.proof_args.sender_address = sender_address;
|
||||
slate = api.contract_new(m, args)?;
|
||||
recipient_address = Some(api.get_slatepack_address(recv_mask, 0)?.pub_key);
|
||||
recipient_address = Some(
|
||||
api.get_slatepack_address(
|
||||
recv_mask,
|
||||
libwallet::slatepack::SlatepackAddressIndex(0),
|
||||
)?
|
||||
.pub_key,
|
||||
);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
@@ -87,7 +99,7 @@ fn contract_early_proofs_rsr_test_impl(
|
||||
assert_eq!(slate.state, SlateState::Invoice1);
|
||||
slate = common::roundtrip_slate(&slate, 5)?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -103,7 +115,7 @@ fn contract_early_proofs_rsr_test_impl(
|
||||
slate = common::roundtrip_slate(&slate, 5)?;
|
||||
|
||||
// Send wallet finalizes and posts
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
recv_wallet.clone(),
|
||||
recv_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -116,7 +128,7 @@ fn contract_early_proofs_rsr_test_impl(
|
||||
assert_eq!(slate.state, SlateState::Invoice3);
|
||||
slate = common::roundtrip_slate(&slate, 5)?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -132,7 +144,7 @@ fn contract_early_proofs_rsr_test_impl(
|
||||
bh += 3;
|
||||
|
||||
// Assert changes in receive wallet
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
recv_wallet.clone(),
|
||||
recv_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -159,7 +171,7 @@ fn contract_early_proofs_rsr_test_impl(
|
||||
)?;
|
||||
|
||||
// Assert changes in send wallet
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -182,7 +194,7 @@ fn contract_early_proofs_rsr_test_impl(
|
||||
|
||||
let mut early_proof = None;
|
||||
// Now some time has passed, sender retrieves and verify the payment proof
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
|
||||
@@ -65,7 +65,7 @@ fn contract_early_proofs_srs_test_impl(test_dir: &'static str) -> Result<(), lib
|
||||
let mut slate = Slate::blank(0, true); // this gets overriden below
|
||||
|
||||
let mut sender_address = None;
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -73,7 +73,13 @@ fn contract_early_proofs_srs_test_impl(test_dir: &'static str) -> Result<(), lib
|
||||
// Send wallet inititates a standard transaction with --send=5
|
||||
let args = &common::contract_new_args(-5_000_000_000);
|
||||
slate = api.contract_new(m, args)?;
|
||||
sender_address = Some(api.get_slatepack_address(send_mask, 0)?.pub_key);
|
||||
sender_address = Some(
|
||||
api.get_slatepack_address(
|
||||
send_mask,
|
||||
libwallet::slatepack::SlatepackAddressIndex(0),
|
||||
)?
|
||||
.pub_key,
|
||||
);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
@@ -81,7 +87,7 @@ fn contract_early_proofs_srs_test_impl(test_dir: &'static str) -> Result<(), lib
|
||||
slate = common::roundtrip_slate(&slate, 4)?;
|
||||
|
||||
let mut recipient_address = None;
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
recv_wallet.clone(),
|
||||
recv_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -93,7 +99,13 @@ fn contract_early_proofs_srs_test_impl(test_dir: &'static str) -> Result<(), lib
|
||||
args.proof_args.memo = Some(PaymentMemo::new("SRS payment".into())?);
|
||||
args.proof_args.sender_address = sender_address;
|
||||
slate = api.contract_sign(m, &slate, args)?;
|
||||
recipient_address = Some(api.get_slatepack_address(recv_mask, 0)?.pub_key);
|
||||
recipient_address = Some(
|
||||
api.get_slatepack_address(
|
||||
recv_mask,
|
||||
libwallet::slatepack::SlatepackAddressIndex(0),
|
||||
)?
|
||||
.pub_key,
|
||||
);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
@@ -102,7 +114,7 @@ fn contract_early_proofs_srs_test_impl(test_dir: &'static str) -> Result<(), lib
|
||||
|
||||
// Send wallet finalizes and posts
|
||||
//let mut sender_part_sig = None;
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -120,7 +132,7 @@ fn contract_early_proofs_srs_test_impl(test_dir: &'static str) -> Result<(), lib
|
||||
assert_eq!(slate.state, SlateState::Standard3);
|
||||
slate = common::roundtrip_slate(&slate, 5)?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -136,7 +148,7 @@ fn contract_early_proofs_srs_test_impl(test_dir: &'static str) -> Result<(), lib
|
||||
bh += 3;
|
||||
|
||||
// Assert changes in receive wallet
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
recv_wallet.clone(),
|
||||
recv_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -163,7 +175,7 @@ fn contract_early_proofs_srs_test_impl(test_dir: &'static str) -> Result<(), lib
|
||||
)?;
|
||||
|
||||
// Assert changes in send wallet
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -186,7 +198,7 @@ fn contract_early_proofs_srs_test_impl(test_dir: &'static str) -> Result<(), lib
|
||||
|
||||
let mut early_proof = None;
|
||||
// Now some time has passed, sender retrieves and verify the payment proof
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -243,7 +255,7 @@ fn contract_early_proofs_srs_test_impl(test_dir: &'static str) -> Result<(), lib
|
||||
// export and verify through the CLI
|
||||
let proof_file = format!("{}/early_proof.json", test_dir);
|
||||
let tampered_file = format!("{}/early_proof_tampered.json", test_dir);
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
|
||||
@@ -41,51 +41,10 @@ fn contract_revoke_other_account_impl(test_dir: &'static str) -> Result<(), libw
|
||||
let mask1 = wallets[0].1.as_ref();
|
||||
|
||||
// Create an early-locked contract in the default account.
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.contract_new(
|
||||
m,
|
||||
&ContractNewArgsAPI {
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(-1_000_000_000),
|
||||
num_participants: 2,
|
||||
add_outputs: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let mut default_tx_id = 0;
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
default_tx_id = txs.last().unwrap().id;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
// Create another early-locked contract in account1.
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account1")?;
|
||||
}
|
||||
let mut slate = Slate::blank(0, true);
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let args = &ContractNewArgsAPI {
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
api.contract_new(
|
||||
m,
|
||||
&ContractNewArgsAPI {
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(-1_000_000_000),
|
||||
@@ -94,96 +53,101 @@ fn contract_revoke_other_account_impl(test_dir: &'static str) -> Result<(), libw
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.contract_new(m, args)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
},
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
let mut default_tx_id = 0;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
default_tx_id = txs.last().unwrap().id;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// Create another early-locked contract in account1.
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_account_by_name("account1")?;
|
||||
}
|
||||
let mut slate = Slate::blank(0, true);
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let args = &ContractNewArgsAPI {
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(-1_000_000_000),
|
||||
num_participants: 2,
|
||||
add_outputs: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.contract_new(m, args)?;
|
||||
Ok(())
|
||||
})?;
|
||||
assert_eq!(slate.state, SlateState::Standard1);
|
||||
|
||||
// Grab the tx id and confirm an input is locked under account1.
|
||||
let mut tx_id = 0;
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
tx_id = txs.last().unwrap().id;
|
||||
let (_, outs) = api.retrieve_outputs(m, true, false, None)?;
|
||||
assert!(outs.iter().any(|o| o.output.status == OutputStatus::Locked));
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
tx_id = txs.last().unwrap().id;
|
||||
let (_, outs) = api.retrieve_outputs(m, true, false, None)?;
|
||||
assert!(outs.iter().any(|o| o.output.status == OutputStatus::Locked));
|
||||
Ok(())
|
||||
})?;
|
||||
assert_eq!(tx_id, default_tx_id);
|
||||
|
||||
// Switch the active account to "default" — different from the inputs' account.
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("default")?;
|
||||
w.set_account_by_name("default")?;
|
||||
}
|
||||
|
||||
// Revoke account1 while the default account is active.
|
||||
let mut revoked = None;
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
revoked = api.contract_revoke(
|
||||
m,
|
||||
&ContractRevokeArgsAPI {
|
||||
tx_id,
|
||||
src_acct_name: Some("account1".to_string()),
|
||||
},
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
revoked = api.contract_revoke(
|
||||
m,
|
||||
&ContractRevokeArgsAPI {
|
||||
tx_id,
|
||||
src_acct_name: Some("account1".to_string()),
|
||||
},
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
assert!(
|
||||
revoked.is_some(),
|
||||
"revoke should produce a self-spend slate"
|
||||
);
|
||||
|
||||
// The default account's transaction is still locked.
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, outs) = api.retrieve_outputs(m, true, false, None)?;
|
||||
assert!(outs.iter().any(|o| {
|
||||
o.output.status == OutputStatus::Locked
|
||||
&& o.output.tx_log_entry == Some(default_tx_id)
|
||||
}));
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let (_, outs) = api.retrieve_outputs(m, true, false, None)?;
|
||||
assert!(outs.iter().any(|o| {
|
||||
o.output.status == OutputStatus::Locked && o.output.tx_log_entry == Some(default_tx_id)
|
||||
}));
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// Back on account1: the original tx is cancelled and no input is left locked.
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("account1")?;
|
||||
w.set_account_by_name("account1")?;
|
||||
}
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let query = libwallet::RetrieveTxQueryArgs {
|
||||
exclude_cancelled: Some(false),
|
||||
..Default::default()
|
||||
};
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, Some(query))?;
|
||||
let tx = txs.iter().find(|t| t.id == tx_id).unwrap();
|
||||
assert!(
|
||||
format!("{:?}", tx.tx_type).contains("Cancelled"),
|
||||
"original tx should be cancelled, was {:?}",
|
||||
tx.tx_type
|
||||
);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let query = libwallet::RetrieveTxQueryArgs {
|
||||
exclude_cancelled: Some(false),
|
||||
..Default::default()
|
||||
};
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, Some(query))?;
|
||||
let tx = txs.iter().find(|t| t.id == tx_id).unwrap();
|
||||
assert!(
|
||||
format!("{:?}", tx.tx_type).contains("Cancelled"),
|
||||
"original tx should be cancelled, was {:?}",
|
||||
tx.tx_type
|
||||
);
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
@@ -221,15 +185,10 @@ fn contract_revoke_resume_impl(test_dir: &'static str) -> Result<(), wallet::Err
|
||||
|
||||
// Send (with early lock), locking an input under the contract tx.
|
||||
let mut slate = Slate::blank(0, true);
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
slate = api.contract_new(m, &args)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
slate = api.contract_new(m, &args)?;
|
||||
Ok(())
|
||||
})?;
|
||||
assert_eq!(slate.state, SlateState::Standard1);
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
@@ -248,34 +207,24 @@ fn contract_revoke_resume_impl(test_dir: &'static str) -> Result<(), wallet::Err
|
||||
}
|
||||
|
||||
let mut tx_id = 0;
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
tx_id = txs.last().unwrap().id;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
tx_id = txs.last().unwrap().id;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// Simulate a revoke that crashed right after cancelling: cancel the tx (inputs become
|
||||
// Unspent, still tagged with tx_id) but do NOT build the self-spend.
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.cancel_tx(m, Some(tx_id), None)?;
|
||||
let (_, outs) = api.retrieve_outputs(m, true, false, None)?;
|
||||
assert!(
|
||||
outs.iter().any(|o| o.output.status == OutputStatus::Unspent
|
||||
&& o.output.tx_log_entry == Some(tx_id)),
|
||||
"input should be Unspent but still tagged with the cancelled tx"
|
||||
);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
api.cancel_tx(m, Some(tx_id), None)?;
|
||||
let (_, outs) = api.retrieve_outputs(m, true, false, None)?;
|
||||
assert!(
|
||||
outs.iter().any(|o| o.output.status == OutputStatus::Unspent
|
||||
&& o.output.tx_log_entry == Some(tx_id)),
|
||||
"input should be Unspent but still tagged with the cancelled tx"
|
||||
);
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// Resume through the command path and write the self-spend to the requested file.
|
||||
let outfile = format!("{}/revoke.slatepack", test_dir);
|
||||
|
||||
@@ -122,7 +122,7 @@ fn contract_rsr_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
},
|
||||
);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -166,7 +166,7 @@ fn contract_rsr_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
);
|
||||
|
||||
// Receive wallet finalizes and posts
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
recv_wallet.clone(),
|
||||
recv_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -196,7 +196,7 @@ fn contract_rsr_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
);
|
||||
|
||||
// Send wallet posts so receive wallet doesn't get the mined amount
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -212,7 +212,7 @@ fn contract_rsr_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
bh += 3;
|
||||
|
||||
// Assert changes in receive wallet
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
recv_wallet.clone(),
|
||||
recv_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -240,7 +240,7 @@ fn contract_rsr_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
)?;
|
||||
|
||||
// Assert changes in send wallet
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
|
||||
@@ -42,7 +42,7 @@ fn contract_self_spend_tx_impl(test_dir: &'static str) -> Result<(), libwallet::
|
||||
|
||||
let mut slate = Slate::blank(0, true); // this gets overriden below
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -64,7 +64,7 @@ fn contract_self_spend_tx_impl(test_dir: &'static str) -> Result<(), libwallet::
|
||||
assert_eq!(slate.state, SlateState::Standard1);
|
||||
|
||||
// Send wallet finalizes and posts
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -80,7 +80,7 @@ fn contract_self_spend_tx_impl(test_dir: &'static str) -> Result<(), libwallet::
|
||||
// In the case of a self-spend, we just finish the slate when it's in the Standard2 state
|
||||
assert_eq!(slate.state, SlateState::Standard2);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -96,7 +96,7 @@ fn contract_self_spend_tx_impl(test_dir: &'static str) -> Result<(), libwallet::
|
||||
bh += 3;
|
||||
|
||||
// Assert changes in send wallet
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -148,7 +148,7 @@ fn contract_fee_floor_impl(test_dir: &'static str) -> Result<(), libwallet::Erro
|
||||
let wallet = wallets[0].0.clone();
|
||||
let mask = wallets[0].1.as_ref();
|
||||
|
||||
wallet::controller::owner_single_use(wallet, mask, PathBuf::from(test_dir), |api, m| {
|
||||
common::owner_single_use(wallet, mask, PathBuf::from(test_dir), |api, m| {
|
||||
let slate = api.contract_new(
|
||||
m,
|
||||
&ContractNewArgsAPI {
|
||||
|
||||
@@ -40,7 +40,7 @@ fn contract_self_spend_cancel_impl(test_dir: &'static str) -> Result<(), libwall
|
||||
|
||||
let mut slate = Slate::blank(0, true); // this gets overriden below
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -62,7 +62,7 @@ fn contract_self_spend_cancel_impl(test_dir: &'static str) -> Result<(), libwall
|
||||
assert_eq!(slate.state, SlateState::Standard1);
|
||||
|
||||
// Send wallet finalizes and posts
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -73,7 +73,7 @@ fn contract_self_spend_cancel_impl(test_dir: &'static str) -> Result<(), libwall
|
||||
)?;
|
||||
|
||||
// Assert tx log has been cancelled
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -149,7 +149,7 @@ fn contract_self_spend_cancel_missing_stored_tx_impl(
|
||||
let send_mask = wallets[0].1.as_ref();
|
||||
|
||||
let mut slate = Slate::blank(0, true);
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -169,7 +169,7 @@ fn contract_self_spend_cancel_missing_stored_tx_impl(
|
||||
)?;
|
||||
|
||||
// Signing a self-spend completes the slate, so the transaction is stored
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -186,7 +186,7 @@ fn contract_self_spend_cancel_missing_stored_tx_impl(
|
||||
|
||||
// Signing locked our inputs, so the cancel below has something to release, and the
|
||||
// entry records where the transaction was stored, as a standard send does
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -208,7 +208,7 @@ fn contract_self_spend_cancel_missing_stored_tx_impl(
|
||||
std::fs::remove_file(&stored).unwrap();
|
||||
|
||||
// Cancelling still releases the inputs
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -218,7 +218,7 @@ fn contract_self_spend_cancel_missing_stored_tx_impl(
|
||||
},
|
||||
)?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
|
||||
@@ -45,7 +45,7 @@ fn contract_self_spend_custom_tx_impl(test_dir: &'static str) -> Result<(), libw
|
||||
let mut use_inputs = String::from("");
|
||||
|
||||
let mut plain_input = None;
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -74,7 +74,7 @@ fn contract_self_spend_custom_tx_impl(test_dir: &'static str) -> Result<(), libw
|
||||
15 * consensus::GRIN_BASE,
|
||||
]),
|
||||
};
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -96,7 +96,7 @@ fn contract_self_spend_custom_tx_impl(test_dir: &'static str) -> Result<(), libw
|
||||
assert_eq!(slate.state, SlateState::Standard1);
|
||||
|
||||
// Send wallet finalizes and posts
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -114,7 +114,7 @@ fn contract_self_spend_custom_tx_impl(test_dir: &'static str) -> Result<(), libw
|
||||
// In the case of a self-spend, we just finish the slate when it's in the Standard2 state
|
||||
assert_eq!(slate.state, SlateState::Standard2);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -130,7 +130,7 @@ fn contract_self_spend_custom_tx_impl(test_dir: &'static str) -> Result<(), libw
|
||||
bh += 3;
|
||||
|
||||
// Assert changes in send wallet
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -151,7 +151,7 @@ fn contract_self_spend_custom_tx_impl(test_dir: &'static str) -> Result<(), libw
|
||||
},
|
||||
)?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -195,7 +195,7 @@ fn contract_self_spend_custom_tx_impl(test_dir: &'static str) -> Result<(), libw
|
||||
)?;
|
||||
|
||||
let (plain_input, plain_commitment) = plain_input.expect("plain output was not found");
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -270,7 +270,7 @@ fn contract_min_confirmations_impl(test_dir: &'static str) -> Result<(), libwall
|
||||
let recv_mask = wallets[1].1.as_ref();
|
||||
let mut slate = Slate::blank(0, true);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -294,55 +294,45 @@ fn contract_min_confirmations_impl(test_dir: &'static str) -> Result<(), libwall
|
||||
)?;
|
||||
assert_eq!(slate.state, SlateState::Standard1);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
recv_wallet,
|
||||
recv_mask,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, outputs) = api.retrieve_outputs(m, true, false, None)?;
|
||||
assert_eq!(outputs.len(), 1);
|
||||
assert!(outputs[0].output.eligible_to_spend(bh, 1));
|
||||
assert!(!outputs[0].output.eligible_to_spend(bh, 10));
|
||||
slate = api.contract_sign(
|
||||
m,
|
||||
&slate,
|
||||
&ContractSetupArgsAPI {
|
||||
net_change: Some(consensus::GRIN_BASE as i64),
|
||||
selection_args: OutputSelectionArgs {
|
||||
minimum_confirmations: Some(10),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
assert_eq!(slate.state, SlateState::Standard2);
|
||||
assert_eq!(slate.tx_or_err()?.inputs().len(), 0);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
send_wallet,
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let args = |minimum| ContractSetupArgsAPI {
|
||||
common::owner_single_use(recv_wallet, recv_mask, PathBuf::from(test_dir), |api, m| {
|
||||
let (_, outputs) = api.retrieve_outputs(m, true, false, None)?;
|
||||
assert_eq!(outputs.len(), 1);
|
||||
assert!(outputs[0].output.eligible_to_spend(bh, 1));
|
||||
assert!(!outputs[0].output.eligible_to_spend(bh, 10));
|
||||
slate = api.contract_sign(
|
||||
m,
|
||||
&slate,
|
||||
&ContractSetupArgsAPI {
|
||||
net_change: Some(consensus::GRIN_BASE as i64),
|
||||
selection_args: OutputSelectionArgs {
|
||||
minimum_confirmations: minimum,
|
||||
minimum_confirmations: Some(10),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
let err = api.contract_sign(m, &slate, &args(Some(12))).unwrap_err();
|
||||
assert!(matches!(
|
||||
err,
|
||||
libwallet::Error::GenericError(ref msg)
|
||||
if msg == "Can't change minimum confirmations after contract setup. setup:10, current:12"
|
||||
));
|
||||
slate = api.contract_sign(m, &slate, &args(None))?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
},
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
assert_eq!(slate.state, SlateState::Standard2);
|
||||
assert_eq!(slate.tx_or_err()?.inputs().len(), 0);
|
||||
|
||||
common::owner_single_use(send_wallet, send_mask, PathBuf::from(test_dir), |api, m| {
|
||||
let args = |minimum| ContractSetupArgsAPI {
|
||||
selection_args: OutputSelectionArgs {
|
||||
minimum_confirmations: minimum,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
let err = api.contract_sign(m, &slate, &args(Some(12))).unwrap_err();
|
||||
assert!(matches!(
|
||||
err,
|
||||
libwallet::Error::GenericError(ref msg)
|
||||
if msg == "Can't change minimum confirmations after contract setup. setup:10, current:12"
|
||||
));
|
||||
slate = api.contract_sign(m, &slate, &args(None))?;
|
||||
Ok(())
|
||||
})?;
|
||||
assert_eq!(slate.state, SlateState::Standard3);
|
||||
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
|
||||
@@ -82,7 +82,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
|
||||
let mut slate = Slate::blank(0, false); // this gets overriden below
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -99,14 +99,14 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
let progress = common::wallet_progress(api, m)?;
|
||||
for count in [0, 3] {
|
||||
args.setup_args.num_participants = count;
|
||||
let err = api.contract_new(m, &mut args).unwrap_err();
|
||||
let err = api.contract_new(m, &args).unwrap_err();
|
||||
assert_participant_error(err, count);
|
||||
}
|
||||
assert_eq!(common::wallet_progress(api, m)?, progress);
|
||||
|
||||
args.setup_args.num_participants = 2;
|
||||
args.ttl_blocks = Some(0);
|
||||
let err = api.contract_new(m, &mut args).unwrap_err();
|
||||
let err = api.contract_new(m, &args).unwrap_err();
|
||||
assert!(matches!(
|
||||
err,
|
||||
libwallet::Error::GenericError(ref msg)
|
||||
@@ -114,7 +114,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
));
|
||||
args.ttl_blocks = Some(20);
|
||||
args.setup_args.fee_rate = Some(0);
|
||||
let err = api.contract_new(m, &mut args).unwrap_err();
|
||||
let err = api.contract_new(m, &args).unwrap_err();
|
||||
assert!(matches!(
|
||||
err,
|
||||
libwallet::Error::GenericError(ref msg)
|
||||
@@ -122,7 +122,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
));
|
||||
args.setup_args.fee_rate = None;
|
||||
assert_eq!(common::wallet_progress(api, m)?, progress);
|
||||
slate = api.contract_new(m, &mut args)?;
|
||||
slate = api.contract_new(m, &args)?;
|
||||
let tx_log = common::tx_log_for_slate(api, m, &slate)?;
|
||||
assert_eq!(tx_log.ttl_cutoff_height, Some(ttl_cutoff));
|
||||
Ok(())
|
||||
@@ -144,7 +144,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
signatures: 0,
|
||||
},
|
||||
);
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -195,7 +195,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
},
|
||||
)?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
recv_wallet.clone(),
|
||||
recv_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -303,7 +303,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
},
|
||||
)?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
recv_wallet.clone(),
|
||||
recv_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -347,7 +347,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
signatures: 1,
|
||||
},
|
||||
);
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
recv_wallet.clone(),
|
||||
recv_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -362,7 +362,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -383,7 +383,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
)?;
|
||||
|
||||
// The sender must reject an unused commitment from its wallet if it was inserted by the receiver.
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -513,7 +513,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
)?;
|
||||
|
||||
// Send wallet finalizes and posts
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -567,7 +567,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
signatures: 2,
|
||||
},
|
||||
);
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
recv_wallet.clone(),
|
||||
recv_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -577,7 +577,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -603,7 +603,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
},
|
||||
)?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -619,7 +619,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
bh += 3;
|
||||
|
||||
// Assert changes in receive wallet
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
recv_wallet.clone(),
|
||||
recv_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -646,7 +646,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
)?;
|
||||
|
||||
// Assert changes in send wallet
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -721,7 +721,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
let receiver_fee = my_fee_contribution(0, 1, 1, 2)?.fee();
|
||||
let net = i64::try_from((receiver_fee + participant_fee) / 2).unwrap();
|
||||
let mut small = Slate::blank(0, false);
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -734,7 +734,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
recv_wallet.clone(),
|
||||
recv_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -745,7 +745,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
|
||||
@@ -45,7 +45,7 @@ fn contract_srs_mwixnet_tx_impl(test_dir: &'static str) -> Result<(), libwallet:
|
||||
|
||||
let mut slate = Slate::blank(0, true); // this gets overriden below
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -65,7 +65,7 @@ fn contract_srs_mwixnet_tx_impl(test_dir: &'static str) -> Result<(), libwallet:
|
||||
)?;
|
||||
assert_eq!(slate.state, SlateState::Standard1);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
recv_wallet.clone(),
|
||||
recv_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -84,7 +84,7 @@ fn contract_srs_mwixnet_tx_impl(test_dir: &'static str) -> Result<(), libwallet:
|
||||
assert_eq!(slate.state, SlateState::Standard2);
|
||||
|
||||
// Send wallet finalizes and posts
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -100,7 +100,7 @@ fn contract_srs_mwixnet_tx_impl(test_dir: &'static str) -> Result<(), libwallet:
|
||||
)?;
|
||||
assert_eq!(slate.state, SlateState::Standard3);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -114,7 +114,7 @@ fn contract_srs_mwixnet_tx_impl(test_dir: &'static str) -> Result<(), libwallet:
|
||||
test_framework::award_blocks_to_wallet(&chain, send_wallet.clone(), send_mask, 3, false);
|
||||
|
||||
// Recipient wallet sends outputs to mwixnet
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
recv_wallet.clone(),
|
||||
recv_mask,
|
||||
PathBuf::from(test_dir),
|
||||
@@ -128,19 +128,23 @@ fn contract_srs_mwixnet_tx_impl(test_dir: &'static str) -> Result<(), libwallet:
|
||||
let server_pubkey_str_3 =
|
||||
"b58ece97d60e71bb7e53218400b0d67bfe6a3cb7d3b4a67a44f8fb7c525cbca5";
|
||||
let server_key_1 =
|
||||
SecretKey::from_slice(&secp, &grin_util::from_hex(&server_pubkey_str_1).unwrap())
|
||||
SecretKey::from_slice(&secp, &grin_util::from_hex(server_pubkey_str_1).unwrap())
|
||||
.unwrap();
|
||||
let server_key_2 =
|
||||
SecretKey::from_slice(&secp, &grin_util::from_hex(&server_pubkey_str_2).unwrap())
|
||||
SecretKey::from_slice(&secp, &grin_util::from_hex(server_pubkey_str_2).unwrap())
|
||||
.unwrap();
|
||||
let server_key_3 =
|
||||
SecretKey::from_slice(&secp, &grin_util::from_hex(&server_pubkey_str_3).unwrap())
|
||||
SecretKey::from_slice(&secp, &grin_util::from_hex(server_pubkey_str_3).unwrap())
|
||||
.unwrap();
|
||||
drop(secp);
|
||||
let params = MixnetReqCreationParams {
|
||||
server_keys: vec![server_key_1, server_key_2, server_key_3],
|
||||
fee_per_hop: 50_000_000,
|
||||
server_keys: [server_key_1, server_key_2, server_key_3]
|
||||
.iter()
|
||||
.map(libwallet::mwixnet::MwixnetServerPublicKey::from_secret)
|
||||
.collect(),
|
||||
fee_per_hop: Some(50_000_000),
|
||||
};
|
||||
let outputs = api.retrieve_outputs(recv_mask, false, false, None)?;
|
||||
let outputs = api.retrieve_outputs(recv_mask, false, true, None)?;
|
||||
// get last output
|
||||
let last_output = outputs.1[outputs.1.len() - 1].clone();
|
||||
|
||||
@@ -148,9 +152,12 @@ fn contract_srs_mwixnet_tx_impl(test_dir: &'static str) -> Result<(), libwallet:
|
||||
|
||||
// check output we created comsig for is indeed locked
|
||||
let outputs = api.retrieve_outputs(recv_mask, false, false, None)?;
|
||||
// get last output
|
||||
let last_output = outputs.1[outputs.1.len() - 1].clone();
|
||||
assert!(last_output.output.status == libwallet::OutputStatus::Locked);
|
||||
let input = outputs
|
||||
.1
|
||||
.iter()
|
||||
.find(|output| output.commit == last_output.commit)
|
||||
.unwrap();
|
||||
assert_eq!(input.output.status, libwallet::OutputStatus::Locked);
|
||||
|
||||
Ok(())
|
||||
},
|
||||
|
||||
+89
-185
@@ -27,11 +27,12 @@ use std::sync::atomic::Ordering;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use grin_wallet_libwallet::{InitTxArgs, IssueInvoiceTxArgs, Slate};
|
||||
use grin_wallet_libwallet::{InitTxArgs, IssueInvoiceTxArgs};
|
||||
|
||||
#[macro_use]
|
||||
mod common;
|
||||
use common::{clean_output_dir, create_wallet_proxy, setup};
|
||||
use grin_wallet_libwallet::slatepack::SlatepackAddressIndex;
|
||||
|
||||
/// self send impl
|
||||
fn file_exchange_test_impl(test_dir: &'static str, use_bin: bool) -> Result<(), libwallet::Error> {
|
||||
@@ -50,9 +51,10 @@ fn file_exchange_test_impl(test_dir: &'static str, use_bin: bool) -> Result<(),
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
@@ -61,9 +63,10 @@ fn file_exchange_test_impl(test_dir: &'static str, use_bin: bool) -> Result<(),
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -76,33 +79,17 @@ fn file_exchange_test_impl(test_dir: &'static str, use_bin: bool) -> Result<(),
|
||||
let reward = core::consensus::REWARD;
|
||||
|
||||
// add some accounts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.create_account_path(m, "mining")?;
|
||||
api.create_account_path(m, "listener")?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api1.create_account_path(mask1, "mining")?;
|
||||
api1.create_account_path(mask1, "listener")?;
|
||||
|
||||
// add some accounts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.create_account_path(m, "account1")?;
|
||||
api.create_account_path(m, "account2")?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api2.create_account_path(mask2, "account1")?;
|
||||
api2.create_account_path(mask2, "account2")?;
|
||||
|
||||
// Get some mining done
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("mining")?;
|
||||
w.set_account_by_name("mining")?;
|
||||
}
|
||||
let mut bh = 10u64;
|
||||
let _ =
|
||||
@@ -122,37 +109,29 @@ fn file_exchange_test_impl(test_dir: &'static str, use_bin: bool) -> Result<(),
|
||||
};
|
||||
|
||||
// Should have 5 in account1 (5 spendable), 5 in account (2 spendable)
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward);
|
||||
// send to send
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: Some("mining".to_owned()),
|
||||
amount: reward * 2,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
let slate = api.init_send_tx(m, args)?;
|
||||
// output tx file
|
||||
PathToSlate((&send_file).into()).put_tx(&slate, use_bin)?;
|
||||
api.tx_lock_outputs(m, &slate)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (wallet1_refreshed, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward);
|
||||
// send to send
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: Some("mining".to_owned()),
|
||||
amount: reward * 2,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
let slate = api1.init_send_tx(mask1, args)?;
|
||||
// output tx file
|
||||
PathToSlate((&send_file).into()).put_tx(&slate, use_bin)?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
|
||||
// Get some mining done
|
||||
{
|
||||
wallet_inst!(wallet2, w);
|
||||
w.set_parent_key_id_by_name("account1")?;
|
||||
w.set_account_by_name("account1")?;
|
||||
}
|
||||
|
||||
let mut slate = PathToSlate((&send_file).into()).get_tx()?.0;
|
||||
@@ -169,52 +148,28 @@ fn file_exchange_test_impl(test_dir: &'static str, use_bin: bool) -> Result<(),
|
||||
},
|
||||
)?;
|
||||
|
||||
// wallet 1 finalises and posts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let mut slate = PathToSlate(receive_file.into()).get_tx()?.0;
|
||||
slate = api.finalize_tx(m, &slate)?;
|
||||
// Output final file for reference
|
||||
PathToSlate((&final_file).into()).put_tx(&slate, use_bin)?;
|
||||
api.post_tx(m, &slate, false)?;
|
||||
bh += 1;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// wallet 1 finalizes and posts
|
||||
let mut slate = PathToSlate(receive_file.into()).get_tx()?.0;
|
||||
slate = api1.finalize_tx(mask1, &slate)?;
|
||||
// Output final file for reference
|
||||
PathToSlate((&final_file).into()).put_tx(&slate, use_bin)?;
|
||||
api1.post_tx(mask1, &slate, false)?;
|
||||
bh += 1;
|
||||
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 3, false);
|
||||
bh += 3;
|
||||
|
||||
// Check total in mining account
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward - reward * 2);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (wallet1_refreshed, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward - reward * 2);
|
||||
|
||||
// Check total in 'wallet 2' account
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet2_refreshed);
|
||||
assert_eq!(wallet2_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet2_info.total, 2 * reward);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (wallet2_refreshed, wallet2_info) = api2.retrieve_summary_info(mask2, true, 1)?;
|
||||
assert!(wallet2_refreshed);
|
||||
assert_eq!(wallet2_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet2_info.total, 2 * reward);
|
||||
|
||||
// Now other types of exchange, for reference
|
||||
// Invoice transaction
|
||||
@@ -231,44 +186,27 @@ fn file_exchange_test_impl(test_dir: &'static str, use_bin: bool) -> Result<(),
|
||||
),
|
||||
};
|
||||
|
||||
let mut slate = Slate::blank(2, true);
|
||||
let args = IssueInvoiceTxArgs {
|
||||
amount: 1000000000,
|
||||
..Default::default()
|
||||
};
|
||||
let mut slate = api2.issue_invoice_tx(mask2, args)?;
|
||||
PathToSlate((&send_file).into()).put_tx(&slate, use_bin)?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let args = IssueInvoiceTxArgs {
|
||||
amount: 1000000000,
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.issue_invoice_tx(m, args)?;
|
||||
PathToSlate((&send_file).into()).put_tx(&slate, use_bin)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: slate.amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
slate = PathToSlate((&send_file).into()).get_tx()?.0;
|
||||
slate = api1.process_invoice_tx(mask1, &slate, args)?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
PathToSlate((&receive_file).into()).put_tx(&slate, use_bin)?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: slate.amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
slate = PathToSlate((&send_file).into()).get_tx()?.0;
|
||||
slate = api.process_invoice_tx(m, &slate, args)?;
|
||||
api.tx_lock_outputs(m, &slate)?;
|
||||
PathToSlate((&receive_file).into()).put_tx(&slate, use_bin)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
wallet::controller::foreign_single_use(
|
||||
wallet2.clone(),
|
||||
PathBuf::from(test_dir),
|
||||
@@ -281,15 +219,8 @@ fn file_exchange_test_impl(test_dir: &'static str, use_bin: bool) -> Result<(),
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.post_tx(m, &slate, false)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
api1.post_tx(mask1, &slate, false)?;
|
||||
|
||||
// Standard, with payment proof
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 3, false);
|
||||
@@ -305,40 +236,22 @@ fn file_exchange_test_impl(test_dir: &'static str, use_bin: bool) -> Result<(),
|
||||
format!("{}/standard_pp_S3.txbin", test_dir),
|
||||
),
|
||||
};
|
||||
let mut slate = Slate::blank(2, true);
|
||||
let mut address = None;
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
address = Some(api.get_slatepack_address(m, 0)?);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let address = Some(api2.get_slatepack_address(mask2, SlatepackAddressIndex(0))?);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
// send to send
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: Some("mining".to_owned()),
|
||||
amount: reward,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
payment_proof_recipient_address: address.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
let slate = api.init_send_tx(m, args)?;
|
||||
PathToSlate((&send_file).into()).put_tx(&slate, use_bin)?;
|
||||
api.tx_lock_outputs(m, &slate)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// send to send
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: Some("mining".to_owned()),
|
||||
amount: reward,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
payment_proof_recipient_address: address.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
let mut slate = api1.init_send_tx(mask1, args)?;
|
||||
PathToSlate((&send_file).into()).put_tx(&slate, use_bin)?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
|
||||
wallet::controller::foreign_single_use(
|
||||
wallet2.clone(),
|
||||
@@ -352,21 +265,12 @@ fn file_exchange_test_impl(test_dir: &'static str, use_bin: bool) -> Result<(),
|
||||
},
|
||||
)?;
|
||||
|
||||
// wallet 1 finalises and posts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
slate = PathToSlate(receive_file.into()).get_tx()?.0;
|
||||
slate = api.finalize_tx(m, &slate)?;
|
||||
// Output final file for reference
|
||||
PathToSlate((&final_file).into()).put_tx(&slate, use_bin)?;
|
||||
api.post_tx(m, &slate, false)?;
|
||||
bh += 1;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// wallet 1 finalizes and posts
|
||||
slate = PathToSlate(receive_file.into()).get_tx()?.0;
|
||||
slate = api1.finalize_tx(mask1, &slate)?;
|
||||
// Output final file for reference
|
||||
PathToSlate((&final_file).into()).put_tx(&slate, use_bin)?;
|
||||
api1.post_tx(mask1, &slate, false)?;
|
||||
|
||||
// let logging finish
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
|
||||
+139
-231
@@ -22,7 +22,7 @@ use grin_wallet_libwallet as libwallet;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use impls::test_framework::{self, LocalWalletClient};
|
||||
use libwallet::{InitTxArgs, IssueInvoiceTxArgs, Slate, SlateState};
|
||||
use libwallet::{InitTxArgs, IssueInvoiceTxArgs, SlateState};
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
@@ -46,9 +46,10 @@ fn invoice_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
true
|
||||
true,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
@@ -57,9 +58,10 @@ fn invoice_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
true
|
||||
true,
|
||||
api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -72,56 +74,41 @@ fn invoice_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
let reward = core::consensus::REWARD;
|
||||
|
||||
// add some accounts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.create_account_path(m, "mining")?;
|
||||
api.create_account_path(m, "listener")?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api1.create_account_path(mask1, "mining")?;
|
||||
api1.create_account_path(mask1, "listener")?;
|
||||
|
||||
// Get some mining done
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("mining")?;
|
||||
w.set_account_by_name("mining")?;
|
||||
}
|
||||
let mut _bh = 10u64;
|
||||
let _ =
|
||||
test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, _bh as usize, false);
|
||||
|
||||
// Sanity check wallet 1 contents
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, _bh);
|
||||
assert_eq!(wallet1_info.total, _bh * reward);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (wallet1_refreshed, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, _bh);
|
||||
assert_eq!(wallet1_info.total, _bh * reward);
|
||||
|
||||
let mut slate = Slate::blank(2, true);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
// Wallet 2 inititates an invoice transaction, requesting payment
|
||||
let args = IssueInvoiceTxArgs {
|
||||
amount: reward * 2,
|
||||
let error = api2
|
||||
.issue_invoice_tx(
|
||||
mask2,
|
||||
IssueInvoiceTxArgs {
|
||||
amount: 0,
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.issue_invoice_tx(m, args)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
},
|
||||
)
|
||||
.unwrap_err();
|
||||
assert_eq!(error, libwallet::Error::InvalidAmount);
|
||||
|
||||
// Wallet 2 initiates an invoice transaction, requesting payment
|
||||
let args = IssueInvoiceTxArgs {
|
||||
amount: reward * 2,
|
||||
..Default::default()
|
||||
};
|
||||
let mut slate = api2.issue_invoice_tx(mask2, args)?;
|
||||
assert_eq!(slate.state, SlateState::Invoice1);
|
||||
|
||||
let receive_result = wallet::controller::foreign_single_use(
|
||||
@@ -131,16 +118,8 @@ fn invoice_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
|api| api.receive_tx(&slate, None, None).map(|_| ()),
|
||||
);
|
||||
assert_eq!(receive_result, Err(libwallet::Error::SlateState));
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, txs) = api.retrieve_txs(m, false, None, Some(slate.id), None)?;
|
||||
assert!(txs.is_empty());
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (_, txs) = api1.retrieve_txs(mask1, false, None, Some(slate.id), None)?;
|
||||
assert!(txs.is_empty());
|
||||
|
||||
// receive must reject every slate state except S1
|
||||
for state in [
|
||||
@@ -162,28 +141,35 @@ fn invoice_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
assert_eq!(res, Err(libwallet::Error::SlateState), "state {}", state);
|
||||
}
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
// Wallet 1 receives the invoice transaction
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: slate.amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.process_invoice_tx(m, &slate, args)?;
|
||||
api.tx_lock_outputs(m, &slate)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// Wallet 1 receives the invoice transaction
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: slate.amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
let mut zero_amount_slate = slate.clone();
|
||||
zero_amount_slate.amount = 0;
|
||||
assert_eq!(
|
||||
api1.process_invoice_tx(mask1, &zero_amount_slate, args.clone())
|
||||
.unwrap_err(),
|
||||
libwallet::Error::InvalidAmount
|
||||
);
|
||||
slate = api1.process_invoice_tx(mask1, &slate, args)?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
assert_eq!(slate.state, SlateState::Invoice2);
|
||||
|
||||
assert_eq!(
|
||||
api2.tx_lock_outputs(mask2, &slate),
|
||||
Err(libwallet::Error::SlateState)
|
||||
);
|
||||
let (_, txs) = api2.retrieve_txs(mask2, false, None, None, None)?;
|
||||
assert_eq!(txs.len(), 1);
|
||||
assert_eq!(txs[0].tx_type, libwallet::TxLogEntryType::TxReceived);
|
||||
|
||||
// wallet 2 finalizes and posts
|
||||
wallet::controller::foreign_single_use(
|
||||
wallet2.clone(),
|
||||
@@ -198,86 +184,54 @@ fn invoice_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
assert_eq!(slate.state, SlateState::Invoice3);
|
||||
|
||||
// wallet 1 posts so wallet 2 doesn't get the mined amount
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.post_tx(m, &slate, false)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api1.post_tx(mask1, &slate, false)?;
|
||||
_bh += 1;
|
||||
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 3, false);
|
||||
_bh += 3;
|
||||
|
||||
// Check transaction log for wallet 2
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, wallet2_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
let (refreshed, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert!(refreshed);
|
||||
assert!(txs.len() == 1);
|
||||
println!(
|
||||
"last confirmed height: {}, bh: {}",
|
||||
wallet2_info.last_confirmed_height, _bh
|
||||
);
|
||||
assert!(refreshed);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (_, wallet2_info) = api2.retrieve_summary_info(mask2, true, 1)?;
|
||||
let (refreshed, txs) = api2.retrieve_txs(mask2, true, None, None, None)?;
|
||||
assert!(refreshed);
|
||||
assert_eq!(txs.len(), 1);
|
||||
println!(
|
||||
"last confirmed height: {}, bh: {}",
|
||||
wallet2_info.last_confirmed_height, _bh
|
||||
);
|
||||
assert!(refreshed);
|
||||
|
||||
// Check transaction log for wallet 1, ensure only 1 entry
|
||||
// exists
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
let (refreshed, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert!(refreshed);
|
||||
assert_eq!(txs.len() as u64, _bh + 1);
|
||||
println!(
|
||||
"Wallet 1: last confirmed height: {}, bh: {}",
|
||||
wallet1_info.last_confirmed_height, _bh
|
||||
);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (_, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
let (refreshed, txs) = api1.retrieve_txs(mask1, true, None, None, None)?;
|
||||
assert!(refreshed);
|
||||
assert_eq!(txs.len() as u64, _bh + 1);
|
||||
println!(
|
||||
"Wallet 1: last confirmed height: {}, bh: {}",
|
||||
wallet1_info.last_confirmed_height, _bh
|
||||
);
|
||||
|
||||
// Test self-sending
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
// Wallet 1 inititates an invoice transaction, requesting payment
|
||||
let args = IssueInvoiceTxArgs {
|
||||
amount: reward * 2,
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.issue_invoice_tx(m, args)?;
|
||||
// Wallet 1 receives the invoice transaction
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: slate.amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
println!("Self invoice slate init: {}", slate);
|
||||
slate = api.process_invoice_tx(m, &slate, args)?;
|
||||
api.tx_lock_outputs(m, &slate)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// Wallet 1 initiates an invoice transaction, requesting payment
|
||||
let args = IssueInvoiceTxArgs {
|
||||
amount: reward * 2,
|
||||
..Default::default()
|
||||
};
|
||||
slate = api1.issue_invoice_tx(mask1, args)?;
|
||||
// Wallet 1 receives the invoice transaction
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: slate.amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
println!("Self invoice slate init: {}", slate);
|
||||
slate = api1.process_invoice_tx(mask1, &slate, args)?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
|
||||
println!("Self invoice slate after process: {}", slate);
|
||||
|
||||
@@ -294,112 +248,66 @@ fn invoice_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
)?;
|
||||
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 3, false);
|
||||
//bh += 3;
|
||||
|
||||
// As above, but use owner API to finalize
|
||||
let mut slate = Slate::blank(2, true);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
// Wallet 2 inititates an invoice transaction, requesting payment
|
||||
let args = IssueInvoiceTxArgs {
|
||||
amount: reward * 2,
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.issue_invoice_tx(m, args)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// Wallet 2 initiates an invoice transaction, requesting payment
|
||||
let args = IssueInvoiceTxArgs {
|
||||
amount: reward * 2,
|
||||
..Default::default()
|
||||
};
|
||||
slate = api2.issue_invoice_tx(mask2, args)?;
|
||||
assert_eq!(slate.state, SlateState::Invoice1);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
// Wallet 1 receives the invoice transaction
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: slate.amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.process_invoice_tx(m, &slate, args)?;
|
||||
api.tx_lock_outputs(m, &slate)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// Wallet 1 receives the invoice transaction
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: slate.amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
slate = api1.process_invoice_tx(mask1, &slate, args)?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
assert_eq!(slate.state, SlateState::Invoice2);
|
||||
|
||||
// wallet 2 finalizes via owner API
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
// Wallet 2 receives the invoice transaction
|
||||
slate = api.finalize_tx(m, &slate)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// Wallet 2 receives and finalizes via owner API
|
||||
slate = api2.finalize_tx(mask2, &slate)?;
|
||||
assert_eq!(slate.state, SlateState::Invoice3);
|
||||
|
||||
// test that payee can only cancel once
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 3, false);
|
||||
_bh += 3;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
// Wallet 2 inititates an invoice transaction, requesting payment
|
||||
let args = IssueInvoiceTxArgs {
|
||||
amount: reward * 2,
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.issue_invoice_tx(m, args)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// Wallet 2 initiates an invoice transaction, requesting payment
|
||||
let args = IssueInvoiceTxArgs {
|
||||
amount: reward * 2,
|
||||
..Default::default()
|
||||
};
|
||||
slate = api2.issue_invoice_tx(mask2, args)?;
|
||||
assert_eq!(slate.state, SlateState::Invoice1);
|
||||
|
||||
let orig_slate = slate.clone();
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
// Wallet 1 receives the invoice transaction
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: slate.amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.process_invoice_tx(m, &slate, args.clone())?;
|
||||
api.tx_lock_outputs(m, &slate)?;
|
||||
// Wallet 1 receives the invoice transaction
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: slate.amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
slate = api1.process_invoice_tx(mask1, &slate, args.clone())?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
|
||||
// Wallet 1 cancels the invoice transaction
|
||||
api.cancel_tx(m, None, Some(slate.id))?;
|
||||
// Wallet 1 cancels the invoice transaction
|
||||
api1.cancel_tx(mask1, None, Some(slate.id))?;
|
||||
|
||||
// Wallet 1 attempts to repay again
|
||||
let res = api.process_invoice_tx(m, &orig_slate, args);
|
||||
assert!(res.is_err());
|
||||
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// Wallet 1 attempts to repay again
|
||||
let res = api1.process_invoice_tx(mask1, &orig_slate, args);
|
||||
assert!(res.is_err());
|
||||
assert_eq!(slate.state, SlateState::Invoice2);
|
||||
|
||||
// let logging finish
|
||||
|
||||
@@ -18,9 +18,8 @@ extern crate grin_wallet_controller as wallet;
|
||||
extern crate grin_wallet_impls as impls;
|
||||
extern crate grin_wallet_libwallet as libwallet;
|
||||
|
||||
use self::libwallet::{InitTxArgs, Slate};
|
||||
use self::libwallet::InitTxArgs;
|
||||
use impls::test_framework::{self, LocalWalletClient};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
@@ -28,6 +27,7 @@ use std::time::Duration;
|
||||
#[macro_use]
|
||||
mod common;
|
||||
use common::{clean_output_dir, create_wallet_proxy, setup};
|
||||
use libwallet::InitTxSendArgs;
|
||||
|
||||
/// self send impl
|
||||
fn late_lock_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
@@ -46,9 +46,10 @@ fn late_lock_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
@@ -57,9 +58,10 @@ fn late_lock_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -69,103 +71,90 @@ fn late_lock_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
});
|
||||
|
||||
// add some accounts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.create_account_path(m, "mining")?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
// add some accounts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.create_account_path(m, "account1")?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api1.create_account_path(mask1, "mining")?;
|
||||
api2.create_account_path(mask2, "account1")?;
|
||||
|
||||
// Get some mining done
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("mining")?;
|
||||
w.set_account_by_name("mining")?;
|
||||
}
|
||||
{
|
||||
wallet_inst!(wallet2, w);
|
||||
w.set_parent_key_id_by_name("account1")?;
|
||||
w.set_account_by_name("account1")?;
|
||||
}
|
||||
|
||||
test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 10, false)?;
|
||||
|
||||
let mut slate = Slate::blank(2, false);
|
||||
let amount = 100_000_000_000;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|sender_api, m| {
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: Some("mining".to_owned()),
|
||||
amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: false,
|
||||
late_lock: Some(true),
|
||||
..Default::default()
|
||||
};
|
||||
let slate_i = sender_api.init_send_tx(m, args)?;
|
||||
println!("S1 SLATE: {}", slate_i);
|
||||
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
|
||||
println!("S2 SLATE: {}", slate);
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: Some("mining".to_owned()),
|
||||
amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: false,
|
||||
late_lock: Some(true),
|
||||
..Default::default()
|
||||
};
|
||||
let slate_i = api1.init_send_tx(mask1, args)?;
|
||||
println!("S1 SLATE: {}", slate_i);
|
||||
let mut slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
|
||||
println!("S2 SLATE: {}", slate);
|
||||
|
||||
// Note we don't call `tx_lock_outputs` on the sender side here,
|
||||
// as the outputs will only be locked during finalization
|
||||
// Note we don't call `tx_lock_outputs` on the sender side here,
|
||||
// as the outputs will only be locked during finalization
|
||||
|
||||
slate = sender_api.finalize_tx(m, &slate)?;
|
||||
println!("S3 SLATE: {}", slate);
|
||||
slate = api1.finalize_tx(mask1, &slate)?;
|
||||
println!("S3 SLATE: {}", slate);
|
||||
|
||||
// Now post tx to our node for inclusion in the next block.
|
||||
sender_api.post_tx(m, &slate, true)?;
|
||||
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// Now post tx to our node for inclusion in the next block.
|
||||
api1.post_tx(mask1, &slate, true)?;
|
||||
|
||||
test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 3, false)?;
|
||||
|
||||
// update/test contents of both accounts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
// Reward from mining 11 blocks, minus the amount sent.
|
||||
// Note: We mined the block containing the tx, so fees are effectively refunded.
|
||||
assert_eq!(560_000_000_000, wallet_info.amount_currently_spendable);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (wallet1_refreshed, wallet_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
// Reward from mining 11 blocks, minus the amount sent.
|
||||
// Note: We mined the block containing the tx, so fees are effectively refunded.
|
||||
assert_eq!(560_000_000_000, wallet_info.amount_currently_spendable);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet2_refreshed, wallet_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet2_refreshed);
|
||||
assert_eq!(amount, wallet_info.amount_currently_spendable);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// Make sure outputs are not locked on failed send with arguments.
|
||||
// Fail sending without starting Tor
|
||||
api1.set_tor_config(Some(grin_wallet_config::TorConfig {
|
||||
use_integrated: Some(false),
|
||||
socks_proxy_addr: "invalid".into(),
|
||||
..Default::default()
|
||||
}))?;
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: Some("mining".to_owned()),
|
||||
amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: false,
|
||||
late_lock: Some(true),
|
||||
send_args: Some(InitTxSendArgs {
|
||||
dest: "tgrin1xtxavwfgs48ckf3gk8wwgcndmn0nt4tvkl8a7ltyejjcy2mc6nfs9gm2lp".into(),
|
||||
post_tx: false,
|
||||
fluff: false,
|
||||
skip_tor: Some(false),
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
let slate = api1.init_send_tx(mask1, args)?;
|
||||
let (_, txs) = api1.retrieve_txs(mask1, false, None, Some(slate.id), None)?;
|
||||
assert!(txs.is_empty());
|
||||
// Make sure spendable balance not changed.
|
||||
let (wallet1_refreshed, wallet_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(560_000_000_000, wallet_info.amount_currently_spendable);
|
||||
|
||||
let (wallet2_refreshed, wallet_info) = api2.retrieve_summary_info(mask2, true, 1)?;
|
||||
assert!(wallet2_refreshed);
|
||||
assert_eq!(amount, wallet_info.amount_currently_spendable);
|
||||
|
||||
// let logging finish
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
|
||||
+215
-112
@@ -18,13 +18,17 @@ extern crate grin_wallet_controller as wallet;
|
||||
extern crate grin_wallet_impls as impls;
|
||||
|
||||
use grin_core as core;
|
||||
use grin_core::core::FeeFields;
|
||||
use grin_util as util;
|
||||
use grin_util::secp::key::SecretKey;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use grin_wallet_libwallet as libwallet;
|
||||
use impls::test_framework::{self, LocalWalletClient};
|
||||
use libwallet::{mwixnet::MixnetReqCreationParams, InitTxArgs};
|
||||
use libwallet::{
|
||||
mwixnet::{MixnetReqCreationParams, MwixnetServerPublicKey, MAX_MWIXNET_HOPS},
|
||||
InitTxArgs, OutputStatus, TxLogEntryType,
|
||||
};
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
@@ -50,9 +54,10 @@ fn mwixnet_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
true
|
||||
true,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -65,144 +70,242 @@ fn mwixnet_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
let reward = core::consensus::REWARD;
|
||||
|
||||
// add some accounts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.create_account_path(m, "mining")?;
|
||||
api.create_account_path(m, "listener")?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api1.create_account_path(mask1, "mining")?;
|
||||
api1.create_account_path(mask1, "listener")?;
|
||||
|
||||
// Get some mining done
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("mining")?;
|
||||
w.set_account_by_name("mining")?;
|
||||
}
|
||||
let mut bh = 10u64;
|
||||
let _ =
|
||||
test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, bh as usize, false);
|
||||
|
||||
// Should have 5 in account1 (5 spendable), 5 in account (2 spendable)
|
||||
wallet::controller::owner_single_use(
|
||||
let (wallet1_refreshed, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward);
|
||||
// send to send
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: Some("mining".to_owned()),
|
||||
amount: reward * 2,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
let mut slate = api1.init_send_tx(mask1, args)?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
// Send directly to self
|
||||
wallet::controller::foreign_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward);
|
||||
// send to send
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: Some("mining".to_owned()),
|
||||
amount: reward * 2,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
let mut slate = api.init_send_tx(m, args)?;
|
||||
api.tx_lock_outputs(m, &slate)?;
|
||||
// Send directly to self
|
||||
wallet::controller::foreign_single_use(
|
||||
wallet1.clone(),
|
||||
PathBuf::from(test_dir),
|
||||
mask1_i.clone(),
|
||||
|api| {
|
||||
slate = api.receive_tx(&slate, Some("listener"), None)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
slate = api.finalize_tx(m, &slate)?;
|
||||
api.post_tx(m, &slate, false)?; // mines a block
|
||||
bh += 1;
|
||||
mask1_i.clone(),
|
||||
|api| {
|
||||
slate = api.receive_tx(&slate, Some("listener"), None)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
slate = api1.finalize_tx(mask1, &slate)?;
|
||||
api1.post_tx(mask1, &slate, false)?; // mines a block
|
||||
bh += 1;
|
||||
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 3, false);
|
||||
bh += 3;
|
||||
|
||||
// Check total in mining account
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward - reward * 2);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (wallet1_refreshed, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward - reward * 2);
|
||||
|
||||
// Check total in 'listener' account
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("listener")?;
|
||||
w.set_account_by_name("listener")?;
|
||||
}
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, 2 * reward);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (wallet1_refreshed, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, 2 * reward);
|
||||
|
||||
// Recipient wallet creates a mwixnet request from the last output
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
let secp_locked = util::static_secp_instance();
|
||||
let secp = secp_locked.lock();
|
||||
let server_pubkey_str_1 = "97444ae673bb92c713c1a2f7b8882ffbfc1c67401a280a775dce1a8651584332";
|
||||
let server_pubkey_str_2 = "0c9414341f2140ed34a5a12a6479bf5a6404820d001ab81d9d3e8cc38f049b4e";
|
||||
let server_pubkey_str_3 = "b58ece97d60e71bb7e53218400b0d67bfe6a3cb7d3b4a67a44f8fb7c525cbca5";
|
||||
let server_key_1 =
|
||||
SecretKey::from_slice(&secp, &grin_util::from_hex(server_pubkey_str_1).unwrap())?;
|
||||
let server_key_2 =
|
||||
SecretKey::from_slice(&secp, &grin_util::from_hex(server_pubkey_str_2).unwrap())?;
|
||||
let server_key_3 =
|
||||
SecretKey::from_slice(&secp, &grin_util::from_hex(server_pubkey_str_3).unwrap())?;
|
||||
let params = MixnetReqCreationParams {
|
||||
server_keys: vec![
|
||||
MwixnetServerPublicKey::from_secret(&server_key_1),
|
||||
MwixnetServerPublicKey::from_secret(&server_key_2),
|
||||
MwixnetServerPublicKey::from_secret(&server_key_3),
|
||||
],
|
||||
fee_per_hop: None,
|
||||
};
|
||||
let outputs = api1.retrieve_outputs(mask1, false, false, None)?;
|
||||
// get last output
|
||||
let last_output = outputs.1[outputs.1.len() - 1].clone();
|
||||
|
||||
// Store the output with an MMR index, like a restored output
|
||||
let mmr_index = Some(chain.get_output_pos(&last_output.commit).unwrap());
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
let mut batch = w.batch(mask1)?;
|
||||
let mut output = last_output.output.clone();
|
||||
batch.delete(&output.key_id, &output.mmr_index)?;
|
||||
output.mmr_index = mmr_index;
|
||||
batch.save(output)?;
|
||||
batch.commit()?;
|
||||
}
|
||||
|
||||
let empty_params = MixnetReqCreationParams {
|
||||
server_keys: vec![],
|
||||
fee_per_hop: params.fee_per_hop,
|
||||
};
|
||||
assert!(api1
|
||||
.create_mwixnet_req(mask1, &empty_params, &last_output.commit, true)
|
||||
.is_err());
|
||||
|
||||
let too_many_params = MixnetReqCreationParams {
|
||||
server_keys: vec![params.server_keys[0]; MAX_MWIXNET_HOPS + 1],
|
||||
fee_per_hop: params.fee_per_hop,
|
||||
};
|
||||
assert!(api1
|
||||
.create_mwixnet_req(mask1, &too_many_params, &last_output.commit, true)
|
||||
.is_err());
|
||||
|
||||
let oversized_fee_params = MixnetReqCreationParams {
|
||||
server_keys: params.server_keys[..2].to_vec(),
|
||||
fee_per_hop: Some(1 << 39),
|
||||
};
|
||||
assert_eq!(
|
||||
api1.create_mwixnet_req(mask1, &oversized_fee_params, &last_output.commit, true)
|
||||
.unwrap_err(),
|
||||
libwallet::Error::Fee("mwixnet total fee exceeds FeeFields limit".to_string())
|
||||
);
|
||||
|
||||
for fee in [0, 12_499_999] {
|
||||
let invalid_params = MixnetReqCreationParams {
|
||||
server_keys: params.server_keys.clone(),
|
||||
fee_per_hop: Some(fee),
|
||||
};
|
||||
assert_eq!(
|
||||
api1.create_mwixnet_req(mask1, &invalid_params, &last_output.commit, true)
|
||||
.unwrap_err(),
|
||||
libwallet::Error::Fee("mwixnet fee is below the swap minimum 0.0125".to_string())
|
||||
);
|
||||
}
|
||||
let custom_params = MixnetReqCreationParams {
|
||||
server_keys: params.server_keys.clone(),
|
||||
fee_per_hop: Some(25_000_000),
|
||||
};
|
||||
let custom = api1.create_mwixnet_req(mask1, &custom_params, &last_output.commit, false)?;
|
||||
let mut onion = custom.request.onion;
|
||||
for server_key in [&server_key_1, &server_key_2, &server_key_3] {
|
||||
let peeled = onion.peel_layer(server_key).unwrap();
|
||||
assert_eq!(peeled.payload.fee, FeeFields::try_from(25_000_000u64)?);
|
||||
onion = peeled.onion;
|
||||
}
|
||||
|
||||
drop(secp);
|
||||
|
||||
// Failed refresh must not create or lock a swap
|
||||
let tx_count = api1.retrieve_txs(mask1, false, None, None, None)?.1.len();
|
||||
let (disconnected, receiver) = std::sync::mpsc::channel();
|
||||
drop(receiver);
|
||||
let original_proxy = std::mem::replace(&mut *client1.proxy_tx.lock(), disconnected);
|
||||
let mut api1 = api1;
|
||||
let result = wallet::command::mwixnet(
|
||||
&mut api1,
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let secp_locked = util::static_secp_instance();
|
||||
let secp = secp_locked.lock();
|
||||
let server_pubkey_str_1 =
|
||||
"97444ae673bb92c713c1a2f7b8882ffbfc1c67401a280a775dce1a8651584332";
|
||||
let server_pubkey_str_2 =
|
||||
"0c9414341f2140ed34a5a12a6479bf5a6404820d001ab81d9d3e8cc38f049b4e";
|
||||
let server_pubkey_str_3 =
|
||||
"b58ece97d60e71bb7e53218400b0d67bfe6a3cb7d3b4a67a44f8fb7c525cbca5";
|
||||
let server_key_1 =
|
||||
SecretKey::from_slice(&secp, &grin_util::from_hex(&server_pubkey_str_1).unwrap())
|
||||
.unwrap();
|
||||
let server_key_2 =
|
||||
SecretKey::from_slice(&secp, &grin_util::from_hex(&server_pubkey_str_2).unwrap())
|
||||
.unwrap();
|
||||
let server_key_3 =
|
||||
SecretKey::from_slice(&secp, &grin_util::from_hex(&server_pubkey_str_3).unwrap())
|
||||
.unwrap();
|
||||
let params = MixnetReqCreationParams {
|
||||
server_keys: vec![server_key_1, server_key_2, server_key_3],
|
||||
fee_per_hop: 50_000_000,
|
||||
};
|
||||
let outputs = api.retrieve_outputs(mask1, false, false, None)?;
|
||||
// get last output
|
||||
let last_output = outputs.1[outputs.1.len() - 1].clone();
|
||||
|
||||
let mwixnet_req = api.create_mwixnet_req(m, ¶ms, &last_output.commit, true)?;
|
||||
|
||||
println!("MWIXNET REQ: {:?}", mwixnet_req);
|
||||
|
||||
// check output we created comsig for is indeed locked
|
||||
let outputs = api.retrieve_outputs(mask1, false, false, None)?;
|
||||
// get last output
|
||||
let last_output = outputs.1[outputs.1.len() - 1].clone();
|
||||
assert!(last_output.output.status == libwallet::OutputStatus::Locked);
|
||||
|
||||
Ok(())
|
||||
wallet::command::MwixnetArgs {
|
||||
server: "mza3u6vkqodqc6kjjapfbcjrg7hgpkuw6nyq5xvfjqp5jm2lfeaocwqd.onion".try_into()?,
|
||||
output: wallet::command::MwixnetOutput::Commitment(last_output.commit),
|
||||
minimum_confirmations: 1,
|
||||
params: MixnetReqCreationParams {
|
||||
server_keys: params.server_keys.clone(),
|
||||
fee_per_hop: None,
|
||||
},
|
||||
},
|
||||
)?;
|
||||
);
|
||||
*client1.proxy_tx.lock() = original_proxy;
|
||||
assert!(result
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("Could not refresh wallet outputs"));
|
||||
assert_eq!(
|
||||
api1.retrieve_txs(mask1, false, None, None, None)?.1.len(),
|
||||
tx_count
|
||||
);
|
||||
let outputs = api1.retrieve_outputs(mask1, false, false, None)?.1;
|
||||
assert_eq!(
|
||||
outputs
|
||||
.iter()
|
||||
.find(|o| o.commit == last_output.commit)
|
||||
.unwrap()
|
||||
.output
|
||||
.status,
|
||||
OutputStatus::Unspent
|
||||
);
|
||||
|
||||
let creation = api1.create_mwixnet_req(mask1, ¶ms, &last_output.commit, true)?;
|
||||
let creation_tx_id = creation.tx_id.unwrap();
|
||||
let fee_per_hop = 12_500_000;
|
||||
let mut onion = creation.request.onion.clone();
|
||||
for server_key in [&server_key_1, &server_key_2, &server_key_3] {
|
||||
let peeled = onion
|
||||
.peel_layer(server_key)
|
||||
.map_err(|e| libwallet::Error::GenericError(e.to_string()))?;
|
||||
assert_eq!(peeled.payload.fee, FeeFields::try_from(fee_per_hop)?);
|
||||
onion = peeled.onion;
|
||||
}
|
||||
|
||||
println!("MWIXNET REQ: {:?}", creation.request);
|
||||
|
||||
// Check the input lock and expected output are tracked together.
|
||||
let outputs = api1.retrieve_outputs(mask1, false, false, None)?;
|
||||
let input = outputs
|
||||
.1
|
||||
.iter()
|
||||
.find(|o| o.commit == last_output.commit)
|
||||
.unwrap();
|
||||
assert_eq!(input.output.status, OutputStatus::Locked);
|
||||
assert_eq!(input.output.mmr_index, mmr_index);
|
||||
let total_fee = fee_per_hop * params.server_keys.len() as u64;
|
||||
let expected_amount = last_output.output.value - total_fee;
|
||||
let expected_output = outputs
|
||||
.1
|
||||
.iter()
|
||||
.find(|o| o.output.status == OutputStatus::Unconfirmed && o.output.value == expected_amount)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
input.output.tx_log_entry,
|
||||
expected_output.output.tx_log_entry
|
||||
);
|
||||
|
||||
let txs = api1.retrieve_txs(mask1, false, None, None, None)?.1;
|
||||
let tx = txs.last().unwrap();
|
||||
assert_eq!(creation_tx_id, tx.id);
|
||||
assert_eq!(tx.tx_type, TxLogEntryType::TxSent);
|
||||
assert_eq!(tx.amount_debited, last_output.output.value);
|
||||
assert_eq!(tx.amount_credited, expected_amount);
|
||||
assert_eq!(tx.num_inputs, 1);
|
||||
assert_eq!(tx.num_outputs, 1);
|
||||
assert_eq!(tx.fee, Some(FeeFields::try_from(total_fee)?));
|
||||
|
||||
assert!(api1
|
||||
.create_mwixnet_req(mask1, ¶ms, &last_output.commit, false)
|
||||
.is_err());
|
||||
|
||||
// let logging finish
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
|
||||
+76
-140
@@ -59,10 +59,11 @@ fn no_change_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api1
|
||||
);
|
||||
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
@@ -72,10 +73,11 @@ fn no_change_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api2
|
||||
);
|
||||
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -92,109 +94,67 @@ fn no_change_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
let fee = core::libtx::tx_fee(1, 1, 1);
|
||||
|
||||
// send a single block's worth of transactions with minimal strategy
|
||||
let mut slate = Slate::blank(2, false);
|
||||
let mut stored_excess = None;
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: reward - fee,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: false,
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.init_send_tx(m, args)?;
|
||||
slate = client1.send_tx_slate_direct("wallet2", &slate)?;
|
||||
api.tx_lock_outputs(m, &slate)?;
|
||||
slate = api.finalize_tx(m, &slate)?;
|
||||
println!("Posted Slate: {:?}", slate);
|
||||
stored_excess = Some(slate.tx.as_ref().unwrap().body.kernels[0].excess);
|
||||
api.post_tx(m, &slate, false)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: reward - fee,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: false,
|
||||
..Default::default()
|
||||
};
|
||||
let mut slate = api1.init_send_tx(mask1, args)?;
|
||||
slate = client1.send_tx_slate_direct("wallet2", &slate)?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
slate = api1.finalize_tx(mask1, &slate)?;
|
||||
println!("Posted Slate: {:?}", slate);
|
||||
let mut stored_excess = Some(slate.tx.as_ref().unwrap().body.kernels[0].excess);
|
||||
api1.post_tx(mask1, &slate, false)?;
|
||||
|
||||
// ensure stored excess is correct in both wallets
|
||||
// Wallet 1 calculated the excess with the full slate // Wallet 2 only had the excess provided by
|
||||
// wallet 1
|
||||
|
||||
// Refresh and check transaction log for wallet 1
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (refreshed, txs) = api.retrieve_txs(m, true, None, Some(slate.id), None)?;
|
||||
assert!(refreshed);
|
||||
let tx = txs[0].clone();
|
||||
println!("SIMPLE SEND - SENDING WALLET");
|
||||
println!("{:?}", tx);
|
||||
println!();
|
||||
assert!(tx.confirmed);
|
||||
assert_eq!(stored_excess, tx.kernel_excess);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (refreshed, txs) = api1.retrieve_txs(mask1, true, None, Some(slate.id), None)?;
|
||||
assert!(refreshed);
|
||||
let tx = txs[0].clone();
|
||||
println!("SIMPLE SEND - SENDING WALLET");
|
||||
println!("{:?}", tx);
|
||||
println!();
|
||||
assert!(tx.confirmed);
|
||||
assert_eq!(stored_excess, tx.kernel_excess);
|
||||
|
||||
// Refresh and check transaction log for wallet 2
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (refreshed, txs) = api.retrieve_txs(m, true, None, Some(slate.id), None)?;
|
||||
assert!(refreshed);
|
||||
let tx = txs[0].clone();
|
||||
println!("SIMPLE SEND - RECEIVING WALLET");
|
||||
println!("{:?}", tx);
|
||||
println!();
|
||||
assert!(tx.confirmed);
|
||||
assert_eq!(stored_excess, tx.kernel_excess);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (refreshed, txs) = api2.retrieve_txs(mask2, true, None, Some(slate.id), None)?;
|
||||
assert!(refreshed);
|
||||
let tx = txs[0].clone();
|
||||
println!("SIMPLE SEND - RECEIVING WALLET");
|
||||
println!("{:?}", tx);
|
||||
println!();
|
||||
assert!(tx.confirmed);
|
||||
assert_eq!(stored_excess, tx.kernel_excess);
|
||||
|
||||
// ensure invoice TX works as well with no change
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
// Wallet 2 inititates an invoice transaction, requesting payment
|
||||
let args = IssueInvoiceTxArgs {
|
||||
amount: reward - fee,
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.issue_invoice_tx(m, args)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// Wallet 2 initiates an invoice transaction, requesting payment
|
||||
let args = IssueInvoiceTxArgs {
|
||||
amount: reward - fee,
|
||||
..Default::default()
|
||||
};
|
||||
slate = api2.issue_invoice_tx(mask2, args)?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
// Wallet 1 receives the invoice transaction
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: slate.amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: false,
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.process_invoice_tx(m, &slate, args)?;
|
||||
api.tx_lock_outputs(m, &slate)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// Wallet 1 receives the invoice transaction
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: slate.amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: false,
|
||||
..Default::default()
|
||||
};
|
||||
slate = api1.process_invoice_tx(mask1, &slate, args)?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
|
||||
// wallet 2 finalizes and posts
|
||||
{
|
||||
@@ -222,54 +182,30 @@ fn no_change_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
println!("Invoice Posted TX: {}", slate);
|
||||
stored_excess = Some(slate.tx.as_ref().unwrap().body.kernels[0].excess);
|
||||
api.post_tx(m, &slate, false)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
println!("Invoice Posted TX: {}", slate);
|
||||
stored_excess = Some(slate.tx.as_ref().unwrap().body.kernels[0].excess);
|
||||
api2.post_tx(mask2, &slate, false)?;
|
||||
|
||||
// check wallet 2's version
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (refreshed, txs) = api.retrieve_txs(m, true, None, Some(slate.id), None)?;
|
||||
assert!(refreshed);
|
||||
for tx in txs {
|
||||
stored_excess = tx.kernel_excess;
|
||||
println!("Wallet 2: {:?}", tx);
|
||||
println!();
|
||||
assert!(tx.confirmed);
|
||||
assert_eq!(stored_excess, tx.kernel_excess);
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (refreshed, txs) = api2.retrieve_txs(mask2, true, None, Some(slate.id), None)?;
|
||||
assert!(refreshed);
|
||||
for tx in txs {
|
||||
stored_excess = tx.kernel_excess;
|
||||
println!("Wallet 2: {:?}", tx);
|
||||
println!();
|
||||
assert!(tx.confirmed);
|
||||
assert_eq!(stored_excess, tx.kernel_excess);
|
||||
}
|
||||
|
||||
// Refresh and check transaction log for wallet 1
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (refreshed, txs) = api.retrieve_txs(m, true, None, Some(slate.id), None)?;
|
||||
assert!(refreshed);
|
||||
for tx in txs {
|
||||
println!("Wallet 1: {:?}", tx);
|
||||
println!();
|
||||
assert_eq!(stored_excess, tx.kernel_excess);
|
||||
assert!(tx.confirmed);
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (refreshed, txs) = api1.retrieve_txs(mask1, true, None, Some(slate.id), None)?;
|
||||
assert!(refreshed);
|
||||
for tx in txs {
|
||||
println!("Wallet 1: {:?}", tx);
|
||||
println!();
|
||||
assert_eq!(stored_excess, tx.kernel_excess);
|
||||
assert!(tx.confirmed);
|
||||
}
|
||||
|
||||
// let logging finish
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
|
||||
@@ -21,7 +21,6 @@ extern crate grin_wallet_util;
|
||||
use grin_wallet_libwallet as libwallet;
|
||||
use impls::test_framework::{self, LocalWalletClient};
|
||||
use libwallet::{InitTxArgs, Slate};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
@@ -29,6 +28,7 @@ use std::time::Duration;
|
||||
#[macro_use]
|
||||
mod common;
|
||||
use common::{clean_output_dir, create_wallet_proxy, setup};
|
||||
use grin_wallet_libwallet::slatepack::SlatepackAddressIndex;
|
||||
|
||||
/// Various tests on accounts within the same wallet
|
||||
fn payment_proofs_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
@@ -45,10 +45,11 @@ fn payment_proofs_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api1
|
||||
);
|
||||
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
@@ -58,10 +59,11 @@ fn payment_proofs_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api2
|
||||
);
|
||||
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -77,99 +79,74 @@ fn payment_proofs_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err
|
||||
let _ =
|
||||
test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, bh as usize, false);
|
||||
|
||||
let mut address = None;
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
address = Some(api.get_slatepack_address(m, 0)?);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let address = Some(api2.get_slatepack_address(mask2, SlatepackAddressIndex(0))?);
|
||||
|
||||
println!("Public address is: {:?}", address);
|
||||
let amount = 60_000_000_000;
|
||||
let mut slate = Slate::blank(1, false);
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|sender_api, m| {
|
||||
// note this will increment the block count as part of the transaction "Posting"
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
payment_proof_recipient_address: address.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
let slate_i = sender_api.init_send_tx(m, args)?;
|
||||
// note this will increment the block count as part of the transaction "Posting"
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
payment_proof_recipient_address: address.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
let slate_i = api1.init_send_tx(mask1, args)?;
|
||||
|
||||
assert_eq!(
|
||||
slate_i.payment_proof.as_ref().unwrap().receiver_address,
|
||||
address.as_ref().unwrap().pub_key,
|
||||
);
|
||||
println!(
|
||||
"Sender addr: {:?}",
|
||||
slate_i.payment_proof.as_ref().unwrap().sender_address
|
||||
);
|
||||
assert_eq!(
|
||||
slate_i.payment_proof.as_ref().unwrap().receiver_address,
|
||||
address.as_ref().unwrap().pub_key,
|
||||
);
|
||||
println!(
|
||||
"Sender addr: {:?}",
|
||||
slate_i.payment_proof.as_ref().unwrap().sender_address
|
||||
);
|
||||
|
||||
// Check we are creating a tx with kernel features 0
|
||||
// We will check this produces a Plain kernel later.
|
||||
assert_eq!(0, slate.kernel_features);
|
||||
// Check we are creating a tx with kernel features 0
|
||||
// We will check this produces a Plain kernel later.
|
||||
assert_eq!(0, slate.kernel_features);
|
||||
|
||||
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
|
||||
sender_api.tx_lock_outputs(m, &slate)?;
|
||||
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
|
||||
// Ensure what's stored in TX log for payment proof is correct
|
||||
let (_, txs) = sender_api.retrieve_txs(m, true, None, Some(slate.id), None)?;
|
||||
assert!(txs[0].payment_proof.is_some());
|
||||
let pp = txs[0].clone().payment_proof.unwrap();
|
||||
assert_eq!(
|
||||
pp.receiver_address,
|
||||
slate_i.payment_proof.as_ref().unwrap().receiver_address
|
||||
);
|
||||
assert!(pp.receiver_signature.is_some());
|
||||
assert_eq!(pp.sender_address_path, 0);
|
||||
assert_eq!(pp.sender_signature, None);
|
||||
// Ensure what's stored in TX log for payment proof is correct
|
||||
let (_, txs) = api1.retrieve_txs(mask1, true, None, Some(slate.id), None)?;
|
||||
assert!(txs[0].payment_proof.is_some());
|
||||
let pp = txs[0].clone().payment_proof.unwrap();
|
||||
assert_eq!(
|
||||
pp.receiver_address,
|
||||
slate_i.payment_proof.as_ref().unwrap().receiver_address
|
||||
);
|
||||
assert!(pp.receiver_signature.is_some());
|
||||
assert_eq!(pp.sender_address_path, SlatepackAddressIndex(1));
|
||||
assert_eq!(pp.sender_signature, None);
|
||||
|
||||
// check we should get an error at this point since proof is not complete
|
||||
let pp = sender_api.retrieve_payment_proof(m, true, None, Some(slate.id));
|
||||
assert!(pp.is_err());
|
||||
// check we should get an error at this point since proof is not complete
|
||||
let pp = api1.retrieve_payment_proof(mask1, true, None, Some(slate.id));
|
||||
assert!(pp.is_err());
|
||||
|
||||
slate = sender_api.finalize_tx(m, &slate)?;
|
||||
sender_api.post_tx(m, &slate, true)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
slate = api1.finalize_tx(mask1, &slate)?;
|
||||
api1.post_tx(mask1, &slate, true)?;
|
||||
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 2, false);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|sender_api, m| {
|
||||
// Check payment proof here
|
||||
let mut pp = sender_api.retrieve_payment_proof(m, true, None, Some(slate.id))?;
|
||||
// Check payment proof here
|
||||
let mut pp = api1.retrieve_payment_proof(mask1, true, None, Some(slate.id))?;
|
||||
|
||||
println!("Payment proof: {:?}", pp);
|
||||
println!("Payment proof: {:?}", pp);
|
||||
|
||||
// verify, should be good
|
||||
let res = sender_api.verify_payment_proof(m, &pp)?;
|
||||
assert_eq!(res, (true, false));
|
||||
// verify, should be good
|
||||
let res = api1.verify_payment_proof(mask1, &pp)?;
|
||||
assert_eq!(res, (true, false));
|
||||
|
||||
// Modify values, should not be good
|
||||
pp.amount = 20;
|
||||
let res = sender_api.verify_payment_proof(m, &pp);
|
||||
assert!(res.is_err());
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// Modify values, should not be good
|
||||
pp.amount = 20;
|
||||
let res = api1.verify_payment_proof(mask1, &pp);
|
||||
assert!(res.is_err());
|
||||
|
||||
// let logging finish
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
|
||||
+79
-169
@@ -21,7 +21,7 @@ extern crate grin_wallet_libwallet as libwallet;
|
||||
use grin_core as core;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use self::libwallet::{InitTxArgs, Slate};
|
||||
use self::libwallet::InitTxArgs;
|
||||
use impls::test_framework::{self, LocalWalletClient};
|
||||
use impls::{PathToSlate, SlateGetter as _, SlatePutter as _};
|
||||
use std::sync::atomic::Ordering;
|
||||
@@ -49,9 +49,10 @@ fn file_repost_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
@@ -60,9 +61,10 @@ fn file_repost_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -75,33 +77,16 @@ fn file_repost_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
let reward = core::consensus::REWARD;
|
||||
|
||||
// add some accounts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.create_account_path(m, "mining")?;
|
||||
api.create_account_path(m, "listener")?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api1.create_account_path(mask1, "mining")?;
|
||||
api1.create_account_path(mask1, "listener")?;
|
||||
|
||||
// add some accounts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.create_account_path(m, "account1")?;
|
||||
api.create_account_path(m, "account2")?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api2.create_account_path(mask2, "account1")?;
|
||||
api2.create_account_path(mask2, "account2")?;
|
||||
|
||||
// Get some mining done
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("mining")?;
|
||||
w.set_account_by_name("mining")?;
|
||||
}
|
||||
let mut bh = 10u64;
|
||||
let _ =
|
||||
@@ -110,34 +95,24 @@ fn file_repost_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
let send_file = format!("{}/part_tx_1.tx", test_dir);
|
||||
let receive_file = format!("{}/part_tx_2.tx", test_dir);
|
||||
|
||||
let mut slate = Slate::blank(2, false);
|
||||
|
||||
// Should have 5 in account1 (5 spendable), 5 in account (2 spendable)
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward);
|
||||
// send to send
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: Some("mining".to_owned()),
|
||||
amount: reward * 2,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
let slate = api.init_send_tx(m, args)?;
|
||||
PathToSlate((&send_file).into()).put_tx(&slate, false)?;
|
||||
api.tx_lock_outputs(m, &slate)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (wallet1_refreshed, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward);
|
||||
// send to send
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: Some("mining".to_owned()),
|
||||
amount: reward * 2,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
let mut slate = api1.init_send_tx(mask1, args)?;
|
||||
PathToSlate((&send_file).into()).put_tx(&slate, false)?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 3, false);
|
||||
bh += 3;
|
||||
@@ -145,7 +120,7 @@ fn file_repost_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
// wallet 1 receives file to different account, completes
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("listener")?;
|
||||
w.set_account_by_name("listener")?;
|
||||
}
|
||||
|
||||
wallet::controller::foreign_single_use(
|
||||
@@ -163,154 +138,89 @@ fn file_repost_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
// wallet 1 receives file to different account, completes
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("mining")?;
|
||||
w.set_account_by_name("mining")?;
|
||||
}
|
||||
|
||||
// wallet 1 finalize
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
slate = PathToSlate((&receive_file).into()).get_tx()?.0;
|
||||
slate = api.finalize_tx(m, &slate)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
slate = PathToSlate((&receive_file).into()).get_tx()?.0;
|
||||
slate = api1.finalize_tx(mask1, &slate)?;
|
||||
|
||||
// Now repost from cached
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, Some(slate.id), None)?;
|
||||
println!("TXS[0]: {:?}", txs[0]);
|
||||
let stored_tx = api.get_stored_tx(m, None, Some(&txs[0].tx_slate_id.unwrap()))?;
|
||||
println!("Stored tx: {:?}", stored_tx);
|
||||
api.post_tx(m, &slate, false)?;
|
||||
bh += 1;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (_, txs) = api1.retrieve_txs(mask1, true, None, Some(slate.id), None)?;
|
||||
println!("TXS[0]: {:?}", txs[0]);
|
||||
let stored_tx = api1.get_stored_tx(mask1, None, Some(&txs[0].tx_slate_id.unwrap()))?;
|
||||
println!("Stored tx: {:?}", stored_tx);
|
||||
api1.post_tx(mask1, &slate, false)?;
|
||||
bh += 1;
|
||||
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 3, false);
|
||||
bh += 3;
|
||||
|
||||
// update/test contents of both accounts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward - reward * 2);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (wallet1_refreshed, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward - reward * 2);
|
||||
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("listener")?;
|
||||
w.set_account_by_name("listener")?;
|
||||
}
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet2_refreshed);
|
||||
assert_eq!(wallet2_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet2_info.total, 2 * reward);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (wallet1_refreshed, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, 2 * reward);
|
||||
|
||||
// as above, but syncronously
|
||||
// as above, but synchronously
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("mining")?;
|
||||
w.set_account_by_name("mining")?;
|
||||
}
|
||||
{
|
||||
wallet_inst!(wallet2, w);
|
||||
w.set_parent_key_id_by_name("account1")?;
|
||||
w.set_account_by_name("account1")?;
|
||||
}
|
||||
|
||||
let mut slate = Slate::blank(2, false);
|
||||
let amount = 60_000_000_000;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|sender_api, m| {
|
||||
// note this will increment the block count as part of the transaction "Posting"
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: reward * 2,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
let slate_i = sender_api.init_send_tx(m, args)?;
|
||||
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
|
||||
sender_api.tx_lock_outputs(m, &slate)?;
|
||||
slate = sender_api.finalize_tx(m, &slate)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// note this will increment the block count as part of the transaction "Posting"
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: reward * 2,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
let slate_i = api1.init_send_tx(mask1, args)?;
|
||||
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
slate = api1.finalize_tx(mask1, &slate)?;
|
||||
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 3, false);
|
||||
bh += 3;
|
||||
|
||||
// Now repost from cached
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, Some(slate.id), None)?;
|
||||
let stored_tx_slate = api.get_stored_tx(m, Some(txs[0].id), None)?.unwrap();
|
||||
api.post_tx(m, &stored_tx_slate, false)?;
|
||||
bh += 1;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (_, txs) = api1.retrieve_txs(mask1, true, None, Some(slate.id), None)?;
|
||||
let stored_tx_slate = api1.get_stored_tx(mask1, Some(txs[0].id), None)?.unwrap();
|
||||
api1.post_tx(mask1, &stored_tx_slate, false)?;
|
||||
bh += 1;
|
||||
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 3, false);
|
||||
bh += 3;
|
||||
//
|
||||
// update/test contents of both accounts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward - reward * 4);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet2_refreshed);
|
||||
assert_eq!(wallet2_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet2_info.total, 2 * amount);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// update/test contents of both accounts
|
||||
let (wallet1_refreshed, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward - reward * 4);
|
||||
|
||||
let (wallet2_refreshed, wallet2_info) = api2.retrieve_summary_info(mask2, true, 1)?;
|
||||
assert!(wallet2_refreshed);
|
||||
assert_eq!(wallet2_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet2_info.total, 2 * amount);
|
||||
|
||||
// let logging finish
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
|
||||
+141
-176
@@ -23,33 +23,25 @@ use grin_core::core::Transaction;
|
||||
use grin_core::global;
|
||||
use grin_keychain::ExtKeychain;
|
||||
use grin_util::secp::key::SecretKey;
|
||||
use grin_util::Mutex;
|
||||
use grin_wallet_controller::controller::owner_single_use as owner;
|
||||
use grin_wallet_api::Owner;
|
||||
use grin_wallet_impls::test_framework::*;
|
||||
use grin_wallet_impls::{DefaultLCProvider, PathToSlate, SlatePutter};
|
||||
use grin_wallet_libwallet as libwallet;
|
||||
use grin_wallet_libwallet::api_impl::types::InitTxArgs;
|
||||
use grin_wallet_libwallet::WalletInst;
|
||||
use log::error;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
type Wallet = Arc<
|
||||
Mutex<
|
||||
Box<
|
||||
dyn WalletInst<
|
||||
'static,
|
||||
DefaultLCProvider<LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
ExtKeychain,
|
||||
>,
|
||||
>,
|
||||
>,
|
||||
type Wallet = grin_wallet_libwallet::WalletHandle<
|
||||
'static,
|
||||
DefaultLCProvider<LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
ExtKeychain,
|
||||
>;
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn revert(
|
||||
test_dir: &'static str,
|
||||
) -> Result<
|
||||
@@ -63,6 +55,8 @@ fn revert(
|
||||
Option<SecretKey>,
|
||||
Wallet,
|
||||
Option<SecretKey>,
|
||||
Owner<DefaultLCProvider<LocalWalletClient, ExtKeychain>, LocalWalletClient, ExtKeychain>,
|
||||
Owner<DefaultLCProvider<LocalWalletClient, ExtKeychain>, LocalWalletClient, ExtKeychain>,
|
||||
),
|
||||
libwallet::Error,
|
||||
> {
|
||||
@@ -82,7 +76,8 @@ fn revert(
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
@@ -94,28 +89,23 @@ fn revert(
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api2
|
||||
);
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
std::thread::spawn(move || {
|
||||
thread::spawn(move || {
|
||||
if let Err(e) = wallet_proxy.run() {
|
||||
error!("Wallet Proxy error: {}", e);
|
||||
}
|
||||
});
|
||||
|
||||
owner(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
api.create_account_path(m, "a")?;
|
||||
api.set_active_account(m, "a")?;
|
||||
Ok(())
|
||||
})?;
|
||||
api1.create_account_path(mask1, "a")?;
|
||||
api1.set_active_account(mask1, "a")?;
|
||||
|
||||
owner(wallet2.clone(), mask2, PathBuf::from(test_dir), |api, m| {
|
||||
api.create_account_path(m, "b")?;
|
||||
api.set_active_account(m, "b")?;
|
||||
Ok(())
|
||||
})?;
|
||||
api2.create_account_path(mask2, "b")?;
|
||||
api2.set_active_account(mask2, "b")?;
|
||||
|
||||
let reward = core::consensus::REWARD;
|
||||
let cm = global::coinbase_maturity() as u64;
|
||||
@@ -126,76 +116,60 @@ fn revert(
|
||||
award_blocks_to_wallet(&chain, wallet1.clone(), mask1, bh as usize, false)?;
|
||||
|
||||
// Sanity check contents
|
||||
owner(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let (refreshed, info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(refreshed);
|
||||
assert_eq!(info.last_confirmed_height, bh);
|
||||
assert_eq!(info.total, bh * reward);
|
||||
assert_eq!(info.amount_currently_spendable, (bh - cm) * reward);
|
||||
assert_eq!(info.amount_reverted, 0);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
let (c, _) = libwallet::TxLogEntry::sum_confirmed(&txs);
|
||||
assert_eq!(info.total, c);
|
||||
assert_eq!(txs.len(), bh as usize);
|
||||
Ok(())
|
||||
})?;
|
||||
let (refreshed, info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(refreshed);
|
||||
assert_eq!(info.last_confirmed_height, bh);
|
||||
assert_eq!(info.total, bh * reward);
|
||||
assert_eq!(info.amount_currently_spendable, (bh - cm) * reward);
|
||||
assert_eq!(info.amount_reverted, 0);
|
||||
// check tx log as well
|
||||
let (_, txs) = api1.retrieve_txs(mask1, true, None, None, None)?;
|
||||
let (c, _) = libwallet::TxLogEntry::sum_confirmed(&txs);
|
||||
assert_eq!(info.total, c);
|
||||
assert_eq!(txs.len(), bh as usize);
|
||||
|
||||
owner(wallet2.clone(), mask2, PathBuf::from(test_dir), |api, m| {
|
||||
let (refreshed, info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(refreshed);
|
||||
assert_eq!(info.last_confirmed_height, bh);
|
||||
assert_eq!(info.total, 0);
|
||||
assert_eq!(info.amount_currently_spendable, 0);
|
||||
assert_eq!(info.amount_reverted, 0);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 0);
|
||||
Ok(())
|
||||
})?;
|
||||
let (refreshed, info) = api2.retrieve_summary_info(mask2, true, 1)?;
|
||||
assert!(refreshed);
|
||||
assert_eq!(info.last_confirmed_height, bh);
|
||||
assert_eq!(info.total, 0);
|
||||
assert_eq!(info.amount_currently_spendable, 0);
|
||||
assert_eq!(info.amount_reverted, 0);
|
||||
// check tx log as well
|
||||
let (_, txs) = api2.retrieve_txs(mask2, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 0);
|
||||
|
||||
// Send some funds
|
||||
let mut tx = None;
|
||||
owner(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
// send to send
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: sent,
|
||||
minimum_confirmations: cm,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: false,
|
||||
..Default::default()
|
||||
};
|
||||
let slate = api.init_send_tx(m, args)?;
|
||||
// output tx file
|
||||
let send_file = format!("{}/part_tx_1.tx", test_dir);
|
||||
PathToSlate(send_file.into()).put_tx(&slate, false)?;
|
||||
api.tx_lock_outputs(m, &slate)?;
|
||||
let slate = client1.send_tx_slate_direct("wallet2", &slate)?;
|
||||
let slate = api.finalize_tx(m, &slate)?;
|
||||
tx = slate.tx;
|
||||
|
||||
Ok(())
|
||||
})?;
|
||||
let tx = tx.expect("tx from slate");
|
||||
// send to send
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: sent,
|
||||
minimum_confirmations: cm,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: false,
|
||||
..Default::default()
|
||||
};
|
||||
let slate = api1.init_send_tx(mask1, args)?;
|
||||
// output tx file
|
||||
let send_file = format!("{}/part_tx_1.tx", test_dir);
|
||||
PathToSlate(send_file.into()).put_tx(&slate, false)?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
let slate = client1.send_tx_slate_direct("wallet2", &slate)?;
|
||||
let slate = api1.finalize_tx(mask1, &slate)?;
|
||||
let tx = slate.tx.expect("tx from slate");
|
||||
|
||||
// Check funds have been received
|
||||
owner(wallet2.clone(), mask2, PathBuf::from(test_dir), |api, m| {
|
||||
let (refreshed, info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(refreshed);
|
||||
assert_eq!(info.last_confirmed_height, bh);
|
||||
assert_eq!(info.total, 0);
|
||||
assert_eq!(info.amount_currently_spendable, 0);
|
||||
assert_eq!(info.amount_reverted, 0);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 1);
|
||||
let tx = &txs[0];
|
||||
assert_eq!(tx.tx_type, libwallet::TxLogEntryType::TxReceived);
|
||||
assert!(!tx.confirmed);
|
||||
Ok(())
|
||||
})?;
|
||||
let (refreshed, info) = api2.retrieve_summary_info(mask2, true, 1)?;
|
||||
assert!(refreshed);
|
||||
assert_eq!(info.last_confirmed_height, bh);
|
||||
assert_eq!(info.total, 0);
|
||||
assert_eq!(info.amount_currently_spendable, 0);
|
||||
assert_eq!(info.amount_reverted, 0);
|
||||
// check tx log as well
|
||||
let (_, txs) = api2.retrieve_txs(mask2, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 1);
|
||||
assert_eq!(txs[0].tx_type, libwallet::TxLogEntryType::TxReceived);
|
||||
assert!(!&txs[0].confirmed);
|
||||
|
||||
// Update parallel chain
|
||||
assert_eq!(chain2.head_header().unwrap().height, 0);
|
||||
@@ -208,8 +182,13 @@ fn revert(
|
||||
|
||||
// Build 2 blocks at same height: 1 with the tx, 1 without
|
||||
let head = chain.head_header().unwrap();
|
||||
let block_with =
|
||||
create_block_for_wallet(&chain, head.clone(), &[tx.clone()], wallet1.clone(), mask1)?;
|
||||
let block_with = create_block_for_wallet(
|
||||
&chain,
|
||||
head.clone(),
|
||||
std::slice::from_ref(&tx),
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
)?;
|
||||
let block_without = create_block_for_wallet(&chain, head, &[], wallet1.clone(), mask1)?;
|
||||
|
||||
// Add block with tx to the chain
|
||||
@@ -223,23 +202,19 @@ fn revert(
|
||||
let bh = bh + 1;
|
||||
|
||||
// Check funds have been confirmed
|
||||
owner(wallet2.clone(), mask2, PathBuf::from(test_dir), |api, m| {
|
||||
let (refreshed, info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(refreshed);
|
||||
assert_eq!(info.last_confirmed_height, bh);
|
||||
assert_eq!(info.total, sent);
|
||||
assert_eq!(info.amount_currently_spendable, sent);
|
||||
assert_eq!(info.amount_reverted, 0);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 1);
|
||||
let tx = &txs[0];
|
||||
assert_eq!(tx.tx_type, libwallet::TxLogEntryType::TxReceived);
|
||||
assert!(tx.confirmed);
|
||||
assert!(tx.kernel_excess.is_some());
|
||||
assert!(tx.reverted_after.is_none());
|
||||
Ok(())
|
||||
})?;
|
||||
let (refreshed, info) = api2.retrieve_summary_info(mask2, true, 1)?;
|
||||
assert!(refreshed);
|
||||
assert_eq!(info.last_confirmed_height, bh);
|
||||
assert_eq!(info.total, sent);
|
||||
assert_eq!(info.amount_currently_spendable, sent);
|
||||
assert_eq!(info.amount_reverted, 0);
|
||||
// check tx log as well
|
||||
let (_, txs) = api2.retrieve_txs(mask2, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 1);
|
||||
assert_eq!(txs[0].tx_type, libwallet::TxLogEntryType::TxReceived);
|
||||
assert!(&txs[0].confirmed);
|
||||
assert!(&txs[0].kernel_excess.is_some());
|
||||
assert!(&txs[0].reverted_after.is_none());
|
||||
|
||||
// Attach more blocks to the parallel chain, making it the longest one
|
||||
award_block_to_wallet(&chain2, &[], wallet1.clone(), mask1)?;
|
||||
@@ -258,32 +233,29 @@ fn revert(
|
||||
let bh = bh + 1;
|
||||
|
||||
// Check funds have been reverted
|
||||
owner(wallet2.clone(), mask2, PathBuf::from(test_dir), |api, m| {
|
||||
api.scan(m, None, false)?;
|
||||
let (refreshed, info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(refreshed);
|
||||
assert_eq!(info.last_confirmed_height, bh);
|
||||
assert_eq!(info.total, 0);
|
||||
assert_eq!(info.amount_currently_spendable, 0);
|
||||
assert_eq!(info.amount_reverted, sent);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 1);
|
||||
let tx = &txs[0];
|
||||
assert_eq!(tx.tx_type, libwallet::TxLogEntryType::TxReverted);
|
||||
assert!(!tx.confirmed);
|
||||
assert!(tx.reverted_after.is_some());
|
||||
Ok(())
|
||||
})?;
|
||||
api2.scan(mask2, None, false)?;
|
||||
let (refreshed, info) = api2.retrieve_summary_info(mask2, true, 1)?;
|
||||
assert!(refreshed);
|
||||
assert_eq!(info.last_confirmed_height, bh);
|
||||
assert_eq!(info.total, 0);
|
||||
assert_eq!(info.amount_currently_spendable, 0);
|
||||
assert_eq!(info.amount_reverted, sent);
|
||||
// check tx log as well
|
||||
let (_, txs) = api2.retrieve_txs(mask2, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 1);
|
||||
assert_eq!(txs[0].tx_type, libwallet::TxLogEntryType::TxReverted);
|
||||
assert!(!&txs[0].confirmed);
|
||||
assert!(&txs[0].reverted_after.is_some());
|
||||
|
||||
stopper2.store(false, Ordering::Relaxed);
|
||||
Ok((
|
||||
chain, stopper, sent, bh, tx, wallet1, mask1_i, wallet2, mask2_i,
|
||||
chain, stopper, sent, bh, tx, wallet1, mask1_i, wallet2, mask2_i, api1, api2,
|
||||
))
|
||||
}
|
||||
|
||||
fn revert_reconfirm_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
let (chain, stopper, sent, bh, tx, wallet1, mask1_i, wallet2, mask2_i) = revert(test_dir)?;
|
||||
let (chain, stopper, sent, bh, tx, wallet1, mask1_i, _wallet2, mask2_i, _api1, api2) =
|
||||
revert(test_dir)?;
|
||||
let mask1 = mask1_i.as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
@@ -293,22 +265,19 @@ fn revert_reconfirm_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
let bh = bh + 1;
|
||||
|
||||
// Check funds have been confirmed again
|
||||
owner(wallet2.clone(), mask2, PathBuf::from(test_dir), |api, m| {
|
||||
let (refreshed, info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(refreshed);
|
||||
assert_eq!(info.last_confirmed_height, bh);
|
||||
assert_eq!(info.total, sent);
|
||||
assert_eq!(info.amount_currently_spendable, sent);
|
||||
assert_eq!(info.amount_reverted, 0);
|
||||
// check tx log as well
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 1);
|
||||
let tx = &txs[0];
|
||||
assert_eq!(tx.tx_type, libwallet::TxLogEntryType::TxReceived);
|
||||
assert!(tx.confirmed);
|
||||
assert!(tx.reverted_after.is_none());
|
||||
Ok(())
|
||||
})?;
|
||||
let (refreshed, info) = api2.retrieve_summary_info(mask2, true, 1)?;
|
||||
assert!(refreshed);
|
||||
assert_eq!(info.last_confirmed_height, bh);
|
||||
assert_eq!(info.total, sent);
|
||||
assert_eq!(info.amount_currently_spendable, sent);
|
||||
assert_eq!(info.amount_reverted, 0);
|
||||
// check tx log as well
|
||||
let (_, txs) = api2.retrieve_txs(mask2, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 1);
|
||||
let tx = &txs[0];
|
||||
assert_eq!(tx.tx_type, libwallet::TxLogEntryType::TxReceived);
|
||||
assert!(tx.confirmed);
|
||||
assert!(tx.reverted_after.is_none());
|
||||
|
||||
// let logging finish
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
@@ -317,41 +286,37 @@ fn revert_reconfirm_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
}
|
||||
|
||||
fn revert_cancel_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
let (_, stopper, sent, bh, _, _, _, wallet2, mask2_i) = revert(test_dir)?;
|
||||
let (_, stopper, sent, bh, _, _, _, _wallet2, mask2_i, _api1, api2) = revert(test_dir)?;
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Cancelling tx
|
||||
owner(wallet2.clone(), mask2, PathBuf::from(test_dir), |api, m| {
|
||||
// Sanity check
|
||||
let (refreshed, info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(refreshed);
|
||||
assert_eq!(info.last_confirmed_height, bh);
|
||||
assert_eq!(info.total, 0);
|
||||
assert_eq!(info.amount_currently_spendable, 0);
|
||||
assert_eq!(info.amount_reverted, sent);
|
||||
// Sanity check
|
||||
let (refreshed, info) = api2.retrieve_summary_info(mask2, true, 1)?;
|
||||
assert!(refreshed);
|
||||
assert_eq!(info.last_confirmed_height, bh);
|
||||
assert_eq!(info.total, 0);
|
||||
assert_eq!(info.amount_currently_spendable, 0);
|
||||
assert_eq!(info.amount_reverted, sent);
|
||||
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 1);
|
||||
let tx = &txs[0];
|
||||
let (_, txs) = api2.retrieve_txs(mask2, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 1);
|
||||
let tx = &txs[0];
|
||||
|
||||
// Cancel
|
||||
api.cancel_tx(m, Some(tx.id), None)?;
|
||||
// Cancel
|
||||
api2.cancel_tx(mask2, Some(tx.id), None)?;
|
||||
|
||||
// Check updated summary info
|
||||
let (refreshed, info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(refreshed);
|
||||
assert_eq!(info.last_confirmed_height, bh);
|
||||
assert_eq!(info.total, 0);
|
||||
assert_eq!(info.amount_currently_spendable, 0);
|
||||
assert_eq!(info.amount_reverted, 0);
|
||||
// Check updated summary info
|
||||
let (refreshed, info) = api2.retrieve_summary_info(mask2, true, 1)?;
|
||||
assert!(refreshed);
|
||||
assert_eq!(info.last_confirmed_height, bh);
|
||||
assert_eq!(info.total, 0);
|
||||
assert_eq!(info.amount_currently_spendable, 0);
|
||||
assert_eq!(info.amount_reverted, 0);
|
||||
|
||||
// Check updated tx log
|
||||
let (_, txs) = api.retrieve_txs(m, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 1);
|
||||
let tx = &txs[0];
|
||||
assert_eq!(tx.tx_type, libwallet::TxLogEntryType::TxReceivedCancelled);
|
||||
Ok(())
|
||||
})?;
|
||||
// Check updated tx log
|
||||
let (_, txs) = api2.retrieve_txs(mask2, true, None, None, None)?;
|
||||
assert_eq!(txs.len(), 1);
|
||||
let tx = &txs[0];
|
||||
assert_eq!(tx.tx_type, libwallet::TxLogEntryType::TxReceivedCancelled);
|
||||
|
||||
// let logging finish
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
|
||||
+100
-70
@@ -30,6 +30,7 @@ use std::time::Duration;
|
||||
#[macro_use]
|
||||
mod common;
|
||||
use common::{clean_output_dir, create_wallet_proxy, setup};
|
||||
use grin_wallet_libwallet::slatepack::SlatepackAddressIndex;
|
||||
|
||||
/// self send impl
|
||||
fn self_send_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
@@ -48,9 +49,10 @@ fn self_send_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
true
|
||||
true,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -63,99 +65,67 @@ fn self_send_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
let reward = core::consensus::REWARD;
|
||||
|
||||
// add some accounts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.create_account_path(m, "mining")?;
|
||||
api.create_account_path(m, "listener")?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api1.create_account_path(mask1, "mining")?;
|
||||
api1.create_account_path(mask1, "listener")?;
|
||||
|
||||
// Get some mining done
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("mining")?;
|
||||
w.set_account_by_name("mining")?;
|
||||
}
|
||||
let mut bh = 10u64;
|
||||
let _ =
|
||||
test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, bh as usize, false);
|
||||
|
||||
// Should have 5 in account1 (5 spendable), 5 in account (2 spendable)
|
||||
wallet::controller::owner_single_use(
|
||||
let (wallet1_refreshed, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward);
|
||||
// send to send
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: Some("mining".to_owned()),
|
||||
amount: reward * 2,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
let mut slate = api1.init_send_tx(mask1, args)?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
// Send directly to self
|
||||
wallet::controller::foreign_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward);
|
||||
// send to send
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: Some("mining".to_owned()),
|
||||
amount: reward * 2,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
let mut slate = api.init_send_tx(m, args)?;
|
||||
api.tx_lock_outputs(m, &slate)?;
|
||||
// Send directly to self
|
||||
wallet::controller::foreign_single_use(
|
||||
wallet1.clone(),
|
||||
PathBuf::from(test_dir),
|
||||
mask1_i.clone(),
|
||||
|api| {
|
||||
slate = api.receive_tx(&slate, Some("listener"), None)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
slate = api.finalize_tx(m, &slate)?;
|
||||
api.post_tx(m, &slate, false)?; // mines a block
|
||||
bh += 1;
|
||||
mask1_i.clone(),
|
||||
|api| {
|
||||
slate = api.receive_tx(&slate, Some("listener"), None)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
slate = api1.finalize_tx(mask1, &slate)?;
|
||||
api1.post_tx(mask1, &slate, false)?; // mines a block
|
||||
bh += 1;
|
||||
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 3, false);
|
||||
bh += 3;
|
||||
|
||||
// Check total in mining account
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward - reward * 2);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (wallet1_refreshed, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward - reward * 2);
|
||||
|
||||
// Check total in 'listener' account
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("listener")?;
|
||||
w.set_account_by_name("listener")?;
|
||||
}
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, 2 * reward);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (wallet1_refreshed, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, 2 * reward);
|
||||
|
||||
// let logging finish
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
@@ -172,3 +142,63 @@ fn wallet_self_send() {
|
||||
}
|
||||
clean_output_dir(test_dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn late_lock_self_send_proof() -> Result<(), libwallet::Error> {
|
||||
let test_dir = "test_output/late_lock_self_send_proof";
|
||||
setup(test_dir);
|
||||
let mut wallet_proxy = create_wallet_proxy(test_dir);
|
||||
let chain = wallet_proxy.chain.clone();
|
||||
let stopper = wallet_proxy.running.clone();
|
||||
create_wallet_and_add!(
|
||||
client1,
|
||||
wallet1,
|
||||
mask1_i,
|
||||
test_dir,
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = mask1_i.as_ref();
|
||||
let worker = thread::spawn(move || wallet_proxy.run());
|
||||
|
||||
let result = (|| {
|
||||
test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 10, false)?;
|
||||
let mut slate = api1.init_send_tx(
|
||||
mask1,
|
||||
InitTxArgs {
|
||||
amount: core::consensus::REWARD,
|
||||
minimum_confirmations: 2,
|
||||
late_lock: Some(true),
|
||||
payment_proof_recipient_address: Some(
|
||||
api1.get_slatepack_address(mask1, SlatepackAddressIndex(0))?,
|
||||
),
|
||||
..Default::default()
|
||||
},
|
||||
)?;
|
||||
wallet::controller::foreign_single_use(
|
||||
wallet1.clone(),
|
||||
PathBuf::from(test_dir),
|
||||
mask1_i.clone(),
|
||||
|api| {
|
||||
slate = api.receive_tx(&slate, None, None)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (_, txs) = api1.retrieve_txs(mask1, false, None, Some(slate.id), None)?;
|
||||
assert_eq!(txs.len(), 1);
|
||||
assert_eq!(txs[0].tx_type, libwallet::TxLogEntryType::TxReceived);
|
||||
|
||||
api1.finalize_tx(mask1, &slate).map(|_| ())
|
||||
})();
|
||||
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
worker.join().unwrap()?;
|
||||
drop(api1);
|
||||
drop(wallet1);
|
||||
drop(chain);
|
||||
clean_output_dir(test_dir);
|
||||
result
|
||||
}
|
||||
|
||||
@@ -48,9 +48,10 @@ fn self_send_cancel_test_impl(test_dir: &'static str) -> Result<(), libwallet::E
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
true
|
||||
true,
|
||||
_api
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -67,45 +68,40 @@ fn self_send_cancel_test_impl(test_dir: &'static str) -> Result<(), libwallet::E
|
||||
test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, bh as usize, false);
|
||||
|
||||
// Should have 5 in account1 (5 spendable), 5 in account (2 spendable)
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward);
|
||||
// send to send
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: reward * 2,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
let mut slate = api.init_send_tx(m, args)?;
|
||||
api.tx_lock_outputs(m, &slate)?;
|
||||
// Send directly to self
|
||||
wallet::controller::foreign_single_use(
|
||||
wallet1.clone(),
|
||||
PathBuf::from(test_dir),
|
||||
mask1_i.clone(),
|
||||
|api| {
|
||||
slate = api.receive_tx(&slate, None, None)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// Now cancel the transaction
|
||||
api.cancel_tx(mask1, None, Some(slate.id.clone()))?;
|
||||
bh += 1;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
common::owner_single_use(wallet1.clone(), mask1, PathBuf::from(test_dir), |api, m| {
|
||||
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
assert!(wallet1_refreshed);
|
||||
assert_eq!(wallet1_info.last_confirmed_height, bh);
|
||||
assert_eq!(wallet1_info.total, bh * reward);
|
||||
// send to send
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: reward * 2,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
let mut slate = api.init_send_tx(m, args)?;
|
||||
api.tx_lock_outputs(m, &slate)?;
|
||||
// Send directly to self
|
||||
wallet::controller::foreign_single_use(
|
||||
wallet1.clone(),
|
||||
PathBuf::from(test_dir),
|
||||
mask1_i.clone(),
|
||||
|api| {
|
||||
slate = api.receive_tx(&slate, None, None)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// Now cancel the transaction
|
||||
api.cancel_tx(mask1, None, Some(slate.id))?;
|
||||
bh += 1;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
common::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|
||||
+530
-432
File diff suppressed because it is too large
Load Diff
+520
-563
File diff suppressed because it is too large
Load Diff
+55
-104
@@ -20,8 +20,7 @@ extern crate grin_wallet_util;
|
||||
|
||||
use grin_wallet_libwallet as libwallet;
|
||||
use impls::test_framework::{self, LocalWalletClient};
|
||||
use libwallet::{InitTxArgs, Slate, TxLogEntryType};
|
||||
use std::path::PathBuf;
|
||||
use libwallet::{InitTxArgs, TxLogEntryType};
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
@@ -45,10 +44,11 @@ fn ttl_cutoff_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api1
|
||||
);
|
||||
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
@@ -58,10 +58,11 @@ fn ttl_cutoff_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api2
|
||||
);
|
||||
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -78,126 +79,76 @@ fn ttl_cutoff_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, bh as usize, false);
|
||||
|
||||
let amount = 60_000_000_000;
|
||||
let mut slate = Slate::blank(1, false);
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|sender_api, m| {
|
||||
// note this will increment the block count as part of the transaction "Posting"
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
ttl_blocks: Some(2),
|
||||
..Default::default()
|
||||
};
|
||||
let slate_i = sender_api.init_send_tx(m, args)?;
|
||||
// note this will increment the block count as part of the transaction "Posting"
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
ttl_blocks: Some(2),
|
||||
..Default::default()
|
||||
};
|
||||
let slate_i = api1.init_send_tx(mask1, args)?;
|
||||
|
||||
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
|
||||
sender_api.tx_lock_outputs(m, &slate)?;
|
||||
let mut slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
|
||||
let (_, txs) = sender_api.retrieve_txs(m, true, None, Some(slate.id), None)?;
|
||||
let tx = txs[0].clone();
|
||||
let (_, txs) = api1.retrieve_txs(mask1, true, None, Some(slate.id), None)?;
|
||||
let tx = txs[0].clone();
|
||||
|
||||
assert_eq!(tx.ttl_cutoff_height, Some(12));
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
assert_eq!(tx.ttl_cutoff_height, Some(12));
|
||||
|
||||
// Now mine past the block, and check again. Transaction should be gone.
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 2, false);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|sender_api, m| {
|
||||
let (_, txs) = sender_api.retrieve_txs(m, true, None, Some(slate.id), None)?;
|
||||
let tx = txs[0].clone();
|
||||
let (_, txs) = api1.retrieve_txs(mask1, true, None, Some(slate.id), None)?;
|
||||
let tx = txs[0].clone();
|
||||
|
||||
assert_eq!(tx.ttl_cutoff_height, Some(12));
|
||||
assert_eq!(tx.tx_type, TxLogEntryType::TxSentCancelled);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
assert_eq!(tx.ttl_cutoff_height, Some(12));
|
||||
assert_eq!(tx.tx_type, TxLogEntryType::TxSentCancelled);
|
||||
|
||||
// Should also be gone in wallet 2, and output gone
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|sender_api, m| {
|
||||
let (_, txs) = sender_api.retrieve_txs(m, true, None, Some(slate.id), None)?;
|
||||
let tx = txs[0].clone();
|
||||
let outputs = sender_api.retrieve_outputs(m, false, true, None)?.1;
|
||||
assert_eq!(outputs.len(), 0);
|
||||
let (_, txs) = api2.retrieve_txs(mask2, true, None, Some(slate.id), None)?;
|
||||
let tx = txs[0].clone();
|
||||
let outputs = api2.retrieve_outputs(mask2, false, true, None)?.1;
|
||||
assert_eq!(outputs.len(), 0);
|
||||
|
||||
assert_eq!(tx.ttl_cutoff_height, Some(12));
|
||||
assert_eq!(tx.tx_type, TxLogEntryType::TxReceivedCancelled);
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
assert_eq!(tx.ttl_cutoff_height, Some(12));
|
||||
assert_eq!(tx.tx_type, TxLogEntryType::TxReceivedCancelled);
|
||||
|
||||
// try again, except try and send off the transaction for completion beyond the expiry
|
||||
let mut slate = Slate::blank(1, false);
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|sender_api, m| {
|
||||
// note this will increment the block count as part of the transaction "Posting"
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
ttl_blocks: Some(2),
|
||||
..Default::default()
|
||||
};
|
||||
let slate_i = sender_api.init_send_tx(m, args)?;
|
||||
sender_api.tx_lock_outputs(m, &slate_i)?;
|
||||
slate = slate_i;
|
||||
// note this will increment the block count as part of the transaction "Posting"
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount,
|
||||
minimum_confirmations: 2,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: true,
|
||||
ttl_blocks: Some(2),
|
||||
..Default::default()
|
||||
};
|
||||
let slate_i = api1.init_send_tx(mask1, args)?;
|
||||
api1.tx_lock_outputs(mask1, &slate_i)?;
|
||||
slate = slate_i;
|
||||
|
||||
let (_, txs) = sender_api.retrieve_txs(m, true, None, Some(slate.id), None)?;
|
||||
let tx = txs[0].clone();
|
||||
let (_, txs) = api1.retrieve_txs(mask1, true, None, Some(slate.id), None)?;
|
||||
let tx = txs[0].clone();
|
||||
|
||||
assert_eq!(tx.ttl_cutoff_height, Some(14));
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
assert_eq!(tx.ttl_cutoff_height, Some(14));
|
||||
|
||||
// Mine past the ttl block and try to send
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 2, false);
|
||||
|
||||
// Wallet 2 will need to have updated past the TTL
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|sender_api, m| {
|
||||
let (_, _) = sender_api.retrieve_txs(m, true, None, Some(slate.id), None)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (_, _) = api2.retrieve_txs(mask2, true, None, Some(slate.id), None)?;
|
||||
|
||||
// And when wallet 1 sends, should be rejected
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|_sender_api, _m| {
|
||||
let res = client1.send_tx_slate_direct("wallet2", &slate);
|
||||
println!("Send after TTL result is: {:?}", res);
|
||||
assert!(res.is_err());
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let res = client1.send_tx_slate_direct("wallet2", &slate);
|
||||
println!("Send after TTL result is: {:?}", res);
|
||||
assert!(res.is_err());
|
||||
|
||||
// let logging finish
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
|
||||
+217
-235
@@ -23,191 +23,214 @@ use grin_core as core;
|
||||
use grin_keychain as keychain;
|
||||
use grin_util as util;
|
||||
use libwallet::{RetrieveTxQueryArgs, RetrieveTxQuerySortField};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use self::libwallet::{InitTxArgs, Slate};
|
||||
use self::libwallet::InitTxArgs;
|
||||
use impls::test_framework::{self, LocalWalletClient};
|
||||
use std::sync::{atomic::Ordering, Arc};
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use util::secp::key::SecretKey;
|
||||
use util::Mutex;
|
||||
|
||||
use self::keychain::ExtKeychain;
|
||||
use self::libwallet::WalletInst;
|
||||
use impls::DefaultLCProvider;
|
||||
|
||||
mod common;
|
||||
use common::{clean_output_dir, create_wallet_proxy, setup};
|
||||
use grin_wallet_api::Owner;
|
||||
|
||||
fn test_wallet_tx_filtering(
|
||||
wallet: Arc<
|
||||
Mutex<
|
||||
Box<
|
||||
dyn WalletInst<
|
||||
'static,
|
||||
DefaultLCProvider<LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
ExtKeychain,
|
||||
>,
|
||||
>,
|
||||
>,
|
||||
>,
|
||||
mask: Option<&SecretKey>,
|
||||
test_dir: &'static str,
|
||||
api: Owner<DefaultLCProvider<LocalWalletClient, ExtKeychain>, LocalWalletClient, ExtKeychain>,
|
||||
) -> Result<(), libwallet::Error> {
|
||||
wallet::controller::owner_single_use(
|
||||
wallet.clone(),
|
||||
mask,
|
||||
PathBuf::from(test_dir),
|
||||
|api, _m| {
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.min_id = Some(5);
|
||||
let query = |args| {
|
||||
api.retrieve_txs(mask, true, None, None, Some(args))
|
||||
.map(|(_, txs)| txs)
|
||||
};
|
||||
let txs = query(RetrieveTxQueryArgs::default())?;
|
||||
assert!(!txs.is_empty());
|
||||
let before_first_tx =
|
||||
txs.iter().map(|tx| tx.creation_ts).min().unwrap() - Duration::from_secs(1);
|
||||
// Max creation time before all test transactions
|
||||
let mut tx_query_args = RetrieveTxQueryArgs {
|
||||
max_creation_timestamp: Some(before_first_tx),
|
||||
..Default::default()
|
||||
};
|
||||
assert!(query(tx_query_args.clone())?.is_empty());
|
||||
|
||||
// Min ID
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results[0].id, 5);
|
||||
assert_eq!(tx_results[tx_results.len() - 1].id, 33);
|
||||
// Min confirmation time should not affect creation time
|
||||
tx_query_args.max_creation_timestamp = None;
|
||||
tx_query_args.min_confirmed_timestamp = Some(before_first_tx);
|
||||
assert_eq!(query(tx_query_args)?.len(), txs.len());
|
||||
|
||||
// Max ID
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.min_id = Some(5);
|
||||
tx_query_args.max_id = Some(20);
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results[0].id, 5);
|
||||
assert_eq!(tx_results[tx_results.len() - 1].id, 20);
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
min_id: Some(5),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// Exclude 1 cancelled
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.exclude_cancelled = Some(true);
|
||||
tx_query_args.min_id = Some(5);
|
||||
tx_query_args.max_id = Some(50);
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 28);
|
||||
// Min ID
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results[0].id, 5);
|
||||
assert_eq!(tx_results[tx_results.len() - 1].id, 33);
|
||||
|
||||
// Exclude 1 cancelled, show confirmed only
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.exclude_cancelled = Some(true);
|
||||
tx_query_args.include_confirmed_only = Some(true);
|
||||
tx_query_args.min_id = Some(5);
|
||||
tx_query_args.max_id = Some(50);
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 14);
|
||||
// Max ID
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
min_id: Some(5),
|
||||
max_id: Some(20),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results[0].id, 5);
|
||||
assert_eq!(tx_results[tx_results.len() - 1].id, 20);
|
||||
|
||||
// show outstanding only (including cancelled)
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.exclude_cancelled = Some(false);
|
||||
tx_query_args.include_outstanding_only = Some(true);
|
||||
tx_query_args.min_id = Some(5);
|
||||
tx_query_args.max_id = Some(50);
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 15);
|
||||
// Exclude 1 canceled
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
exclude_cancelled: Some(true),
|
||||
min_id: Some(5),
|
||||
max_id: Some(50),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 28);
|
||||
|
||||
// outstanding only and confirmed only should give empty set
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.exclude_cancelled = Some(false);
|
||||
tx_query_args.include_outstanding_only = Some(true);
|
||||
tx_query_args.include_confirmed_only = Some(true);
|
||||
tx_query_args.min_id = Some(5);
|
||||
tx_query_args.max_id = Some(50);
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 0);
|
||||
// Exclude 1 canceled, show confirmed only
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
exclude_cancelled: Some(true),
|
||||
include_confirmed_only: Some(true),
|
||||
min_id: Some(5),
|
||||
max_id: Some(50),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 14);
|
||||
|
||||
// include sent only
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.include_sent_only = Some(true);
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 15);
|
||||
// show outstanding only (including canceled)
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
exclude_cancelled: Some(false),
|
||||
include_outstanding_only: Some(true),
|
||||
min_id: Some(5),
|
||||
max_id: Some(50),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 15);
|
||||
|
||||
// include received only (none in this set)
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.include_received_only = Some(true);
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 0);
|
||||
// outstanding only and confirmed only should give empty set
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
exclude_cancelled: Some(false),
|
||||
include_outstanding_only: Some(true),
|
||||
include_confirmed_only: Some(true),
|
||||
min_id: Some(5),
|
||||
max_id: Some(50),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 0);
|
||||
|
||||
// include reverted only (none in this set)
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.include_reverted_only = Some(true);
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 0);
|
||||
// include sent only
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
include_sent_only: Some(true),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 15);
|
||||
|
||||
// include coinbase only
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.include_coinbase_only = Some(true);
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 19);
|
||||
// include received only (none in this set)
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
include_received_only: Some(true),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 0);
|
||||
|
||||
// Amounts
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.min_amount = Some(60_000_000_000 - 59_963_300_000);
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 27);
|
||||
// include reverted only (none in this set)
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
include_reverted_only: Some(true),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 0);
|
||||
|
||||
// amount, should see as above with coinbases excluded
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.min_amount = Some(60_000_000_000 - 59_963_300_000);
|
||||
tx_query_args.max_amount = Some(60_000_000_000 - 1);
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 8);
|
||||
// include coinbase only
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
include_coinbase_only: Some(true),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 19);
|
||||
|
||||
// Amount - should only see coinbase (incoming)
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.min_amount = Some(60_000_000_000);
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 19);
|
||||
// Amounts
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
min_amount: Some(60_000_000_000 - 59_963_300_000),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 27);
|
||||
|
||||
// sort order
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.sort_order = Some(libwallet::RetrieveTxQuerySortOrder::Desc);
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
// amount, should see as above with coinbases excluded
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
min_amount: Some(60_000_000_000 - 59_963_300_000),
|
||||
max_amount: Some(60_000_000_000 - 1),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 8);
|
||||
|
||||
assert_eq!(tx_results[0].id, 33);
|
||||
assert_eq!(tx_results[tx_results.len() - 1].id, 0);
|
||||
// Amount - should only see coinbase (incoming)
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
min_amount: Some(60_000_000_000),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 19);
|
||||
|
||||
// change sort field to amount desc, should have coinbases first
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.sort_order = Some(libwallet::RetrieveTxQuerySortOrder::Desc);
|
||||
tx_query_args.sort_field = Some(RetrieveTxQuerySortField::TotalAmount);
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results[0].amount_credited, 60_000_000_000);
|
||||
// sort order
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
sort_order: Some(libwallet::RetrieveTxQuerySortOrder::Desc),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
|
||||
/*for entry in tx_results.iter() {
|
||||
println!("{:?}", entry);
|
||||
}*/
|
||||
assert_eq!(tx_results[0].id, 33);
|
||||
assert_eq!(tx_results[tx_results.len() - 1].id, 0);
|
||||
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
// change sort field to amount desc, should have coinbases first
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
sort_order: Some(libwallet::RetrieveTxQuerySortOrder::Desc),
|
||||
sort_field: Some(RetrieveTxQuerySortField::TotalAmount),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results[0].amount_credited, 60_000_000_000);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -229,9 +252,10 @@ fn build_chain_for_tx_filtering(
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
true
|
||||
true,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
debug!("Mask1: {:?}", mask1);
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
@@ -241,9 +265,10 @@ fn build_chain_for_tx_filtering(
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
debug!("Mask2: {:?}", mask2);
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
@@ -255,25 +280,8 @@ fn build_chain_for_tx_filtering(
|
||||
|
||||
// Stop the scanning updater threads because it extends the time needed to build the chain
|
||||
// exponentially
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, _m| {
|
||||
api.stop_updater()?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, _m| {
|
||||
api.stop_updater()?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api1.stop_updater()?;
|
||||
api2.stop_updater()?;
|
||||
|
||||
// few values to keep things shorter
|
||||
let reward = core::consensus::REWARD;
|
||||
@@ -285,22 +293,14 @@ fn build_chain_for_tx_filtering(
|
||||
let mut wallet_1_has_funds = false;
|
||||
|
||||
// Check wallet 1 contents
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let (_, wallet1_info) = api.retrieve_summary_info(m, true, 1)?;
|
||||
debug!(
|
||||
"Wallet 1 spendable - {}",
|
||||
wallet1_info.amount_currently_spendable
|
||||
);
|
||||
if wallet1_info.amount_currently_spendable > reward {
|
||||
wallet_1_has_funds = true;
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let (_, wallet1_info) = api1.retrieve_summary_info(mask1, true, 1)?;
|
||||
debug!(
|
||||
"Wallet 1 spendable - {}",
|
||||
wallet1_info.amount_currently_spendable
|
||||
);
|
||||
if wallet1_info.amount_currently_spendable > reward {
|
||||
wallet_1_has_funds = true;
|
||||
}
|
||||
|
||||
if !wallet_1_has_funds {
|
||||
let _ =
|
||||
@@ -312,62 +312,44 @@ fn build_chain_for_tx_filtering(
|
||||
let num_txs = 1;
|
||||
for _ in 0..num_txs {
|
||||
let amount: u64 = i as u64 * 1_000_000;
|
||||
let mut slate = Slate::blank(1, false);
|
||||
debug!("Creating TX for {}", amount);
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|sender_api, m| {
|
||||
// note this will increment the block count as part of the transaction "Posting"
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: amount,
|
||||
minimum_confirmations: 1,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: false,
|
||||
..Default::default()
|
||||
};
|
||||
let slate_i = sender_api.init_send_tx(m, args)?;
|
||||
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
|
||||
sender_api.tx_lock_outputs(m, &slate)?;
|
||||
slate = sender_api.finalize_tx(m, &slate)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
// Cancel a tx for filtering testing
|
||||
let amount: u64 = 1_000_000;
|
||||
let mut slate = Slate::blank(1, false);
|
||||
debug!("Creating TX for {}", amount);
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|sender_api, m| {
|
||||
// note this will increment the block count as part of the transaction "Posting"
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount: amount,
|
||||
amount,
|
||||
minimum_confirmations: 1,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: false,
|
||||
..Default::default()
|
||||
};
|
||||
let slate_i = sender_api.init_send_tx(m, args)?;
|
||||
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
|
||||
sender_api.tx_lock_outputs(m, &slate)?;
|
||||
sender_api.cancel_tx(m, Some(33), None)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
let slate_i = api1.init_send_tx(mask1, args)?;
|
||||
let slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
api1.finalize_tx(mask1, &slate)?;
|
||||
}
|
||||
}
|
||||
|
||||
// Cancel a tx for filtering testing
|
||||
let amount: u64 = 1_000_000;
|
||||
debug!("Creating TX for {}", amount);
|
||||
// note this will increment the block count as part of the transaction "Posting"
|
||||
let args = InitTxArgs {
|
||||
src_acct_name: None,
|
||||
amount,
|
||||
minimum_confirmations: 1,
|
||||
max_outputs: 500,
|
||||
num_change_outputs: 1,
|
||||
selection_strategy_is_use_all: false,
|
||||
..Default::default()
|
||||
};
|
||||
let slate_i = api1.init_send_tx(mask1, args)?;
|
||||
let slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
|
||||
api1.tx_lock_outputs(mask1, &slate)?;
|
||||
api1.cancel_tx(mask1, Some(33), None)?;
|
||||
|
||||
// Perform actual testing
|
||||
test_wallet_tx_filtering(wallet1, mask1, test_dir)?;
|
||||
test_wallet_tx_filtering(mask1, api1)?;
|
||||
|
||||
// let logging finish
|
||||
stopper.store(false, Ordering::Relaxed);
|
||||
|
||||
@@ -46,9 +46,10 @@ fn updater_thread_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err
|
||||
"wallet1",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
@@ -57,9 +58,10 @@ fn updater_thread_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err
|
||||
"wallet2",
|
||||
None,
|
||||
&mut wallet_proxy,
|
||||
false
|
||||
false,
|
||||
api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -69,33 +71,16 @@ fn updater_thread_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err
|
||||
});
|
||||
|
||||
// add some accounts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.create_account_path(m, "mining")?;
|
||||
api.create_account_path(m, "listener")?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api1.create_account_path(mask1, "mining")?;
|
||||
api1.create_account_path(mask1, "listener")?;
|
||||
|
||||
// add some accounts
|
||||
wallet::controller::owner_single_use(
|
||||
wallet2.clone(),
|
||||
mask2,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
api.create_account_path(m, "account1")?;
|
||||
api.create_account_path(m, "account2")?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
api2.create_account_path(mask2, "account1")?;
|
||||
api2.create_account_path(mask2, "account2")?;
|
||||
|
||||
// Get some mining done
|
||||
{
|
||||
wallet_inst!(wallet1, w);
|
||||
w.set_parent_key_id_by_name("mining")?;
|
||||
w.set_account_by_name("mining")?;
|
||||
}
|
||||
let bh = 10u64;
|
||||
let _ =
|
||||
|
||||
Reference in New Issue
Block a user