Exemple #1
0
    def test_update_attempt_list(self):
        trigger = AttemptListTrigger(
            tx="792873", receiver=1, currency="waves", senders=[TransactionSender(address="723789")])

        attempt_list = TransactionAttemptList(
            trigger=trigger,
            attempts=[
                TransactionAttempt(
                    currency="coin",
                    fee=100,
                    receivers=[TransactionAttemptReceiver(address="973846", amount=234)],
                    sender="739264857")
            ])

        expected_query = dict()
        expected_query[TransactionAttemptList.DICT_ID] = attempt_list.attempt_list_id
        mock_find_one_result = MagicMock()
        mock_attempt_list_as_dict_result = MagicMock()

        self._collection.find_one_and_replace.return_value = mock_find_one_result
        self._serializer.attempt_list_as_dict.return_value = mock_attempt_list_as_dict_result

        self._storage.update_attempt_list(attempt_list)

        self._collection.find_one_and_replace.assert_called_once_with(expected_query, mock_attempt_list_as_dict_result)
        self._serializer.attempt_list_as_dict.assert_called_once_with(attempt_list)
Exemple #2
0
    def test_revert_attempt_list_conversion_waves(self):
        """Ensures that the fee is not converted when using the asset_integer_converter_service."""
        trigger = AttemptListTrigger(
            tx="792873",
            receiver=1,
            currency="coin",
            senders=[TransactionSender(address="723789")])

        attempt_list = TransactionAttemptList(
            trigger=trigger,
            attempts=[
                TransactionAttempt(
                    currency="waves",
                    fee=100,
                    receivers=[
                        TransactionAttemptReceiver(address="973846",
                                                   amount=234),
                        TransactionAttemptReceiver(address="9327468",
                                                   amount=235)
                    ],
                    sender="739264857")
            ])

        expected_attempt_list = TransactionAttemptList(
            trigger=trigger,
            attempts=[
                TransactionAttempt(
                    currency="waves",
                    fee=100,
                    receivers=[
                        TransactionAttemptReceiver(address="973846",
                                                   amount=0.234),
                        TransactionAttemptReceiver(address="9327468",
                                                   amount=0.235)
                    ],
                    sender="739264857")
            ])

        def mock_converter(value: Any):
            return value / 1000

        self._asset_integer_converter_service.revert_amount_conversion.side_effect = mock_converter

        res = self._attempt_list_converter.revert_attempt_list_conversion(
            attempt_list)

        self.assertEqual(res, expected_attempt_list)
    def setUp(self):
        self._attempt_list_serializer = TransactionAttemptListSerializer()

        trigger = AttemptListTrigger(
            tx="792873", receiver=1, currency="waves", senders=[TransactionSender(address="723789")])

        self._attempt_list = TransactionAttemptList(
            trigger=trigger,
            attempts=[
                TransactionAttempt(
                    currency="coin",
                    fee=100,
                    receivers=[
                        TransactionAttemptReceiver(address="973846", amount=234),
                        TransactionAttemptReceiver(address="9327468", amount=235)
                    ],
                    sender="739264857")
            ])
Exemple #4
0
    def test_continue_transaction_attempt_list(self, mock_datetime: MagicMock):
        now = MagicMock()
        mock_datetime.utcnow.return_value = now

        trigger = AttemptListTrigger(
            tx="792873", receiver=1, currency="waves", senders=[TransactionSender(address="723789")])

        attempt_list = TransactionAttemptList(
            trigger=trigger,
            attempts=[
                TransactionAttempt(
                    currency="coin",
                    fee=100,
                    receivers=[TransactionAttemptReceiver(address="973846", amount=234)],
                    sender="739264857")
            ],
            created_at=now,
            last_modified=now)

        expected_attempt_list = TransactionAttemptList(
            trigger=trigger,
            attempts=[
                TransactionAttempt(
                    currency="coin",
                    fee=100,
                    receivers=[TransactionAttemptReceiver(address="973846", amount=234)],
                    sender="739264857"),
            ],
            transactions=["97238"],
            created_at=now,
            last_modified=now)

        mock_transaction = Transaction(tx="97238", receivers=[TransactionReceiver(address="973846", amount=234)])

        mock_secret = "9723684"

        self._secret_service.get_secret_by_address.return_value = mock_secret
        self._transaction_service.send_coin.return_value = mock_transaction

        self._attempt_list_service.continue_transaction_attempt_list(attempt_list)

        self._storage.update_attempt_list.assert_called_once_with(expected_attempt_list)
        self._transaction_service.send_coin.assert_called_once_with(attempt_list.attempts[0], mock_secret)
        self._secret_service.get_secret_by_address("coin", "739264857")
Exemple #5
0
    def _convert_node_response_to_transaction(self, res: dict) -> Optional[Transaction]:
        if 'assetId' not in res or res['assetId'] != self._asset_id:
            return None

        if res['type'] != 4:
            return None

        try:
            address = res['recipient'].split(':')[1]
        except IndexError:
            address = res['recipient']
        try:
            sender = res['sender'].split(':')[1]
        except IndexError:
            sender = res['sender']

        return Transaction(
            tx=res['id'],
            receivers=[TransactionReceiver(address=address, amount=res['amount'])],
            senders=[TransactionSender(address=sender)])
 def _sender_from_dict(self, data: dict) -> TransactionSender:
     return TransactionSender(address=data[TransactionSender.DICT_ADDRESS_KEY])