def test_fet_token_balance(self): """Test the token_balance for the fet tokens.""" ledger_apis = LedgerApis({ETHEREUM: DEFAULT_ETHEREUM_CONFIG, FETCHAI: DEFAULT_FETCHAI_CONFIG}) api = ledger_apis.apis[FETCHAI] with mock.patch.object(api.tokens, 'balance', return_value=10): balance = ledger_apis.token_balance(FETCHAI, fet_address) assert balance == 10 assert ledger_apis.last_tx_statuses[FETCHAI] == 'OK' with mock.patch.object(api.tokens, 'balance', return_value=0, side_effect=Exception): balance = ledger_apis.token_balance(FETCHAI, eth_address) assert balance == 0, "This must be 0 since the address is wrong" assert ledger_apis.last_tx_statuses[FETCHAI] == 'ERROR'
def test_unknown_token_balance(self): """Test the token_balance for the unknown tokens.""" ledger_apis = LedgerApis({ETHEREUM: DEFAULT_ETHEREUM_CONFIG, FETCHAI: DEFAULT_FETCHAI_CONFIG}) with pytest.raises(AssertionError): balance = ledger_apis.token_balance("UNKNOWN", fet_address) assert balance == 0, "Unknown identifier so it will return 0"
def _try_get_balance(agent_config, wallet, type_): try: ledger_apis = LedgerApis(agent_config.ledger_apis_dict, agent_config.default_ledger) address = wallet.addresses[type_] return ledger_apis.token_balance(type_, address) except (AssertionError, ValueError) as e: # pragma: no cover logger.error(str(e)) sys.exit(1)
def test_eth_token_balance(self): """Test the token_balance for the eth tokens.""" ledger_apis = LedgerApis( {ETHEREUM: DEFAULT_ETHEREUM_CONFIG, FETCHAI: DEFAULT_FETCHAI_CONFIG}, FETCHAI, ) api = ledger_apis.apis[ETHEREUM] with mock.patch.object(api.api.eth, "getBalance", return_value=10): balance = ledger_apis.token_balance(ETHEREUM, eth_address) assert balance == 10 assert ledger_apis.last_tx_statuses[ETHEREUM] == "OK" with mock.patch.object( api.api.eth, "getBalance", return_value=0, side_effect=Exception ): balance = ledger_apis.token_balance(ETHEREUM, fet_address) assert balance == 0, "This must be 0 since the address is wrong" assert ledger_apis.last_tx_statuses[ETHEREUM] == "ERROR"
def _try_get_balance(agent_config, wallet, type_): try: if type_ not in agent_config.ledger_apis_dict: raise ValueError( "No ledger api config for {} provided in aea-config.yaml.". format(type_)) ledger_apis = LedgerApis(agent_config.ledger_apis_dict, agent_config.default_ledger) address = wallet.addresses[type_] return ledger_apis.token_balance(type_, address) except (AssertionError, ValueError) as e: # pragma: no cover raise click.ClickException(str(e))