From 32dbf724b9a0b182fcb2a373e35644ff355c3dc6 Mon Sep 17 00:00:00 2001 From: Ayush Mishra Date: Wed, 7 Aug 2024 10:57:48 +0530 Subject: [PATCH] Added Logs and Events for OCW-DAC Validation (#411) ## Description ## Types of Changes Please select the branch type you are merging and fill in the relevant template. - [ ] Hotfix - [ ] Release - [ ] Fix or Feature ## Fix or Feature ### Types of Changes - [ ] Tech Debt (Code improvements) - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Dependency upgrade (A change in substrate or any 3rd party crate version) ### Migrations and Hooks - [ ] This change requires a runtime migration. - [ ] Modifies `on_initialize` - [ ] Modifies `on_finalize` ### Checklist for Fix or Feature - [ ] Change has been tested locally. - [ ] Change adds / updates tests if applicable. - [ ] Changelog doc updated. - [ ] `spec_version` has been incremented. - [ ] `network-relayer`'s [events](https://github.com/Cerebellum-Network/network-relayer/blob/dev-cere/shared/substrate/events.go) have been updated according to the blockchain events if applicable. - [ ] All CI checks have been passed successfully ## Checklist for Hotfix - [ ] Change has been deployed to Testnet. - [ ] Change has been tested in Testnet. - [ ] Changelog has been updated. - [ ] Crate version has been updated. - [ ] `spec_version` has been incremented. - [ ] Transaction version has been updated if required. - [ ] Pull Request to `dev` has been created. - [ ] Pull Request to `staging` has been created. - [ ] `network-relayer`'s [events](https://github.com/Cerebellum-Network/network-relayer/blob/dev-cere/shared/substrate/events.go) have been updated according to the blockchain events if applicable. - [ ] All CI checks have been passed successfully ## Checklist for Release - [ ] Change has been deployed to Devnet. - [ ] Change has been tested in Devnet. - [ ] Change has been deployed to Qanet. - [ ] Change has been tested in Qanet. - [ ] Change has been deployed to Testnet. - [ ] Change has been tested in Testnet. - [ ] Changelog has been updated. - [ ] Crate version has been updated. - [ ] Spec version has been updated. - [ ] Transaction version has been updated if required. - [ ] All CI checks have been passed successfully --- Cargo.lock | 1 + pallets/ddc-payouts/Cargo.toml | 2 + pallets/ddc-payouts/src/lib.rs | 55 +- pallets/ddc-payouts/src/mock.rs | 76 ++- pallets/ddc-payouts/src/tests.rs | 922 ++++++++++++++------------- pallets/ddc-verification/src/lib.rs | 119 +++- pallets/ddc-verification/src/mock.rs | 1 + primitives/src/lib.rs | 4 +- runtime/cere-dev/src/lib.rs | 9 +- runtime/cere/src/lib.rs | 7 +- 10 files changed, 709 insertions(+), 487 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 277d650ba..801bb4ec4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5342,6 +5342,7 @@ dependencies = [ "frame-election-provider-support", "frame-support", "frame-system", + "hex", "log", "pallet-balances", "parity-scale-codec", diff --git a/pallets/ddc-payouts/Cargo.toml b/pallets/ddc-payouts/Cargo.toml index e26ad53d2..02eab6699 100644 --- a/pallets/ddc-payouts/Cargo.toml +++ b/pallets/ddc-payouts/Cargo.toml @@ -20,6 +20,7 @@ frame-benchmarking = { workspace = true, optional = true } frame-election-provider-support = { workspace = true } frame-support = { workspace = true } frame-system = { workspace = true } +hex = { workspace = true } sp-core = { workspace = true } sp-io = { workspace = true } sp-runtime = { workspace = true } @@ -39,6 +40,7 @@ substrate-test-utils = { workspace = true, default-features = true } [features] default = ["std"] std = [ + "hex/std", "codec/std", "ddc-primitives/std", "frame-support/std", diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index ebce8dd24..362f9b246 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -49,7 +49,8 @@ use frame_support::{ }; use frame_system::pallet_prelude::*; pub use pallet::*; -use sp_runtime::{traits::Convert, PerThing, Perquintill}; +use scale_info::prelude::string::String; +use sp_runtime::{traits::Convert, AccountId32, PerThing, Perquintill}; use sp_std::prelude::*; /// Stores reward in tokens(units) of node provider as per NodeUsage #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone)] @@ -126,6 +127,7 @@ pub mod pallet { type WeightInfo: WeightInfo; type VoteScoreToU64: Convert, u64>; type ValidatorVisitor: ValidatorVisitor; + type AccountIdConverter: From + Into; } #[pallet::event] @@ -258,6 +260,7 @@ pub mod pallet { NotBucketOwner, IncorrectClusterId, ClusterProtocolParamsNotSet, + TotalStoredBytesLessThanZero, } #[pallet::storage] @@ -468,7 +471,7 @@ pub mod pallet { let mut updated_billing_report = billing_report; for (customer_id, bucket_id, customer_usage) in payers { - log::info!("🏭send_charging_customers_batch get_customer_charge customer_id: {:?} - bucket_id: {:?} - era:{:?} - cluster-id:{:?}", customer_id.encode(), bucket_id, era, cluster_id); + log::info!("🏭send_charging_customers_batch get_customer_charge customer_id: {:?} - bucket_id: {:?} - era:{:?} - cluster-id:{:?}", Self::get_account_id_string(customer_id.clone()), bucket_id, era, cluster_id); let mut customer_charge = get_customer_charge::( &cluster_id, &customer_usage, @@ -1084,7 +1087,7 @@ pub mod pallet { .map_err(Into::>::into)? .map_or(0, |customer_usage| customer_usage.stored_bytes); - ensure!(total_stored_bytes >= 0, Error::::ArithmeticOverflow); + ensure!(total_stored_bytes >= 0, Error::::TotalStoredBytesLessThanZero); total_stored_bytes = total_stored_bytes .checked_add(usage.stored_bytes) @@ -1170,7 +1173,10 @@ pub mod pallet { start_era: i64, end_era: i64, ) -> DispatchResult { - log::info!("🏭begin_billing_report called by: {:?}", origin.encode()); + log::info!( + "🏭begin_billing_report called by: {:?}", + Self::get_account_id_string(origin.clone()) + ); let origin = frame_system::RawOrigin::Signed(origin).into(); Self::begin_billing_report(origin, cluster_id, era_id, start_era, end_era) } @@ -1181,7 +1187,10 @@ pub mod pallet { era_id: DdcEra, max_batch_index: BatchIndex, ) -> DispatchResult { - log::info!("🏭begin_charging_customers called by: {:?}", origin.encode()); + log::info!( + "🏭begin_charging_customers called by: {:?}", + Self::get_account_id_string(origin.clone()) + ); let origin = frame_system::RawOrigin::Signed(origin).into(); Self::begin_charging_customers(origin, cluster_id, era_id, max_batch_index) } @@ -1194,7 +1203,10 @@ pub mod pallet { payers: &[(T::AccountId, BucketId, CustomerUsage)], batch_proof: MMRProof, ) -> DispatchResult { - log::info!("🏭send_charging_customers_batch called by: {:?}", origin.encode()); + log::info!( + "🏭send_charging_customers_batch called by: {:?}", + Self::get_account_id_string(origin.clone()) + ); let origin = frame_system::RawOrigin::Signed(origin).into(); Self::send_charging_customers_batch( origin, @@ -1211,7 +1223,10 @@ pub mod pallet { cluster_id: ClusterId, era_id: DdcEra, ) -> DispatchResult { - log::info!("🏭end_charging_customers called by: {:?}", origin.encode()); + log::info!( + "🏭end_charging_customers called by: {:?}", + Self::get_account_id_string(origin.clone()) + ); let origin = frame_system::RawOrigin::Signed(origin).into(); Self::end_charging_customers(origin, cluster_id, era_id) } @@ -1223,7 +1238,10 @@ pub mod pallet { max_batch_index: BatchIndex, total_node_usage: NodeUsage, ) -> DispatchResult { - log::info!("🏭begin_rewarding_providers called by: {:?}", origin.encode()); + log::info!( + "🏭begin_rewarding_providers called by: {:?}", + Self::get_account_id_string(origin.clone()) + ); let origin = frame_system::RawOrigin::Signed(origin).into(); Self::begin_rewarding_providers( origin, @@ -1242,7 +1260,10 @@ pub mod pallet { payees: &[(T::AccountId, NodeUsage)], batch_proof: MMRProof, ) -> DispatchResult { - log::info!("🏭send_rewarding_providers_batch called by: {:?}", origin.encode()); + log::info!( + "🏭send_rewarding_providers_batch called by: {:?}", + Self::get_account_id_string(origin.clone()) + ); let origin = frame_system::RawOrigin::Signed(origin).into(); Self::send_rewarding_providers_batch( origin, @@ -1259,7 +1280,10 @@ pub mod pallet { cluster_id: ClusterId, era_id: DdcEra, ) -> DispatchResult { - log::info!("🏭end_rewarding_providers called by: {:?}", origin.encode()); + log::info!( + "🏭end_rewarding_providers called by: {:?}", + Self::get_account_id_string(origin.clone()) + ); let origin = frame_system::RawOrigin::Signed(origin).into(); Self::end_rewarding_providers(origin, cluster_id, era_id) } @@ -1269,7 +1293,10 @@ pub mod pallet { cluster_id: ClusterId, era_id: DdcEra, ) -> DispatchResult { - log::info!("🏭end_billing_report called by: {:?}", origin.encode()); + log::info!( + "🏭end_billing_report called by: {:?}", + Self::get_account_id_string(origin.clone()) + ); let origin = frame_system::RawOrigin::Signed(origin).into(); Self::end_billing_report(origin, cluster_id, era_id) } @@ -1349,6 +1376,12 @@ pub mod pallet { T::PalletId::get().into_account_truncating() } + pub fn get_account_id_string(caller: T::AccountId) -> String { + let account_id: T::AccountIdConverter = caller.into(); + let account_id_32: AccountId32 = account_id.into(); + let account_ref: &[u8; 32] = account_id_32.as_ref(); + hex::encode(account_ref) + } pub fn sub_account_id(cluster_id: ClusterId, era: DdcEra) -> T::AccountId { let mut bytes = Vec::new(); bytes.extend_from_slice(&cluster_id[..]); diff --git a/pallets/ddc-payouts/src/mock.rs b/pallets/ddc-payouts/src/mock.rs index 32f828e8b..096299c53 100644 --- a/pallets/ddc-payouts/src/mock.rs +++ b/pallets/ddc-payouts/src/mock.rs @@ -26,15 +26,16 @@ use sp_io::TestExternalities; #[cfg(feature = "try-runtime")] use sp_runtime::TryRuntimeError; use sp_runtime::{ - traits::{BlakeTwo256, Identity, IdentityLookup}, - BuildStorage, DispatchError, Perquintill, + traits::{BlakeTwo256, IdentifyAccount, Identity, IdentityLookup, Verify}, + BuildStorage, DispatchError, MultiSignature, Perquintill, }; use sp_std::prelude::*; use crate::{self as pallet_ddc_payouts, *}; +pub type Signature = MultiSignature; /// The AccountId alias in this test module. -pub type AccountId = u128; +pub type AccountId = <::Signer as IdentifyAccount>::AccountId; pub(crate) type AccountIndex = u64; pub(crate) type BlockNumber = u64; pub(crate) type Balance = u128; @@ -135,19 +136,25 @@ impl crate::pallet::Config for Test { type VoteScoreToU64 = Identity; type WeightInfo = (); type ValidatorVisitor = MockValidatorVisitor; + type AccountIdConverter = AccountId; } pub struct MockValidatorVisitor; impl ValidatorVisitor for MockValidatorVisitor where - ::AccountId: From, + ::AccountId: From, { fn setup_validators(_validators: Vec) { unimplemented!() } fn is_ocw_validator(caller: T::AccountId) -> bool { - let validators = [DAC_ACCOUNT_ID.into(), 123u128.into()]; + let account_id: [u8; 32] = [123; 32]; + let dac: [u8; 32] = DAC_ACCOUNT_ID; + let validators = [ + T::AccountId::decode(&mut &dac[..]).unwrap(), + T::AccountId::decode(&mut &account_id[..]).unwrap(), + ]; validators.contains(&caller) } fn is_customers_batch_valid( @@ -193,15 +200,15 @@ impl CustomerCharger for TestCustomerCharger { amount: u128, ) -> Result { let mut amount_to_charge = amount; - let mut temp = ACCOUNT_ID_1.to_ne_bytes(); + let mut temp: [u8; 32] = ACCOUNT_ID_1; let account_1 = T::AccountId::decode(&mut &temp[..]).unwrap(); - temp = ACCOUNT_ID_2.to_ne_bytes(); + temp = ACCOUNT_ID_2; let account_2 = T::AccountId::decode(&mut &temp[..]).unwrap(); - temp = ACCOUNT_ID_3.to_ne_bytes(); + temp = ACCOUNT_ID_3; let account_3 = T::AccountId::decode(&mut &temp[..]).unwrap(); - temp = ACCOUNT_ID_4.to_ne_bytes(); + temp = ACCOUNT_ID_4; let account_4 = T::AccountId::decode(&mut &temp[..]).unwrap(); - temp = ACCOUNT_ID_5.to_ne_bytes(); + temp = ACCOUNT_ID_5; let account_5 = T::AccountId::decode(&mut &temp[..]).unwrap(); if content_owner == account_1 || @@ -233,13 +240,13 @@ impl CustomerCharger for TestCustomerCharger { } } -pub const ACCOUNT_ID_1: AccountId = 1; -pub const ACCOUNT_ID_2: AccountId = 2; -pub const ACCOUNT_ID_3: AccountId = 3; -pub const ACCOUNT_ID_4: AccountId = 4; -pub const ACCOUNT_ID_5: AccountId = 5; -pub const ACCOUNT_ID_6: AccountId = 6; -pub const ACCOUNT_ID_7: AccountId = 7; +pub const ACCOUNT_ID_1: [u8; 32] = [1; 32]; +pub const ACCOUNT_ID_2: [u8; 32] = [2; 32]; +pub const ACCOUNT_ID_3: [u8; 32] = [3; 32]; +pub const ACCOUNT_ID_4: [u8; 32] = [4; 32]; +pub const ACCOUNT_ID_5: [u8; 32] = [5; 32]; +pub const ACCOUNT_ID_6: [u8; 32] = [6; 32]; +pub const ACCOUNT_ID_7: [u8; 32] = [7; 32]; pub struct TestClusterCreator; impl ClusterCreator for TestClusterCreator { fn create_cluster( @@ -263,12 +270,12 @@ impl CustomerDepositor for TestCustomerDepositor { } } -pub const DAC_ACCOUNT_ID: AccountId = 2; -pub const RESERVE_ACCOUNT_ID: AccountId = 999; -pub const TREASURY_ACCOUNT_ID: AccountId = 888; -pub const VALIDATOR1_ACCOUNT_ID: AccountId = 111; -pub const VALIDATOR2_ACCOUNT_ID: AccountId = 222; -pub const VALIDATOR3_ACCOUNT_ID: AccountId = 333; +pub const DAC_ACCOUNT_ID: [u8; 32] = [2; 32]; +pub const RESERVE_ACCOUNT_ID: [u8; 32] = [9; 32]; +pub const TREASURY_ACCOUNT_ID: [u8; 32] = [8; 32]; +pub const VALIDATOR1_ACCOUNT_ID: [u8; 32] = [111; 32]; +pub const VALIDATOR2_ACCOUNT_ID: [u8; 32] = [222; 32]; +pub const VALIDATOR3_ACCOUNT_ID: [u8; 32] = [250; 32]; pub const VALIDATOR1_SCORE: u64 = 30; pub const VALIDATOR2_SCORE: u64 = 45; @@ -358,14 +365,13 @@ pub const PRICING_FEES_ZERO: ClusterFeesParams = ClusterFeesParams { pub struct TestTreasuryVisitor; impl PalletVisitor for TestTreasuryVisitor { fn get_account_id() -> T::AccountId { - let reserve_account = TREASURY_ACCOUNT_ID.to_ne_bytes(); + let reserve_account: [u8; 32] = TREASURY_ACCOUNT_ID; T::AccountId::decode(&mut &reserve_account[..]).unwrap() } } -fn create_account_id_from_u128(id: u128) -> T::AccountId { - let bytes = id.to_ne_bytes(); - T::AccountId::decode(&mut &bytes[..]).unwrap() +fn create_account_id_from_u128(id: [u8; 32]) -> T::AccountId { + T::AccountId::decode(&mut &id[..]).unwrap() } pub struct TestValidatorVisitor(sp_std::marker::PhantomData); @@ -521,7 +527,7 @@ impl ClusterProtocol> for TestClusterProtocol { } fn get_reserve_account_id(_cluster_id: &ClusterId) -> Result { - let reserve_account = RESERVE_ACCOUNT_ID.to_ne_bytes(); + let reserve_account: [u8; 32] = RESERVE_ACCOUNT_ID; Ok(T::AccountId::decode(&mut &reserve_account[..]).unwrap()) } @@ -561,13 +567,13 @@ impl ExtBuilder { let _balance_genesis = pallet_balances::GenesisConfig:: { balances: vec![ - (1, 10000000000000000000000000000), - (2, USER2_BALANCE), // < PARTIAL_CHARGE - (3, USER3_BALANCE), // > PARTIAL_CHARGE - (4, 1000000000000000000000000), - (5, 1000000000000000000000000), - (6, 1000000000000000000000000), - (7, 1000000000000000000000000), + ([1; 32].into(), 10000000000000000000000000000), + ([2; 32].into(), USER2_BALANCE), // < PARTIAL_CHARGE + ([3; 32].into(), USER3_BALANCE), // > PARTIAL_CHARGE + ([4; 32].into(), 1000000000000000000000000), + ([5; 32].into(), 1000000000000000000000000), + ([6; 32].into(), 1000000000000000000000000), + ([7; 32].into(), 1000000000000000000000000), ], } .assimilate_storage(&mut storage); diff --git a/pallets/ddc-payouts/src/tests.rs b/pallets/ddc-payouts/src/tests.rs index acccb17d7..aa481cb3d 100644 --- a/pallets/ddc-payouts/src/tests.rs +++ b/pallets/ddc-payouts/src/tests.rs @@ -13,18 +13,21 @@ fn set_authorised_caller_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let root_account = 1u128; - let dac_account = 2u128; + let root_account = AccountId::from([1; 32]); + let dac_account = AccountId::from([2; 32]); assert_noop!( - DdcPayouts::set_authorised_caller(RuntimeOrigin::signed(root_account), dac_account), + DdcPayouts::set_authorised_caller( + RuntimeOrigin::signed(root_account), + dac_account.clone() + ), BadOrigin ); - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); System::assert_last_event( - Event::AuthorisedCaller { authorised_caller: dac_account }.into(), + Event::AuthorisedCaller { authorised_caller: dac_account.clone() }.into(), ); assert_eq!(DdcPayouts::authorised_caller().unwrap(), dac_account); @@ -34,8 +37,8 @@ fn set_authorised_caller_works() { #[test] fn begin_billing_report_fails_for_unauthorised() { ExtBuilder.build_and_execute(|| { - let root_account = 1u128; - let dac_account = 2u128; + let root_account = AccountId::from([1; 32]); + let dac_account = AccountId::from([2; 32]); let cluster_id = ClusterId::from([1; 20]); let era = 100; let start_date = NaiveDate::from_ymd_opt(2023, 4, 1).unwrap(); // April 1st @@ -49,7 +52,7 @@ fn begin_billing_report_fails_for_unauthorised() { assert_noop!( DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account + 1), + RuntimeOrigin::signed(AccountId::from([3; 32])), cluster_id, era, start_era, @@ -76,7 +79,7 @@ fn begin_billing_report_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 2u128; + let dac_account = AccountId::from([2; 32]); let cluster_id = ClusterId::from([12; 20]); let era = 100; let start_date = NaiveDate::from_ymd_opt(2023, 4, 1).unwrap(); // April 1st @@ -86,7 +89,7 @@ fn begin_billing_report_works() { DateTime::::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; - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( RuntimeOrigin::signed(dac_account), @@ -108,7 +111,7 @@ fn begin_billing_report_works() { #[test] fn begin_charging_customers_fails_uninitialised() { ExtBuilder.build_and_execute(|| { - let dac_account = 3u128; + let dac_account = AccountId::from([3; 32]); let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 2; @@ -133,11 +136,11 @@ fn begin_charging_customers_fails_uninitialised() { BadOrigin ); - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), DAC_ACCOUNT_ID)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), DAC_ACCOUNT_ID.into())); assert_noop!( DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(DAC_ACCOUNT_ID), + RuntimeOrigin::signed(DAC_ACCOUNT_ID.into()), cluster_id, era, max_batch_index, @@ -152,7 +155,7 @@ fn begin_charging_customers_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 2u128; + let dac_account = AccountId::from([2; 32]); let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 2; @@ -163,10 +166,10 @@ fn begin_charging_customers_works() { DateTime::::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; - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -191,10 +194,10 @@ fn begin_charging_customers_works() { #[test] fn send_charging_customers_batch_fails_uninitialised() { ExtBuilder.build_and_execute(|| { - let root_account = 1u128; - let dac_account = 2u128; - let user1 = 3u128; - let user2 = 4u128; + let root_account = AccountId::from([1; 32]); + let dac_account = AccountId::from([2; 32]); + let user1 = AccountId::from([3; 32]); + let user2 = AccountId::from([4; 32]); let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 2; @@ -208,7 +211,7 @@ fn send_charging_customers_batch_fails_uninitialised() { number_of_puts: 200, }; let payers1 = vec![(user1, bucket_id1, customer_usage)]; - let payers2 = vec![(user2, bucket_id2, CustomerUsage::default())]; + let payers2 = vec![(user2.clone(), bucket_id2, CustomerUsage::default())]; let start_date = NaiveDate::from_ymd_opt(2023, 4, 1).unwrap(); // April 1st let time = NaiveTime::from_hms_opt(0, 0, 0).unwrap(); // Midnight @@ -240,11 +243,11 @@ fn send_charging_customers_batch_fails_uninitialised() { BadOrigin ); - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_noop!( DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -255,7 +258,7 @@ fn send_charging_customers_batch_fails_uninitialised() { ); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -264,7 +267,7 @@ fn send_charging_customers_batch_fails_uninitialised() { assert_noop!( DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -275,7 +278,7 @@ fn send_charging_customers_batch_fails_uninitialised() { ); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -283,7 +286,7 @@ fn send_charging_customers_batch_fails_uninitialised() { assert_noop!( DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -295,7 +298,7 @@ fn send_charging_customers_batch_fails_uninitialised() { let payers1 = vec![(user2, bucket_id2, CustomerUsage::default())]; assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -305,7 +308,7 @@ fn send_charging_customers_batch_fails_uninitialised() { assert_noop!( DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -420,11 +423,11 @@ fn send_charging_customers_batch_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 123u128; - let user1 = 1u128; - let user2_debtor = 2u128; - let user3_debtor = 3u128; - let user4 = 4u128; + let dac_account = AccountId::from([123; 32]); + let user1 = AccountId::from([1; 32]); + let user2_debtor = AccountId::from([2; 32]); + let user3_debtor = AccountId::from([3; 32]); + let user4 = AccountId::from([4; 32]); let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 3; @@ -462,19 +465,21 @@ fn send_charging_customers_batch_works() { number_of_puts: 3456345, number_of_gets: 242334563456423, }; - let payers1 = - vec![(user2_debtor, bucket_id2, usage2.clone()), (user4, bucket_id4, usage4.clone())]; - let payers2 = vec![(user1, bucket_id1, usage1.clone())]; - let payers3 = vec![(user3_debtor, bucket_id3, usage3.clone())]; + let payers1 = vec![ + (user2_debtor.clone(), bucket_id2, usage2.clone()), + (user4.clone(), bucket_id4, usage4.clone()), + ]; + let payers2 = vec![(user1.clone(), bucket_id1, usage1.clone())]; + let payers3 = vec![(user3_debtor.clone(), bucket_id3, usage3.clone())]; let start_date = NaiveDate::from_ymd_opt(2023, 4, 1).unwrap(); // April 1st let time = NaiveTime::from_hms_opt(0, 0, 0).unwrap(); // Midnight let start_era: i64 = DateTime::::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; - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -482,7 +487,7 @@ fn send_charging_customers_batch_works() { )); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -491,7 +496,7 @@ fn send_charging_customers_batch_works() { // batch 1 assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -500,7 +505,7 @@ fn send_charging_customers_batch_works() { )); let usage4_charge = calculate_charge_for_month(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor.clone()).unwrap(); let expected_charge2 = calculate_charge_for_month(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -523,7 +528,7 @@ fn send_charging_customers_batch_works() { Event::ChargeFailed { cluster_id, era, - customer_id: user2_debtor, + customer_id: user2_debtor.clone(), bucket_id: bucket_id2, batch_index, charged: USER2_BALANCE, @@ -561,7 +566,7 @@ fn send_charging_customers_batch_works() { let mut before_total_customer_charge = report.total_customer_charge; batch_index += 1; assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -575,7 +580,7 @@ fn send_charging_customers_batch_works() { era, batch_index, bucket_id: bucket_id1, - customer_id: user1, + customer_id: user1.clone(), amount: calculate_charge_for_month(cluster_id, usage1.clone()), } .into(), @@ -642,7 +647,7 @@ fn send_charging_customers_batch_works() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor.clone()).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -650,7 +655,7 @@ fn send_charging_customers_batch_works() { Event::Indebted { cluster_id, era, - customer_id: user3_debtor, + customer_id: user3_debtor.clone(), bucket_id: bucket_id3, batch_index, amount: user3_debt, @@ -678,9 +683,9 @@ fn end_charging_customers_works_small_usage_1_hour() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 123u128; - let user6 = 6u128; - let user7 = 7u128; + let dac_account = AccountId::from([123; 32]); + let user6 = AccountId::from([6; 32]); + let user7 = AccountId::from([7; 32]); let cluster_id = HIGH_FEES_CLUSTER_ID; let era = 100; let max_batch_index = 0; @@ -700,17 +705,19 @@ fn end_charging_customers_works_small_usage_1_hour() { number_of_puts: 0, number_of_gets: 0, }; - let payers1 = - vec![(user6, bucket_id6, usage6.clone()), (user7, bucket_id7, usage7.clone())]; + let payers1 = vec![ + (user6.clone(), bucket_id6, usage6.clone()), + (user7.clone(), bucket_id7, usage7.clone()), + ]; let start_date = NaiveDate::from_ymd_opt(2023, 4, 1).unwrap(); // April 1st let time = NaiveTime::from_hms_opt(0, 0, 0).unwrap(); // Midnight let start_era: i64 = DateTime::::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 - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -718,7 +725,7 @@ fn end_charging_customers_works_small_usage_1_hour() { )); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -727,7 +734,7 @@ fn end_charging_customers_works_small_usage_1_hour() { // batch 1 assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -776,19 +783,19 @@ fn end_charging_customers_works_small_usage_1_hour() { let charge = usage7_charge + usage6_charge; assert_eq!(balance - Balances::minimum_balance(), charge); - balance = Balances::free_balance(TREASURY_ACCOUNT_ID); + balance = Balances::free_balance(AccountId::from(TREASURY_ACCOUNT_ID)); assert_eq!(balance, 0); - balance = Balances::free_balance(RESERVE_ACCOUNT_ID); + balance = Balances::free_balance(AccountId::from(RESERVE_ACCOUNT_ID)); assert_eq!(balance, 0); - balance = Balances::free_balance(VALIDATOR1_ACCOUNT_ID); + balance = Balances::free_balance(AccountId::from(VALIDATOR1_ACCOUNT_ID)); assert_eq!(balance, 0); - balance = Balances::free_balance(VALIDATOR2_ACCOUNT_ID); + balance = Balances::free_balance(AccountId::from(VALIDATOR2_ACCOUNT_ID)); assert_eq!(balance, 0); - balance = Balances::free_balance(VALIDATOR3_ACCOUNT_ID); + balance = Balances::free_balance(AccountId::from(VALIDATOR3_ACCOUNT_ID)); assert_eq!(balance, 0); assert_ok!(DdcPayouts::end_charging_customers( @@ -817,15 +824,15 @@ fn end_charging_customers_works_small_usage_1_hour() { assert_eq!(fees.validators_share, PRICING_FEES_HIGH.validators_share); assert_eq!(fees.cluster_reserve_share, PRICING_FEES_HIGH.cluster_reserve_share); - balance = Balances::free_balance(TREASURY_ACCOUNT_ID); + balance = Balances::free_balance(AccountId::from(TREASURY_ACCOUNT_ID)); assert_eq!(balance, get_fees(&cluster_id).treasury_share * charge); assert!(balance > 0); - balance = Balances::free_balance(RESERVE_ACCOUNT_ID); + balance = Balances::free_balance(AccountId::from(RESERVE_ACCOUNT_ID)); assert_eq!(balance, get_fees(&cluster_id).cluster_reserve_share * charge); assert!(balance > 0); - balance = Balances::free_balance(VALIDATOR1_ACCOUNT_ID); + balance = Balances::free_balance(AccountId::from(VALIDATOR1_ACCOUNT_ID)); let mut ratio = Perquintill::from_rational( VALIDATOR1_SCORE, VALIDATOR1_SCORE + VALIDATOR2_SCORE + VALIDATOR3_SCORE, @@ -833,7 +840,7 @@ fn end_charging_customers_works_small_usage_1_hour() { assert_eq!(balance, get_fees(&cluster_id).validators_share * ratio * charge); assert!(balance > 0); - balance = Balances::free_balance(VALIDATOR2_ACCOUNT_ID); + balance = Balances::free_balance(AccountId::from(VALIDATOR2_ACCOUNT_ID)); ratio = Perquintill::from_rational( VALIDATOR2_SCORE, VALIDATOR1_SCORE + VALIDATOR2_SCORE + VALIDATOR3_SCORE, @@ -841,7 +848,7 @@ fn end_charging_customers_works_small_usage_1_hour() { assert_eq!(balance, get_fees(&cluster_id).validators_share * ratio * charge); assert!(balance > 0); - balance = Balances::free_balance(VALIDATOR3_ACCOUNT_ID); + balance = Balances::free_balance(AccountId::from(VALIDATOR3_ACCOUNT_ID)); ratio = Perquintill::from_rational( VALIDATOR3_SCORE, VALIDATOR1_SCORE + VALIDATOR2_SCORE + VALIDATOR3_SCORE, @@ -875,11 +882,11 @@ fn send_charging_customers_batch_works_for_day() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 123u128; - let user1 = 1u128; - let user2_debtor = 2u128; - let user3_debtor = 3u128; - let user4 = 4u128; + let dac_account = AccountId::from([123; 32]); + let user1 = AccountId::from([1; 32]); + let user2_debtor = AccountId::from([2; 32]); + let user3_debtor = AccountId::from([3; 32]); + let user4 = AccountId::from([4; 32]); let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 3; @@ -917,19 +924,21 @@ fn send_charging_customers_batch_works_for_day() { number_of_puts: 3456345, number_of_gets: 242334563456423, }; - let payers1 = - vec![(user2_debtor, bucket_id2, usage2.clone()), (user4, bucket_id4, usage4.clone())]; - let payers2 = vec![(user1, bucket_id1, usage1.clone())]; - let payers3 = vec![(user3_debtor, bucket_id3, usage3.clone())]; + let payers1 = vec![ + (user2_debtor.clone(), bucket_id2, usage2.clone()), + (user4.clone(), bucket_id4, usage4.clone()), + ]; + let payers2 = vec![(user1.clone(), bucket_id1, usage1.clone())]; + let payers3 = vec![(user3_debtor.clone(), bucket_id3, usage3.clone())]; let start_date = NaiveDate::from_ymd_opt(2023, 4, 1).unwrap(); // April 1st let time = NaiveTime::from_hms_opt(0, 0, 0).unwrap(); // Midnight let start_era: i64 = DateTime::::from_naive_utc_and_offset(start_date.and_time(time), Utc).timestamp(); let end_era: i64 = start_era + (1.0 * 24.0 * 3600.0) as i64; - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -937,7 +946,7 @@ fn send_charging_customers_batch_works_for_day() { )); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -946,7 +955,7 @@ fn send_charging_customers_batch_works_for_day() { // batch 1 assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -955,7 +964,7 @@ fn send_charging_customers_batch_works_for_day() { )); let usage4_charge = calculate_charge_for_day(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor.clone()).unwrap(); let expected_charge2 = calculate_charge_for_day(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -978,7 +987,7 @@ fn send_charging_customers_batch_works_for_day() { Event::ChargeFailed { cluster_id, era, - customer_id: user2_debtor, + customer_id: user2_debtor.clone(), bucket_id: bucket_id2, batch_index, charged: USER2_BALANCE, @@ -1016,7 +1025,7 @@ fn send_charging_customers_batch_works_for_day() { let mut before_total_customer_charge = report.total_customer_charge; batch_index += 1; assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -1029,7 +1038,7 @@ fn send_charging_customers_batch_works_for_day() { cluster_id, era, batch_index, - customer_id: user1, + customer_id: user1.clone(), bucket_id: bucket_id1, amount: calculate_charge_for_day(cluster_id, usage1.clone()), } @@ -1097,7 +1106,7 @@ fn send_charging_customers_batch_works_for_day() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor.clone()).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -1105,7 +1114,7 @@ fn send_charging_customers_batch_works_for_day() { Event::Indebted { cluster_id, era, - customer_id: user3_debtor, + customer_id: user3_debtor.clone(), bucket_id: bucket_id3, batch_index, amount: user3_debt, @@ -1133,11 +1142,11 @@ fn send_charging_customers_batch_works_for_day_free_storage() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 123u128; - let user1 = 1u128; - let user2_debtor = 2u128; - let user3_debtor = 3u128; - let user4 = 4u128; + let dac_account = AccountId::from([123; 32]); + let user1 = AccountId::from([1; 32]); + let user2_debtor = AccountId::from([2; 32]); + let user3_debtor = AccountId::from([3; 32]); + let user4 = AccountId::from([4; 32]); let cluster_id = STORAGE_ZERO_CLUSTER_ID; let era = 100; let max_batch_index = 3; @@ -1175,19 +1184,21 @@ fn send_charging_customers_batch_works_for_day_free_storage() { number_of_puts: 3456345, number_of_gets: 242334563456423, }; - let payers1 = - vec![(user2_debtor, bucket_id2, usage2.clone()), (user4, bucket_id4, usage4.clone())]; - let payers2 = vec![(user1, bucket_id1, usage1.clone())]; - let payers3 = vec![(user3_debtor, bucket_id3, usage3.clone())]; + let payers1 = vec![ + (user2_debtor.clone(), bucket_id2, usage2.clone()), + (user4.clone(), bucket_id4, usage4.clone()), + ]; + let payers2 = vec![(user1.clone(), bucket_id1, usage1.clone())]; + let payers3 = vec![(user3_debtor.clone(), bucket_id3, usage3.clone())]; let start_date = NaiveDate::from_ymd_opt(2023, 4, 1).unwrap(); // April 1st let time = NaiveTime::from_hms_opt(0, 0, 0).unwrap(); // Midnight let start_era: i64 = DateTime::::from_naive_utc_and_offset(start_date.and_time(time), Utc).timestamp(); let end_era: i64 = start_era + (1.0 * 24.0 * 3600.0) as i64; - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -1195,7 +1206,7 @@ fn send_charging_customers_batch_works_for_day_free_storage() { )); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -1204,7 +1215,7 @@ fn send_charging_customers_batch_works_for_day_free_storage() { // batch 1 assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -1213,7 +1224,7 @@ fn send_charging_customers_batch_works_for_day_free_storage() { )); let usage4_charge = calculate_charge_for_day(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor.clone()).unwrap(); let expected_charge2 = calculate_charge_for_day(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -1236,7 +1247,7 @@ fn send_charging_customers_batch_works_for_day_free_storage() { Event::ChargeFailed { cluster_id, era, - customer_id: user2_debtor, + customer_id: user2_debtor.clone(), bucket_id: bucket_id2, batch_index, charged: USER2_BALANCE, @@ -1274,7 +1285,7 @@ fn send_charging_customers_batch_works_for_day_free_storage() { let mut before_total_customer_charge = report.total_customer_charge; batch_index += 1; assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -1287,7 +1298,7 @@ fn send_charging_customers_batch_works_for_day_free_storage() { cluster_id, era, batch_index, - customer_id: user1, + customer_id: user1.clone(), bucket_id: bucket_id1, amount: calculate_charge_for_day(cluster_id, usage1.clone()), } @@ -1355,7 +1366,7 @@ fn send_charging_customers_batch_works_for_day_free_storage() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor.clone()).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -1363,7 +1374,7 @@ fn send_charging_customers_batch_works_for_day_free_storage() { Event::Indebted { cluster_id, era, - customer_id: user3_debtor, + customer_id: user3_debtor.clone(), bucket_id: bucket_id3, batch_index, amount: user3_debt, @@ -1391,11 +1402,11 @@ fn send_charging_customers_batch_works_for_day_free_stream() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 123u128; - let user1 = 1u128; - let user2_debtor = 2u128; - let user3_debtor = 3u128; - let user4 = 4u128; + let dac_account = AccountId::from([123; 32]); + let user1 = AccountId::from([1; 32]); + let user2_debtor = AccountId::from([2; 32]); + let user3_debtor = AccountId::from([3; 32]); + let user4 = AccountId::from([4; 32]); let cluster_id = STREAM_ZERO_CLUSTER_ID; let era = 100; let max_batch_index = 3; @@ -1433,19 +1444,21 @@ fn send_charging_customers_batch_works_for_day_free_stream() { number_of_puts: 3456345, number_of_gets: 242334563456423, }; - let payers1 = - vec![(user2_debtor, bucket_id2, usage2.clone()), (user4, bucket_id4, usage4.clone())]; - let payers2 = vec![(user1, bucket_id1, usage1.clone())]; - let payers3 = vec![(user3_debtor, bucket_id3, usage3.clone())]; + let payers1 = vec![ + (user2_debtor.clone(), bucket_id2, usage2.clone()), + (user4.clone(), bucket_id4, usage4.clone()), + ]; + let payers2 = vec![(user1.clone(), bucket_id1, usage1.clone())]; + let payers3 = vec![(user3_debtor.clone(), bucket_id3, usage3.clone())]; let start_date = NaiveDate::from_ymd_opt(2023, 4, 1).unwrap(); // April 1st let time = NaiveTime::from_hms_opt(0, 0, 0).unwrap(); // Midnight let start_era: i64 = DateTime::::from_naive_utc_and_offset(start_date.and_time(time), Utc).timestamp(); let end_era: i64 = start_era + (1.0 * 24.0 * 3600.0) as i64; - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -1453,7 +1466,7 @@ fn send_charging_customers_batch_works_for_day_free_stream() { )); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -1462,7 +1475,7 @@ fn send_charging_customers_batch_works_for_day_free_stream() { // batch 1 assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -1471,7 +1484,7 @@ fn send_charging_customers_batch_works_for_day_free_stream() { )); let usage4_charge = calculate_charge_for_day(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor.clone()).unwrap(); let expected_charge2 = calculate_charge_for_day(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -1494,7 +1507,7 @@ fn send_charging_customers_batch_works_for_day_free_stream() { Event::ChargeFailed { cluster_id, era, - customer_id: user2_debtor, + customer_id: user2_debtor.clone(), bucket_id: bucket_id2, batch_index, charged: USER2_BALANCE, @@ -1532,7 +1545,7 @@ fn send_charging_customers_batch_works_for_day_free_stream() { let mut before_total_customer_charge = report.total_customer_charge; batch_index += 1; assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -1545,7 +1558,7 @@ fn send_charging_customers_batch_works_for_day_free_stream() { cluster_id, era, batch_index, - customer_id: user1, + customer_id: user1.clone(), bucket_id: bucket_id1, amount: calculate_charge_for_day(cluster_id, usage1.clone()), } @@ -1613,7 +1626,7 @@ fn send_charging_customers_batch_works_for_day_free_stream() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor.clone()).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -1621,7 +1634,7 @@ fn send_charging_customers_batch_works_for_day_free_stream() { Event::Indebted { cluster_id, era, - customer_id: user3_debtor, + customer_id: user3_debtor.clone(), bucket_id: bucket_id3, batch_index, amount: user3_debt, @@ -1649,11 +1662,11 @@ fn send_charging_customers_batch_works_for_day_free_get() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 123u128; - let user1 = 1u128; - let user2_debtor = 2u128; - let user3_debtor = 3u128; - let user4 = 4u128; + let dac_account = AccountId::from([123; 32]); + let user1 = AccountId::from([1; 32]); + let user2_debtor = AccountId::from([2; 32]); + let user3_debtor = AccountId::from([3; 32]); + let user4 = AccountId::from([4; 32]); let cluster_id = GET_ZERO_CLUSTER_ID; let era = 100; let max_batch_index = 3; @@ -1691,19 +1704,21 @@ fn send_charging_customers_batch_works_for_day_free_get() { number_of_puts: 3456345, number_of_gets: 242334563456423, }; - let payers1 = - vec![(user2_debtor, bucket_id2, usage2.clone()), (user4, bucket_id4, usage4.clone())]; - let payers2 = vec![(user1, bucket_id1, usage1.clone())]; - let payers3 = vec![(user3_debtor, bucket_id3, usage3.clone())]; + let payers1 = vec![ + (user2_debtor.clone(), bucket_id2, usage2.clone()), + (user4.clone(), bucket_id4, usage4.clone()), + ]; + let payers2 = vec![(user1.clone(), bucket_id1, usage1.clone())]; + let payers3 = vec![(user3_debtor.clone(), bucket_id3, usage3.clone())]; let start_date = NaiveDate::from_ymd_opt(2023, 4, 1).unwrap(); // April 1st let time = NaiveTime::from_hms_opt(0, 0, 0).unwrap(); // Midnight let start_era: i64 = DateTime::::from_naive_utc_and_offset(start_date.and_time(time), Utc).timestamp(); let end_era: i64 = start_era + (1.0 * 24.0 * 3600.0) as i64; - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -1711,7 +1726,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { )); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -1720,7 +1735,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { // batch 1 assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -1729,7 +1744,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { )); let usage4_charge = calculate_charge_for_day(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor.clone()).unwrap(); let expected_charge2 = calculate_charge_for_day(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -1752,7 +1767,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { Event::ChargeFailed { cluster_id, era, - customer_id: user2_debtor, + customer_id: user2_debtor.clone(), bucket_id: bucket_id2, batch_index, charged: USER2_BALANCE, @@ -1765,7 +1780,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { Event::Indebted { cluster_id, era, - customer_id: user2_debtor, + customer_id: user2_debtor.clone(), bucket_id: bucket_id2, batch_index, amount: debt, @@ -1790,7 +1805,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { let mut before_total_customer_charge = report.total_customer_charge; batch_index += 1; assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -1803,7 +1818,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { cluster_id, era, batch_index, - customer_id: user1, + customer_id: user1.clone(), bucket_id: bucket_id1, amount: calculate_charge_for_day(cluster_id, usage1.clone()), } @@ -1871,7 +1886,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor.clone()).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -1879,7 +1894,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { Event::Indebted { cluster_id, era, - customer_id: user3_debtor, + customer_id: user3_debtor.clone(), bucket_id: bucket_id3, batch_index, amount: user3_debt, @@ -1907,11 +1922,11 @@ fn send_charging_customers_batch_works_for_day_free_put() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 123u128; - let user1 = 1u128; - let user2_debtor = 2u128; - let user3_debtor = 3u128; - let user4 = 4u128; + let dac_account = AccountId::from([123; 32]); + let user1 = AccountId::from([1; 32]); + let user2_debtor = AccountId::from([2; 32]); + let user3_debtor = AccountId::from([3; 32]); + let user4 = AccountId::from([4; 32]); let cluster_id = PUT_ZERO_CLUSTER_ID; let era = 100; let max_batch_index = 3; @@ -1949,19 +1964,21 @@ fn send_charging_customers_batch_works_for_day_free_put() { number_of_puts: 3456345, number_of_gets: 242334563456423, }; - let payers1 = - vec![(user2_debtor, bucket_id2, usage2.clone()), (user4, bucket_id4, usage4.clone())]; - let payers2 = vec![(user1, bucket_id1, usage1.clone())]; - let payers3 = vec![(user3_debtor, bucket_id3, usage3.clone())]; + let payers1 = vec![ + (user2_debtor.clone(), bucket_id2, usage2.clone()), + (user4.clone(), bucket_id4, usage4.clone()), + ]; + let payers2 = vec![(user1.clone(), bucket_id1, usage1.clone())]; + let payers3 = vec![(user3_debtor.clone(), bucket_id3, usage3.clone())]; let start_date = NaiveDate::from_ymd_opt(2023, 4, 1).unwrap(); // April 1st let time = NaiveTime::from_hms_opt(0, 0, 0).unwrap(); // Midnight let start_era: i64 = DateTime::::from_naive_utc_and_offset(start_date.and_time(time), Utc).timestamp(); let end_era: i64 = start_era + (1.0 * 24.0 * 3600.0) as i64; - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -1969,7 +1986,7 @@ fn send_charging_customers_batch_works_for_day_free_put() { )); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -1978,7 +1995,7 @@ fn send_charging_customers_batch_works_for_day_free_put() { // batch 1 assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -1987,7 +2004,7 @@ fn send_charging_customers_batch_works_for_day_free_put() { )); let usage4_charge = calculate_charge_for_day(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor.clone()).unwrap(); let expected_charge2 = calculate_charge_for_day(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -2010,7 +2027,7 @@ fn send_charging_customers_batch_works_for_day_free_put() { Event::ChargeFailed { cluster_id, era, - customer_id: user2_debtor, + customer_id: user2_debtor.clone(), bucket_id: bucket_id2, batch_index, charged: USER2_BALANCE, @@ -2048,7 +2065,7 @@ fn send_charging_customers_batch_works_for_day_free_put() { let mut before_total_customer_charge = report.total_customer_charge; batch_index += 1; assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -2062,7 +2079,7 @@ fn send_charging_customers_batch_works_for_day_free_put() { era, batch_index, bucket_id: bucket_id1, - customer_id: user1, + customer_id: user1.clone(), amount: calculate_charge_for_day(cluster_id, usage1.clone()), } .into(), @@ -2129,7 +2146,7 @@ fn send_charging_customers_batch_works_for_day_free_put() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor.clone()).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -2137,7 +2154,7 @@ fn send_charging_customers_batch_works_for_day_free_put() { Event::Indebted { cluster_id, era, - customer_id: user3_debtor, + customer_id: user3_debtor.clone(), bucket_id: bucket_id3, batch_index, amount: user3_debt, @@ -2165,11 +2182,11 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 123u128; - let user1 = 1u128; - let user2_debtor = 2u128; - let user3_debtor = 3u128; - let user4 = 4u128; + let dac_account = AccountId::from([123; 32]); + let user1 = AccountId::from([1; 32]); + let user2_debtor = AccountId::from([2; 32]); + let user3_debtor = AccountId::from([3; 32]); + let user4 = AccountId::from([4; 32]); let cluster_id = STORAGE_STREAM_ZERO_CLUSTER_ID; let era = 100; let max_batch_index = 3; @@ -2207,19 +2224,21 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { number_of_puts: 3456345, number_of_gets: 242334563456423, }; - let payers1 = - vec![(user2_debtor, bucket_id2, usage2.clone()), (user4, bucket_id4, usage4.clone())]; - let payers2 = vec![(user1, bucket_id1, usage1.clone())]; - let payers3 = vec![(user3_debtor, bucket_id3, usage3.clone())]; + let payers1 = vec![ + (user2_debtor.clone(), bucket_id2, usage2.clone()), + (user4.clone(), bucket_id4, usage4.clone()), + ]; + let payers2 = vec![(user1.clone(), bucket_id1, usage1.clone())]; + let payers3 = vec![(user3_debtor.clone(), bucket_id3, usage3.clone())]; let start_date = NaiveDate::from_ymd_opt(2023, 4, 1).unwrap(); // April 1st let time = NaiveTime::from_hms_opt(0, 0, 0).unwrap(); // Midnight let start_era: i64 = DateTime::::from_naive_utc_and_offset(start_date.and_time(time), Utc).timestamp(); let end_era: i64 = start_era + (1.0 * 24.0 * 3600.0) as i64; - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -2227,7 +2246,7 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { )); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -2236,7 +2255,7 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { // batch 1 assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -2245,7 +2264,7 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { )); let usage4_charge = calculate_charge_for_day(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor.clone()).unwrap(); let expected_charge2 = calculate_charge_for_day(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -2268,7 +2287,7 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { Event::ChargeFailed { cluster_id, era, - customer_id: user2_debtor, + customer_id: user2_debtor.clone(), bucket_id: bucket_id2, batch_index, charged: USER2_BALANCE, @@ -2306,7 +2325,7 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { let mut before_total_customer_charge = report.total_customer_charge; batch_index += 1; assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -2320,7 +2339,7 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { era, batch_index, bucket_id: bucket_id1, - customer_id: user1, + customer_id: user1.clone(), amount: calculate_charge_for_day(cluster_id, usage1.clone()), } .into(), @@ -2387,7 +2406,7 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor.clone()).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -2395,7 +2414,7 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { Event::Indebted { cluster_id, era, - customer_id: user3_debtor, + customer_id: user3_debtor.clone(), bucket_id: bucket_id3, batch_index, amount: user3_debt, @@ -2423,8 +2442,8 @@ fn send_charging_customers_batch_works_zero_fees() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 123u128; - let user5 = 5u128; + let dac_account = AccountId::from([123; 32]); + let user5 = AccountId::from([5; 32]); let cluster_id = ONE_CLUSTER_ID; let era = 100; let max_batch_index = 0; @@ -2444,9 +2463,9 @@ fn send_charging_customers_batch_works_zero_fees() { DateTime::::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; - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -2454,7 +2473,7 @@ fn send_charging_customers_batch_works_zero_fees() { )); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -2501,9 +2520,9 @@ fn send_charging_customers_batch_works_zero_fees() { #[test] fn end_charging_customers_fails_uninitialised() { ExtBuilder.build_and_execute(|| { - let root_account = 100u128; - let dac_account = 123u128; - let user1 = 1u128; + let root_account = AccountId::from([100; 32]); + let dac_account = AccountId::from([123; 32]); + let user1 = AccountId::from([1; 32]); let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 2; @@ -2530,15 +2549,19 @@ fn end_charging_customers_fails_uninitialised() { BadOrigin ); - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_noop!( - DdcPayouts::end_charging_customers(RuntimeOrigin::signed(dac_account), cluster_id, era,), + DdcPayouts::end_charging_customers( + RuntimeOrigin::signed(dac_account.clone()), + cluster_id, + era, + ), Error::::BillingReportDoesNotExist ); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -2546,24 +2569,32 @@ fn end_charging_customers_fails_uninitialised() { )); assert_noop!( - DdcPayouts::end_charging_customers(RuntimeOrigin::signed(dac_account), cluster_id, era,), + DdcPayouts::end_charging_customers( + RuntimeOrigin::signed(dac_account.clone()), + cluster_id, + era, + ), Error::::NotExpectedState ); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, )); assert_noop!( - DdcPayouts::end_charging_customers(RuntimeOrigin::signed(dac_account), cluster_id, era,), + DdcPayouts::end_charging_customers( + RuntimeOrigin::signed(dac_account.clone()), + cluster_id, + era, + ), Error::::BatchesMissed ); assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -2583,8 +2614,8 @@ fn end_charging_customers_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 123u128; - let user1 = 1u128; + let dac_account = AccountId::from([123; 32]); + let user1 = AccountId::from([1; 32]); let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 0; @@ -2596,7 +2627,7 @@ fn end_charging_customers_works() { number_of_puts: 4456456345234523, number_of_gets: 523423, }; - let payers = vec![(user1, bucket_id1, usage1.clone())]; + let payers = vec![(user1.clone(), bucket_id1, usage1.clone())]; let start_date = NaiveDate::from_ymd_opt(2023, 4, 1).unwrap(); // April 1st let time = NaiveTime::from_hms_opt(0, 0, 0).unwrap(); // Midnight @@ -2604,10 +2635,10 @@ fn end_charging_customers_works() { DateTime::::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; - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -2615,14 +2646,14 @@ fn end_charging_customers_works() { )); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, )); assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -2683,15 +2714,15 @@ fn end_charging_customers_works() { get_fees(&cluster_id).cluster_reserve_share) .left_from_one(); - balance = Balances::free_balance(TREASURY_ACCOUNT_ID); + balance = Balances::free_balance(AccountId::from(TREASURY_ACCOUNT_ID)); let mut expected_fees = get_fees(&cluster_id).treasury_share * charge; assert_eq!(balance, expected_fees); - balance = Balances::free_balance(RESERVE_ACCOUNT_ID); + balance = Balances::free_balance(AccountId::from(RESERVE_ACCOUNT_ID)); expected_fees = get_fees(&cluster_id).cluster_reserve_share * charge; assert_eq!(balance, expected_fees); - balance = Balances::free_balance(VALIDATOR1_ACCOUNT_ID); + balance = Balances::free_balance(AccountId::from(VALIDATOR1_ACCOUNT_ID)); let mut ratio = Perquintill::from_rational( VALIDATOR1_SCORE, VALIDATOR1_SCORE + VALIDATOR2_SCORE + VALIDATOR3_SCORE, @@ -2702,13 +2733,13 @@ fn end_charging_customers_works() { Event::ValidatorRewarded { cluster_id, era, - validator_id: VALIDATOR1_ACCOUNT_ID, + validator_id: AccountId::from(VALIDATOR1_ACCOUNT_ID), amount: expected_fees, } .into(), ); - balance = Balances::free_balance(VALIDATOR2_ACCOUNT_ID); + balance = Balances::free_balance(AccountId::from(VALIDATOR2_ACCOUNT_ID)); ratio = Perquintill::from_rational( VALIDATOR2_SCORE, VALIDATOR1_SCORE + VALIDATOR2_SCORE + VALIDATOR3_SCORE, @@ -2719,13 +2750,13 @@ fn end_charging_customers_works() { Event::ValidatorRewarded { cluster_id, era, - validator_id: VALIDATOR2_ACCOUNT_ID, + validator_id: AccountId::from(VALIDATOR2_ACCOUNT_ID), amount: expected_fees, } .into(), ); - balance = Balances::free_balance(VALIDATOR3_ACCOUNT_ID); + balance = Balances::free_balance(AccountId::from(VALIDATOR3_ACCOUNT_ID)); ratio = Perquintill::from_rational( VALIDATOR3_SCORE, VALIDATOR1_SCORE + VALIDATOR2_SCORE + VALIDATOR3_SCORE, @@ -2736,7 +2767,7 @@ fn end_charging_customers_works() { Event::ValidatorRewarded { cluster_id, era, - validator_id: VALIDATOR3_ACCOUNT_ID, + validator_id: AccountId::from(VALIDATOR3_ACCOUNT_ID), amount: expected_fees, } .into(), @@ -2766,8 +2797,8 @@ fn end_charging_customers_works_zero_fees() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 123u128; - let user1 = 1u128; + let dac_account = AccountId::from([123; 32]); + let user1 = AccountId::from([1; 32]); let cluster_id = ClusterId::zero(); let era = 100; let max_batch_index = 0; @@ -2779,7 +2810,7 @@ fn end_charging_customers_works_zero_fees() { number_of_puts: 1, number_of_gets: 1, }; - let payers = vec![(user1, bucket_id1, usage1.clone())]; + let payers = vec![(user1.clone(), bucket_id1, usage1.clone())]; let start_date = NaiveDate::from_ymd_opt(2023, 4, 1).unwrap(); // April 1st let time = NaiveTime::from_hms_opt(0, 0, 0).unwrap(); // Midnight @@ -2787,10 +2818,10 @@ fn end_charging_customers_works_zero_fees() { DateTime::::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; - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -2798,14 +2829,14 @@ fn end_charging_customers_works_zero_fees() { )); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, )); assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -2855,19 +2886,19 @@ fn end_charging_customers_works_zero_fees() { assert_eq!(fees.validators_share, Perquintill::zero()); assert_eq!(fees.cluster_reserve_share, Perquintill::zero()); - balance = Balances::free_balance(TREASURY_ACCOUNT_ID); + balance = Balances::free_balance(AccountId::from(TREASURY_ACCOUNT_ID)); assert_eq!(balance, 0); - balance = Balances::free_balance(RESERVE_ACCOUNT_ID); + balance = Balances::free_balance(AccountId::from(RESERVE_ACCOUNT_ID)); assert_eq!(balance, 0); - balance = Balances::free_balance(VALIDATOR1_ACCOUNT_ID); + balance = Balances::free_balance(AccountId::from(VALIDATOR1_ACCOUNT_ID)); assert_eq!(balance, 0); - balance = Balances::free_balance(VALIDATOR2_ACCOUNT_ID); + balance = Balances::free_balance(AccountId::from(VALIDATOR2_ACCOUNT_ID)); assert_eq!(balance, 0); - balance = Balances::free_balance(VALIDATOR3_ACCOUNT_ID); + balance = Balances::free_balance(AccountId::from(VALIDATOR3_ACCOUNT_ID)); assert_eq!(balance, 0); assert_eq!( @@ -2892,9 +2923,9 @@ fn end_charging_customers_works_zero_fees() { #[test] fn begin_rewarding_providers_fails_uninitialised() { ExtBuilder.build_and_execute(|| { - let root_account = 1u128; - let dac_account = 2u128; - let user1 = 3u128; + let root_account = AccountId::from([1; 32]); + let dac_account = AccountId::from([2; 32]); + let user1 = AccountId::from([3; 32]); let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 2; @@ -2931,11 +2962,11 @@ fn begin_rewarding_providers_fails_uninitialised() { BadOrigin ); - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_noop!( DdcPayouts::begin_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -2945,7 +2976,7 @@ fn begin_rewarding_providers_fails_uninitialised() { ); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -2954,7 +2985,7 @@ fn begin_rewarding_providers_fails_uninitialised() { assert_noop!( DdcPayouts::begin_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -2964,7 +2995,7 @@ fn begin_rewarding_providers_fails_uninitialised() { ); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -2972,7 +3003,7 @@ fn begin_rewarding_providers_fails_uninitialised() { assert_noop!( DdcPayouts::begin_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -2982,7 +3013,7 @@ fn begin_rewarding_providers_fails_uninitialised() { ); assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -2992,7 +3023,7 @@ fn begin_rewarding_providers_fails_uninitialised() { assert_noop!( DdcPayouts::begin_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -3002,7 +3033,7 @@ fn begin_rewarding_providers_fails_uninitialised() { ); assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index + 1, @@ -3028,8 +3059,8 @@ fn begin_rewarding_providers_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 123u128; - let user1 = 1u128; + let dac_account = AccountId::from([123; 32]); + let user1 = AccountId::from([1; 32]); let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 0; @@ -3044,10 +3075,10 @@ fn begin_rewarding_providers_works() { DateTime::::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; - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -3058,14 +3089,14 @@ fn begin_rewarding_providers_works() { assert_eq!(report.state, PayoutState::Initialized); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, )); assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -3074,7 +3105,7 @@ fn begin_rewarding_providers_works() { )); assert_ok!(DdcPayouts::end_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, )); @@ -3097,11 +3128,11 @@ fn begin_rewarding_providers_works() { #[test] fn send_rewarding_providers_batch_fails_uninitialised() { ExtBuilder.build_and_execute(|| { - let root_account = 1u128; - let dac_account = 2u128; - let user1 = 3u128; - let user2 = 4u128; - let node1 = 33u128; + let root_account = AccountId::from([1; 32]); + let dac_account = AccountId::from([2; 32]); + let user1 = AccountId::from([3; 32]); + let user2 = AccountId::from([4; 32]); + let node1 = AccountId::from([33; 32]); let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 1; @@ -3142,11 +3173,11 @@ fn send_rewarding_providers_batch_fails_uninitialised() { BadOrigin ); - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_noop!( DdcPayouts::send_rewarding_providers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -3157,7 +3188,7 @@ fn send_rewarding_providers_batch_fails_uninitialised() { ); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -3166,7 +3197,7 @@ fn send_rewarding_providers_batch_fails_uninitialised() { assert_noop!( DdcPayouts::send_rewarding_providers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -3177,7 +3208,7 @@ fn send_rewarding_providers_batch_fails_uninitialised() { ); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -3185,7 +3216,7 @@ fn send_rewarding_providers_batch_fails_uninitialised() { assert_noop!( DdcPayouts::send_rewarding_providers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -3196,7 +3227,7 @@ fn send_rewarding_providers_batch_fails_uninitialised() { ); assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -3206,7 +3237,7 @@ fn send_rewarding_providers_batch_fails_uninitialised() { assert_noop!( DdcPayouts::send_rewarding_providers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -3217,7 +3248,7 @@ fn send_rewarding_providers_batch_fails_uninitialised() { ); assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index + 1, @@ -3227,7 +3258,7 @@ fn send_rewarding_providers_batch_fails_uninitialised() { assert_noop!( DdcPayouts::send_rewarding_providers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -3238,7 +3269,7 @@ fn send_rewarding_providers_batch_fails_uninitialised() { ); assert_ok!(DdcPayouts::end_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, )); @@ -3262,11 +3293,11 @@ fn send_rewarding_providers_batch_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let dac_account = 123u128; - let user1 = 1u128; - let node1 = 10u128; - let node2 = 11u128; - let node3 = 12u128; + let dac_account = AccountId::from([123; 32]); + let user1 = AccountId::from([1; 32]); + let node1 = AccountId::from([10; 32]); + let node2 = AccountId::from([11; 32]); + let node3 = AccountId::from([12; 32]); let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 0; @@ -3321,8 +3352,9 @@ fn send_rewarding_providers_batch_works() { }; let payers = vec![(user1, bucket_id1, usage1)]; - let payees1 = vec![(node1, node_usage1.clone()), (node2, node_usage2.clone())]; - let payees2 = vec![(node3, node_usage3.clone())]; + let payees1 = + vec![(node1.clone(), node_usage1.clone()), (node2.clone(), node_usage2.clone())]; + let payees2 = vec![(node3.clone(), node_usage3.clone())]; let start_date = NaiveDate::from_ymd_opt(2023, 4, 1).unwrap(); // April 1st let time = NaiveTime::from_hms_opt(0, 0, 0).unwrap(); // Midnight @@ -3330,10 +3362,10 @@ fn send_rewarding_providers_batch_works() { DateTime::::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; - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -3341,14 +3373,14 @@ fn send_rewarding_providers_batch_works() { )); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, )); assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -3358,7 +3390,7 @@ fn send_rewarding_providers_batch_works() { let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); assert_ok!(DdcPayouts::end_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, )); @@ -3387,7 +3419,7 @@ fn send_rewarding_providers_batch_works() { ); assert_ok!(DdcPayouts::begin_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_node_batch_index, @@ -3395,7 +3427,7 @@ fn send_rewarding_providers_batch_works() { )); assert_ok!(DdcPayouts::send_rewarding_providers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_node_index, @@ -3427,7 +3459,7 @@ fn send_rewarding_providers_batch_works() { ); let mut gets_charge = ratio1_gets * report_after.total_customer_charge.gets; - let balance_node1 = Balances::free_balance(node1); + let balance_node1 = Balances::free_balance(node1.clone()); assert_eq!(balance_node1, transfer_charge + storage_charge + puts_charge + gets_charge); let mut report_reward = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); @@ -3467,7 +3499,7 @@ fn send_rewarding_providers_batch_works() { ); gets_charge = ratio2_gets * report_after.total_customer_charge.gets; - let balance_node2 = Balances::free_balance(node2); + let balance_node2 = Balances::free_balance(node2.clone()); assert_eq!(balance_node2, transfer_charge + storage_charge + puts_charge + gets_charge); assert_eq!(report_reward.total_distributed_reward, balance_node1 + balance_node2); @@ -3485,7 +3517,7 @@ fn send_rewarding_providers_batch_works() { // batch 2 assert_ok!(DdcPayouts::send_rewarding_providers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_node_index + 1, @@ -3518,7 +3550,7 @@ fn send_rewarding_providers_batch_works() { gets_charge = ratio3_gets * report_after.total_customer_charge.gets; report_reward = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); - let balance_node3 = Balances::free_balance(node3); + let balance_node3 = Balances::free_balance(node3.clone()); assert_eq!(balance_node3, transfer_charge + storage_charge + puts_charge + gets_charge); System::assert_has_event( @@ -3558,10 +3590,10 @@ fn send_rewarding_providers_batch_100_nodes_small_usage_works() { ExtBuilder.build_and_execute(|| { System::set_block_number(1); - let num_nodes = 100; + let num_nodes = 10; let num_users = 5; - let dac_account = 123u128; - let bank = 1u128; + let dac_account = AccountId::from([123; 32]); + let bank = AccountId::from([1; 32]); let cluster_id = ONE_CLUSTER_ID; let era = 100; let user_batch_size = 10; @@ -3606,8 +3638,8 @@ fn send_rewarding_providers_batch_100_nodes_small_usage_works() { number_of_gets: usage1.number_of_gets * 2, }; - let mut payees: Vec> = Vec::new(); - let mut node_batch: Vec<(u128, NodeUsage)> = Vec::new(); + let mut payees: Vec> = Vec::new(); + let mut node_batch: Vec<(AccountId, NodeUsage)> = Vec::new(); let mut total_nodes_usage = NodeUsage::default(); for i in 10..10 + num_nodes { let node_usage = match i % 3 { @@ -3621,7 +3653,7 @@ fn send_rewarding_providers_batch_100_nodes_small_usage_works() { total_nodes_usage.number_of_puts += node_usage.number_of_puts; total_nodes_usage.number_of_gets += node_usage.number_of_gets; - node_batch.push((i, node_usage)); + node_batch.push((AccountId::from([i; 32]), node_usage)); if node_batch.len() == node_batch_size { payees.push(node_batch.clone()); node_batch.clear(); @@ -3632,9 +3664,9 @@ fn send_rewarding_providers_batch_100_nodes_small_usage_works() { } let mut total_charge = 0u128; - let mut payers: Vec> = Vec::new(); - let mut user_batch: Vec<(u128, BucketId, CustomerUsage)> = Vec::new(); - for user_id in 1000..1000 + num_users { + let mut payers: Vec> = Vec::new(); + let mut user_batch: Vec<(AccountId, BucketId, CustomerUsage)> = Vec::new(); + for user_id in 100u8..100 + num_users { let ratio = match user_id % 5 { 0 => Perquintill::one(), 1 => Perquintill::from_float(0.5), @@ -3652,14 +3684,14 @@ fn send_rewarding_providers_batch_100_nodes_small_usage_works() { let expected_charge = calculate_charge_for_month(cluster_id, user_usage.clone()); Balances::transfer( - RuntimeOrigin::signed(bank), - user_id, + RuntimeOrigin::signed(bank.clone()), + AccountId::from([user_id; 32]), (expected_charge * 2).max(Balances::minimum_balance()), ) .unwrap(); total_charge += expected_charge; - user_batch.push((user_id, bucketid1, user_usage)); + user_batch.push((AccountId::from([user_id; 32]), bucketid1, user_usage)); if user_batch.len() == user_batch_size { payers.push(user_batch.clone()); user_batch.clear(); @@ -3669,16 +3701,16 @@ fn send_rewarding_providers_batch_100_nodes_small_usage_works() { payers.push(user_batch.clone()); } - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, end_era, )); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, (payers.len() - 1) as u16, @@ -3686,7 +3718,7 @@ fn send_rewarding_providers_batch_100_nodes_small_usage_works() { for batch in payers.iter() { assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_user_index, @@ -3702,7 +3734,7 @@ fn send_rewarding_providers_batch_100_nodes_small_usage_works() { cluster_id, era, bucket_id: bucketid1, - customer_id: *customer_id, + customer_id: customer_id.clone(), batch_index: batch_user_index, amount: charge, } @@ -3713,14 +3745,14 @@ fn send_rewarding_providers_batch_100_nodes_small_usage_works() { } let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); - let balance1 = Balances::free_balance(report_before.vault); + let balance1 = Balances::free_balance(report_before.vault.clone()); let balance2 = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance1, balance2); assert_eq!(report_before.vault, DdcPayouts::account_id()); assert_eq!(balance1 - Balances::minimum_balance(), total_charge); assert_ok!(DdcPayouts::end_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, )); @@ -3756,7 +3788,7 @@ fn send_rewarding_providers_batch_100_nodes_small_usage_works() { ); assert_ok!(DdcPayouts::begin_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, (payees.len() - 1) as u16, @@ -3766,7 +3798,7 @@ fn send_rewarding_providers_batch_100_nodes_small_usage_works() { for batch in payees.iter() { let before_batch = Balances::free_balance(DdcPayouts::account_id()); assert_ok!(DdcPayouts::send_rewarding_providers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_node_index, @@ -3828,10 +3860,10 @@ fn send_rewarding_providers_batch_100_nodes_large_usage_works() { let start_era: i64 = DateTime::::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 num_nodes = 100; + let num_nodes = 10; let num_users = 5; - let dac_account = 123u128; - let bank = 1u128; + let dac_account = AccountId::from([123; 32]); + let bank = AccountId::from([1; 32]); let cluster_id = ONE_CLUSTER_ID; let era = 100; let user_batch_size = 10; @@ -3871,10 +3903,10 @@ fn send_rewarding_providers_batch_100_nodes_large_usage_works() { number_of_gets: usage1.number_of_gets * 2, }; - let mut payees: Vec> = Vec::new(); - let mut node_batch: Vec<(u128, NodeUsage)> = Vec::new(); + let mut payees: Vec> = Vec::new(); + let mut node_batch: Vec<(AccountId, NodeUsage)> = Vec::new(); let mut total_nodes_usage = NodeUsage::default(); - for i in 10..10 + num_nodes { + for i in 10u8..10 + num_nodes { let ratio = match i % 5 { 0 => Perquintill::from_float(1_000_000.0), 1 => Perquintill::from_float(10_000_000.0), @@ -3899,7 +3931,7 @@ fn send_rewarding_providers_batch_100_nodes_large_usage_works() { total_nodes_usage.number_of_puts += node_usage.number_of_puts; total_nodes_usage.number_of_gets += node_usage.number_of_gets; - node_batch.push((i, node_usage)); + node_batch.push((AccountId::from([i; 32]), node_usage)); if node_batch.len() == node_batch_size { payees.push(node_batch.clone()); node_batch.clear(); @@ -3910,9 +3942,9 @@ fn send_rewarding_providers_batch_100_nodes_large_usage_works() { } let mut total_charge = 0u128; - let mut payers: Vec> = Vec::new(); - let mut user_batch: Vec<(u128, BucketId, CustomerUsage)> = Vec::new(); - for user_id in 1000..1000 + num_users { + let mut payers: Vec> = Vec::new(); + let mut user_batch: Vec<(AccountId, BucketId, CustomerUsage)> = Vec::new(); + for user_id in 100u8..100 + num_users { let ratio = match user_id % 5 { 0 => Perquintill::from_float(1_000_000.0), 1 => Perquintill::from_float(10_000_000.0), @@ -3930,14 +3962,14 @@ fn send_rewarding_providers_batch_100_nodes_large_usage_works() { let expected_charge = calculate_charge_for_month(cluster_id, user_usage.clone()); Balances::transfer( - RuntimeOrigin::signed(bank), - user_id, + RuntimeOrigin::signed(bank.clone()), + AccountId::from([user_id; 32]), (expected_charge * 2).max(Balances::minimum_balance()), ) .unwrap(); total_charge += expected_charge; - user_batch.push((user_id, bucket_id, user_usage)); + user_batch.push((AccountId::from([user_id; 32]), bucket_id, user_usage)); if user_batch.len() == user_batch_size { payers.push(user_batch.clone()); user_batch.clear(); @@ -3947,16 +3979,16 @@ fn send_rewarding_providers_batch_100_nodes_large_usage_works() { payers.push(user_batch.clone()); } - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, end_era, )); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, (payers.len() - 1) as u16, @@ -3964,7 +3996,7 @@ fn send_rewarding_providers_batch_100_nodes_large_usage_works() { for batch in payers.iter() { assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_user_index, @@ -3980,7 +4012,7 @@ fn send_rewarding_providers_batch_100_nodes_large_usage_works() { cluster_id, era, bucket_id: bucketid1, - customer_id: *customer_id, + customer_id: customer_id.clone(), batch_index: batch_user_index, amount: charge, } @@ -3991,14 +4023,14 @@ fn send_rewarding_providers_batch_100_nodes_large_usage_works() { } let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); - let balance1 = Balances::free_balance(report_before.vault); + let balance1 = Balances::free_balance(report_before.vault.clone()); let balance2 = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance1, balance2); assert_eq!(report_before.vault, DdcPayouts::account_id()); assert_eq!(balance1 - Balances::minimum_balance(), total_charge); assert_ok!(DdcPayouts::end_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, )); @@ -4034,7 +4066,7 @@ fn send_rewarding_providers_batch_100_nodes_large_usage_works() { ); assert_ok!(DdcPayouts::begin_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, (payees.len() - 1) as u16, @@ -4044,7 +4076,7 @@ fn send_rewarding_providers_batch_100_nodes_large_usage_works() { for batch in payees.iter() { let before_batch = Balances::free_balance(DdcPayouts::account_id()); assert_ok!(DdcPayouts::send_rewarding_providers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_node_index, @@ -4106,10 +4138,10 @@ fn send_rewarding_providers_batch_100_nodes_small_large_usage_works() { let start_era: i64 = DateTime::::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 num_nodes = 100; + let num_nodes = 10; let num_users = 5; - let dac_account = 123u128; - let bank = 1u128; + let dac_account = AccountId::from([123; 32]); + let bank = AccountId::from([1; 32]); let cluster_id = ONE_CLUSTER_ID; let era = 100; let bucketid1: BucketId = 1; @@ -4148,10 +4180,10 @@ fn send_rewarding_providers_batch_100_nodes_small_large_usage_works() { number_of_gets: usage1.number_of_gets * 2, }; - let mut payees: Vec> = Vec::new(); - let mut node_batch: Vec<(u128, NodeUsage)> = Vec::new(); + let mut payees: Vec> = Vec::new(); + let mut node_batch: Vec<(AccountId, NodeUsage)> = Vec::new(); let mut total_nodes_usage = NodeUsage::default(); - for i in 10..10 + num_nodes { + for i in 10u8..10 + num_nodes { let ratio = match i % 5 { 0 => Perquintill::from_float(1_000_000.0), 1 => Perquintill::from_float(0.5), @@ -4176,7 +4208,7 @@ fn send_rewarding_providers_batch_100_nodes_small_large_usage_works() { total_nodes_usage.number_of_puts += node_usage.number_of_puts; total_nodes_usage.number_of_gets += node_usage.number_of_gets; - node_batch.push((i, node_usage)); + node_batch.push((AccountId::from([i; 32]), node_usage)); if node_batch.len() == node_batch_size { payees.push(node_batch.clone()); node_batch.clear(); @@ -4187,9 +4219,9 @@ fn send_rewarding_providers_batch_100_nodes_small_large_usage_works() { } let mut total_charge = 0u128; - let mut payers: Vec> = Vec::new(); - let mut user_batch: Vec<(u128, BucketId, CustomerUsage)> = Vec::new(); - for user_id in 1000..1000 + num_users { + let mut payers: Vec> = Vec::new(); + let mut user_batch: Vec<(AccountId, BucketId, CustomerUsage)> = Vec::new(); + for user_id in 100u8..100 + num_users { let ratio = match user_id % 5 { 0 => Perquintill::from_float(1_000_000.0), 1 => Perquintill::from_float(10_000_000.0), @@ -4207,14 +4239,14 @@ fn send_rewarding_providers_batch_100_nodes_small_large_usage_works() { let expected_charge = calculate_charge_for_month(cluster_id, user_usage.clone()); Balances::transfer( - RuntimeOrigin::signed(bank), - user_id, + RuntimeOrigin::signed(bank.clone()), + AccountId::from([user_id; 32]), (expected_charge * 2).max(Balances::minimum_balance()), ) .unwrap(); total_charge += expected_charge; - user_batch.push((user_id, bucketid1, user_usage)); + user_batch.push((AccountId::from([user_id; 32]), bucketid1, user_usage)); if user_batch.len() == user_batch_size { payers.push(user_batch.clone()); user_batch.clear(); @@ -4224,16 +4256,16 @@ fn send_rewarding_providers_batch_100_nodes_small_large_usage_works() { payers.push(user_batch.clone()); } - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, end_era, )); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, (payers.len() - 1) as u16, @@ -4241,7 +4273,7 @@ fn send_rewarding_providers_batch_100_nodes_small_large_usage_works() { for batch in payers.iter() { assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_user_index, @@ -4256,7 +4288,7 @@ fn send_rewarding_providers_batch_100_nodes_small_large_usage_works() { Event::Charged { cluster_id, era, - customer_id: *customer_id, + customer_id: customer_id.clone(), bucket_id: bucketid1, batch_index: batch_user_index, amount: charge, @@ -4268,14 +4300,14 @@ fn send_rewarding_providers_batch_100_nodes_small_large_usage_works() { } let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); - let balance1 = Balances::free_balance(report_before.vault); + let balance1 = Balances::free_balance(report_before.vault.clone()); let balance2 = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance1, balance2); assert_eq!(report_before.vault, DdcPayouts::account_id()); assert_eq!(balance1 - Balances::minimum_balance(), total_charge); assert_ok!(DdcPayouts::end_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, )); @@ -4311,7 +4343,7 @@ fn send_rewarding_providers_batch_100_nodes_small_large_usage_works() { ); assert_ok!(DdcPayouts::begin_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, (payees.len() - 1) as u16, @@ -4321,7 +4353,7 @@ fn send_rewarding_providers_batch_100_nodes_small_large_usage_works() { for batch in payees.iter() { let before_batch = Balances::free_balance(DdcPayouts::account_id()); assert_ok!(DdcPayouts::send_rewarding_providers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_node_index, @@ -4393,10 +4425,10 @@ fn send_rewarding_providers_batch_100_nodes_random_usage_works() { let mock_randomness = MockRandomness::default(); let min: u64 = 1024; let max: u64 = 1024 * 1024; - let num_nodes = 100; - let num_users = 100; - let dac_account = 123u128; - let bank = 1u128; + let num_nodes = 10; + let num_users = 10; + let dac_account = AccountId::from([123; 32]); + let bank = AccountId::from([1; 32]); let cluster_id = CERE_CLUSTER_ID; let era = 100; let user_batch_size = 10; @@ -4404,10 +4436,10 @@ fn send_rewarding_providers_batch_100_nodes_random_usage_works() { let mut batch_user_index = 0; let mut batch_node_index = 0; let bucket_id1: BucketId = 1; - let mut payees: Vec> = Vec::new(); - let mut node_batch: Vec<(u128, NodeUsage)> = Vec::new(); + let mut payees: Vec> = Vec::new(); + let mut node_batch: Vec<(AccountId, NodeUsage)> = Vec::new(); let mut total_nodes_usage = NodeUsage::default(); - for i in 10..10 + num_nodes { + for i in 10u8..10 + num_nodes { let node_usage = NodeUsage { transferred_bytes: generate_random_u64(&mock_randomness, min, max), stored_bytes: (generate_random_u64(&mock_randomness, min, max)) as i64, @@ -4420,7 +4452,7 @@ fn send_rewarding_providers_batch_100_nodes_random_usage_works() { total_nodes_usage.number_of_puts += node_usage.number_of_puts; total_nodes_usage.number_of_gets += node_usage.number_of_gets; - node_batch.push((i, node_usage)); + node_batch.push((AccountId::from([i; 32]), node_usage)); if node_batch.len() == node_batch_size { payees.push(node_batch.clone()); node_batch.clear(); @@ -4431,9 +4463,9 @@ fn send_rewarding_providers_batch_100_nodes_random_usage_works() { } let mut total_charge = 0u128; - let mut payers: Vec> = Vec::new(); - let mut user_batch: Vec<(u128, BucketId, CustomerUsage)> = Vec::new(); - for user_id in 1000..1000 + num_users { + let mut payers: Vec> = Vec::new(); + let mut user_batch: Vec<(AccountId, BucketId, CustomerUsage)> = Vec::new(); + for user_id in 100u8..100 + num_users { let user_usage = CustomerUsage { transferred_bytes: generate_random_u64(&mock_randomness, min, max), stored_bytes: (generate_random_u64(&mock_randomness, min, max)) as i64, @@ -4443,14 +4475,14 @@ fn send_rewarding_providers_batch_100_nodes_random_usage_works() { let expected_charge = calculate_charge_for_month(cluster_id, user_usage.clone()); Balances::transfer( - RuntimeOrigin::signed(bank), - user_id, + RuntimeOrigin::signed(bank.clone()), + AccountId::from([user_id; 32]), (expected_charge * 2).max(Balances::minimum_balance()), ) .unwrap(); total_charge += expected_charge; - user_batch.push((user_id, bucket_id1, user_usage)); + user_batch.push((AccountId::from([user_id; 32]), bucket_id1, user_usage)); if user_batch.len() == user_batch_size { payers.push(user_batch.clone()); user_batch.clear(); @@ -4460,16 +4492,16 @@ fn send_rewarding_providers_batch_100_nodes_random_usage_works() { payers.push(user_batch.clone()); } - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, end_era, )); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, (payers.len() - 1) as u16, @@ -4477,7 +4509,7 @@ fn send_rewarding_providers_batch_100_nodes_random_usage_works() { for batch in payers.iter() { assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_user_index, @@ -4493,7 +4525,7 @@ fn send_rewarding_providers_batch_100_nodes_random_usage_works() { cluster_id, era, bucket_id: bucket_id1, - customer_id: *customer_id, + customer_id: customer_id.clone(), batch_index: batch_user_index, amount: charge, } @@ -4504,14 +4536,14 @@ fn send_rewarding_providers_batch_100_nodes_random_usage_works() { } let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); - let balance1 = Balances::free_balance(report_before.vault); + let balance1 = Balances::free_balance(report_before.vault.clone()); let balance2 = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance1, balance2); assert_eq!(report_before.vault, DdcPayouts::account_id()); assert_eq!(balance1 - Balances::minimum_balance(), total_charge); assert_ok!(DdcPayouts::end_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, )); @@ -4547,7 +4579,7 @@ fn send_rewarding_providers_batch_100_nodes_random_usage_works() { ); assert_ok!(DdcPayouts::begin_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, (payees.len() - 1) as u16, @@ -4557,7 +4589,7 @@ fn send_rewarding_providers_batch_100_nodes_random_usage_works() { for batch in payees.iter() { let before_batch = Balances::free_balance(DdcPayouts::account_id()); assert_ok!(DdcPayouts::send_rewarding_providers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_node_index, @@ -4611,11 +4643,11 @@ fn send_rewarding_providers_batch_100_nodes_random_usage_works() { #[test] fn end_rewarding_providers_fails_uninitialised() { ExtBuilder.build_and_execute(|| { - let root_account = 1u128; - let dac_account = 2u128; - let user1 = 3u128; - let user2 = 4u128; - let node1 = 33u128; + let root_account = AccountId::from([1; 32]); + let dac_account = AccountId::from([2; 32]); + let user1 = AccountId::from([3; 32]); + let user2 = AccountId::from([4; 32]); + let node1 = AccountId::from([33; 32]); let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 1; @@ -4647,11 +4679,11 @@ fn end_rewarding_providers_fails_uninitialised() { BadOrigin ); - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_noop!( DdcPayouts::end_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, ), @@ -4659,7 +4691,7 @@ fn end_rewarding_providers_fails_uninitialised() { ); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -4668,7 +4700,7 @@ fn end_rewarding_providers_fails_uninitialised() { assert_noop!( DdcPayouts::end_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, ), @@ -4676,7 +4708,7 @@ fn end_rewarding_providers_fails_uninitialised() { ); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -4684,7 +4716,7 @@ fn end_rewarding_providers_fails_uninitialised() { assert_noop!( DdcPayouts::end_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, ), @@ -4692,7 +4724,7 @@ fn end_rewarding_providers_fails_uninitialised() { ); assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -4702,7 +4734,7 @@ fn end_rewarding_providers_fails_uninitialised() { assert_noop!( DdcPayouts::end_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, ), @@ -4710,7 +4742,7 @@ fn end_rewarding_providers_fails_uninitialised() { ); assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index + 1, @@ -4720,7 +4752,7 @@ fn end_rewarding_providers_fails_uninitialised() { assert_noop!( DdcPayouts::end_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, ), @@ -4728,14 +4760,14 @@ fn end_rewarding_providers_fails_uninitialised() { ); assert_ok!(DdcPayouts::end_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, )); assert_noop!( DdcPayouts::end_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, ), @@ -4743,7 +4775,7 @@ fn end_rewarding_providers_fails_uninitialised() { ); assert_ok!(DdcPayouts::begin_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -4752,7 +4784,7 @@ fn end_rewarding_providers_fails_uninitialised() { assert_noop!( DdcPayouts::end_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, ), @@ -4760,7 +4792,7 @@ fn end_rewarding_providers_fails_uninitialised() { ); assert_ok!(DdcPayouts::send_rewarding_providers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -4790,9 +4822,9 @@ fn end_rewarding_providers_works() { let start_era: i64 = DateTime::::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 dac_account = 2u128; - let user1 = 1u128; - let node1 = 33u128; + let dac_account = AccountId::from([2; 32]); + let user1 = AccountId::from([1; 32]); + let node1 = AccountId::from([33; 32]); let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 0; @@ -4816,10 +4848,10 @@ fn end_rewarding_providers_works() { let payers = vec![(user1, bucket_id1, usage1)]; let payees = vec![(node1, node_usage1)]; - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -4830,14 +4862,14 @@ fn end_rewarding_providers_works() { assert_eq!(report.state, PayoutState::Initialized); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, )); assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -4846,13 +4878,13 @@ fn end_rewarding_providers_works() { )); assert_ok!(DdcPayouts::end_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, )); assert_ok!(DdcPayouts::begin_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -4860,7 +4892,7 @@ fn end_rewarding_providers_works() { )); assert_ok!(DdcPayouts::send_rewarding_providers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -4869,7 +4901,7 @@ fn end_rewarding_providers_works() { )); assert_ok!(DdcPayouts::end_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, )); @@ -4890,11 +4922,11 @@ fn end_billing_report_fails_uninitialised() { let start_era: i64 = DateTime::::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 root_account = 1u128; - let dac_account = 2u128; - let user1 = 3u128; - let user2 = 4u128; - let node1 = 33u128; + let root_account = AccountId::from([1; 32]); + let dac_account = AccountId::from([2; 32]); + let user1 = AccountId::from([3; 32]); + let user2 = AccountId::from([4; 32]); + let node1 = AccountId::from([33; 32]); let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 1; @@ -4916,15 +4948,19 @@ fn end_billing_report_fails_uninitialised() { BadOrigin ); - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_noop!( - DdcPayouts::end_billing_report(RuntimeOrigin::signed(dac_account), cluster_id, era,), + DdcPayouts::end_billing_report( + RuntimeOrigin::signed(dac_account.clone()), + cluster_id, + era, + ), Error::::BillingReportDoesNotExist ); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -4932,24 +4968,32 @@ fn end_billing_report_fails_uninitialised() { )); assert_noop!( - DdcPayouts::end_billing_report(RuntimeOrigin::signed(dac_account), cluster_id, era,), + DdcPayouts::end_billing_report( + RuntimeOrigin::signed(dac_account.clone()), + cluster_id, + era, + ), Error::::NotExpectedState ); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, )); assert_noop!( - DdcPayouts::end_billing_report(RuntimeOrigin::signed(dac_account), cluster_id, era,), + DdcPayouts::end_billing_report( + RuntimeOrigin::signed(dac_account.clone()), + cluster_id, + era, + ), Error::::NotExpectedState ); assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -4958,12 +5002,16 @@ fn end_billing_report_fails_uninitialised() { )); assert_noop!( - DdcPayouts::end_billing_report(RuntimeOrigin::signed(dac_account), cluster_id, era,), + DdcPayouts::end_billing_report( + RuntimeOrigin::signed(dac_account.clone()), + cluster_id, + era, + ), Error::::NotExpectedState ); assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index + 1, @@ -4972,23 +5020,31 @@ fn end_billing_report_fails_uninitialised() { )); assert_noop!( - DdcPayouts::end_billing_report(RuntimeOrigin::signed(dac_account), cluster_id, era,), + DdcPayouts::end_billing_report( + RuntimeOrigin::signed(dac_account.clone()), + cluster_id, + era, + ), Error::::NotExpectedState ); assert_ok!(DdcPayouts::end_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, )); assert_noop!( - DdcPayouts::end_billing_report(RuntimeOrigin::signed(dac_account), cluster_id, era,), + DdcPayouts::end_billing_report( + RuntimeOrigin::signed(dac_account.clone()), + cluster_id, + era, + ), Error::::NotExpectedState ); assert_ok!(DdcPayouts::begin_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -4996,12 +5052,16 @@ fn end_billing_report_fails_uninitialised() { )); assert_noop!( - DdcPayouts::end_billing_report(RuntimeOrigin::signed(dac_account), cluster_id, era,), + DdcPayouts::end_billing_report( + RuntimeOrigin::signed(dac_account.clone()), + cluster_id, + era, + ), Error::::NotExpectedState ); assert_ok!(DdcPayouts::send_rewarding_providers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -5010,12 +5070,16 @@ fn end_billing_report_fails_uninitialised() { )); assert_noop!( - DdcPayouts::end_billing_report(RuntimeOrigin::signed(dac_account), cluster_id, era,), + DdcPayouts::end_billing_report( + RuntimeOrigin::signed(dac_account.clone()), + cluster_id, + era, + ), Error::::NotExpectedState ); assert_ok!(DdcPayouts::send_rewarding_providers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index + 1, @@ -5041,9 +5105,9 @@ fn end_billing_report_works() { let start_era: i64 = DateTime::::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 dac_account = 2u128; - let user1 = 3u128; - let node1 = 33u128; + let dac_account = AccountId::from([2; 32]); + let user1 = AccountId::from([3; 32]); + let node1 = AccountId::from([33; 32]); let cluster_id = ClusterId::from([12; 20]); let era = 100; let max_batch_index = 0; @@ -5053,10 +5117,10 @@ fn end_billing_report_works() { let payers = vec![(user1, bucket_id1, CustomerUsage::default())]; let payees = vec![(node1, NodeUsage::default())]; - assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account)); + assert_ok!(DdcPayouts::set_authorised_caller(RuntimeOrigin::root(), dac_account.clone())); assert_ok!(DdcPayouts::begin_billing_report( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, start_era, @@ -5067,14 +5131,14 @@ fn end_billing_report_works() { assert_eq!(report.state, PayoutState::Initialized); assert_ok!(DdcPayouts::begin_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, )); assert_ok!(DdcPayouts::send_charging_customers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -5083,13 +5147,13 @@ fn end_billing_report_works() { )); assert_ok!(DdcPayouts::end_charging_customers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, )); assert_ok!(DdcPayouts::begin_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, max_batch_index, @@ -5097,7 +5161,7 @@ fn end_billing_report_works() { )); assert_ok!(DdcPayouts::send_rewarding_providers_batch( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, batch_index, @@ -5106,7 +5170,7 @@ fn end_billing_report_works() { )); assert_ok!(DdcPayouts::end_rewarding_providers( - RuntimeOrigin::signed(dac_account), + RuntimeOrigin::signed(dac_account.clone()), cluster_id, era, )); diff --git a/pallets/ddc-verification/src/lib.rs b/pallets/ddc-verification/src/lib.rs index 3d90bbfa9..12e3dd47b 100644 --- a/pallets/ddc-verification/src/lib.rs +++ b/pallets/ddc-verification/src/lib.rs @@ -55,6 +55,7 @@ mod tests; pub mod pallet { use ddc_primitives::{BucketId, MergeActivityHash, KEY_TYPE}; use frame_support::PalletId; + use sp_core::crypto::AccountId32; use sp_runtime::SaturatedConversion; use super::*; @@ -112,6 +113,7 @@ pub mod pallet { const MAX_PAYOUT_BATCH_SIZE: u16; /// The access to staking functionality. type StakingVisitor: StakingInterface; + type AccountIdConverter: From + Into; } /// The event type. @@ -272,6 +274,15 @@ pub mod pallet { era_id: DdcEra, validator: T::AccountId, }, + EraValidationRootsPosted { + cluster_id: ClusterId, + era_id: DdcEra, + validator: T::AccountId, + payers_merkle_root_hash: ActivityHash, + payees_merkle_root_hash: ActivityHash, + payers_batch_merkle_root_hashes: Vec, + payees_batch_merkle_root_hashes: Vec, + }, } /// Consensus Errors @@ -632,7 +643,13 @@ pub mod pallet { Self::process_dac_data(&cluster_id, None, &dac_nodes, min_nodes, batch_size.into()); match processed_dac_data { - Ok(Some((era_activity, payers_merkle_root_hash, payees_merkle_root_hash))) => { + Ok(Some(( + era_activity, + payers_merkle_root_hash, + payees_merkle_root_hash, + payers_batch_merkle_root_hashes, + payees_batch_merkle_root_hashes, + ))) => { log::info!( "🏭🚀 Processing era_id: {:?} for cluster_id: {:?}", era_activity.clone(), @@ -645,6 +662,10 @@ pub mod pallet { era_activity: era_activity.clone(), payers_merkle_root_hash, payees_merkle_root_hash, + payers_batch_merkle_root_hashes: payers_batch_merkle_root_hashes + .clone(), + payees_batch_merkle_root_hashes: payees_batch_merkle_root_hashes + .clone(), } }); @@ -792,11 +813,22 @@ pub mod pallet { min_nodes, ) { Ok(Some((era_id, batch_payout))) => { + let payers_log: Vec<(String, BucketId, CustomerUsage)> = batch_payout + .payers + .clone() + .into_iter() + .map(|(acc_id, bucket_id, customer_usage)| { + let account_id: T::AccountIdConverter = acc_id.into(); + let account_id_32: AccountId32 = account_id.into(); + let account_ref: &[u8; 32] = account_id_32.as_ref(); + (hex::encode(account_ref), bucket_id, customer_usage) + }) + .collect(); log::info!( "🏭🎁 prepare_send_charging_customers_batch processed successfully for cluster_id: {:?}, era_id: {:?} , batch_payout: {:?}", cluster_id, era_id, - batch_payout.payers + payers_log ); if let Some((_, res)) = @@ -1141,13 +1173,17 @@ pub mod pallet { } impl Pallet { + #[allow(clippy::type_complexity)] pub(crate) fn process_dac_data( cluster_id: &ClusterId, era_id_to_process: Option, dac_nodes: &[(NodePubKey, StorageNodeParams)], min_nodes: u16, batch_size: usize, - ) -> Result, Vec> { + ) -> Result< + Option<(EraActivity, ActivityHash, ActivityHash, Vec, Vec)>, + Vec, + > { log::info!("🚀 Processing dac data for cluster_id: {:?}", cluster_id); // todo! Need to debug follwing condition. Why it is not working on Devnet @@ -1184,7 +1220,12 @@ pub mod pallet { Percent::from_percent(T::MAJORITY), )?; - log::info!("🪅 customers_activity_in_consensus executed successfully. "); + log::info!( + "🧗‍ Customer Activity for ClusterId: {:?} EraId: {:?} is: {:?}", + cluster_id, + era_activity.id, + customers_activity_in_consensus + ); let customers_activity_batch_roots = Self::convert_to_batch_merkle_roots( cluster_id, era_activity.id, @@ -1192,6 +1233,16 @@ pub mod pallet { ) .map_err(|err| vec![err])?; + let customer_batch_roots_string: Vec = + customers_activity_batch_roots.clone().into_iter().map(hex::encode).collect(); + + log::info!( + "🧗‍ Customer Activity_batch_roots for ClusterId: {:?} EraId: {:?} is: {:?}", + cluster_id, + era_activity.id, + customer_batch_roots_string + ); + let customers_activity_root = Self::create_merkle_root( cluster_id, era_activity.id, @@ -1199,6 +1250,13 @@ pub mod pallet { ) .map_err(|err| vec![err])?; + log::info!( + "🧗‍ Customer Activity _ roots for ClusterId: {:?} EraId: {:?} is: {:?}", + cluster_id, + era_activity.id, + hex::encode(customers_activity_root) + ); + let nodes_activity_in_consensus = Self::get_consensus_for_activities( cluster_id, era_activity.id, @@ -1207,7 +1265,12 @@ pub mod pallet { Percent::from_percent(T::MAJORITY), )?; - log::info!("🪅 nodes_activity_in_consensus executed successfully. "); + log::info!( + "🧗‍ Node Activity for ClusterId: {:?} EraId: {:?} is: {:?}", + cluster_id, + era_activity.id, + nodes_activity_in_consensus + ); let nodes_activity_batch_roots = Self::convert_to_batch_merkle_roots( cluster_id, era_activity.id, @@ -1215,10 +1278,26 @@ pub mod pallet { ) .map_err(|err| vec![err])?; + let nodes_activity_batch_roots_string: Vec = + nodes_activity_batch_roots.clone().into_iter().map(hex::encode).collect(); + + log::info!( + "🧗‍ Node Activity_batch_roots for ClusterId: {:?} EraId: {:?} is: {:?}", + cluster_id, + era_activity.id, + nodes_activity_batch_roots_string + ); let nodes_activity_root = Self::create_merkle_root(cluster_id, era_activity.id, &nodes_activity_batch_roots) .map_err(|err| vec![err])?; + log::info!( + "🧗‍ Node Activity _ roots for ClusterId: {:?} EraId: {:?} is: {:?}", + cluster_id, + era_activity.id, + hex::encode(nodes_activity_root) + ); + Self::store_validation_activities( cluster_id, era_activity.id, @@ -1230,7 +1309,13 @@ pub mod pallet { &nodes_activity_batch_roots, ); log::info!("🙇‍ Dac data processing completed for cluster_id: {:?}", cluster_id); - Ok(Some((era_activity, customers_activity_root, nodes_activity_root))) + Ok(Some(( + era_activity, + customers_activity_root, + nodes_activity_root, + customers_activity_batch_roots, + nodes_activity_batch_roots, + ))) } #[allow(dead_code)] @@ -1835,6 +1920,11 @@ pub mod pallet { ActivityHash, Vec, )> { + log::info!( + "🏠 Off-chain validation_activities cache hit for ClusterId: {:?} EraId: {:?}", + cluster_id, + era_id + ); let key = Self::derive_key(cluster_id, era_id); // Retrieve encoded tuple from local storage @@ -2358,11 +2448,15 @@ pub mod pallet { if let Ok(NodeParams::StorageParams(storage_params)) = T::NodeVisitor::get_node_params(&node_pub_key) { + let NodePubKey::StoragePubKey(key) = node_pub_key.clone(); + let node_pub_key_ref: &[u8; 32] = key.as_ref(); + let node_pub_key_string = hex::encode(node_pub_key_ref); log::info!( "🏭📝Get DAC Node for cluster_id: {:?} and node_pub_key: {:?}", cluster_id, - node_pub_key.encode() + node_pub_key_string ); + // Add to the results if the mode matches dac_nodes.push((node_pub_key, storage_params)); } @@ -2493,6 +2587,8 @@ pub mod pallet { era_activity: EraActivity, payers_merkle_root_hash: ActivityHash, payees_merkle_root_hash: ActivityHash, + payers_batch_merkle_root_hashes: Vec, + payees_batch_merkle_root_hashes: Vec, ) -> DispatchResult { let caller = ensure_signed(origin)?; @@ -2555,6 +2651,15 @@ pub mod pallet { // Update the EraValidations storage >::insert(cluster_id, era_activity.id, era_validation); + Self::deposit_event(Event::::EraValidationRootsPosted { + cluster_id, + era_id: era_activity.id, + validator: caller, + payers_merkle_root_hash, + payees_merkle_root_hash, + payers_batch_merkle_root_hashes, + payees_batch_merkle_root_hashes, + }); if should_deposit_ready_event { Self::deposit_event(Event::::EraValidationReady { cluster_id, diff --git a/pallets/ddc-verification/src/mock.rs b/pallets/ddc-verification/src/mock.rs index b290f3a29..5f6604f2f 100644 --- a/pallets/ddc-verification/src/mock.rs +++ b/pallets/ddc-verification/src/mock.rs @@ -231,6 +231,7 @@ impl crate::Config for Test { const MAX_PAYOUT_BATCH_COUNT: u16 = MAX_PAYOUT_BATCH_COUNT; type ActivityHash = H256; type StakingVisitor = Staking; + type AccountIdConverter = AccountId; } // Build genesis storage according to the mock runtime. diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 4b9bb4e13..07cdb12a2 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -221,7 +221,7 @@ pub struct ClusterNodesStats { /// Stores usage of customers #[derive( - PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone, Serialize, Deserialize, + PartialEq, Eq, Encode, Decode, Debug, TypeInfo, Default, Clone, Serialize, Deserialize, )] pub struct CustomerUsage { pub transferred_bytes: u64, @@ -232,7 +232,7 @@ pub struct CustomerUsage { /// Stores usage of node provider #[derive( - PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo, Default, Clone, Serialize, Deserialize, + PartialEq, Eq, Encode, Decode, Debug, TypeInfo, Default, Clone, Serialize, Deserialize, )] pub struct NodeUsage { pub transferred_bytes: u64, diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index c3724a421..25f13f340 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -79,7 +79,10 @@ pub use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdj use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; use sp_api::impl_runtime_apis; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; -use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256}; +use sp_core::{ + crypto::{AccountId32, KeyTypeId}, + OpaqueMetadata, H256, +}; use sp_inherents::{CheckInherentsResult, InherentData}; use sp_io::hashing::blake2_128; #[cfg(any(feature = "std", test))] @@ -146,7 +149,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 54111, + spec_version: 54112, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 19, @@ -1215,6 +1218,7 @@ impl pallet_ddc_payouts::Config for Runtime { type WeightInfo = pallet_ddc_payouts::weights::SubstrateWeight; type VoteScoreToU64 = IdentityConvert; // used for UseNominatorsAndValidatorsMap type ValidatorVisitor = pallet_ddc_verification::Pallet; + type AccountIdConverter = AccountId32; } parameter_types! { @@ -1308,6 +1312,7 @@ impl pallet_ddc_verification::Config for Runtime { const MAX_PAYOUT_BATCH_COUNT: u16 = MAX_PAYOUT_BATCH_COUNT; type ActivityHash = H256; type StakingVisitor = pallet_staking::Pallet; + type AccountIdConverter = AccountId32; } construct_runtime!( diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index 23b83fe54..8c2354551 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -73,7 +73,10 @@ pub use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdj use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; use sp_api::impl_runtime_apis; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; -use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256}; +use sp_core::{ + crypto::{AccountId32, KeyTypeId}, + OpaqueMetadata, H256, +}; use sp_inherents::{CheckInherentsResult, InherentData}; use sp_io::hashing::blake2_128; #[cfg(any(feature = "std", test))] @@ -1204,6 +1207,7 @@ impl pallet_ddc_payouts::Config for Runtime { type WeightInfo = pallet_ddc_payouts::weights::SubstrateWeight; type VoteScoreToU64 = IdentityConvert; type ValidatorVisitor = pallet_ddc_verification::Pallet; + type AccountIdConverter = AccountId32; } parameter_types! { @@ -1316,6 +1320,7 @@ impl pallet_ddc_verification::Config for Runtime { const MAX_PAYOUT_BATCH_COUNT: u16 = MAX_PAYOUT_BATCH_COUNT; type ActivityHash = H256; type StakingVisitor = pallet_staking::Pallet; + type AccountIdConverter = AccountId32; } construct_runtime!(