Skip to content

Commit

Permalink
wip: fixing payouts tests 2
Browse files Browse the repository at this point in the history
  • Loading branch information
yahortsaryk committed Dec 2, 2024
1 parent 43f00ca commit afc84d3
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions pallets/ddc-payouts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,7 @@ fn end_charging_customers_works_small_usage_1_hour() {
let user7 = CUSTOMER7_KEY_32;
let cluster_id = HIGH_FEES_CLUSTER_ID;
let era = 100;
let max_batch_index = 0;
let batch_index = 0;
let max_charging_batch_index = 0;
let bucket_id6: BucketId = BUCKET_ID6;
let bucket_id7: BucketId = BUCKET_ID7;

Expand All @@ -754,12 +753,15 @@ fn end_charging_customers_works_small_usage_1_hour() {
DateTime::<Utc>::from_naive_utc_and_offset(start_date.and_time(time), Utc).timestamp();
let end_era: i64 = start_era + (1.0 * 1.0 * 3600.0) as i64; // 1 hour
let cluster_usage = NodeUsage::default();

let (payers1_batch_root, _, _) = hash_bucket_payable_usage_batch(payers1.clone());

let fingerprint = get_fingerprint(
&cluster_id,
era,
start_era,
end_era,
DEFAULT_PAYERS_ROOT,
payers1_batch_root,
DEFAULT_PAYEES_ROOT,
&cluster_usage,
);
Expand All @@ -770,7 +772,7 @@ fn end_charging_customers_works_small_usage_1_hour() {
era,
start_era,
end_era,
DEFAULT_PAYERS_ROOT,
payers1_batch_root,
DEFAULT_PAYEES_ROOT,
cluster_usage,
));
Expand All @@ -784,15 +786,15 @@ fn end_charging_customers_works_small_usage_1_hour() {
assert_ok!(<DdcPayouts as PayoutProcessor<Test>>::begin_charging_customers(
cluster_id,
era,
max_batch_index,
max_charging_batch_index,
));
assert_eq!(System::events().len(), 2);
assert_eq!(System::events().len(), 3);

// batch 1
assert_ok!(<DdcPayouts as PayoutProcessor<Test>>::send_charging_customers_batch(
cluster_id,
era,
batch_index,
0,
&payers1,
MMRProof::default(),
));
Expand All @@ -816,7 +818,7 @@ fn end_charging_customers_works_small_usage_1_hour() {
era,
customer_id: user6,
bucket_id: bucket_id6,
batch_index,
batch_index: 0,
amount: usage6_charge,
}
.into(),
Expand All @@ -828,7 +830,7 @@ fn end_charging_customers_works_small_usage_1_hour() {
era,
customer_id: user7,
bucket_id: bucket_id7,
batch_index,
batch_index: 0,
amount: usage7_charge,
}
.into(),
Expand Down Expand Up @@ -2756,9 +2758,8 @@ fn end_charging_customers_works() {

let user1 = CUSTOMER1_KEY_32;
let cluster_id = ClusterId::from([12; 20]);
let node_key = NodePubKey::StoragePubKey(NODE1_PUB_KEY_32);
let era = 100;
let max_batch_index = 0;
let max_charging_batch_index = 0;
let batch_index = 0;
let bucket_id1: BucketId = BUCKET_ID1;
let usage1 = BucketUsage {
Expand All @@ -2775,12 +2776,15 @@ fn end_charging_customers_works() {
DateTime::<Utc>::from_naive_utc_and_offset(start_date.and_time(time), Utc).timestamp();
let end_era: i64 = start_era + (30.44 * 24.0 * 3600.0) as i64;
let cluster_usage = NodeUsage::default();

let (payers_batch_root, _, _) = hash_bucket_payable_usage_batch(payers.clone());

let fingerprint = get_fingerprint(
&cluster_id,
era,
start_era,
end_era,
DEFAULT_PAYERS_ROOT,
payers_batch_root,
DEFAULT_PAYEES_ROOT,
&cluster_usage,
);
Expand All @@ -2791,7 +2795,7 @@ fn end_charging_customers_works() {
era,
start_era,
end_era,
DEFAULT_PAYERS_ROOT,
payers_batch_root,
DEFAULT_PAYEES_ROOT,
cluster_usage,
));
Expand All @@ -2805,7 +2809,7 @@ fn end_charging_customers_works() {
assert_ok!(<DdcPayouts as PayoutProcessor<Test>>::begin_charging_customers(
cluster_id,
era,
max_batch_index,
max_charging_batch_index,
));

assert_ok!(<DdcPayouts as PayoutProcessor<Test>>::send_charging_customers_batch(
Expand All @@ -2832,7 +2836,7 @@ fn end_charging_customers_works() {

let mut balance = Balances::free_balance(DdcPayouts::account_id());
assert_eq!(balance - Balances::minimum_balance(), charge);
assert_eq!(System::events().len(), 3 + 1); // 1 for Currency::transfer
assert_eq!(System::events().len(), 4 + 1); // 1 for Currency::transfer

assert_ok!(<DdcPayouts as PayoutProcessor<Test>>::end_charging_customers(cluster_id, era,));

Expand All @@ -2855,7 +2859,7 @@ fn end_charging_customers_works() {
);

let transfers = 3 + 3 + 3 * 3; // for Currency::transfer
assert_eq!(System::events().len(), 7 + 1 + 3 + transfers);
assert_eq!(System::events().len(), 7 + 2 + 3 + transfers);

let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap();
assert_eq!(report_after.state, PayoutState::CustomersChargedWithFees);
Expand Down Expand Up @@ -2950,7 +2954,6 @@ fn end_charging_customers_works_zero_fees() {

let user1: AccountId = CUSTOMER1_KEY_32;
let cluster_id = ClusterId::zero();
let node_key = NodePubKey::StoragePubKey(NODE1_PUB_KEY_32);
let era = 100;
let max_batch_index = 0;
let batch_index = 0;
Expand All @@ -2969,12 +2972,15 @@ fn end_charging_customers_works_zero_fees() {
DateTime::<Utc>::from_naive_utc_and_offset(start_date.and_time(time), Utc).timestamp();
let end_era: i64 = start_era + (30.44 * 24.0 * 3600.0) as i64;
let cluster_usage = NodeUsage::default();

let (payers_batch_root, _, _) = hash_bucket_payable_usage_batch(payers.clone());

let fingerprint = get_fingerprint(
&cluster_id,
era,
start_era,
end_era,
DEFAULT_PAYERS_ROOT,
payers_batch_root,
DEFAULT_PAYEES_ROOT,
&cluster_usage,
);
Expand All @@ -2985,7 +2991,7 @@ fn end_charging_customers_works_zero_fees() {
era,
start_era,
end_era,
DEFAULT_PAYERS_ROOT,
payers_batch_root,
DEFAULT_PAYEES_ROOT,
cluster_usage,
));
Expand Down Expand Up @@ -3026,12 +3032,12 @@ fn end_charging_customers_works_zero_fees() {

let mut balance = Balances::free_balance(DdcPayouts::account_id());
assert_eq!(balance - Balances::minimum_balance(), charge);
assert_eq!(System::events().len(), 3 + 1); // 1 for Currency::transfer
assert_eq!(System::events().len(), 4 + 1); // 1 for Currency::transfer

assert_ok!(<DdcPayouts as PayoutProcessor<Test>>::end_charging_customers(cluster_id, era,));

System::assert_has_event(Event::ChargingFinished { cluster_id, era }.into());
assert_eq!(System::events().len(), 4 + 1);
assert_eq!(System::events().len(), 5 + 1);

let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap();
assert_eq!(report_after.state, PayoutState::CustomersChargedWithFees);
Expand Down

0 comments on commit afc84d3

Please sign in to comment.