From 7f02afd0aa7fe1d6aa744f4c2b9ce696de0fb475 Mon Sep 17 00:00:00 2001 From: Mihai Date: Tue, 12 Dec 2023 13:49:23 -0500 Subject: [PATCH 1/2] initial commit --- lib/ethpy/ethpy/base/retry_utils_test.py | 2 +- lib/ethpy/ethpy/base/transactions_test.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 lib/ethpy/ethpy/base/transactions_test.py diff --git a/lib/ethpy/ethpy/base/retry_utils_test.py b/lib/ethpy/ethpy/base/retry_utils_test.py index df602d58ee..5006760437 100644 --- a/lib/ethpy/ethpy/base/retry_utils_test.py +++ b/lib/ethpy/ethpy/base/retry_utils_test.py @@ -1,4 +1,4 @@ -"""Test executing transactions.""" +"""Test retry utils.""" import logging import time diff --git a/lib/ethpy/ethpy/base/transactions_test.py b/lib/ethpy/ethpy/base/transactions_test.py new file mode 100644 index 0000000000..ad14e7d59a --- /dev/null +++ b/lib/ethpy/ethpy/base/transactions_test.py @@ -0,0 +1,23 @@ +"""Test executing transactions.""" +from ethpy.base.transactions import smart_contract_transact + +import pytest +from fixedpointmath import FixedPoint + +from agent0.hyperdrive.interactive import InteractiveHyperdrive, LocalChain + + +@pytest.mark.anvil +def test_smart_contract_transact(chain: LocalChain): + """Verify that a bogus call produces the correct number of retries.""" + interactive_hyperdrive = InteractiveHyperdrive(chain) + alice = interactive_hyperdrive.init_agent(base=FixedPoint(100), name="alice") + _deployed_hyperdrive = interactive_hyperdrive._deployed_hyperdrive # pylint: disable=protected-access + smart_contract_transact( + chain._web3, # pylint: disable=protected-access + _deployed_hyperdrive.base_token_contract, + _deployed_hyperdrive.deploy_account, + "mint(address,uint256)", + alice.agent.checksum_address, + FixedPoint(100).scaled_value, + ) From dfaff5c3d7836de5771f71ad16c8e031913c5a1e Mon Sep 17 00:00:00 2001 From: Mihai Date: Tue, 12 Dec 2023 13:56:14 -0500 Subject: [PATCH 2/2] add failure test --- lib/ethpy/ethpy/base/transactions_test.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/ethpy/ethpy/base/transactions_test.py b/lib/ethpy/ethpy/base/transactions_test.py index ad14e7d59a..152fc6a817 100644 --- a/lib/ethpy/ethpy/base/transactions_test.py +++ b/lib/ethpy/ethpy/base/transactions_test.py @@ -1,15 +1,14 @@ """Test executing transactions.""" -from ethpy.base.transactions import smart_contract_transact - import pytest from fixedpointmath import FixedPoint from agent0.hyperdrive.interactive import InteractiveHyperdrive, LocalChain +from ethpy.base.transactions import smart_contract_transact @pytest.mark.anvil -def test_smart_contract_transact(chain: LocalChain): - """Verify that a bogus call produces the correct number of retries.""" +def test_smart_contract_transact_success(chain: LocalChain): + """Transact with a known correct function.""" interactive_hyperdrive = InteractiveHyperdrive(chain) alice = interactive_hyperdrive.init_agent(base=FixedPoint(100), name="alice") _deployed_hyperdrive = interactive_hyperdrive._deployed_hyperdrive # pylint: disable=protected-access @@ -21,3 +20,19 @@ def test_smart_contract_transact(chain: LocalChain): alice.agent.checksum_address, FixedPoint(100).scaled_value, ) + + +@pytest.mark.anvil +def test_smart_contract_transact_failure(chain: LocalChain): + """Transact with a known incorrect function name.""" + interactive_hyperdrive = InteractiveHyperdrive(chain) + alice = interactive_hyperdrive.init_agent(base=FixedPoint(100), name="alice") + _deployed_hyperdrive = interactive_hyperdrive._deployed_hyperdrive # pylint: disable=protected-access + smart_contract_transact( + chain._web3, # pylint: disable=protected-access + _deployed_hyperdrive.base_token_contract, + _deployed_hyperdrive.deploy_account, + "mintx(address,uint256)", + alice.agent.checksum_address, + FixedPoint(100).scaled_value, + )