Skip to content

Commit

Permalink
fix: depositing extra amount is fixed (#333) (#334)
Browse files Browse the repository at this point in the history
<!-- Describe what change this PR is implementing -->
Companion for [Hotfix
#333](#333)


<!--- Check the following box with an x if the following applies: -->
- [x] Hotfix
- [ ] Release
- [ ] Fix or Feature

<!--- Check the following box with an x if the following applies: -->

<!--- What types of changes does your code introduce? -->
- [ ] 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)

<!--- Check the following box with an x if the following applies: -->
- [ ] This change requires a runtime migration.
- [ ] Modifies `on_initialize`
- [ ] Modifies `on_finalize`

<!--- All boxes need to be checked. Follow this checklist before
requiring PR review -->
- [x] Change has been tested locally.
- [x] Change adds / updates tests if applicable.
- [x] Changelog doc updated.

<!--- All boxes need to be checked. Follow this checklist before
requiring PR review -->
- [ ] 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.
- [x] Pull Request to `dev` has been created.
- [ ] Pull Request to `staging` has been created.

<!--- All boxes need to be checked. Follow this checklist before
requiring PR review -->
- [ ] 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.
  • Loading branch information
yahortsaryk authored May 11, 2024
1 parent b1afc1d commit ae76090
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions pallets/ddc-customers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,12 @@ pub mod pallet {
fn update_ledger_and_deposit(
owner: &T::AccountId,
ledger: &AccountsLedger<T>,
amount: BalanceOf<T>,
) -> DispatchResult {
<T as pallet::Config>::Currency::transfer(
owner,
&Self::account_id(),
ledger.total,
amount,
ExistenceRequirement::AllowDeath,
)?;
<Ledger<T>>::insert(owner, ledger);
Expand Down Expand Up @@ -694,14 +695,14 @@ pub mod pallet {

let owner_balance = <T as pallet::Config>::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::<T>::TransferFailed)?;
Self::deposit_event(Event::<T>::Deposited { owner_id: owner, amount: value });

Expand All @@ -725,7 +726,7 @@ pub mod pallet {
Error::<T>::InsufficientDeposit
);

Self::update_ledger_and_deposit(&owner, &ledger)
Self::update_ledger_and_deposit(&owner, &ledger, extra)
.map_err(|_| Error::<T>::TransferFailed)?;
Self::deposit_event(Event::<T>::Deposited { owner_id: owner, amount: extra });

Expand Down
22 changes: 16 additions & 6 deletions pallets/ddc-customers/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn deposit_and_deposit_extra_works() {
Error::<Test>::TransferFailed
);

let amount1 = 10_u128;
let amount1 = 90_u128;
// Deposited
assert_ok!(DdcCustomers::deposit(RuntimeOrigin::signed(account_1), amount1));

Expand Down Expand Up @@ -140,23 +140,33 @@ fn deposit_and_deposit_extra_works() {
Error::<Test>::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::<Test>::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(),
);
})
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/cere-dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion runtime/cere/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ae76090

Please sign in to comment.