def test_parse_config_file_content(self):
        config_file = """
            [node]
            coin = http://bla:[email protected]:20000
            waves = http://342.234.234.253:6869

            [fee]
            coin = 0.02000000
            gateway = 0.01000000

            [gateway_address]
            owner = akgsjfhsjkghweg
            waves_public_key = hjskgfj234786hfjk
            waves_private_key = 698473256icz7zftj
            coin_public_key = cgi34zvci7

            [mongodb]
            host = localhost
            port = 27017
            database = ltc-gateway

            [other]
            environment = test
            waves_chain = testnet
        """

        parsed = self._parser.parse_config_file_content(config_file)

        # --- [node] ---
        self.assertEqual(parsed.coin_node,
                         "http://*****:*****@345.234.23.234:20000")
        self.assertEqual(parsed.waves_node, "http://342.234.234.253:6869")

        # --- [fee] ---
        self.assertEqual(parsed.coin_fee, Decimal("0.02"))
        self.assertEqual(parsed.gateway_fee, Decimal("0.01"))

        # --- [gateway_address] ---
        self.assertEqual(parsed.gateway_owner_address, "akgsjfhsjkghweg")
        self.assertEqual(
            parsed.gateway_waves_address_secret,
            KeyPair(public="hjskgfj234786hfjk", secret="698473256icz7zftj"))
        self.assertEqual(parsed.gateway_coin_address_secret,
                         KeyPair(public="cgi34zvci7", secret=None))

        # --- [mongodb] ---
        self.assertEqual(parsed.mongo_host, "localhost")
        self.assertEqual(parsed.mongo_port, 27017)
        self.assertEqual(parsed.mongo_database, "ltc-gateway")

        # --- [other] ---
        self.assertEqual(parsed.environment, "test")
        self.assertEqual(parsed.waves_chain, "testnet")
 def test_serialize(self):
     secret = KeyPair('public', 'secret')
     serialized = self._serializer.as_dict(secret)
     self.assertIsInstance(serialized, dict)
     unserialized = self._serializer.from_dict(serialized)
     self.assertIsInstance(unserialized, KeyPair)
     self.assertEqual(secret, unserialized)
    def setUp(self):
        self._coin_standard_fee = 7269
        self._gateway_waves_receiver = TransactionReceiver("9823748", 923235)
        self._gateway_waves_address_secret = KeyPair(public="9238746",
                                                     secret="9236478")
        self._coin_transaction_service = MagicMock()
        self._waves_chain_query_service = MagicMock(
            spec=WavesChainQueryServiceImpl)
        self._waves_transaction_storage = MagicMock()
        self._logger = MagicMock()
        self._gateway_coin_address_secret = KeyPair(public="9374682o",
                                                    secret="sdkjrlig")
        self._coin_transaction_storage = MagicMock()
        self._gateway_owner_coin_holder = "23u4oi362"
        self._gateway_fee = 0
        self._gateway_owner_address = "923768"
        self._fee_service = MagicMock()
        self._only_one_transaction_receiver = True
        self._attempt_service = MagicMock()
        self._gateway_pywaves_address = MagicMock()
        self._gateway_pywaves_address.address = self._gateway_waves_receiver.address
        self._attempt_list_storage = MagicMock()
        self._coin_address_validation_service = MagicMock()

        self._waves_transaction_consumer_impl = WavesTransactionConsumerImpl(
            gateway_waves_address_secret=self._gateway_waves_address_secret,
            waves_chain_query_service=cast(WavesChainQueryServiceImpl,
                                           self._waves_chain_query_service),
            logger=cast(Logger, self._logger),
            gateway_owner_address=self._gateway_owner_address,
            gateway_coin_address_secret=self._gateway_coin_address_secret,
            fee_service=cast(FeeService, self._fee_service),
            only_one_transaction_receiver=cast(
                bool, self._only_one_transaction_receiver),
            attempt_service=cast(TransactionAttemptListService,
                                 self._attempt_service),
            gateway_pywaves_address=cast(pywaves.Address,
                                         self._gateway_pywaves_address),
            attempt_list_storage=cast(TransactionAttemptListStorage,
                                      self._attempt_list_storage),
            coin_address_validation_service=cast(
                AddressValidationService,
                self._coin_address_validation_service))

        self._fee_service.get_coin_fee.return_value = self._coin_standard_fee
        self._fee_service.get_gateway_fee.return_value = self._gateway_fee
