Skip to content

Commit

Permalink
fix pallet-investments tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NunoAlexandre committed Oct 25, 2023
1 parent c2daa47 commit 797dedf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
22 changes: 13 additions & 9 deletions pallets/investments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,21 +615,25 @@ where
Error::<T>::CollectRequired
);

Self::do_update_redeem_order(
total_order,
&who,
investment_id,
info,
order,
amount,
)?;

order.update_submitted_at(cur_order_id);

// Remove order from storage if empty
if amount == T::Amount::zero() {
*maybe_order = None;
}
else {
// nuno: check that this is ok. Amount == 0 removes the order, so there's
// no point in processing a transfer of 0 which fails because it would
// kill the account (< ED)
Self::do_update_redeem_order(
total_order,
&who,
investment_id,
info,
order,
amount,
)?;
}

Ok(cur_order_id)
},
Expand Down
18 changes: 9 additions & 9 deletions pallets/investments/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,15 @@ impl TestExternalitiesBuilder {
orml_tokens::GenesisConfig::<MockRuntime> {
balances: vec![
// Owner holds enough capital to satisfy redemptions
(Owner::get(), AUSD_CURRENCY_ID, OWNER_START_BALANCE),
(InvestorA::get(), AUSD_CURRENCY_ID, 100 * CURRENCY),
(InvestorB::get(), AUSD_CURRENCY_ID, 100 * CURRENCY),
(InvestorC::get(), AUSD_CURRENCY_ID, 100 * CURRENCY),
(InvestorD::get(), AUSD_CURRENCY_ID, 100 * CURRENCY),
(TrancheHolderA::get(), INVESTMENT_0_0.into(), 100 * CURRENCY),
(TrancheHolderB::get(), INVESTMENT_0_0.into(), 100 * CURRENCY),
(TrancheHolderC::get(), INVESTMENT_0_0.into(), 100 * CURRENCY),
(TrancheHolderD::get(), INVESTMENT_0_0.into(), 100 * CURRENCY),
(Owner::get(), AUSD_CURRENCY_ID, OWNER_START_BALANCE + ExistentialDeposit::get()),
(InvestorA::get(), AUSD_CURRENCY_ID, 100 * CURRENCY + ExistentialDeposit::get()),
(InvestorB::get(), AUSD_CURRENCY_ID, 100 * CURRENCY + ExistentialDeposit::get()),
(InvestorC::get(), AUSD_CURRENCY_ID, 100 * CURRENCY + ExistentialDeposit::get()),
(InvestorD::get(), AUSD_CURRENCY_ID, 100 * CURRENCY + ExistentialDeposit::get()),
(TrancheHolderA::get(), INVESTMENT_0_0.into(), 100 * CURRENCY + ExistentialDeposit::get()),
(TrancheHolderB::get(), INVESTMENT_0_0.into(), 100 * CURRENCY + ExistentialDeposit::get()),
(TrancheHolderC::get(), INVESTMENT_0_0.into(), 100 * CURRENCY + ExistentialDeposit::get()),
(TrancheHolderD::get(), INVESTMENT_0_0.into(), 100 * CURRENCY + ExistentialDeposit::get()),
],
}
.assimilate_storage(&mut storage)
Expand Down
27 changes: 16 additions & 11 deletions pallets/investments/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn update_invest_works() {
free_balance_of(investment_account(INVESTMENT_0_0), AUSD_CURRENCY_ID),
2 * amount
);
assert_eq!(free_balance_of(InvestorA::get(), AUSD_CURRENCY_ID), 0);
assert_eq!(free_balance_of(InvestorA::get(), AUSD_CURRENCY_ID), ExistentialDeposit::get());
assert_eq!(
last_event(),
Event::InvestOrderUpdated {
Expand Down Expand Up @@ -136,7 +136,7 @@ fn update_invest_works() {
);
assert_eq!(
free_balance_of(InvestorA::get(), AUSD_CURRENCY_ID),
amount + amount / 2
amount + amount / 2 + ExistentialDeposit::get()
);
assert_eq!(
last_event(),
Expand Down Expand Up @@ -164,7 +164,7 @@ fn update_invest_works() {
free_balance_of(investment_account(INVESTMENT_0_0), AUSD_CURRENCY_ID),
amount
);
assert_eq!(free_balance_of(InvestorA::get(), AUSD_CURRENCY_ID), amount);
assert_eq!(free_balance_of(InvestorA::get(), AUSD_CURRENCY_ID), amount + ExistentialDeposit::get());
assert_eq!(
last_event(),
Event::InvestOrderUpdated {
Expand Down Expand Up @@ -368,14 +368,17 @@ fn update_redeem_works() {
INVESTMENT_0_0,
2 * amount,
));

assert_eq!(
free_balance_of(investment_account(INVESTMENT_0_0), INVESTMENT_0_0.into()),
2 * amount
);

assert_eq!(
free_balance_of(TrancheHolderA::get(), INVESTMENT_0_0.into()),
0
ExistentialDeposit::get()
);

assert_eq!(
last_event(),
Event::RedeemOrderUpdated {
Expand Down Expand Up @@ -419,7 +422,7 @@ fn update_redeem_works() {
);
assert_eq!(
free_balance_of(TrancheHolderA::get(), INVESTMENT_0_0.into()),
amount + amount / 2
amount + amount / 2 + ExistentialDeposit::get()
);
assert_eq!(
last_event(),
Expand Down Expand Up @@ -449,7 +452,7 @@ fn update_redeem_works() {
);
assert_eq!(
free_balance_of(TrancheHolderA::get(), INVESTMENT_0_0.into()),
amount
amount + ExistentialDeposit::get()
);
assert_eq!(
last_event(),
Expand Down Expand Up @@ -523,6 +526,7 @@ fn update_redeem_to_zero_removes_order() {
Some(Order::new(2 * amount, 0))
);

// nuno: this fails with
assert_ok!(Investments::update_redeem_order(
RuntimeOrigin::signed(TrancheHolderA::get()),
INVESTMENT_0_0,
Expand Down Expand Up @@ -696,11 +700,11 @@ fn fulfillment_flow_for_everything_works() {
{
assert_eq!(
free_balance_of(Owner::get(), AUSD_CURRENCY_ID),
TOTAL_INVEST_AMOUNT + OWNER_START_BALANCE
TOTAL_INVEST_AMOUNT + OWNER_START_BALANCE + ExistentialDeposit::get()
);
assert_eq!(
free_balance_of(investment_account(INVESTMENT_0_0), AUSD_CURRENCY_ID),
0
0
);
assert_eq!(
free_balance_of(investment_account(INVESTMENT_0_0), INVESTMENT_0_0.into()),
Expand Down Expand Up @@ -783,10 +787,11 @@ fn fulfillment_flow_for_everything_works() {
{
assert_eq!(
free_balance_of(Owner::get(), AUSD_CURRENCY_ID),
TOTAL_INVEST_AMOUNT + OWNER_START_BALANCE
TOTAL_INVEST_AMOUNT + OWNER_START_BALANCE + ExistentialDeposit::get()
- PRICE
.checked_mul_int(TOTAL_REDEEM_AMOUNT)
.expect("Unwrapping test checked_mul_int must work")

);
assert_eq!(
free_balance_of(investment_account(INVESTMENT_0_0), AUSD_CURRENCY_ID),
Expand Down Expand Up @@ -921,7 +926,7 @@ fn fulfillment_partially_works_low_price() {
.checked_mul_int(PERC_REDEEM_FULFILL.mul_floor(TOTAL_REDEEM_AMOUNT))
.expect("Unwrapping checked_mul_int must work")
)
.expect("Unwrapping checked_sub must work")
.expect("Unwrapping checked_sub must work") + ExistentialDeposit::get()
);
assert_eq!(free_balance_of(Owner::get(), INVESTMENT_0_0.into()), 0);
}
Expand Down Expand Up @@ -1606,7 +1611,7 @@ fn fulfillment_partially_works_high_price() {
.checked_mul_int(PERC_REDEEM_FULFILL.mul_floor(TOTAL_REDEEM_AMOUNT))
.expect("Unwrapping checked_mul_int must work")
)
.expect("Unwrapping checked_sub must work")
.expect("Unwrapping checked_sub must work") + ExistentialDeposit::get()
);
assert_eq!(free_balance_of(Owner::get(), INVESTMENT_0_0.into()), 0);
}
Expand Down

0 comments on commit 797dedf

Please sign in to comment.