-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test consistency #239
Merged
Merged
Test consistency #239
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e841e19
test refactor
nerfZael c8afae9
prompt fixes
nerfZael b5d8644
minimized swap prompt while fixing issue
nerfZael 9610536
updated couple of tests to 90% since they're inconsistent
nerfZael 9684447
Merge remote-tracking branch 'origin/main' into nerfzael/test-consist…
nerfZael f3a75b9
Merge remote-tracking branch 'origin/main' into nerfzael/test-consist…
nerfZael f5c7ddc
typos
nerfZael File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from autotx.utils.ethereum.eth_address import ETHAddress | ||
|
||
def test_research_and_swap_many_tokens_subjective_simple(configuration, auto_tx): | ||
(_, _, _, manager) = configuration | ||
uni_address = ETHAddress(auto_tx.network.tokens["uni"]) | ||
|
||
uni_balance_in_safe = manager.balance_of(uni_address) | ||
assert uni_balance_in_safe == 0 | ||
|
||
starting_balance = manager.balance_of() | ||
|
||
prompt = f"I want to use 3 ETH to purchase 3 of the best projects in: GameFi, AI, and MEMEs. Please research the top projects, come up with a strategy, and purchase the tokens that look most promising. All of this should be on ETH mainnet." | ||
|
||
result = auto_tx.run(prompt, non_interactive=True) | ||
|
||
ending_balance = manager.balance_of() | ||
|
||
# Verify the balance is lower by max 3 ETH | ||
assert starting_balance - ending_balance <= 3 | ||
# Verify there are at least 3 transactions | ||
assert len(result.transactions) == 3 | ||
# Verify there are only swap transactions | ||
assert all([tx.summary.startswith("Swap") for tx in result.transactions]) | ||
# Verify the tokens are different | ||
assert len(set([tx.summary.split(" ")[-1] for tx in result.transactions])) == 3 | ||
|
||
def test_research_and_swap_many_tokens_subjective_complex(configuration, auto_tx): | ||
(_, _, _, manager) = configuration | ||
uni_address = ETHAddress(auto_tx.network.tokens["uni"]) | ||
|
||
uni_balance_in_safe = manager.balance_of(uni_address) | ||
assert uni_balance_in_safe == 0 | ||
|
||
starting_balance = manager.balance_of() | ||
|
||
prompt = f"I want to use 3 ETH to purchase exactly 10 of the best projects in: GameFi, NFTs, ZK, AI, and MEMEs. Please research the top projects, come up with a strategy, and purchase the tokens that look most promising. All of this should be on ETH mainnet." | ||
|
||
result = auto_tx.run(prompt, non_interactive=True) | ||
|
||
ending_balance = manager.balance_of() | ||
|
||
# Verify the balance is lower by max 3 ETH | ||
assert starting_balance - ending_balance <= 3 | ||
# Verify there are at least 5 transactions | ||
assert len(result.transactions) == 10 | ||
# Verify there are only swap transactions | ||
assert all([tx.summary.startswith("Swap") for tx in result.transactions]) | ||
# Verify the tokens are different | ||
assert len(set([tx.summary.split(" ")[-1] for tx in result.transactions])) == 10 |
78 changes: 20 additions & 58 deletions
78
autotx/tests/agents/token/research/test_research_and_swap.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,48 @@ | ||
from autotx.utils.ethereum import load_w3 | ||
from autotx.utils.ethereum.eth_address import ETHAddress | ||
from autotx.utils.ethereum.get_erc20_balance import get_erc20_balance | ||
|
||
def test_research_and_swap_meme_token(configuration, auto_tx): | ||
def test_research_and_buy_one(configuration, auto_tx): | ||
(_, _, _, manager) = configuration | ||
|
||
shib_address = ETHAddress(auto_tx.network.tokens["shib"]) | ||
shib_balance_in_safe = manager.balance_of(shib_address) | ||
assert shib_balance_in_safe == 0 | ||
|
||
prompt = ( | ||
f"Swap 1 ETH for the meme token with the largest market cap in ethereum mainnet" | ||
f"Buy 1 ETH worth of a meme token with the largest market cap in ethereum mainnet" | ||
) | ||
|
||
auto_tx.run(prompt, non_interactive=True) | ||
|
||
shib_balance_in_safe = manager.balance_of(shib_address) | ||
assert shib_balance_in_safe > 1000 | ||
|
||
def test_research_swap_and_send_governance_token(configuration, auto_tx, test_accounts): | ||
def test_research_and_buy_multiple(configuration, auto_tx): | ||
(_, _, _, manager) = configuration | ||
web3 = load_w3() | ||
|
||
uni_address = ETHAddress(auto_tx.network.tokens["uni"]) | ||
uni_balance_in_safe = manager.balance_of(uni_address) | ||
|
||
assert uni_balance_in_safe == 0 | ||
receiver = test_accounts[0] | ||
|
||
prompt = f"Swap 1 ETH for the governance token with the largest market cap in ethereum mainnet and send 100 units of the bought token to {receiver}" | ||
|
||
auto_tx.run(prompt, non_interactive=True) | ||
shib_address = ETHAddress(auto_tx.network.tokens["shib"]) | ||
shib_balance_in_safe = manager.balance_of(shib_address) | ||
assert shib_balance_in_safe == 0 | ||
|
||
uni_balance_in_safe = manager.balance_of(uni_address) | ||
assert uni_balance_in_safe > 90 | ||
receiver_balance = get_erc20_balance(web3, uni_address, receiver) | ||
assert receiver_balance == 100 | ||
|
||
def test_research_and_swap_many_tokens_subjective_simple(configuration, auto_tx): | ||
(_, _, _, manager) = configuration | ||
uni_address = ETHAddress(auto_tx.network.tokens["uni"]) | ||
|
||
uni_balance_in_safe = manager.balance_of(uni_address) | ||
assert uni_balance_in_safe == 0 | ||
|
||
starting_balance = manager.balance_of() | ||
|
||
prompt = f"I want to use 3 ETH to purchase 3 of the best projects in: GameFi, AI, and MEMEs. Please research the top projects, come up with a strategy, and purchase the tokens that look most promising. All of this should be on ETH mainnet." | ||
old_eth_balance = manager.balance_of() | ||
|
||
result = auto_tx.run(prompt, non_interactive=True) | ||
|
||
ending_balance = manager.balance_of() | ||
|
||
# Verify the balance is lower by max 3 ETH | ||
assert starting_balance - ending_balance <= 3 | ||
# Verify there are at least 5 transactions | ||
assert len(result.transactions) == 3 | ||
# Verify there are only swap transactions | ||
assert all([tx.summary.startswith("Swap") for tx in result.transactions]) | ||
# Verify the tokens are different | ||
assert len(set([tx.summary.split(" ")[-1] for tx in result.transactions])) == 3 | ||
|
||
def test_research_and_swap_many_tokens_subjective_complex(configuration, auto_tx): | ||
(_, _, _, manager) = configuration | ||
uni_address = ETHAddress(auto_tx.network.tokens["uni"]) | ||
prompt = f""" | ||
Buy 1 ETH worth of a meme token with the largest market cap | ||
Then buy the governance token with the largest market cap with 0.5 ETH | ||
This should be on ethereum mainnet | ||
""" | ||
|
||
uni_balance_in_safe = manager.balance_of(uni_address) | ||
assert uni_balance_in_safe == 0 | ||
|
||
starting_balance = manager.balance_of() | ||
|
||
prompt = f"I want to use 3 ETH to purchase 10 of the best projects in: GameFi, NFTs, ZK, AI, and MEMEs. Please research the top projects, come up with a strategy, and purchase the tokens that look most promising. All of this should be on ETH mainnet." | ||
auto_tx.run(prompt, non_interactive=True) | ||
|
||
new_eth_balance = manager.balance_of() | ||
|
||
result = auto_tx.run(prompt, non_interactive=True) | ||
assert old_eth_balance - new_eth_balance == 1.5 | ||
|
||
ending_balance = manager.balance_of() | ||
shib_balance_in_safe = manager.balance_of(shib_address) | ||
assert shib_balance_in_safe > 1000 | ||
|
||
# Verify the balance is lower by max 3 ETH | ||
assert starting_balance - ending_balance <= 3 | ||
# Verify there are at least 5 transactions | ||
assert len(result.transactions) == 10 | ||
# Verify there are only swap transactions | ||
assert all([tx.summary.startswith("Swap") for tx in result.transactions]) | ||
# Verify the tokens are different | ||
assert len(set([tx.summary.split(" ")[-1] for tx in result.transactions])) == 10 | ||
uni_balance_in_safe = manager.balance_of(uni_address) | ||
assert uni_balance_in_safe > 90 |
93 changes: 93 additions & 0 deletions
93
autotx/tests/agents/token/research/test_research_swap_and_send.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from autotx.utils.ethereum import get_erc20_balance, load_w3 | ||
from autotx.utils.ethereum.eth_address import ETHAddress | ||
|
||
DIFFERENCE_PERCENTAGE = 0.01 | ||
|
||
def test_research_buy_one_send_one(configuration, auto_tx, test_accounts): | ||
(_, _, _, manager) = configuration | ||
web3 = load_w3() | ||
|
||
receiver = test_accounts[0] | ||
|
||
shib_address = ETHAddress(auto_tx.network.tokens["shib"]) | ||
shib_balance_in_safe = manager.balance_of(shib_address) | ||
assert shib_balance_in_safe == 0 | ||
|
||
prompt = ( | ||
f"Buy 1 ETH worth of a meme token with the largest market cap in ethereum mainnet then send it to {receiver}" | ||
) | ||
|
||
auto_tx.run(prompt, non_interactive=True) | ||
|
||
shib_balance_in_safe = manager.balance_of(shib_address) | ||
|
||
receiver_balance = get_erc20_balance(web3, shib_address, receiver) | ||
assert receiver_balance > 10000 | ||
|
||
assert shib_balance_in_safe / receiver_balance < DIFFERENCE_PERCENTAGE | ||
|
||
def test_research_buy_one_send_multiple(configuration, auto_tx, test_accounts): | ||
(_, _, _, manager) = configuration | ||
web3 = load_w3() | ||
|
||
receiver_1 = test_accounts[0] | ||
receiver_2 = test_accounts[1] | ||
|
||
shib_address = ETHAddress(auto_tx.network.tokens["shib"]) | ||
shib_balance_in_safe = manager.balance_of(shib_address) | ||
assert shib_balance_in_safe == 0 | ||
|
||
prompt = ( | ||
f"Buy 1 ETH worth of a meme token with the largest market cap in ethereum mainnet then 10,000 of it to {receiver_1} and 250 of it to {receiver_2}" | ||
) | ||
|
||
auto_tx.run(prompt, non_interactive=True) | ||
|
||
shib_balance_in_safe = manager.balance_of(shib_address) | ||
|
||
receiver_1_balance = get_erc20_balance(web3, shib_address, receiver_1) | ||
assert receiver_1_balance == 10000 | ||
|
||
receiver_2_balance = get_erc20_balance(web3, shib_address, receiver_2) | ||
assert receiver_2_balance == 250 | ||
|
||
assert shib_balance_in_safe > 10000 | ||
|
||
def test_research_buy_multiple_send_multiple(configuration, auto_tx, test_accounts): | ||
(_, _, _, manager) = configuration | ||
web3 = load_w3() | ||
|
||
receiver_1 = test_accounts[0] | ||
receiver_2 = test_accounts[1] | ||
|
||
shib_address = ETHAddress(auto_tx.network.tokens["shib"]) | ||
shib_balance_in_safe = manager.balance_of(shib_address) | ||
assert shib_balance_in_safe == 0 | ||
|
||
uni_address = ETHAddress(auto_tx.network.tokens["uni"]) | ||
uni_balance_in_safe = manager.balance_of(uni_address) | ||
assert uni_balance_in_safe == 0 | ||
|
||
old_eth_balance = manager.balance_of() | ||
|
||
prompt = f""" | ||
Buy 1 ETH worth of a meme token with the largest market cap | ||
Then buy the governance token with the largest market cap with 0.5 ETH | ||
This should be on ethereum mainnet. | ||
Send all of the meme token to {receiver_1} and all of the governance token to {receiver_2} | ||
""" | ||
|
||
auto_tx.run(prompt, non_interactive=True) | ||
|
||
new_eth_balance = manager.balance_of() | ||
|
||
assert old_eth_balance - new_eth_balance == 1.5 | ||
|
||
shib_balance = get_erc20_balance(web3, shib_address, receiver_1) | ||
assert shib_balance > 10000 | ||
|
||
uni_balance = get_erc20_balance(web3, uni_address, receiver_2) | ||
assert uni_balance > 90 | ||
|
||
assert shib_balance_in_safe / shib_balance < DIFFERENCE_PERCENTAGE | ||
assert uni_balance_in_safe / uni_balance < DIFFERENCE_PERCENTAGE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have a lot of tests that fetch the meme coin with largest market cap - since this is dynamic, should we get the data from coingecko in each test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I just made an issue for it here: #247
Seems a bit lower prio though since the highest market cap coins won't likely change that soon