Skip to content

Commit

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

## Types of Changes
Please select the branch type you are merging and fill in the relevant
template.
<!--- Check the following box with an x if the following applies: -->
- [x] Hotfix
- [ ] Release
- [ ] Fix or Feature

## Fix or Feature
<!--- Check the following box with an x if the following applies: -->

### Types of Changes
<!--- 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)

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

### Checklist for Fix or Feature
<!--- 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.

## Checklist for Hotfix
<!--- 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.
- [ ] Pull Request to `dev` has been created.
- [ ] Pull Request to `staging` has been created.

## Checklist for Release
<!--- 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 10, 2024
1 parent 51e8f8a commit f25a6f6
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 37 deletions.
10 changes: 2 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@ 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.2.2]

### Added

- ...

### Changed

- ...
- [C,D] Depositing extra amount in ddc-customers pallet is fixed

## [5.2.1]

Expand Down
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "5.2.1"
version = "5.2.2"
authors = ["Cerebellum-Network"]
edition = "2021"
homepage = "https://cere.network/"
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 @@ -557,11 +557,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 @@ -693,14 +694,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 @@ -724,7 +725,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 @@ -111,7 +111,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 @@ -141,23 +141,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 @@ -133,7 +133,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: 52100,
spec_version: 52200,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 15,
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 @@ -128,7 +128,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: 52100,
spec_version: 52200,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 15,
Expand Down

0 comments on commit f25a6f6

Please sign in to comment.