merge staging

This commit is contained in:
wiesche
2026-10-17 07:52:36 +02:00
137 changed files with 7846 additions and 7319 deletions
+185 -189
View File
@@ -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);
+31 -64
View File
@@ -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
+14 -23
View File
@@ -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
View File
@@ -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));
+83 -73
View File
@@ -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)
}
+13 -5
View File
@@ -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());
+150 -207
View File
@@ -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);
+113 -158
View File
@@ -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);
+6 -6
View File
@@ -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),
+22 -10
View File
@@ -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),
+22 -10
View File
@@ -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),
+94 -145
View File
@@ -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);
+5 -5
View File
@@ -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),
+5 -5
View File
@@ -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),
+43 -53
View File
@@ -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);
+20 -20
View File
@@ -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),
+21 -14
View File
@@ -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
View File
@@ -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
View File
@@ -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
+71 -82
View File
@@ -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
View File
@@ -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, &params, &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, &params, &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, &params, &last_output.commit, false)
.is_err());
// let logging finish
stopper.store(false, Ordering::Relaxed);
+76 -140
View File
@@ -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);
+59 -82
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
}
+36 -40
View File
@@ -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),
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+55 -104
View File
@@ -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
View File
@@ -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);
+11 -26
View File
@@ -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 _ =