use super::*;
use serial_test::parallel;
#[test]
#[parallel]
fn success() {
initialize();
let amount: u64 = 66;
let (wallet, online) = get_empty_wallet!();
let (rcv_wallet, rcv_online) = get_funded_wallet!();
let bak_info_before = wallet.database.get_backup_info().unwrap();
assert!(bak_info_before.is_none());
let unspent_list_settled = test_list_unspents(&wallet, None, true);
let bak_info_after = wallet.database.get_backup_info().unwrap();
assert!(bak_info_after.is_none());
assert_eq!(unspent_list_settled.len(), 0);
let unspent_list_all = test_list_unspents(&wallet, None, false);
assert_eq!(unspent_list_all.len(), 0);
fund_wallet(test_get_address(&wallet));
mine(false);
let unspent_list_settled = test_list_unspents(&wallet, Some(&online), true);
assert_eq!(unspent_list_settled.len(), 1);
let unspent_list_all = test_list_unspents(&wallet, None, false);
assert_eq!(unspent_list_all.len(), 1);
assert!(unspent_list_all.iter().all(|u| !u.utxo.colorable));
test_create_utxos_default(&wallet, &online);
let asset = test_issue_asset_nia(&wallet, &online, None);
let unspent_list_settled = test_list_unspents(&wallet, None, true);
assert_eq!(unspent_list_settled.len(), UTXO_NUM as usize + 1);
let unspent_list_all = test_list_unspents(&wallet, None, false);
assert_eq!(unspent_list_all.len(), UTXO_NUM as usize + 1);
assert_eq!(
unspent_list_all.iter().filter(|u| u.utxo.colorable).count(),
UTXO_NUM as usize
);
assert_eq!(
unspent_list_all
.iter()
.filter(|u| !u.utxo.colorable)
.count(),
1
);
let mut settled_allocations = vec![];
unspent_list_settled
.iter()
.for_each(|u| settled_allocations.extend(u.rgb_allocations.clone()));
assert_eq!(settled_allocations.len(), 1);
assert!(settled_allocations
.iter()
.all(|a| a.asset_id == Some(asset.asset_id.clone()) && a.amount == AMOUNT && a.settled));
let receive_data_fail = test_blind_receive(&rcv_wallet);
test_fail_transfers_blind(&rcv_wallet, &rcv_online, &receive_data_fail.recipient_id);
show_unspent_colorings(&rcv_wallet, "after blind fail");
let unspent_list_all = test_list_unspents(&rcv_wallet, None, false);
let mut allocations = vec![];
unspent_list_all
.iter()
.for_each(|u| allocations.extend(u.rgb_allocations.clone()));
assert_eq!(allocations.len(), 0);
let receive_data = test_blind_receive(&rcv_wallet);
let recipient_map = HashMap::from([(
asset.asset_id.clone(),
vec![Recipient {
amount,
recipient_data: RecipientData::BlindedUTXO(
SecretSeal::from_str(&receive_data.recipient_id).unwrap(),
),
transport_endpoints: TRANSPORT_ENDPOINTS.clone(),
}],
)]);
let txid = test_send(&wallet, &online, &recipient_map);
assert!(!txid.is_empty());
test_fail_transfers_txid(&wallet, &online, &txid);
show_unspent_colorings(&wallet, "after send fail");
let unspent_list_all = test_list_unspents(&wallet, None, false);
assert_eq!(
unspent_list_all.iter().filter(|u| u.utxo.colorable).count(),
UTXO_NUM as usize
);
assert_eq!(
unspent_list_all
.iter()
.filter(|u| !u.utxo.colorable)
.count(),
1
);
let mut allocations = vec![];
unspent_list_all
.iter()
.for_each(|u| allocations.extend(u.rgb_allocations.clone()));
assert_eq!(allocations.len(), 1);
assert!(allocations
.iter()
.all(|a| a.asset_id == Some(asset.asset_id.clone()) && a.amount == AMOUNT && a.settled));
drain_wallet(&wallet, &online);
fund_wallet(test_get_address(&wallet));
mine(false);
test_create_utxos_default(&wallet, &online);
drain_wallet(&rcv_wallet, &rcv_online);
fund_wallet(test_get_address(&rcv_wallet));
mine(false);
test_create_utxos_default(&rcv_wallet, &rcv_online);
let asset = test_issue_asset_nia(&wallet, &online, None);
let receive_data = test_blind_receive(&rcv_wallet);
let recipient_map = HashMap::from([(
asset.asset_id.clone(),
vec![Recipient {
amount,
recipient_data: RecipientData::BlindedUTXO(
SecretSeal::from_str(&receive_data.recipient_id).unwrap(),
),
transport_endpoints: TRANSPORT_ENDPOINTS.clone(),
}],
)]);
let txid = test_send(&wallet, &online, &recipient_map);
assert!(!txid.is_empty());
show_unspent_colorings(&rcv_wallet, "receiver after send - WaitingCounterparty");
show_unspent_colorings(&wallet, "sender after send - WaitingCounterparty");
let rcv_unspent_list = test_list_unspents(&rcv_wallet, None, true);
assert!(!rcv_unspent_list
.iter()
.any(|u| !u.rgb_allocations.is_empty()));
let rcv_unspent_list_all = test_list_unspents(&rcv_wallet, None, false);
let mut allocations = vec![];
rcv_unspent_list_all
.iter()
.for_each(|u| allocations.extend(u.rgb_allocations.clone()));
assert!(!allocations.iter().any(|a| a.settled));
assert_eq!(allocations.iter().filter(|a| !a.settled).count(), 1);
let unspent_list_settled = test_list_unspents(&wallet, None, true);
let mut settled_allocations = vec![];
unspent_list_settled
.iter()
.for_each(|u| settled_allocations.extend(u.rgb_allocations.clone()));
assert_eq!(settled_allocations.len(), 1);
assert!(settled_allocations
.iter()
.all(|a| a.asset_id == Some(asset.asset_id.clone()) && a.amount == AMOUNT && a.settled));
let unspent_list_all = test_list_unspents(&wallet, None, false);
assert_eq!(
unspent_list_all.iter().filter(|u| u.utxo.colorable).count(),
UTXO_NUM as usize
);
assert_eq!(
unspent_list_all
.iter()
.filter(|u| !u.utxo.colorable)
.count(),
1
);
let mut pending_allocations = vec![];
let mut settled_allocations = vec![];
unspent_list_all
.iter()
.for_each(|u| pending_allocations.extend(u.rgb_allocations.iter().filter(|a| !a.settled)));
assert_eq!(pending_allocations.len(), 1);
assert!(pending_allocations
.iter()
.all(|a| a.asset_id == Some(asset.asset_id.clone()) && a.amount == AMOUNT - amount));
unspent_list_all
.iter()
.for_each(|u| settled_allocations.extend(u.rgb_allocations.iter().filter(|a| a.settled)));
assert_eq!(settled_allocations.len(), 1);
assert!(settled_allocations
.iter()
.all(|a| a.asset_id == Some(asset.asset_id.clone()) && a.amount == AMOUNT));
stop_mining();
test_refresh_all(&rcv_wallet, &rcv_online);
test_refresh_asset(&wallet, &online, &asset.asset_id);
show_unspent_colorings(&rcv_wallet, "receiver after send - WaitingConfirmations");
show_unspent_colorings(&wallet, "sender after send - WaitingConfirmations");
let rcv_unspent_list = test_list_unspents(&rcv_wallet, None, true);
assert!(!rcv_unspent_list
.iter()
.any(|u| !u.rgb_allocations.is_empty()));
let rcv_unspent_list_all = test_list_unspents(&rcv_wallet, None, false);
let mut allocations = vec![];
rcv_unspent_list_all
.iter()
.for_each(|u| allocations.extend(u.rgb_allocations.clone()));
assert!(!allocations.iter().any(|a| a.settled));
assert_eq!(allocations.iter().filter(|a| !a.settled).count(), 1);
assert!(allocations
.iter()
.all(|a| a.asset_id == Some(asset.asset_id.clone()) && a.amount == amount));
let unspent_list_settled = test_list_unspents(&wallet, None, true);
let mut settled_allocations = vec![];
unspent_list_settled
.iter()
.for_each(|u| settled_allocations.extend(u.rgb_allocations.clone()));
assert_eq!(settled_allocations.len(), 1);
assert!(settled_allocations
.iter()
.all(|a| a.asset_id == Some(asset.asset_id.clone()) && a.amount == AMOUNT && a.settled));
let unspent_list_all = test_list_unspents(&wallet, None, false);
let mut pending_allocations = vec![];
unspent_list_all
.iter()
.for_each(|u| pending_allocations.extend(u.rgb_allocations.iter().filter(|a| !a.settled)));
assert_eq!(pending_allocations.len(), 1);
assert!(pending_allocations
.iter()
.all(|a| a.asset_id == Some(asset.asset_id.clone()) && a.amount == AMOUNT - amount));
mine(true);
rcv_wallet.refresh(rcv_online, None, vec![]).unwrap();
test_refresh_asset(&wallet, &online, &asset.asset_id);
show_unspent_colorings(&rcv_wallet, "receiver after send - Settled");
show_unspent_colorings(&wallet, "sender after send - Settled");
let rcv_unspent_list = test_list_unspents(&rcv_wallet, None, true);
let mut settled_allocations = vec![];
rcv_unspent_list
.iter()
.for_each(|u| settled_allocations.extend(u.rgb_allocations.clone()));
assert!(settled_allocations.iter().all(|a| a.settled));
assert_eq!(settled_allocations.len(), 1);
assert!(settled_allocations
.iter()
.all(|a| a.asset_id == Some(asset.asset_id.clone()) && a.amount == amount));
let rcv_unspent_list_all = test_list_unspents(&rcv_wallet, None, false);
let mut allocations = vec![];
rcv_unspent_list_all
.iter()
.for_each(|u| allocations.extend(u.rgb_allocations.clone()));
assert_eq!(allocations, settled_allocations);
let unspent_list_settled = test_list_unspents(&wallet, None, true);
let mut settled_allocations = vec![];
unspent_list_settled
.iter()
.for_each(|u| settled_allocations.extend(u.rgb_allocations.clone()));
assert_eq!(settled_allocations.len(), 1);
assert!(settled_allocations
.iter()
.all(|a| a.asset_id == Some(asset.asset_id.clone())
&& a.amount == AMOUNT - amount
&& a.settled));
let unspent_list_all = test_list_unspents(&wallet, None, false);
let mut allocations = vec![];
unspent_list_all
.iter()
.for_each(|u| allocations.extend(u.rgb_allocations.clone()));
assert_eq!(allocations, settled_allocations);
}