From 0261661229b5c73188b90b08fa9eb8b9891f53fd Mon Sep 17 00:00:00 2001 From: Alejandro-Morales Date: Tue, 3 Oct 2023 10:49:11 -0600 Subject: [PATCH] fis: revert fund_agent to original --- python/examples/06-send-tokens/main.py | 4 +-- .../08-local-network-interaction/agent1.py | 2 +- .../08-local-network-interaction/agent2.py | 2 +- .../09-booking-protocol-demo/restaurant.py | 2 +- .../examples/09-booking-protocol-demo/user.py | 2 +- python/examples/10-cleaning-demo/cleaner.py | 2 +- python/examples/10-cleaning-demo/user.py | 2 +- python/examples/11-mailbox-agents/alice.py | 2 +- python/examples/11-mailbox-agents/bob.py | 2 +- python/examples/12-remote-agents/agent1.py | 2 +- python/examples/12-remote-agents/agent2.py | 2 +- .../examples/13-agent-name-service/agent1.py | 4 +-- .../examples/13-agent-name-service/agent2.py | 2 +- python/examples/14-broadcast/main.py | 6 ++--- python/src/uagents/setup.py | 25 ++++++------------- python/tests/test_agent_registration.py | 4 +-- 16 files changed, 28 insertions(+), 37 deletions(-) diff --git a/python/examples/06-send-tokens/main.py b/python/examples/06-send-tokens/main.py index 3da95aaa..0ab63069 100644 --- a/python/examples/06-send-tokens/main.py +++ b/python/examples/06-send-tokens/main.py @@ -19,8 +19,8 @@ class TransactionInfo(Model): alice = Agent(name="alice", seed="alice secret phrase") bob = Agent(name="bob", seed="bob secret phrase") -fund_agent_if_low(alice) -fund_agent_if_low(bob) +fund_agent_if_low(alice.wallet.address()) +fund_agent_if_low(bob.wallet.address()) @alice.on_interval(period=10.0) diff --git a/python/examples/08-local-network-interaction/agent1.py b/python/examples/08-local-network-interaction/agent1.py index ed4e95f9..157cb34f 100644 --- a/python/examples/08-local-network-interaction/agent1.py +++ b/python/examples/08-local-network-interaction/agent1.py @@ -16,7 +16,7 @@ class Message(Model): endpoint=["http://127.0.0.1:8001/submit"], ) -fund_agent_if_low(bob) +fund_agent_if_low(bob.wallet.address()) @bob.on_message(model=Message) diff --git a/python/examples/08-local-network-interaction/agent2.py b/python/examples/08-local-network-interaction/agent2.py index c8f9d000..6b6b7a84 100644 --- a/python/examples/08-local-network-interaction/agent2.py +++ b/python/examples/08-local-network-interaction/agent2.py @@ -17,7 +17,7 @@ class Message(Model): endpoint=["http://127.0.0.1:8000/submit"], ) -fund_agent_if_low(alice) +fund_agent_if_low(alice.wallet.address()) @alice.on_interval(period=2.0) diff --git a/python/examples/09-booking-protocol-demo/restaurant.py b/python/examples/09-booking-protocol-demo/restaurant.py index ad37a0b9..b74ca64a 100644 --- a/python/examples/09-booking-protocol-demo/restaurant.py +++ b/python/examples/09-booking-protocol-demo/restaurant.py @@ -15,7 +15,7 @@ }, ) -fund_agent_if_low(restaurant) +fund_agent_if_low(restaurant.wallet.address()) # build the restaurant agent from stock protocols and publish their details restaurant.include(query_proto, publish_manifest=True) diff --git a/python/examples/09-booking-protocol-demo/user.py b/python/examples/09-booking-protocol-demo/user.py index fda06c6a..fc09668a 100644 --- a/python/examples/09-booking-protocol-demo/user.py +++ b/python/examples/09-booking-protocol-demo/user.py @@ -19,7 +19,7 @@ }, ) -fund_agent_if_low(user) +fund_agent_if_low(user.wallet.address()) table_query = QueryTableRequest( guests=3, diff --git a/python/examples/10-cleaning-demo/cleaner.py b/python/examples/10-cleaning-demo/cleaner.py index cd2ce745..5a300c05 100644 --- a/python/examples/10-cleaning-demo/cleaner.py +++ b/python/examples/10-cleaning-demo/cleaner.py @@ -19,7 +19,7 @@ }, ) -fund_agent_if_low(cleaner) +fund_agent_if_low(cleaner.wallet.address()) # build the cleaning service agent from the cleaning protocol diff --git a/python/examples/10-cleaning-demo/user.py b/python/examples/10-cleaning-demo/user.py index 41a4962a..c0bc4cea 100644 --- a/python/examples/10-cleaning-demo/user.py +++ b/python/examples/10-cleaning-demo/user.py @@ -23,7 +23,7 @@ }, ) -fund_agent_if_low(user) +fund_agent_if_low(user.wallet.address()) request = ServiceRequest( user=user.name, diff --git a/python/examples/11-mailbox-agents/alice.py b/python/examples/11-mailbox-agents/alice.py index 160a6d82..a822ec8b 100644 --- a/python/examples/11-mailbox-agents/alice.py +++ b/python/examples/11-mailbox-agents/alice.py @@ -22,7 +22,7 @@ class Message(Model): mailbox=f"{API_KEY}@wss://agentverse.ai", ) -fund_agent_if_low(agent) +fund_agent_if_low(agent.wallet.address()) @agent.on_message(model=Message, replies={Message}) diff --git a/python/examples/11-mailbox-agents/bob.py b/python/examples/11-mailbox-agents/bob.py index 4b48838e..06dd3c0a 100644 --- a/python/examples/11-mailbox-agents/bob.py +++ b/python/examples/11-mailbox-agents/bob.py @@ -25,7 +25,7 @@ class Message(Model): mailbox=f"{API_KEY}@wss://agentverse.ai", ) -fund_agent_if_low(agent) +fund_agent_if_low(agent.wallet.address()) @agent.on_interval(period=2.0) diff --git a/python/examples/12-remote-agents/agent1.py b/python/examples/12-remote-agents/agent1.py index 34359e39..09a4bd02 100644 --- a/python/examples/12-remote-agents/agent1.py +++ b/python/examples/12-remote-agents/agent1.py @@ -29,7 +29,7 @@ class Message(Model): endpoint=[f"{http_tunnel.public_url}/submit"], ) -fund_agent_if_low(alice) +fund_agent_if_low(alice.wallet.address()) @alice.on_message(model=Message) diff --git a/python/examples/12-remote-agents/agent2.py b/python/examples/12-remote-agents/agent2.py index 6b489233..c9661ed7 100644 --- a/python/examples/12-remote-agents/agent2.py +++ b/python/examples/12-remote-agents/agent2.py @@ -16,7 +16,7 @@ class Message(Model): endpoint=["http://127.0.0.1:8001/submit"], ) -fund_agent_if_low(bob) +fund_agent_if_low(bob.wallet.address()) ALICE_ADDRESS = "agent1qv2l7qzcd2g2rcv2p93tqflrcaq5dk7c2xc7fcnfq3s37zgkhxjmq5mfyvz" diff --git a/python/examples/13-agent-name-service/agent1.py b/python/examples/13-agent-name-service/agent1.py index 1dc4eaef..d25e3aab 100644 --- a/python/examples/13-agent-name-service/agent1.py +++ b/python/examples/13-agent-name-service/agent1.py @@ -21,14 +21,14 @@ class Message(Model): endpoint=["http://localhost:8001/submit"], ) -fund_agent_if_low(bob) +fund_agent_if_low(bob.wallet.address()) my_wallet = LocalWallet.from_unsafe_seed("registration test wallet") name_service_contract = get_name_service_contract() DOMAIN = "agent" faucet = get_faucet() -ledger = get_ledger(True) +ledger = get_ledger(test=True) WALLET_BALANCE = ledger.query_bank_balance(my_wallet) if WALLET_BALANCE < REGISTRATION_FEE: diff --git a/python/examples/13-agent-name-service/agent2.py b/python/examples/13-agent-name-service/agent2.py index 7fde1832..c10fb882 100644 --- a/python/examples/13-agent-name-service/agent2.py +++ b/python/examples/13-agent-name-service/agent2.py @@ -13,7 +13,7 @@ class Message(Model): endpoint=["http://localhost:8000/submit"], ) -fund_agent_if_low(alice) +fund_agent_if_low(alice.wallet.address()) @alice.on_interval(period=5) diff --git a/python/examples/14-broadcast/main.py b/python/examples/14-broadcast/main.py index 86c30caa..457ce6f9 100644 --- a/python/examples/14-broadcast/main.py +++ b/python/examples/14-broadcast/main.py @@ -8,9 +8,9 @@ bob = Agent(name="bob", seed="bob recovery phrase") charles = Agent(name="charles", seed="charles recovery phrase") -fund_agent_if_low(alice) -fund_agent_if_low(bob) -fund_agent_if_low(charles) +fund_agent_if_low(alice.wallet.address()) +fund_agent_if_low(bob.wallet.address()) +fund_agent_if_low(charles.wallet.address()) class BroadcastExampleRequest(Model): diff --git a/python/src/uagents/setup.py b/python/src/uagents/setup.py index 616e9a0b..44a51ceb 100644 --- a/python/src/uagents/setup.py +++ b/python/src/uagents/setup.py @@ -10,10 +10,9 @@ LOGGER = get_logger("setup") -# pylint: disable=protected-access -def fund_agent_if_low(agent: Agent): +def fund_agent_if_low(wallet_address: str): """ - Checks the agent's wallet balance and adds funds if it's below the registration fee. + Checks the agent's wallet balance and adds testnet funds if it's below the registration fee. Args: wallet_address (str): The wallet address of the agent. @@ -21,26 +20,18 @@ def fund_agent_if_low(agent: Agent): Returns: None """ - ledger = get_ledger(agent._test) + ledger = get_ledger(test=True) faucet = get_faucet() - agent_balance = ledger.query_bank_balance(Address(agent.wallet.address())) - - if not agent._test: - LOGGER.warning( - "Faucet only available for testnet, please add FET tokens to your wallet " - f"{agent.wallet.address()}" - ) - LOGGER.info(f"Current FET balance: {agent_balance}") - return + agent_balance = ledger.query_bank_balance(Address(wallet_address)) if agent_balance < REGISTRATION_FEE: try: - LOGGER.info("Adding funds to agent...") - faucet.get_wealth(agent.wallet.address()) - LOGGER.info("Adding funds to agent...complete") + LOGGER.info("Adding testnet funds to agent...") + faucet.get_wealth(wallet_address) + LOGGER.info("Adding testnet funds to agent...complete") except Exception as ex: - LOGGER.error(f"Failed to add funds to agent: {str(ex)}") + LOGGER.error(f"Failed to add testnet funds to agent: {str(ex)}") def register_agent_with_mailbox(agent: Agent, email: str): diff --git a/python/tests/test_agent_registration.py b/python/tests/test_agent_registration.py index c04b3d56..90675a51 100644 --- a/python/tests/test_agent_registration.py +++ b/python/tests/test_agent_registration.py @@ -11,7 +11,7 @@ class TestRegistration(unittest.IsolatedAsyncioTestCase): async def test_almanac_registration(self): agent = Agent(endpoint=["http://localhost:8000/submit"]) - fund_agent_if_low(agent) + fund_agent_if_low(agent.wallet.address()) await agent.register() @@ -48,7 +48,7 @@ async def test_name_service_registration(self): domain = "agent" - fund_agent_if_low(agent) + fund_agent_if_low(agent.wallet.address()) await agent.register()