Ejemplo n.º 4
0
    def test_save_address_secret(self):
        mock_key_pair = KeyPair(public="7296357", secret="172o7358")
        mock_serialized_key_pair = MagicMock()

        self._key_pair_serializer.as_dict.return_value = mock_serialized_key_pair

        self._wallet_storage.save_address_secret(mock_key_pair)

        self._collection.insert_one.assert_called_once_with(mock_serialized_key_pair)
    def test_get_secret_by_address_other(self):
        address = '802389724'
        secret = '8023984'
        pair = KeyPair(address, secret)

        self._wallet_storage.get_secret_by_public_address.return_value = pair

        res = self._secret_service.get_secret_by_address('coin', address)

        self.assertEqual(res, secret)
        self._wallet_storage.get_secret_by_public_address.assert_called_once_with(address)
    def setUp(self):
        self._wallet_storage = MagicMock()
        self._coin_gateway_address_secret = KeyPair('937846', '79632748')
        self._gateway_pywaves_address = MagicMock()
        self._gateway_pywaves_address.address = '9786296758'
        self._gateway_pywaves_address.privateKey = '92758'

        self._secret_service = SecretService(
            wallet_storage=cast(WalletStorage, self._wallet_storage),
            gateway_coin_address_secret=cast(KeyPair, self._coin_gateway_address_secret),
            gateway_pywaves_address=cast(pywaves.Address, self._gateway_pywaves_address))
    def test_safely_save_address_secret_success(self):
        key_pair = KeyPair(public='pub', secret='sec')

        with patch.multiple(self._wallet_storage,
                            public_address_exists=MagicMock(),
                            save_address_secret=MagicMock()):
            self._wallet_storage.public_address_exists.return_value = False

            self._wallet_storage.safely_save_address_secret(key_pair)

            self._wallet_storage.public_address_exists.assert_called_once_with(
                key_pair.public)
            self._wallet_storage.save_address_secret.assert_called_once_with(
                key_pair)
    def test_safely_save_address_secret_raises(self):
        key_pair = KeyPair(public='pub', secret='sec')

        with patch.multiple(self._wallet_storage,
                            public_address_exists=MagicMock(),
                            save_address_secret=MagicMock()):
            self._wallet_storage.public_address_exists.return_value = True

            with self.assertRaises(DuplicateSecretError):
                self._wallet_storage.safely_save_address_secret(key_pair)

            self._wallet_storage.public_address_exists.assert_called_once_with(
                key_pair.public)
            self._wallet_storage.save_address_secret.assert_not_called()
Ejemplo n.º 9
0
    def from_dict(self, data: dict) -> KeyPair:
        """
        Tries to reconstruct a KeyPair from the given dictionary.
        This may fail if the dictionary does not define the necessary properties.
        In this case a ParseError is thrown.
        """

        if KeyPair.DICT_PUBLIC_KEY not in data:
            raise ParseError("required key '" + KeyPair.DICT_PUBLIC_KEY +
                             "' is missing")

        if KeyPair.DICT_SECRET_KEY not in data:
            raise ParseError("required key '" + KeyPair.DICT_SECRET_KEY +
                             "' is missing")

        return KeyPair(public=data[KeyPair.DICT_PUBLIC_KEY],
                       secret=data[KeyPair.DICT_SECRET_KEY])
Ejemplo n.º 10
0
    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)