Skip to content

Commit

Permalink
addresses comment about cleaner constants imports #399 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikewcasale committed Mar 28, 2024
1 parent e9b17ee commit 85e1feb
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 45 deletions.
4 changes: 2 additions & 2 deletions fastlane_bot/tests/deterministic/dtest_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from typing import Dict

from fastlane_bot.tests.deterministic.dtest_cmd_line_args import TestCommandLineArgs
from fastlane_bot.tests.deterministic.dtest_constants import KNOWN_UNABLE_TO_DELETE
from fastlane_bot.tests.deterministic import dtest_constants as constants
from fastlane_bot.tests.deterministic.dtest_manager import TestManager
from fastlane_bot.tests.deterministic.dtest_pool import TestPool
from fastlane_bot.tests.deterministic.dtest_pool_params_builder import TestPoolParamsBuilder
Expand Down Expand Up @@ -89,7 +89,7 @@ def get_carbon_strategies_and_delete_task(

# These strategies cannot be deleted on Ethereum
assert all(
x in KNOWN_UNABLE_TO_DELETE for x in undeleted_strategies
x in constants.KNOWN_UNABLE_TO_DELETE for x in undeleted_strategies
), f"Strategies not deleted that are unknown: {undeleted_strategies}"


Expand Down
24 changes: 9 additions & 15 deletions fastlane_bot/tests/deterministic/dtest_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@
from web3.contract import Contract

from fastlane_bot.data.abi import CARBON_CONTROLLER_ABI
from fastlane_bot.tests.deterministic.dtest_constants import (
DEFAULT_GAS,
DEFAULT_GAS_PRICE,
ETH_ADDRESS,
TEST_DATA_DIR,
TOKENS_MODIFICATIONS,
)
from fastlane_bot.tests.deterministic import dtest_constants as constants
from fastlane_bot.tests.deterministic.dtest_cmd_line_args import TestCommandLineArgs
from fastlane_bot.tests.deterministic.dtest_strategy import TestStrategy

Expand Down Expand Up @@ -304,7 +298,7 @@ def set_balance_via_faucet(
"""
token_address = w3.to_checksum_address(token_address)
wallet = w3.to_checksum_address(wallet)
if token_address in {ETH_ADDRESS}:
if token_address in {constants.ETH_ADDRESS}:
method = "tenderly_setBalance"
params = [[wallet], w3.to_hex(amount_wei)]
else:
Expand Down Expand Up @@ -371,7 +365,7 @@ def modify_tokens_for_deletion(self, args: argparse.Namespace) -> None:
Args:
args (argparse.Namespace): The command-line arguments.
"""
for token_name, details in TOKENS_MODIFICATIONS.items():
for token_name, details in constants.TOKENS_MODIFICATIONS.items():
args.logger.debug(f"Modifying {token_name} token..., details: {details}")
self.modify_token(
args,
Expand All @@ -396,8 +390,8 @@ def create_strategy(self, args: argparse.Namespace, strategy: TestStrategy) -> s
tx_params = {
"from": strategy.wallet.address,
"nonce": strategy.wallet.nonce,
"gasPrice": DEFAULT_GAS_PRICE,
"gas": DEFAULT_GAS,
"gasPrice": constants.DEFAULT_GAS_PRICE,
"gas": constants.DEFAULT_GAS,
}
if strategy.value:
tx_params["value"] = strategy.value
Expand Down Expand Up @@ -434,8 +428,8 @@ def delete_strategy(self, strategy_id: int, wallet: Address) -> int:
tx_params = {
"from": wallet,
"nonce": nonce,
"gasPrice": DEFAULT_GAS_PRICE,
"gas": DEFAULT_GAS,
"gasPrice": constants.DEFAULT_GAS_PRICE,
"gas": constants.DEFAULT_GAS,
}
tx_hash = self.carbon_controller.functions.deleteStrategy(strategy_id).transact(
tx_params
Expand Down Expand Up @@ -496,7 +490,7 @@ def get_test_strategies(args: argparse.Namespace) -> Dict:
Gets test strategies from a JSON file.
"""
test_strategies_path = os.path.normpath(
f"{TEST_DATA_DIR}/test_strategies.json"
f"{constants.TEST_DATA_DIR}/test_strategies.json"
)
with open(test_strategies_path) as file:
test_strategies = json.load(file)["test_strategies"]
Expand Down Expand Up @@ -546,7 +540,7 @@ def write_strategy_txhashs_to_json(test_strategy_txhashs: Dict):
test_strategy_txhashs (dict): The test strategy txhashs.
"""
test_strategy_txhashs_path = os.path.normpath(
f"{TEST_DATA_DIR}/test_strategy_txhashs.json"
f"{constants.TEST_DATA_DIR}/test_strategy_txhashs.json"
)
with open(test_strategy_txhashs_path, "w") as f:
json.dump(test_strategy_txhashs, f)
Expand Down
9 changes: 3 additions & 6 deletions fastlane_bot/tests/deterministic/dtest_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
from web3 import Web3
from web3.types import RPCEndpoint

from fastlane_bot.tests.deterministic.dtest_constants import (
SUPPORTED_EXCHANGES,
TEST_DATA_DIR,
)
from fastlane_bot.tests.deterministic import dtest_constants as constants
from fastlane_bot.tests.deterministic.dtest_token import TestTokenBalance


Expand Down Expand Up @@ -81,7 +78,7 @@ def is_supported(self):
"""
Returns True if the pool is supported, otherwise False.
"""
return self.exchange_type in SUPPORTED_EXCHANGES
return self.exchange_type in constants.SUPPORTED_EXCHANGES

def set_balance_via_faucet(self, args: argparse.Namespace,
w3: Web3, token_id: int):
Expand Down Expand Up @@ -114,6 +111,6 @@ def set_balance_via_faucet(self, args: argparse.Namespace,
def load_test_pools():
# Import pool data
static_pool_data_testing_path = os.path.normpath(
f"{TEST_DATA_DIR}/static_pool_data_testing.csv"
f"{constants.TEST_DATA_DIR}/static_pool_data_testing.csv"
)
return pd.read_csv(static_pool_data_testing_path, dtype=str)
25 changes: 9 additions & 16 deletions fastlane_bot/tests/deterministic/dtest_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@
from web3 import Web3

from fastlane_bot.data.abi import ERC20_ABI
from fastlane_bot.tests.deterministic.dtest_constants import (
BNT_ADDRESS,
DEFAULT_GAS,
DEFAULT_GAS_PRICE,
TEST_MODE_AMT,
USDC_ADDRESS,
USDT_ADDRESS,
)
from fastlane_bot.tests.deterministic import dtest_constants as constants
from fastlane_bot.tests.deterministic.dtest_token import TestToken
from fastlane_bot.tests.deterministic.dtest_wallet import TestWallet

Expand Down Expand Up @@ -78,16 +71,16 @@ def get_token_approval(
"""
token = self.token0 if token_id == 0 else self.token1
if token.address in [
BNT_ADDRESS,
USDC_ADDRESS,
USDT_ADDRESS,
constants.BNT_ADDRESS,
constants.USDC_ADDRESS,
constants.USDT_ADDRESS,
]:
function_call = token.contract.functions.approve(
approval_address, 0
).transact(
{
"gasPrice": DEFAULT_GAS_PRICE,
"gas": DEFAULT_GAS,
"gasPrice": constants.DEFAULT_GAS_PRICE,
"gas": constants.DEFAULT_GAS,
"from": self.wallet.address,
"nonce": self.wallet.nonce,
}
Expand All @@ -103,11 +96,11 @@ def get_token_approval(
args.logger.debug(f"tx_hash = {tx_hash}")

function_call = token.contract.functions.approve(
approval_address, TEST_MODE_AMT
approval_address, constants.TEST_MODE_AMT
).transact(
{
"gasPrice": DEFAULT_GAS_PRICE,
"gas": DEFAULT_GAS,
"gasPrice": constants.DEFAULT_GAS_PRICE,
"gas": constants.DEFAULT_GAS,
"from": self.wallet.address,
"nonce": self.wallet.nonce,
}
Expand Down
4 changes: 2 additions & 2 deletions fastlane_bot/tests/deterministic/dtest_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from web3 import Web3
from web3.contract import Contract

from fastlane_bot.tests.deterministic.dtest_constants import ETH_ADDRESS
from fastlane_bot.tests.deterministic import dtest_constants as constants


@dataclass
Expand All @@ -32,7 +32,7 @@ def __post_init__(self):

@property
def is_eth(self):
return self.address == ETH_ADDRESS
return self.address == constants.ETH_ADDRESS


@dataclass
Expand Down
6 changes: 2 additions & 4 deletions fastlane_bot/tests/deterministic/dtest_tx_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
import time
from typing import Dict, List

from fastlane_bot.tests.deterministic.dtest_constants import (
TEST_DATA_DIR,
)
from fastlane_bot.tests.deterministic import dtest_constants as constants


class TestTxHelper:
Expand Down Expand Up @@ -175,7 +173,7 @@ def load_json_file(file_name: str, args: argparse.Namespace) -> Dict:
dict: The data from the json file.
"""
file_path = (
os.path.normpath(f"{TEST_DATA_DIR}/{file_name}")
os.path.normpath(f"{constants.TEST_DATA_DIR}/{file_name}")
if "/" not in file_name
else os.path.normpath(file_name)
)
Expand Down

0 comments on commit 85e1feb

Please sign in to comment.