def test_serialize(self): entry = MappingEntry(coin_address='coin', waves_address='waves') serialized = self._serializer.as_dict(entry) self.assertIsInstance(serialized, dict) self.assertEqual(serialized[MappingEntry.DICT_COIN_KEY], 'coin') self.assertEqual(serialized[MappingEntry.DICT_WAVES_KEY], 'waves')
def test_save_mapping(self): mock_mapping = MappingEntry(coin_address="23535", waves_address="3425246") mock_serialized_mapping = MagicMock() self._serializer.as_dict.return_value = mock_serialized_mapping self._map_storage.save_mapping(mock_mapping) self._collection.insert_one.assert_called_once_with( mock_serialized_mapping)
def create_address(self, waves_address: str) -> str: """inherit""" self._logger.debug( "Client requested coin address for waves address '%s'", waves_address) if not self._waves_address_validation_service.validate_address( waves_address): raise WavesAddressInvalidError() if self._map_storage.waves_address_exists(waves_address): coin_address = self._map_storage.get_coin_address_by_waves_address( waves_address) self._logger.debug("Found associated coin_address '%s'", coin_address) return coin_address else: create_address_result = self._coin_address_factory.create_address() if isinstance(create_address_result, str): mapping = MappingEntry(waves_address, create_address_result) self._map_storage.safely_save_mapping(mapping) self._logger.info("Created new mapping '%s'", str(mapping)) return create_address_result elif isinstance(create_address_result, KeyPair): mapping = MappingEntry(waves_address, create_address_result.public) self._wallet_storage.safely_save_address_secret( create_address_result) self._map_storage.safely_save_mapping(mapping) self._logger.info("Created new mapping '%s'", str(mapping)) return create_address_result.public else: raise TypeError( 'Result of create_address is neither a CoinAddress nor a CoinAddressSecret' )
def test_create_address_not_exists_is_string(self): mock_waves_address = "72936587" mock_coin_address = "8120743689" expected_mapping = MappingEntry(coin_address=mock_coin_address, waves_address=mock_waves_address) self._waves_address_validation_service.validate_address.return_value = True self._map_storage.waves_address_exists.return_value = False self._coin_address_factory.create_address.return_value = mock_coin_address res = self._gateway_controller.create_address(mock_waves_address) self._map_storage.safely_save_mapping.assert_called_once_with( expected_mapping) self.assertEqual(res, mock_coin_address)
def test_safely_save_mapping_success(self): mapping = MappingEntry(coin_address='34435', waves_address='3432') with patch.multiple(self._map_storage, waves_address_exists=MagicMock(), coin_address_exists=MagicMock(), save_mapping=MagicMock()): self._map_storage.waves_address_exists.return_value = False self._map_storage.coin_address_exists.return_value = False self._map_storage.safely_save_mapping(mapping) self._map_storage.waves_address_exists.assert_called_once_with( mapping.waves_address) self._map_storage.coin_address_exists.assert_called_once_with( mapping.coin_address) self._map_storage.save_mapping.assert_called_once_with(mapping)
def test_safely_save_mapping_waves_address_exists(self): mapping = MappingEntry(coin_address='34435', waves_address='3432') with patch.multiple(self._map_storage, waves_address_exists=MagicMock(), coin_address_exists=MagicMock(), save_mapping=MagicMock()): self._map_storage.waves_address_exists.return_value = True self._map_storage.coin_address_exists.return_value = False with self.assertRaises(DuplicateMappingError): self._map_storage.safely_save_mapping(mapping) self._map_storage.waves_address_exists.assert_called_once_with( mapping.waves_address) self._map_storage.coin_address_exists.assert_not_called() self._map_storage.save_mapping.assert_not_called()
def test_create_address_not_exists_is_key_pair(self): mock_waves_address = "72936587" mock_coin_address = "8120743689" mock_coin_secret = "2736984" mock_key_pair = KeyPair(public=mock_coin_address, secret=mock_coin_secret) expected_mapping = MappingEntry(coin_address=mock_coin_address, waves_address=mock_waves_address) self._waves_address_validation_service.validate_address.return_value = True self._map_storage.waves_address_exists.return_value = False self._coin_address_factory.create_address.return_value = mock_key_pair res = self._gateway_controller.create_address(mock_waves_address) self._wallet_storage.safely_save_address_secret.assert_called_once_with( mock_key_pair) self._map_storage.safely_save_mapping.assert_called_once_with( expected_mapping) self.assertEqual(res, mock_coin_address)