Skip to content

Commit 5357ae9

Browse files
authored
bill action tests,add checks that people cant do bill actions on (#465)
1 parent 337cce4 commit 5357ae9

File tree

9 files changed

+222
-21
lines changed

9 files changed

+222
-21
lines changed

crates/bcr-ebill-api/src/service/bill_service/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ pub mod tests {
818818
let returned_bills = res.unwrap();
819819
assert!(returned_bills.len() == 1);
820820
assert_eq!(returned_bills[0].id, TEST_BILL_ID.to_string());
821+
assert!(returned_bills[0].status.payment.requested_to_pay);
821822
assert!(returned_bills[0].status.payment.paid);
822823
}
823824

@@ -4014,6 +4015,23 @@ pub mod tests {
40144015
.check_requests_for_expiration(&bill_payment, 1731593928)
40154016
.unwrap()
40164017
);
4018+
assert!(
4019+
!service
4020+
.check_requests_for_expiration(&bill_payment, 1431593928)
4021+
.unwrap()
4022+
);
4023+
bill_payment.data.maturity_date = "2018-07-15".into(); // before ts
4024+
assert!(
4025+
!service
4026+
.check_requests_for_expiration(&bill_payment, 1531593929)
4027+
.unwrap()
4028+
);
4029+
// 2 days after req to pay, but not yet 2 days after end of day maturity date
4030+
assert!(
4031+
!service
4032+
.check_requests_for_expiration(&bill_payment, 1531780429)
4033+
.unwrap()
4034+
);
40174035

40184036
let mut bill_acceptance = get_baseline_cached_bill(TEST_BILL_ID.to_string());
40194037
bill_acceptance.status.acceptance = BillAcceptanceStatus {

crates/bcr-ebill-api/src/service/bill_service/test_utils.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,11 @@ pub fn get_service(mut ctx: MockBillContext) -> BillService {
176176
)
177177
});
178178
bitcoin_client.expect_generate_link_to_pay().returning(|_,_,_| String::from("bitcoin:1Jfn2nZcJ4T7bhE8FdMRz8T3P3YV4LsWn2?amount=0.01&message=Payment in relation to bill some bill"));
179-
ctx.contact_store
180-
.expect_get()
181-
.returning(|_| Ok(Some(get_baseline_contact())));
179+
ctx.contact_store.expect_get().returning(|node_id| {
180+
let mut contact = get_baseline_contact();
181+
contact.node_id = node_id.to_owned();
182+
Ok(Some(contact))
183+
});
182184
ctx.contact_store
183185
.expect_get_map()
184186
.returning(|| Ok(HashMap::new()));

crates/bcr-ebill-core/src/bill/validation.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
Block, Blockchain,
55
bill::{
66
BillBlockchain, BillOpCode, OfferToSellWaitingForPayment, RecourseWaitingForPayment,
7-
block::BillRequestRecourseBlockData,
7+
block::{BillRecourseReasonBlockData, BillRequestRecourseBlockData},
88
},
99
},
1010
constants::{ACCEPT_DEADLINE_SECONDS, PAYMENT_DEADLINE_SECONDS, RECOURSE_DEADLINE_SECONDS},
@@ -180,11 +180,15 @@ pub fn validate_bill_action(
180180
}
181181
};
182182
}
183-
BillAction::Recourse(recoursee, sum, currency, _reason) => {
183+
BillAction::Recourse(recoursee, sum, currency, reason) => {
184184
// not waiting for req to pay
185185
bill_waiting_for_req_to_pay(blockchain, maturity_date, timestamp, is_paid)?;
186186
// not waiting for offer to sell
187187
bill_waiting_for_offer_to_sell(blockchain, bill_keys, timestamp)?;
188+
let recourse_reason = match reason {
189+
RecourseReason::Pay(_, _) => BillRecourseReasonBlockData::Pay,
190+
RecourseReason::Accept => BillRecourseReasonBlockData::Accept,
191+
};
188192

189193
if let RecourseWaitingForPayment::Yes(payment_info) = blockchain
190194
.is_last_request_to_recourse_block_waiting_for_payment(bill_keys, timestamp)?
@@ -193,6 +197,7 @@ pub fn validate_bill_action(
193197
|| payment_info.currency != *currency
194198
|| payment_info.recoursee.node_id != recoursee.node_id
195199
|| payment_info.recourser.node_id != signer_node_id
200+
|| payment_info.reason != recourse_reason
196201
{
197202
return Err(ValidationError::BillRecourseDataInvalid);
198203
}

0 commit comments

Comments
 (0)