Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Roznovjak committed Jul 21, 2023
1 parent 1ae60c4 commit 88291ab
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
14 changes: 10 additions & 4 deletions pallets/bonds/src/tests/issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn issue_bonds_should_work_when_fee_is_zero() {

assert_eq!(Tokens::free_balance(HDX, &<Test as Config>::FeeReceiver::get()), 0);

assert_eq!(Tokens::free_balance(HDX, &Bonds::account_id()), amount);
assert_eq!(Tokens::free_balance(HDX, &Bonds::pallet_account_id()), amount);
});
}

Expand Down Expand Up @@ -137,7 +137,10 @@ fn issue_bonds_should_work_when_fee_is_non_zero() {

assert_eq!(Tokens::free_balance(HDX, &<Test as Config>::FeeReceiver::get()), fee);

assert_eq!(Tokens::free_balance(HDX, &Bonds::account_id()), amount_without_fee);
assert_eq!(
Tokens::free_balance(HDX, &Bonds::pallet_account_id()),
amount_without_fee
);
});
}

Expand Down Expand Up @@ -290,10 +293,13 @@ fn issue_bonds_should_work_when_issuing_multiple_bonds() {
assert_eq!(Tokens::free_balance(DAI, &<Test as Config>::FeeReceiver::get()), fee);

assert_eq!(
Tokens::free_balance(HDX, &Bonds::account_id()),
Tokens::free_balance(HDX, &Bonds::pallet_account_id()),
amount_without_fee.checked_mul(2).unwrap()
);
assert_eq!(Tokens::free_balance(DAI, &Bonds::account_id()), amount_without_fee);
assert_eq!(
Tokens::free_balance(DAI, &Bonds::pallet_account_id()),
amount_without_fee
);
});
}

Expand Down
19 changes: 11 additions & 8 deletions pallets/bonds/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@
use crate as pallet_bonds;
use crate::*;

use frame_support::traits::{ConstU128, Everything, GenesisBuild};
use frame_support::{construct_runtime, parameter_types, traits::ConstU32};
use frame_support::{
construct_runtime, parameter_types,
sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
},
traits::{ConstU128, ConstU32, Everything, GenesisBuild},
};
use frame_system::{EnsureRoot, EnsureSigned};
use hydradx_traits::{BondRegistry, Registry};
use orml_traits::parameter_type_with_key;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
use std::{cell::RefCell, collections::HashMap};

use hydradx_traits::{BondRegistry, Registry};
use orml_traits::parameter_type_with_key;

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
pub type AssetDetailsT = AssetDetails<AssetId, Balance, BoundedVec<u8, ConstU32<32>>>;
Expand Down
13 changes: 8 additions & 5 deletions pallets/bonds/src/tests/redeem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ fn partially_redeem_bonds_should_work_when_with_zero_fee() {

assert_eq!(Tokens::free_balance(HDX, &<Test as Config>::FeeReceiver::get()), 0);

assert_eq!(Tokens::free_balance(HDX, &Bonds::account_id()), amount - redeem_amount);
assert_eq!(
Tokens::free_balance(HDX, &Bonds::pallet_account_id()),
amount - redeem_amount
);
});
}

Expand Down Expand Up @@ -117,7 +120,7 @@ fn partially_redeem_bonds_should_work_when_with_non_zero_fee() {
assert_eq!(Tokens::free_balance(HDX, &<Test as Config>::FeeReceiver::get()), fee);

assert_eq!(
Tokens::free_balance(HDX, &Bonds::account_id()),
Tokens::free_balance(HDX, &Bonds::pallet_account_id()),
amount_without_fee - redeem_amount
);
});
Expand Down Expand Up @@ -154,7 +157,7 @@ fn fully_redeem_bonds_should_work_when_with_zero_fee() {

assert_eq!(Tokens::free_balance(HDX, &<Test as Config>::FeeReceiver::get()), 0);

assert_eq!(Tokens::free_balance(HDX, &Bonds::account_id()), 0);
assert_eq!(Tokens::free_balance(HDX, &Bonds::pallet_account_id()), 0);
});
}

Expand Down Expand Up @@ -194,7 +197,7 @@ fn fully_redeem_bonds_should_work_when_with_non_zero_fee() {

assert_eq!(Tokens::free_balance(HDX, &<Test as Config>::FeeReceiver::get()), fee);

assert_eq!(Tokens::free_balance(HDX, &Bonds::account_id()), 0);
assert_eq!(Tokens::free_balance(HDX, &Bonds::pallet_account_id()), 0);
});
}

Expand Down Expand Up @@ -235,7 +238,7 @@ fn redeem_bonds_should_work_when_redeemed_from_non_issuer_account() {
assert_eq!(Tokens::free_balance(HDX, &<Test as Config>::FeeReceiver::get()), 0);

assert_eq!(
Tokens::free_balance(HDX, &Bonds::account_id()),
Tokens::free_balance(HDX, &Bonds::pallet_account_id()),
amount.checked_sub(redeem_amount).unwrap()
);
});
Expand Down

0 comments on commit 88291ab

Please sign in to comment.