Skip to content
Merged
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
Prev Previous commit
Fix TestGasPriceCalculator
  • Loading branch information
Ivan Loboda committed Feb 9, 2022
commit 7e1d9909391bdee3fd25ad57b74353a6068a1070
20 changes: 10 additions & 10 deletions proxy/testing/test_gas_price_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def test_success_update_price(self, mock_get_price, mock_get_current_time):
mock_get_price.side_effect = [{'status': 1, 'price': sol_price}]

gas_price = self.testee.get_min_gas_price()
expected_price = (sol_price / NEON_PRICE_USD) * (1 + OPERATOR_FEE)
expected_price = (sol_price / NEON_PRICE_USD) * (1 + OPERATOR_FEE) * pow(Decimal(10), 9)
self.assertEqual(gas_price, expected_price)

mock_get_current_time.assert_called_once()
mock_get_price.assert_called_once()
mock_get_price.assert_called_once_with('Crypto.SOL/USD')


@patch.object(GasPriceCalculator, 'get_current_time')
Expand All @@ -53,11 +53,11 @@ def test_success_update_price_after_retry_due_to_wrong_price_status(self, mock_g
]

gas_price = self.testee.get_min_gas_price()
expected_price = (sol_price / NEON_PRICE_USD) * (1 + OPERATOR_FEE)
expected_price = (sol_price / NEON_PRICE_USD) * (1 + OPERATOR_FEE) * pow(Decimal(10), 9)
self.assertEqual(gas_price, expected_price)

mock_get_current_time.assert_called_once()
mock_get_price.assert_has_calls([call()] * 2)
mock_get_price.assert_has_calls([call('Crypto.SOL/USD')] * 2)


@patch.object(GasPriceCalculator, 'get_current_time')
Expand All @@ -76,11 +76,11 @@ def test_success_update_price_after_retry_due_to_get_price_exception(self, mock_
]

gas_price = self.testee.get_min_gas_price()
expected_price = (sol_price / NEON_PRICE_USD) * (1 + OPERATOR_FEE)
expected_price = (sol_price / NEON_PRICE_USD) * (1 + OPERATOR_FEE) * pow(Decimal(10), 9)
self.assertEqual(gas_price, expected_price)

mock_get_current_time.assert_called_once()
mock_get_price.assert_has_calls([call()] * 2)
mock_get_price.assert_has_calls([call('Crypto.SOL/USD')] * 2)


@patch.object(GasPriceCalculator, 'get_current_time')
Expand All @@ -99,7 +99,7 @@ def test_failed_update_retries_exhausted(self, mock_get_price, mock_get_current_
self.testee.get_min_gas_price()

mock_get_current_time.assert_called_once()
mock_get_price.assert_has_calls([call()] * GET_SOL_PRICE_MAX_RETRIES)
mock_get_price.assert_has_calls([call('Crypto.SOL/USD')] * GET_SOL_PRICE_MAX_RETRIES)


@patch.object(GasPriceCalculator, 'get_current_time')
Expand All @@ -123,15 +123,15 @@ def test_success_get_price_time_intervals(self, mock_get_price, mock_get_current
{'status': 1, 'price': sol_price2}]

gas_price1 = self.testee.get_min_gas_price()
expected_price1 = (sol_price1 / NEON_PRICE_USD) * (1 + OPERATOR_FEE)
expected_price1 = (sol_price1 / NEON_PRICE_USD) * (1 + OPERATOR_FEE) * pow(Decimal(10), 9)
self.assertEqual(gas_price1, expected_price1)

gas_price2 = self.testee.get_min_gas_price()
self.assertEqual(gas_price2, expected_price1)

gas_price3 = self.testee.get_min_gas_price()
expected_price2 = (sol_price2 / NEON_PRICE_USD) * (1 + OPERATOR_FEE)
expected_price2 = (sol_price2 / NEON_PRICE_USD) * (1 + OPERATOR_FEE) * pow(Decimal(10), 9)
self.assertEqual(gas_price3, expected_price2)

mock_get_current_time.assert_has_calls([call()] * 3)
mock_get_price.assert_has_calls([call()] * 2)
mock_get_price.assert_has_calls([call('Crypto.SOL/USD')] * 2)