From e80527ee1062d5b4cbd6d892c36b0b23a59ca71f Mon Sep 17 00:00:00 2001 From: Muhammad Abdul Hakim Shibghatallah <70675129+abdulhakim2902@users.noreply.github.com> Date: Mon, 26 Sep 2022 13:09:44 +0700 Subject: [PATCH] fix: change to customer when setGeneticAnalysisOrderPaid (#356) --- pallets/genetic-analysis-orders/src/interface.rs | 2 +- pallets/genetic-analysis-orders/src/lib.rs | 15 +++++++-------- pallets/genetic-analysis-orders/src/tests.rs | 6 +++--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/pallets/genetic-analysis-orders/src/interface.rs b/pallets/genetic-analysis-orders/src/interface.rs index bbb54fca..bb061e07 100644 --- a/pallets/genetic-analysis-orders/src/interface.rs +++ b/pallets/genetic-analysis-orders/src/interface.rs @@ -15,7 +15,7 @@ pub trait GeneticAnalysisOrderInterface { genetic_analysis_order_id: &T::Hash, ) -> Result; fn set_genetic_analysis_order_paid( - escrow_account_id: &T::AccountId, + customer_id: &T::AccountId, genetic_analysis_order_id: &T::Hash, ) -> Result; fn fulfill_genetic_analysis_order( diff --git a/pallets/genetic-analysis-orders/src/lib.rs b/pallets/genetic-analysis-orders/src/lib.rs index 929042ba..782d2d09 100644 --- a/pallets/genetic-analysis-orders/src/lib.rs +++ b/pallets/genetic-analysis-orders/src/lib.rs @@ -706,19 +706,18 @@ impl GeneticAnalysisOrderInterface for Pallet { } fn set_genetic_analysis_order_paid( - escrow_account_id: &T::AccountId, + customer_id: &T::AccountId, genetic_analysis_order_id: &T::Hash, ) -> Result { - if escrow_account_id.clone() != EscrowKey::::get().unwrap() { - return Err(Error::::Unauthorized) - } + let genetic_analysis_order = GeneticAnalysisOrders::::get(genetic_analysis_order_id) + .ok_or(Error::::GeneticAnalysisOrderNotFound)?; - let genetic_analysis_order = GeneticAnalysisOrders::::get(genetic_analysis_order_id); - if genetic_analysis_order.is_none() { - return Err(Error::::GeneticAnalysisOrderNotFound) + if customer_id != &genetic_analysis_order.customer_id { + let _ = EscrowKey::::get() + .filter(|account_id| account_id == customer_id) + .ok_or(Error::::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, diff --git a/pallets/genetic-analysis-orders/src/tests.rs b/pallets/genetic-analysis-orders/src/tests.rs index 4315c3eb..c9136af8 100644 --- a/pallets/genetic-analysis-orders/src/tests.rs +++ b/pallets/genetic-analysis-orders/src/tests.rs @@ -288,7 +288,7 @@ fn cancel_genetic_analysis_order_with_refund_works() { EscrowKey::::put(3); assert_ok!(GeneticAnalysisOrders::set_genetic_analysis_order_paid( - Origin::signed(3), + Origin::signed(1), _genetic_analysis_order_id )); @@ -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::::InsufficientFunds @@ -2003,7 +2003,7 @@ fn call_event_should_work() { EscrowKey::::put(3); assert_ok!(GeneticAnalysisOrders::set_genetic_analysis_order_paid( - Origin::signed(3), + Origin::signed(1), _genetic_analysis_order_id ));