mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-12-01 19:33:56 +01:00
support contract minimum confirmations
This commit is contained in:
@@ -87,6 +87,15 @@ pub fn clean_output_dir(test_dir: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn contract_selection_args() -> libwallet::contract::types::OutputSelectionArgs {
|
||||
// Contract fixtures mine only a few blocks.
|
||||
libwallet::contract::types::OutputSelectionArgs {
|
||||
minimum_confirmations: Some(1),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn setup(test_dir: &str) {
|
||||
util::init_test_logger();
|
||||
clean_output_dir(test_dir);
|
||||
|
||||
@@ -169,6 +169,7 @@ fn contract_accounts_impl(test_dir: &'static str) -> Result<(), libwallet::Error
|
||||
// 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()
|
||||
},
|
||||
@@ -189,6 +190,7 @@ fn contract_accounts_impl(test_dir: &'static str) -> Result<(), libwallet::Error
|
||||
|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()
|
||||
};
|
||||
@@ -209,6 +211,7 @@ fn contract_accounts_impl(test_dir: &'static str) -> Result<(), libwallet::Error
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let args = &ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.contract_sign(m, &slate, args)?;
|
||||
@@ -331,6 +334,7 @@ fn contract_unknown_account_impl(test_dir: &'static str) -> Result<(), libwallet
|
||||
|api, m| {
|
||||
let args = &ContractNewArgsAPI {
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(-1_000_000_000),
|
||||
src_acct_name: Some("does_not_exist".to_string()),
|
||||
..Default::default()
|
||||
@@ -372,6 +376,7 @@ fn contract_missing_net_change_impl(test_dir: &'static str) -> Result<(), libwal
|
||||
|api, m| {
|
||||
let args = &ContractNewArgsAPI {
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: None,
|
||||
..Default::default()
|
||||
},
|
||||
|
||||
@@ -111,6 +111,7 @@ fn contract_accounts_switch_impl(test_dir: &'static str) -> Result<(), libwallet
|
||||
// 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()
|
||||
},
|
||||
@@ -134,6 +135,7 @@ fn contract_accounts_switch_impl(test_dir: &'static str) -> Result<(), libwallet
|
||||
|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()
|
||||
};
|
||||
@@ -155,6 +157,7 @@ fn contract_accounts_switch_impl(test_dir: &'static str) -> Result<(), libwallet
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let args = &ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.contract_sign(m, &slate, args)?;
|
||||
|
||||
@@ -68,6 +68,7 @@ fn contract_early_lock_tx_impl(test_dir: &'static str) -> Result<(), libwallet::
|
||||
// Send wallet inititates a standard transaction with --send=80
|
||||
let args = &ContractNewArgsAPI {
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(-80_000_000_000),
|
||||
num_participants: 2,
|
||||
add_outputs: true,
|
||||
@@ -115,6 +116,7 @@ fn contract_early_lock_tx_impl(test_dir: &'static str) -> Result<(), libwallet::
|
||||
m,
|
||||
&slate,
|
||||
&ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(80_000_000_000),
|
||||
..Default::default()
|
||||
},
|
||||
|
||||
@@ -81,6 +81,7 @@ fn contract_early_proofs_rsr_test_impl(test_dir: &'static str) -> Result<(), lib
|
||||
// Receive wallet (invoice) calls --receive=5
|
||||
let args = &mut ContractNewArgsAPI {
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(5_000_000_000),
|
||||
..Default::default()
|
||||
},
|
||||
@@ -106,6 +107,7 @@ fn contract_early_proofs_rsr_test_impl(test_dir: &'static str) -> Result<(), lib
|
||||
|api, m| {
|
||||
// Sending wallet (invoice) signs
|
||||
let args = &ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(-5_000_000_000),
|
||||
..Default::default()
|
||||
};
|
||||
@@ -125,6 +127,7 @@ fn contract_early_proofs_rsr_test_impl(test_dir: &'static str) -> Result<(), lib
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let args = &ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.contract_sign(m, &slate, args)?;
|
||||
|
||||
@@ -69,6 +69,7 @@ fn contract_early_proofs_srs_test_impl(test_dir: &'static str) -> Result<(), lib
|
||||
// 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()
|
||||
},
|
||||
@@ -90,6 +91,7 @@ fn contract_early_proofs_srs_test_impl(test_dir: &'static str) -> Result<(), lib
|
||||
|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()
|
||||
};
|
||||
@@ -112,6 +114,7 @@ fn contract_early_proofs_srs_test_impl(test_dir: &'static str) -> Result<(), lib
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let args = &ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
..Default::default()
|
||||
};
|
||||
let mut tampered = slate.clone();
|
||||
|
||||
@@ -49,6 +49,7 @@ fn contract_revoke_other_account_impl(test_dir: &'static str) -> Result<(), libw
|
||||
m,
|
||||
&ContractNewArgsAPI {
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(-1_000_000_000),
|
||||
num_participants: 2,
|
||||
add_outputs: true,
|
||||
@@ -85,6 +86,7 @@ fn contract_revoke_other_account_impl(test_dir: &'static str) -> Result<(), libw
|
||||
|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,
|
||||
@@ -215,6 +217,7 @@ fn contract_revoke_resume_impl(test_dir: &'static str) -> Result<(), libwallet::
|
||||
|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,
|
||||
|
||||
@@ -52,6 +52,7 @@ fn contract_rsr_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
// Receive wallet inititates an invoice transaction with --receive=5
|
||||
let args = &mut ContractNewArgsAPI {
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(5_000_000_000),
|
||||
..Default::default()
|
||||
},
|
||||
@@ -70,6 +71,7 @@ fn contract_rsr_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
|api, m| {
|
||||
// Send Wallet calls --send=5
|
||||
let args = &ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(-5_000_000_000),
|
||||
..Default::default()
|
||||
};
|
||||
@@ -86,6 +88,7 @@ fn contract_rsr_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let args = &mut ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.contract_sign(m, &slate, args)?;
|
||||
|
||||
@@ -50,6 +50,7 @@ fn contract_self_spend_tx_impl(test_dir: &'static str) -> Result<(), libwallet::
|
||||
// Send wallet inititates a standard transaction with --send=0
|
||||
let args = &ContractNewArgsAPI {
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(0),
|
||||
num_participants: 1,
|
||||
..Default::default()
|
||||
@@ -69,6 +70,7 @@ fn contract_self_spend_tx_impl(test_dir: &'static str) -> Result<(), libwallet::
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let args = &ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.contract_sign(m, &slate, args)?;
|
||||
|
||||
@@ -48,6 +48,7 @@ fn contract_self_spend_cancel_impl(test_dir: &'static str) -> Result<(), libwall
|
||||
// Send wallet initiates a standard transaction with --send=0
|
||||
let args = &ContractNewArgsAPI {
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(0),
|
||||
num_participants: 1,
|
||||
..Default::default()
|
||||
@@ -137,6 +138,7 @@ fn contract_self_spend_cancel_missing_stored_tx_impl(
|
||||
|api, m| {
|
||||
let args = &ContractNewArgsAPI {
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(0),
|
||||
num_participants: 1,
|
||||
..Default::default()
|
||||
@@ -155,6 +157,7 @@ fn contract_self_spend_cancel_missing_stored_tx_impl(
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let args = &ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.contract_sign(m, &slate, args)?;
|
||||
|
||||
@@ -62,7 +62,7 @@ fn contract_self_spend_custom_tx_impl(test_dir: &'static str) -> Result<(), libw
|
||||
let mut slate = Slate::blank(0, true); // this gets overriden below
|
||||
|
||||
let selection_args = OutputSelectionArgs {
|
||||
min_input_confirmation: 0,
|
||||
minimum_confirmations: Some(0),
|
||||
use_inputs: Some(use_inputs.clone()), // we will use two coinbase inputs
|
||||
// the sum is such that it will need to pick another input making total of 3 inputs
|
||||
make_outputs: Some(vec![
|
||||
@@ -100,7 +100,10 @@ fn contract_self_spend_custom_tx_impl(test_dir: &'static str) -> Result<(), libw
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let mut current_selection = selection_args.clone();
|
||||
current_selection.minimum_confirmations = None;
|
||||
let args = &ContractSetupArgsAPI {
|
||||
selection_args: current_selection,
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.contract_sign(m, &slate, args)?;
|
||||
@@ -196,3 +199,102 @@ fn wallet_contract_self_spend_custom_tx() -> Result<(), libwallet::Error> {
|
||||
clean_output_dir(test_dir);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn contract_min_confirmations() -> Result<(), libwallet::Error> {
|
||||
let test_dir = "test_output/contract_min_confirmations";
|
||||
setup(test_dir);
|
||||
let (wallets, _, stopper, bh) = create_wallets(
|
||||
vec![
|
||||
vec![("default", 7)],
|
||||
vec![("default", 1)],
|
||||
vec![("default", 3)],
|
||||
],
|
||||
test_dir,
|
||||
)
|
||||
.unwrap();
|
||||
let send_wallet = wallets[0].0.clone();
|
||||
let send_mask = wallets[0].1.as_ref();
|
||||
let recv_wallet = wallets[1].0.clone();
|
||||
let recv_mask = wallets[1].1.as_ref();
|
||||
let mut slate = Slate::blank(0, true);
|
||||
|
||||
wallet::controller::owner_single_use(
|
||||
send_wallet.clone(),
|
||||
send_mask,
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
slate = api.contract_new(
|
||||
m,
|
||||
&ContractNewArgsAPI {
|
||||
setup_args: 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::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 {
|
||||
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);
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
clean_output_dir(test_dir);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
// Send wallet inititates a standard transaction with --send=5
|
||||
let args = &mut ContractNewArgsAPI {
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(-5_000_000_000),
|
||||
..Default::default()
|
||||
},
|
||||
@@ -71,6 +72,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
|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()
|
||||
};
|
||||
@@ -252,6 +254,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let args = &mut ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
..Default::default()
|
||||
};
|
||||
slate = api.contract_sign(m, &slate, args)?;
|
||||
|
||||
@@ -53,6 +53,7 @@ fn contract_srs_mwixnet_tx_impl(test_dir: &'static str) -> Result<(), libwallet:
|
||||
// Send wallet inititates a standard transaction with --send=5
|
||||
let args = &mut ContractNewArgsAPI {
|
||||
setup_args: ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
net_change: Some(-5_000_000_000),
|
||||
..Default::default()
|
||||
},
|
||||
@@ -71,6 +72,7 @@ fn contract_srs_mwixnet_tx_impl(test_dir: &'static str) -> Result<(), libwallet:
|
||||
|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()
|
||||
};
|
||||
@@ -88,6 +90,7 @@ fn contract_srs_mwixnet_tx_impl(test_dir: &'static str) -> Result<(), libwallet:
|
||||
PathBuf::from(test_dir),
|
||||
|api, m| {
|
||||
let args = &mut ContractSetupArgsAPI {
|
||||
selection_args: common::contract_selection_args(),
|
||||
..Default::default()
|
||||
};
|
||||
args.proof_args.suppress_proof = true;
|
||||
|
||||
Reference in New Issue
Block a user