Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: depositing extra amount is fixed (#333) #334

Merged
merged 2 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 14 additions & 14 deletions 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 Expand Up @@ -309,20 +309,20 @@ impl InstanceFilter<RuntimeCall> 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(..)),
}
Expand Down Expand Up @@ -662,8 +662,8 @@ impl Get<Option<BalancingConfig>> for OffchainRandomBalancing {
max => {
let seed = sp_io::offchain::random_seed();
let random = <u32>::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
},
};
Expand Down
28 changes: 14 additions & 14 deletions 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 Expand Up @@ -303,20 +303,20 @@ impl InstanceFilter<RuntimeCall> 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(..)),
}
Expand Down Expand Up @@ -659,8 +659,8 @@ impl Get<Option<BalancingConfig>> for OffchainRandomBalancing {
max => {
let seed = sp_io::offchain::random_seed();
let random = <u32>::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
},
};
Expand Down
Loading