From 605c92c479b59009cf0921bec3c530e64dfce101 Mon Sep 17 00:00:00 2001 From: Yahor Tsaryk Date: Fri, 10 May 2024 17:13:10 +0200 Subject: [PATCH] fix: depositing extra amount is fixed (#333) Please select the branch type you are merging and fill in the relevant template. - [x] Hotfix - [ ] Release - [ ] Fix or Feature - [ ] Tech Debt (Code improvements) - [x] 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) - [ ] This change requires a runtime migration. - [ ] Modifies `on_initialize` - [ ] Modifies `on_finalize` - [x] Change has been tested locally. - [x] Change adds / updates tests if applicable. - [x] Changelog doc updated. - [ ] Change has been deployed to Testnet. - [ ] Change has been tested in Testnet. - [x] Changelog has been updated. - [x] Crate version has been updated. - [x] Spec version has been updated. - [ ] Transaction version has been updated if required. - [ ] Pull Request to `dev` has been created. - [ ] Pull Request to `staging` has been created. - [ ] 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. --- CHANGELOG.md | 11 ++++++++++- pallets/ddc-customers/src/lib.rs | 9 +++++---- pallets/ddc-customers/src/tests.rs | 22 ++++++++++++++++------ runtime/cere-dev/src/lib.rs | 28 ++++++++++++++-------------- runtime/cere/src/lib.rs | 28 ++++++++++++++-------------- 5 files changed, 59 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82b09606c..0e6bee847 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [C] Changes is `Cere` Runtime - [D] Changes is `Cere Dev` Runtime -## [VNext] ## [5.3.0] @@ -19,6 +18,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [C,D] Introduction of the OpenGov - [C,D] `pallet-ddc-clusters`: Added Erasure coding and Replication in cluster params +## [5.2.2] + +- [C,D] Depositing extra amount in ddc-customers pallet is fixed + +## [5.2.1] + +### Changed + +- [C,D] Fix inflation parameters for the staking reward curve + ## [5.2.0] ### Added diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 7e8876693..41b15a364 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -558,11 +558,12 @@ pub mod pallet { fn update_ledger_and_deposit( owner: &T::AccountId, ledger: &AccountsLedger, + amount: BalanceOf, ) -> DispatchResult { ::Currency::transfer( owner, &Self::account_id(), - ledger.total, + amount, ExistenceRequirement::AllowDeath, )?; >::insert(owner, ledger); @@ -694,14 +695,14 @@ pub mod pallet { let owner_balance = ::Currency::free_balance(&owner); let value = value.min(owner_balance); - let item = AccountsLedger { + let ledger = AccountsLedger { owner: owner.clone(), total: value, active: value, unlocking: Default::default(), }; - Self::update_ledger_and_deposit(&owner, &item) + Self::update_ledger_and_deposit(&owner, &ledger, value) .map_err(|_| Error::::TransferFailed)?; Self::deposit_event(Event::::Deposited { owner_id: owner, amount: value }); @@ -725,7 +726,7 @@ pub mod pallet { Error::::InsufficientDeposit ); - Self::update_ledger_and_deposit(&owner, &ledger) + Self::update_ledger_and_deposit(&owner, &ledger, extra) .map_err(|_| Error::::TransferFailed)?; Self::deposit_event(Event::::Deposited { owner_id: owner, amount: extra }); diff --git a/pallets/ddc-customers/src/tests.rs b/pallets/ddc-customers/src/tests.rs index 890796198..86d1e0bf9 100644 --- a/pallets/ddc-customers/src/tests.rs +++ b/pallets/ddc-customers/src/tests.rs @@ -110,7 +110,7 @@ fn deposit_and_deposit_extra_works() { Error::::TransferFailed ); - let amount1 = 10_u128; + let amount1 = 90_u128; // Deposited assert_ok!(DdcCustomers::deposit(RuntimeOrigin::signed(account_1), amount1)); @@ -140,23 +140,33 @@ fn deposit_and_deposit_extra_works() { Error::::NotOwner ); + // Deposit of an extra amount that is more than the customer's total balance fails + let extra_amount1 = 20_u128; + assert_noop!( + DdcCustomers::deposit_extra(RuntimeOrigin::signed(account_1), extra_amount1), + Error::::TransferFailed + ); + + let extra_amount2 = 5_u128; + // Deposited extra - let amount2 = 20_u128; - assert_ok!(DdcCustomers::deposit_extra(RuntimeOrigin::signed(account_1), amount2)); + assert_ok!(DdcCustomers::deposit_extra(RuntimeOrigin::signed(account_1), extra_amount2)); // Check storage assert_eq!( DdcCustomers::ledger(account_1), Some(AccountsLedger { owner: account_1, - total: amount1 + amount2, - active: amount1 + amount2, + total: amount1 + extra_amount2, + active: amount1 + extra_amount2, unlocking: Default::default(), }) ); // Checking that event was emitted - System::assert_last_event(Event::Deposited { owner_id: account_1, amount: amount2 }.into()); + System::assert_last_event( + Event::Deposited { owner_id: account_1, amount: extra_amount2 }.into(), + ); }) } diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 5ea327e61..980b1792f 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -140,7 +140,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: 53002, + spec_version: 53003, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 17, @@ -309,20 +309,20 @@ impl InstanceFilter for ProxyType { ProxyType::Any => true, ProxyType::NonTransfer => !matches!( c, - RuntimeCall::Balances(..) | - RuntimeCall::Vesting(pallet_vesting::Call::vested_transfer { .. }) | - RuntimeCall::Indices(pallet_indices::Call::transfer { .. }) | - RuntimeCall::NominationPools(..) | - RuntimeCall::ConvictionVoting(..) | - RuntimeCall::Referenda(..) | - RuntimeCall::Whitelist(..) + RuntimeCall::Balances(..) + | RuntimeCall::Vesting(pallet_vesting::Call::vested_transfer { .. }) + | RuntimeCall::Indices(pallet_indices::Call::transfer { .. }) + | RuntimeCall::NominationPools(..) + | RuntimeCall::ConvictionVoting(..) + | RuntimeCall::Referenda(..) + | RuntimeCall::Whitelist(..) ), ProxyType::Governance => matches!( c, - RuntimeCall::Treasury(..) | - RuntimeCall::ConvictionVoting(..) | - RuntimeCall::Referenda(..) | - RuntimeCall::Whitelist(..) + RuntimeCall::Treasury(..) + | RuntimeCall::ConvictionVoting(..) + | RuntimeCall::Referenda(..) + | RuntimeCall::Whitelist(..) ), ProxyType::Staking => matches!(c, RuntimeCall::Staking(..)), } @@ -662,8 +662,8 @@ impl Get> for OffchainRandomBalancing { max => { let seed = sp_io::offchain::random_seed(); let random = ::decode(&mut TrailingZeroInput::new(&seed)) - .expect("input is padded with zeroes; qed") % - max.saturating_add(1); + .expect("input is padded with zeroes; qed") + % max.saturating_add(1); random as usize }, }; diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index 07fc82db9..eec2d13a4 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -134,7 +134,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: 53002, + spec_version: 53003, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 17, @@ -303,20 +303,20 @@ impl InstanceFilter for ProxyType { ProxyType::Any => true, ProxyType::NonTransfer => !matches!( c, - RuntimeCall::Balances(..) | - RuntimeCall::Vesting(pallet_vesting::Call::vested_transfer { .. }) | - RuntimeCall::Indices(pallet_indices::Call::transfer { .. }) | - RuntimeCall::NominationPools(..) | - RuntimeCall::ConvictionVoting(..) | - RuntimeCall::Referenda(..) | - RuntimeCall::Whitelist(..) + RuntimeCall::Balances(..) + | RuntimeCall::Vesting(pallet_vesting::Call::vested_transfer { .. }) + | RuntimeCall::Indices(pallet_indices::Call::transfer { .. }) + | RuntimeCall::NominationPools(..) + | RuntimeCall::ConvictionVoting(..) + | RuntimeCall::Referenda(..) + | RuntimeCall::Whitelist(..) ), ProxyType::Governance => matches!( c, - RuntimeCall::Treasury(..) | - RuntimeCall::ConvictionVoting(..) | - RuntimeCall::Referenda(..) | - RuntimeCall::Whitelist(..) + RuntimeCall::Treasury(..) + | RuntimeCall::ConvictionVoting(..) + | RuntimeCall::Referenda(..) + | RuntimeCall::Whitelist(..) ), ProxyType::Staking => matches!(c, RuntimeCall::Staking(..)), } @@ -659,8 +659,8 @@ impl Get> for OffchainRandomBalancing { max => { let seed = sp_io::offchain::random_seed(); let random = ::decode(&mut TrailingZeroInput::new(&seed)) - .expect("input is padded with zeroes; qed") % - max.saturating_add(1); + .expect("input is padded with zeroes; qed") + % max.saturating_add(1); random as usize }, };