Skip to content
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

refactor environment variables handling and remove unused code #33

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

0xjunha
Copy link
Contributor

@0xjunha 0xjunha commented Sep 27, 2024

Description

  • common.py: removed default INDEXER_URL value since it shouldn't be set when we're running localnet without an indexer.

  • integration_test.py: decoupled from common.py since currently it is also loaded in each test case, but only imported once at import time of integration_test.py. This nullifies environment variable handling in the setUpClass method.

  • multikey.py: removed unused code

  • README.md: APTOS_CORE_REPO => APTOS_CORE_PATH

Test Plan

Related Links

* common.py: removed default `INDEXER_URL` value since it shouldn't be set when we're running localnet without an indexer.

* integration_test.py: decoupled from common.py since currently it is also loaded in each test case, but only imported once at import time of integration_test.py. This nullifies environment variable handling in the `setUpClass` method.

* multikey.py: removed unused code

* README.md: `APTOS_CORE_REPO` => `APTOS_CORE_PATH`
@0xjunha 0xjunha requested review from davidiw, gregnazario and a team as code owners September 27, 2024 06:41
Copy link
Contributor

@davidiw davidiw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

We use indexer here: https://github.com/aptos-labs/aptos-python-sdk/blob/main/examples/transfer_coin.py#L68

better to keep it around since we likely will use it for some SDK Api, sooner than later.

@0xjunha
Copy link
Contributor Author

0xjunha commented Sep 29, 2024

@davidiw Got it!
Yes, the SDK should cover the following cases for local integration tests:

  1. APTOS_CLI_PATH, APTOS_CORE_REPO set, and make integration_test will automatically bootstrap a localnet, and setup node/faucet urls in setUpClass of integration_test.py. However this currently doesn't work and the integration tests run on devnet as set in common.py as default values, this is why I decoupled common.py from integration_test.py. I think once the common.py is imported in integration_test.py, it is cached and each test case doesn't import it again.

    integration_test.py: decoupled from common.py since currently it is also loaded in each test case, but only imported once at import time of integration_test.py. This nullifies environment variable handling in the setUpClass method.

  2. User runs a localnet manually with an indexer and APTOS_INDEXER_URL is set to http://127.0.0.1:8090/v1/graphql

    • Actually we should remove os.environ["APTOS_INDEXER_URL"] = "none" from setUpClass
      because it is currently overwriting the indexer url to none, not utilizing the local indexer even it is running.
    • (Added another commit below to remove this)
  3. User runs a localnet manually without an indexer and APTOS_INDEXER_URL is not set

All the cases are handled properly in https://github.com/aptos-labs/aptos-python-sdk/blob/main/examples/transfer_coin.py#L16

This will still allow utilizing the indexer in local/devnet/testnet tests once the APTOS_INDEXER_URL is set properly

…gration_test.py` to utilize local indexer if it is running
Copy link
Contributor

@davidiw davidiw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost there

INDEXER_URL = os.getenv(
"APTOS_INDEXER_URL",
"https://api.devnet.aptoslabs.com/v1/graphql",
)
INDEXER_URL = os.getenv("APTOS_INDEXER_URL")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This first looks into APTOS_INDEXER_URL, but in the case user is running localnet without the --with-indexer-api (and without APTOS_INDEXER_URL) this default value will give us the devnet indexer url, when we're running local tests without an indexer.

Test cases using indexer like test_transfer_coin fails if we keep this default value.


class Test(unittest.IsolatedAsyncioTestCase):
_node: Optional[AptosInstance] = None
_aptos_core_path: str
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this refactor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we import common.py here,

os.environ["APTOS_FAUCET_URL"] = "http://127.0.0.1:8081"
os.environ["APTOS_NODE_URL"] = "http://127.0.0.1:8080/v1"

of setUpClass method in integration_test.py will not be applied in each test case.

So make integration_test is basically running tests on devnet right now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... because it is setUpClass, let's move these to setUp then. Good call!

@davidiw
Copy link
Contributor

davidiw commented Oct 1, 2024

applying 2), we should keep the default value of INDEXER_URL of common.py removed since with the default value it will look into the devnet indexer, failing the integration test.

but how does one even test common otherwise?


os.environ["APTOS_FAUCET_URL"] = "http://127.0.0.1:8081"
os.environ["APTOS_INDEXER_CLIENT"] = "none"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so what you're saying is that this doesn't actually set the environment variable and it is overwritten each time in common.py?

That doesn't make a lot of sense according to the docs.

The way it should work is that we set this once during the class call to "none", each common.py should see that it is set to "none" and leave it alone, during loading of the indexer client we should see it is "none" and not touch it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants