Exemple #1
0
    def test_is_tx_settled_ethereum(self):
        """Test if the transaction is settled for eth."""
        ledger_apis = LedgerApis(
            {ETHEREUM: DEFAULT_ETHEREUM_CONFIG, FETCHAI: DEFAULT_FETCHAI_CONFIG},
            FETCHAI,
        )
        tx_digest = "97fcacaaf94b62318c4e4bbf53fd2608c15062f17a6d1bffee0ba7af9b710e35"
        result = HexBytes(
            "0xf85f808082c35094d898d5e829717c72e7438bad593076686d7d164a80801ba005c2e99ecee98a12fbf28ab9577423f42e9e88f2291b3acc8228de743884c874a077d6bc77a47ad41ec85c96aac2ad27f05a039c4787fca8a1e5ee2d8c7ec1bb6a"
        )
        with mock.patch.object(
            ledger_apis.apis[ETHEREUM].api.eth,
            "getTransactionReceipt",
            return_value=result,
        ):
            is_successful = ledger_apis._is_tx_settled(ETHEREUM, tx_digest=tx_digest)
            assert is_successful
            assert ledger_apis.last_tx_statuses[ETHEREUM] == "OK"

        with mock.patch.object(
            ledger_apis.apis[ETHEREUM].api.eth,
            "getTransactionReceipt",
            side_effect=Exception,
        ):
            is_successful = ledger_apis._is_tx_settled(ETHEREUM, tx_digest=tx_digest)
            assert not is_successful
            assert ledger_apis.last_tx_statuses[ETHEREUM] == "ERROR"
Exemple #2
0
    def test_is_tx_settled_fetchai(self):
        """Test if the transaction is settled for fetchai."""
        ledger_apis = LedgerApis(
            {ETHEREUM: DEFAULT_ETHEREUM_CONFIG, FETCHAI: DEFAULT_FETCHAI_CONFIG},
            FETCHAI,
        )
        tx_digest = "97fcacaaf94b62318c4e4bbf53fd2608c15062f17a6d1bffee0ba7af9b710e35"
        with pytest.raises(AssertionError):
            ledger_apis._is_tx_settled("Unknown", tx_digest=tx_digest)

        tx_status = TxStatus(
            digest=tx_digest.encode(),
            status="Executed",
            exit_code=0,
            charge=2,
            charge_rate=1,
            fee=10,
        )
        with mock.patch.object(
            ledger_apis.apis[FETCHAI].api.tx, "status", return_value=tx_status
        ):
            is_successful = ledger_apis._is_tx_settled(FETCHAI, tx_digest=tx_digest)
            assert is_successful
            assert ledger_apis.last_tx_statuses[FETCHAI] == "OK"

        with mock.patch.object(
            ledger_apis.apis[FETCHAI].api.tx, "status", side_effect=Exception
        ):
            is_successful = ledger_apis._is_tx_settled(FETCHAI, tx_digest=tx_digest)
            assert not is_successful
            assert ledger_apis.last_tx_statuses[FETCHAI] == "ERROR"