Skip to content

Commit

Permalink
fix: change to customer when setGeneticAnalysisOrderPaid (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulhakim2902 authored Sep 26, 2022
1 parent 9438ac0 commit e80527e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pallets/genetic-analysis-orders/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub trait GeneticAnalysisOrderInterface<T: frame_system::Config> {
genetic_analysis_order_id: &T::Hash,
) -> Result<Self::GeneticAnalysisOrder, Self::Error>;
fn set_genetic_analysis_order_paid(
escrow_account_id: &T::AccountId,
customer_id: &T::AccountId,
genetic_analysis_order_id: &T::Hash,
) -> Result<Self::GeneticAnalysisOrder, Self::Error>;
fn fulfill_genetic_analysis_order(
Expand Down
15 changes: 7 additions & 8 deletions pallets/genetic-analysis-orders/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,19 +706,18 @@ impl<T: Config> GeneticAnalysisOrderInterface<T> for Pallet<T> {
}

fn set_genetic_analysis_order_paid(
escrow_account_id: &T::AccountId,
customer_id: &T::AccountId,
genetic_analysis_order_id: &T::Hash,
) -> Result<Self::GeneticAnalysisOrder, Self::Error> {
if escrow_account_id.clone() != EscrowKey::<T>::get().unwrap() {
return Err(Error::<T>::Unauthorized)
}
let genetic_analysis_order = GeneticAnalysisOrders::<T>::get(genetic_analysis_order_id)
.ok_or(Error::<T>::GeneticAnalysisOrderNotFound)?;

let genetic_analysis_order = GeneticAnalysisOrders::<T>::get(genetic_analysis_order_id);
if genetic_analysis_order.is_none() {
return Err(Error::<T>::GeneticAnalysisOrderNotFound)
if customer_id != &genetic_analysis_order.customer_id {
let _ = EscrowKey::<T>::get()
.filter(|account_id| account_id == customer_id)
.ok_or(Error::<T>::Unauthorized)?;
}

let genetic_analysis_order = genetic_analysis_order.unwrap();
if !Self::is_balance_sufficient_for_payment(
&genetic_analysis_order.customer_id,
genetic_analysis_order.total_price,
Expand Down
6 changes: 3 additions & 3 deletions pallets/genetic-analysis-orders/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fn cancel_genetic_analysis_order_with_refund_works() {
EscrowKey::<Test>::put(3);

assert_ok!(GeneticAnalysisOrders::set_genetic_analysis_order_paid(
Origin::signed(3),
Origin::signed(1),
_genetic_analysis_order_id
));

Expand Down Expand Up @@ -1417,7 +1417,7 @@ fn cant_set_genetic_analysis_order_paid_when_insufficient_funds() {

assert_noop!(
GeneticAnalysisOrders::set_genetic_analysis_order_paid(
Origin::signed(3),
Origin::signed(1),
_genetic_analysis_order_id,
),
Error::<Test>::InsufficientFunds
Expand Down Expand Up @@ -2003,7 +2003,7 @@ fn call_event_should_work() {
EscrowKey::<Test>::put(3);

assert_ok!(GeneticAnalysisOrders::set_genetic_analysis_order_paid(
Origin::signed(3),
Origin::signed(1),
_genetic_analysis_order_id
));

Expand Down

0 comments on commit e80527e

Please sign in to comment.