Added back calc buy/sell tests
@@ -3,6 +3,7 @@ pub use crate::mock::{
calculate_sale_price, Currency, ExtBuilder, Origin, System, Test, TestEvent, ACA, ALICE, AMM, BOB, DOT, HDX,
};
use frame_support::{assert_noop, assert_ok};
+use hydra_dx_math;
use primitives::traits::AMM as AMMPool;
pub fn new_test_ext() -> sp_io::TestExternalities {
@@ -1093,3 +1094,47 @@ fn single_sell_more_than_ratio_in_should_not_work() {
);
});
}
+
+#[test]
+fn test_calculate_sell_price() {
+ ExtBuilder::default().build().execute_with(|| {
+ let sell_reserve: Balance = 10000000000000;
+ let buy_reserve: Balance = 100000;
+ let sell_amount: Balance = 100000000000;
+ let result = hydra_dx_math::calculate_sell_price(sell_reserve, buy_reserve, sell_amount);
+ assert_eq!(result, Some(991));
+ });
+}
+
+#[test]
+fn test_calculate_sell_price_invalid() {
+ ExtBuilder::default().build().execute_with(|| {
+ let sell_reserve: Balance = 0;
+ let buy_reserve: Balance = 1000;
+ let sell_amount: Balance = 0;
+ let result = hydra_dx_math::calculate_sell_price(sell_reserve, buy_reserve, sell_amount);
+ assert_eq!(result, None);
+ });
+}
+
+#[test]
+fn test_calculate_buy_price_insufficient_pool_balance() {
+ ExtBuilder::default().build().execute_with(|| {
+ let sell_reserve: Balance = 10000000000000;
+ let buy_reserve: Balance = 100000;
+ let buy_amount: Balance = 100000000000;
+ let result = hydra_dx_math::calculate_buy_price(sell_reserve, buy_reserve, buy_amount);
+ assert_eq!(result, None);
+ });
+}
+
+#[test]
+fn test_calculate_buy_price() {
+ ExtBuilder::default().build().execute_with(|| {
+ let sell_reserve: Balance = 10000000000000;
+ let buy_reserve: Balance = 10000000;
+ let buy_amount: Balance = 1000000;
+ let result = hydra_dx_math::calculate_buy_price(sell_reserve, buy_reserve, buy_amount);
+ assert_eq!(result, Some(1111111111112));
+ });
+}
