diff --git a/proxy/indexer/airdropper.py b/proxy/indexer/airdropper.py index 310f6fbdd..7f53f4a5b 100644 --- a/proxy/indexer/airdropper.py +++ b/proxy/indexer/airdropper.py @@ -110,7 +110,9 @@ def __init__(self, self._constants = SQLDict(tablename="constants") if start_slot == 'CONTINUE': self.info('Trying to use latest processed slot from previous run') - start_slot = self._constants.get('latest_processed_slot', 0) + start_slot = self._constants.get('latest_processed_slot', None) + if start_slot is None: + raise Exception('START_SLOT set to CONINUE but recent slot number not found in DB') elif start_slot == 'LATEST': self.info('Airdropper will start at latest blockchain slot') client = SolanaClient(solana_url) @@ -118,10 +120,9 @@ def __init__(self, else: try: start_slot = int(start_slot) - except Exception as err: - self.warning(f'''Unsupported value for start_slot: {start_slot}. - Must be either integer value or one of [CONTINUE,LATEST]''') - raise + except: + raise Exception(f'Failed to parse start_slot value: {start_slot}') + self.info(f'Start slot is {start_slot}') IndexerBase.__init__(self, solana_url, evm_loader_id, start_slot) @@ -362,13 +363,16 @@ def run_airdropper(solana_url, Price provider solana: {pp_solana_url}, Max confidence interval: {max_conf}""") - airdropper = Airdropper(solana_url, - evm_loader_id, - pyth_mapping_account, - faucet_url, - wrapper_whitelist, - neon_decimals, - start_slot, - pp_solana_url, - max_conf) - airdropper.run() + try: + airdropper = Airdropper(solana_url, + evm_loader_id, + pyth_mapping_account, + faucet_url, + wrapper_whitelist, + neon_decimals, + start_slot, + pp_solana_url, + max_conf) + airdropper.run() + except Exception as err: + logger.error(f'Failed to start Airdropper: {err}') diff --git a/proxy/testing/test_airdropper.py b/proxy/testing/test_airdropper.py index b0bd9cef0..999c6b31d 100644 --- a/proxy/testing/test_airdropper.py +++ b/proxy/testing/test_airdropper.py @@ -264,6 +264,24 @@ def test_init_airdropper_slot_continue(self, mock_get_slot, mock_dict_get): mock_dict_get.assert_called_once_with('latest_processed_slot', ANY) mock_get_slot.assert_not_called() + @patch.object(SQLDict, 'get') + @patch.object(SolanaClient, 'get_slot') + def test_init_airdropper_slot_continue_recent_slot_not_found(self, mock_get_slot, mock_dict_get): + mock_dict_get.side_effect = [None] + with self.assertRaises(Exception): + self.create_airdropper('CONTINUE') + mock_dict_get.assert_called_once_with('latest_processed_slot', ANY) + mock_get_slot.assert_not_called() + + + @patch.object(SQLDict, 'get') + @patch.object(SolanaClient, 'get_slot') + def test_init_airdropper_start_slot_parse_error(self, mock_get_slot, mock_dict_get): + with self.assertRaises(Exception): + self.create_airdropper('Wrong value') + mock_dict_get.assert_not_called() + mock_get_slot.assert_not_called() + @patch.object(SQLDict, 'get') @patch.object(SolanaClient, 'get_slot')