From 70932e1b0b2b6146478099cc1d2a8b0be4a52990 Mon Sep 17 00:00:00 2001 From: Victor Genin Date: Tue, 28 Nov 2023 14:26:58 +0200 Subject: [PATCH 1/2] batch index events --- pallets/ddc-payouts/src/lib.rs | 4 ++++ pallets/ddc-payouts/src/tests.rs | 31 +++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index f5c2a1192..57c2b30e7 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -129,12 +129,14 @@ pub mod pallet { Charged { cluster_id: ClusterId, era: DdcEra, + batch_index: BatchIndex, customer_id: T::AccountId, amount: u128, }, ChargeFailed { cluster_id: ClusterId, era: DdcEra, + batch_index: BatchIndex, customer_id: T::AccountId, amount: u128, }, @@ -420,6 +422,7 @@ pub mod pallet { Self::deposit_event(Event::::ChargeFailed { cluster_id, era, + batch_index, customer_id, amount: total_customer_charge, }); @@ -436,6 +439,7 @@ pub mod pallet { Self::deposit_event(Event::::Charged { cluster_id, era, + batch_index, customer_id, amount: total_customer_charge, }); diff --git a/pallets/ddc-payouts/src/tests.rs b/pallets/ddc-payouts/src/tests.rs index d63d799e3..792a6c7c1 100644 --- a/pallets/ddc-payouts/src/tests.rs +++ b/pallets/ddc-payouts/src/tests.rs @@ -277,7 +277,7 @@ fn send_charging_customers_batch_works() { let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 3; - let batch_index = 0; + let mut batch_index = 0; let usage1 = CustomerUsage { // should pass without debt transferred_bytes: 23452345, @@ -343,20 +343,35 @@ fn send_charging_customers_batch_works() { assert_eq!(user2_debt, debt); System::assert_has_event( - Event::ChargeFailed { cluster_id, era, customer_id: user2_debtor, amount: debt }.into(), + Event::ChargeFailed { + cluster_id, + era, + customer_id: user2_debtor, + batch_index, + amount: debt, + } + .into(), ); System::assert_last_event( - Event::Charged { cluster_id, era, customer_id: user4, amount: usage4_charge }.into(), + Event::Charged { + cluster_id, + era, + customer_id: user4, + batch_index, + amount: usage4_charge, + } + .into(), ); assert_eq!(System::events().len(), 5 + 3); // 3 for Currency::transfer // batch 2 + batch_index += 1; assert_ok!(DdcPayouts::send_charging_customers_batch( RuntimeOrigin::signed(dac_account), cluster_id, era, - batch_index + 1, + batch_index, payers2, )); @@ -364,6 +379,7 @@ fn send_charging_customers_batch_works() { Event::Charged { cluster_id, era, + batch_index, customer_id: user1, amount: calculate_charge(usage1), } @@ -377,11 +393,12 @@ fn send_charging_customers_batch_works() { let balance_before = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); // batch 3 + batch_index += 2; assert_ok!(DdcPayouts::send_charging_customers_batch( RuntimeOrigin::signed(dac_account), cluster_id, era, - batch_index + 2, + batch_index, payers3, )); @@ -398,6 +415,7 @@ fn send_charging_customers_batch_works() { Event::ChargeFailed { cluster_id, era, + batch_index, customer_id: user3_debtor, amount: user3_charge, } @@ -522,7 +540,8 @@ fn end_charging_customers_works() { let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); let charge = calculate_charge(usage1); System::assert_last_event( - Event::Charged { cluster_id, era, customer_id: user1, amount: charge }.into(), + Event::Charged { cluster_id, era, batch_index, customer_id: user1, amount: charge } + .into(), ); let mut balance = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era)); From 594d50358c7b7b360012b769087a6ff990f9a871 Mon Sep 17 00:00:00 2001 From: Victor Genin Date: Tue, 28 Nov 2023 14:33:50 +0200 Subject: [PATCH 2/2] merge + fmt --- pallets/ddc-payouts/src/tests.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/ddc-payouts/src/tests.rs b/pallets/ddc-payouts/src/tests.rs index fb147b98f..b4df284ae 100644 --- a/pallets/ddc-payouts/src/tests.rs +++ b/pallets/ddc-payouts/src/tests.rs @@ -384,7 +384,7 @@ fn send_charging_customers_batch_works() { // batch 2 let mut before_total_customer_charge = report.total_customer_charge.clone(); - batch_index += 1; + batch_index += 1; assert_ok!(DdcPayouts::send_charging_customers_batch( RuntimeOrigin::signed(dac_account), cluster_id, @@ -431,7 +431,6 @@ fn send_charging_customers_batch_works() { // batch 3 batch_index += 2; before_total_customer_charge = report.total_customer_charge.clone(); - batch_index += 2; assert_ok!(DdcPayouts::send_charging_customers_batch( RuntimeOrigin::signed(dac_account), cluster_id, @@ -719,7 +718,8 @@ fn end_charging_customers_works_zero_fees() { let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); let charge = calculate_charge(usage1); System::assert_last_event( - Event::Charged { cluster_id, era, customer_id: user1, amount: charge }.into(), + Event::Charged { cluster_id, era, customer_id: user1, batch_index, amount: charge } + .into(), ); let mut balance = Balances::free_balance(DdcPayouts::sub_account_id(cluster_id, era));