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})
        tx_digest = "97fcacaaf94b62318c4e4bbf53fd2608c15062f17a6d1bffee0ba7af9b710e35"
        result = HexBytes(
            '0xf85f808082c35094d898d5e829717c72e7438bad593076686d7d164a80801ba005c2e99ecee98a12fbf28ab9577423f42e9e88f2291b3acc8228de743884c874a077d6bc77a47ad41ec85c96aac2ad27f05a039c4787fca8a1e5ee2d8c7ec1bb6a')
        with mock.patch.object(ledger_apis.apis[ETHEREUM].eth, "getTransactionReceipt", return_value=result):
            is_successful = ledger_apis.is_tx_settled(ETHEREUM, tx_digest=tx_digest, amount=10)
            assert is_successful
            assert ledger_apis.last_tx_statuses[ETHEREUM] == 'OK'

        with mock.patch.object(ledger_apis.apis[ETHEREUM].eth, "getTransactionReceipt", side_effect=Exception):
            is_successful = ledger_apis.is_tx_settled(ETHEREUM, tx_digest=tx_digest, amount=10)
            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})
        tx_digest = "97fcacaaf94b62318c4e4bbf53fd2608c15062f17a6d1bffee0ba7af9b710e35"
        with pytest.raises(AssertionError):
            ledger_apis.is_tx_settled("Unknown", tx_digest=tx_digest, amount=10)

        with mock.patch.object(ledger_apis.apis[FETCHAI].tx, "status", return_value='Submitted'):
            is_successful = ledger_apis.is_tx_settled(FETCHAI, tx_digest=tx_digest, amount=10)
            assert is_successful
            assert ledger_apis.last_tx_statuses[FETCHAI] == 'OK'

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