Changed emitter amounts to negatives values to ease tallies.

This commit is contained in:
didier amyot committed 2023-04-06 16:56:05 -04:00
1 parent 4810603dd7
commit a980b1a9b1
2 files changed
+35 -18

No files matched your search

+26 -9
View File
@@ -1,6 +1,7 @@
use rusqlite::{ffi, params, Connection, Savepoint, Transaction};
use crate::db::accounts;
use crate::db::accounts::AccountType;
use crate::db::cheques::{Cheque, WireTransferRequest};
use crate::db::external_id::AccountId;
@@ -17,9 +18,9 @@ fn _transfer_securities_from_one_account_to_another(
)> {
let drawer_receipt = accounts::add_to_account(tx, drawer_account_id, -amount)?;
let payee_receipt = accounts::add_to_account(tx, payee_account_id, amount)?;
if drawer_receipt.amount < 0 {
if drawer_receipt.amount < 0 && drawer_receipt.account_type != AccountType::SecurityEmitter {
let m = format!(
"Drawer of {:?} does not have sufficient amount in account.",
"Drawer of {:} does not have sufficient amount in account.",
drawer_account_id
);
return Err(Error::InvalidAmount(m));
@@ -177,7 +178,7 @@ fn cash_cheque_unsafe(
if !accounts::is_owner(&savepoint, payee_account_id, &cheque.payee_user_id)? {
return Err(Error::InvalidPayee(format!(
"Trying to cash the cheque {:?} in \
an account {:?} that is not owned by the payee.",
an account {:} that is not owned by the payee.",
cheque, payee_account_id
)));
}
@@ -207,12 +208,12 @@ fn cash_wire_transfer_request_unsafe(
savepoint: &Savepoint,
wire_transfer: &WireTransferRequest,
) -> CustomResult<()> {
if wire_transfer.amount < 0 {
return Err(Error::InvalidAmount(format!(
"The cheque {:?} has a negative amount.",
wire_transfer
)));
}
// if wire_transfer.amount < 0 {
// return Err(Error::InvalidAmount(format!(
// "The cheque {:?} has a negative amount.",
// wire_transfer
// )));
// }
let (drawer_receipt, payee_receipt) = _transfer_wire_transfer_securities(&savepoint, wire_transfer)?;
_add_wire_transfer_request_to_wire_transfers_log(&savepoint, wire_transfer, &drawer_receipt, &payee_receipt)?;
Ok(())
@@ -407,6 +408,22 @@ mod test_caching_cheques {
}
}
#[test]
fn test_unfounded_cheque() -> CustomResult<()> {
let (mut conn, drawer, payee, payee_account) = setup_basic();
let mut tx = conn.transaction().unwrap();
let cheque = Cheque::new(drawer, payee, 1_000_000, 99);
let ret = cash_cheque(&mut tx, &cheque, &payee_account);
match ret {
Err(Error::InvalidAmount(_)) => Ok(()),
_ => Err(Error::Testing(
"Expected invalid amount error here.".to_string(),
)),
}
}
#[test]
fn test_negative_security_emitter_cheque() -> CustomResult<()> {
let (mut conn, security_emitter, payee, payee_account) = setup_security_emitter();