Skip to content

Commit

Permalink
Fix test capitalisation until test_crypto, oceanutil.
Browse files Browse the repository at this point in the history
  • Loading branch information
calina-c committed Jun 28, 2023
1 parent cb50a20 commit d6dd11e
Show file tree
Hide file tree
Showing 28 changed files with 169 additions and 167 deletions.
4 changes: 2 additions & 2 deletions df_py/challenge/judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def _from_addr(tx):

@enforce_types
def _nft_addr_to_pred_vals(nft_addr: str, judge_acct) -> List[float]:
nft = oceanutil.getDataNFT(nft_addr)
pred_vals_str_enc = oceanutil.getDataField(nft, "predictions")
nft = oceanutil.get_data_nft(nft_addr)
pred_vals_str_enc = oceanutil.get_data_field(nft, "predictions")
try:
pred_vals_str = crypto.asym_decrypt(pred_vals_str_enc, judge_acct.private_key)
pred_vals = [float(s) for s in pred_vals_str[1:-1].split(",")]
Expand Down
4 changes: 2 additions & 2 deletions df_py/challenge/test/test_dftool_challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _test(tmp_path, DEADLINE: Optional[str]):
)

# Mock the connection, use test data
with patch("df_py.util.dftool_module.recordDeployedContracts"):
with patch("df_py.util.dftool_module.record_deployed_contracts"):
with patch.object(dftool_module.judge, "get_challenge_data") as mock:
mock.return_value = (target_from_addrs, target_nft_addrs, target_nmses)
with sysargs_context(sysargs):
Expand Down Expand Up @@ -83,7 +83,7 @@ def setup_function():

networkutil.connect(CHAINID)
accounts = brownie.network.accounts
oceanutil.recordDevDeployedContracts()
oceanutil.record_dev_deployed_contracts()
oceantestutil.fill_accounts_with_OCEAN()

DFTOOL_ACCT = accounts.add()
Expand Down
6 changes: 3 additions & 3 deletions df_py/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from enforce_typing import enforce_types

from df_py.util import networkutil
from df_py.util.oceanutil import OCEANtoken, recordDevDeployedContracts
from df_py.util.oceanutil import OCEAN_token, record_dev_deployed_contracts


@enforce_types
Expand All @@ -21,6 +21,6 @@ def network_setup_and_teardown():

def pytest_sessionstart():
networkutil.connect_dev()
recordDevDeployedContracts()
record_dev_deployed_contracts()
accs = brownie.network.accounts
OCEANtoken().mint(accs[0], 1e24, {"from": accs[0]})
OCEAN_token().mint(accs[0], 1e24, {"from": accs[0]})
4 changes: 2 additions & 2 deletions df_py/tests/stress.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):

def main():
networkutil.connect(CHAINID) # Connect to ganache
oceanutil.recordDevDeployedContracts() # Record deployed contract addresses on ganache
oceanutil.record_dev_deployed_contracts() # Record deployed contract addresses on ganache

CSV_DIR = str("/tmp/df_stress_test")

Expand All @@ -64,7 +64,7 @@ def main():
accounts = brownie.network.accounts
assert len(test_accounts) == NUMBER_OF_ACCOUNTS

OCEAN = oceanutil.OCEANtoken()
OCEAN = oceanutil.OCEAN_token()

## Deploy pool
print("Deploying pool")
Expand Down
30 changes: 15 additions & 15 deletions df_py/util/dftool_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
)
from df_py.util.oceanutil import (
FeeDistributor,
OCEANtoken,
recordDeployedContracts,
OCEAN_token,
record_deployed_contracts,
veAllocate,
)
from df_py.util.retry import retry_function
Expand Down Expand Up @@ -96,7 +96,7 @@ def do_volsym():
# brownie setup
networkutil.connect(CHAINID)
chain = brownie.network.chain
recordDeployedContracts(ADDRESS_FILE)
record_deployed_contracts(ADDRESS_FILE)

# main work
rng = blockrange.create_range(
Expand Down Expand Up @@ -329,7 +329,7 @@ def do_challenge_data():

# brownie setup
networkutil.connect(CHAINID)
recordDeployedContracts(ADDRESS_FILE)
record_deployed_contracts(ADDRESS_FILE)
judge_acct = judge.get_judge_acct()

# main work
Expand Down Expand Up @@ -447,7 +447,7 @@ def do_calc():
address_path = os.path.join(
current_dir, "..", "..", ".github", "workflows", "data", "address.json"
)
recordDeployedContracts(address_path)
record_deployed_contracts(address_path)
TOT_OCEAN = get_active_reward_amount_for_week_eth_by_stream(
START_DATE, arguments.SUBSTREAM
)
Expand Down Expand Up @@ -716,7 +716,7 @@ def do_init_dev_wallets():
networkutil.connect(CHAINID)

# main work
recordDeployedContracts(ADDRESS_FILE)
record_deployed_contracts(ADDRESS_FILE)
oceantestutil.fill_accounts_with_OCEAN()

print("dftool init_dev_wallets: Done.")
Expand Down Expand Up @@ -749,8 +749,8 @@ def do_many_random():
networkutil.connect(CHAINID)

# main work
recordDeployedContracts(ADDRESS_FILE)
OCEAN = OCEANtoken()
record_deployed_contracts(ADDRESS_FILE)
OCEAN = OCEAN_token()

num_nfts = 10 # magic number
tups = random_create_dataNFT_with_FREs(num_nfts, OCEAN, brownie.network.accounts)
Expand Down Expand Up @@ -885,7 +885,7 @@ def do_ve_set_allocation():
networkutil.connect(arguments.CHAINID)
ADDRESS_FILE = os.environ.get("ADDRESS_FILE")
if ADDRESS_FILE is not None:
recordDeployedContracts(ADDRESS_FILE)
record_deployed_contracts(ADDRESS_FILE)
from_account = _getPrivateAccount()
veAllocate().setAllocation(
arguments.amount,
Expand Down Expand Up @@ -945,8 +945,8 @@ def do_acct_info():
# Give balance for OCEAN token too.
ADDRESS_FILE = os.environ.get("ADDRESS_FILE")
if ADDRESS_FILE is not None:
recordDeployedContracts(ADDRESS_FILE)
OCEAN = OCEANtoken()
record_deployed_contracts(ADDRESS_FILE)
OCEAN = OCEAN_token()
if OCEAN.address != TOKEN_ADDR:
print(f" {from_wei(OCEAN.balanceOf(ACCOUNT_ADDR))} OCEAN")

Expand Down Expand Up @@ -989,7 +989,7 @@ def do_dispense_passive():
networkutil.connect(arguments.CHAINID)

ADDRESS_FILE = _getAddressEnvvarOrExit()
recordDeployedContracts(ADDRESS_FILE)
record_deployed_contracts(ADDRESS_FILE)

AMOUNT = arguments.AMOUNT

Expand All @@ -998,7 +998,7 @@ def do_dispense_passive():
AMOUNT = get_active_reward_amount_for_week_eth(START_DATE)

feedist = FeeDistributor()
OCEAN = OCEANtoken()
OCEAN = OCEAN_token()
retry_function(dispense.dispense_passive, 3, 60, OCEAN, feedist, AMOUNT)

print("Dispensed passive rewards")
Expand Down Expand Up @@ -1027,7 +1027,7 @@ def do_calculate_passive():
S_PER_WEEK = 7 * 86400
timestamp = timestamp // S_PER_WEEK * S_PER_WEEK
ADDRESS_FILE = _getAddressEnvvarOrExit()
recordDeployedContracts(ADDRESS_FILE)
record_deployed_contracts(ADDRESS_FILE)

# load vebals csv file
passive_fname = csvs.passive_csv_filename(CSV_DIR)
Expand Down Expand Up @@ -1059,7 +1059,7 @@ def do_checkpoint_feedist():

ADDRESS_FILE = _getAddressEnvvarOrExit()

recordDeployedContracts(ADDRESS_FILE)
record_deployed_contracts(ADDRESS_FILE)
from_account = _getPrivateAccount()
feedist = FeeDistributor()

Expand Down
6 changes: 3 additions & 3 deletions df_py/util/oceantestutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def fill_accounts_with_token(token):

@enforce_types
def fill_accounts_with_OCEAN():
OCEAN = oceanutil.OCEANtoken()
OCEAN = oceanutil.OCEAN_token()
fill_accounts_with_token(OCEAN)


Expand Down Expand Up @@ -118,7 +118,7 @@ def random_create_dataNFT_with_FREs(num_FRE: int, base_token, accounts):
account_i = FRE_i
else:
account_i = random.randint(0, len(accounts))
(data_NFT, DT, exchangeId) = oceanutil.createDataNFTWithFRE(
(data_NFT, DT, exchangeId) = oceanutil.create_data_nft_with_fre(
accounts[account_i], base_token
)
assert oceanutil.FixedPrice().isActive(exchangeId) is True
Expand Down Expand Up @@ -176,7 +176,7 @@ def random_lock_and_allocate(tups: list):
# tups = [(pub_account_i, data_NFT, DT, exchangeId)]

acc1 = network.accounts[0]
OCEAN = oceanutil.OCEANtoken()
OCEAN = oceanutil.OCEAN_token()
veOCEAN = oceanutil.veOCEAN()

accounts = network.accounts[: len(tups)]
Expand Down
62 changes: 32 additions & 30 deletions df_py/util/oceanutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ def _contracts(key: str):
chainID = brownie.network.chain.id
if chainID not in CONTRACTS:
address_file = networkutil.chain_id_to_address_file(chainID)
recordDeployedContracts(address_file)
record_deployed_contracts(address_file)

return CONTRACTS[chainID][key]


@enforce_types
def recordDevDeployedContracts():
def record_dev_deployed_contracts():
assert brownie.network.is_connected()
assert brownie.network.chain.id == networkutil.DEV_CHAINID
address_file = networkutil.chain_id_to_address_file(networkutil.DEV_CHAINID)
recordDeployedContracts(address_file)
record_deployed_contracts(address_file)


@enforce_types
def recordDeployedContracts(address_file: str):
def record_deployed_contracts(address_file: str):
"""Records deployed Ocean contracts at currently connected network"""
assert brownie.network.is_connected()
chainID = brownie.network.chain.id
Expand Down Expand Up @@ -80,12 +80,12 @@ def recordDeployedContracts(address_file: str):
CONTRACTS[chainID] = C


def OCEANtoken():
def OCEAN_token():
return _contracts("Ocean")


def OCEAN_address() -> str:
return OCEANtoken().address.lower()
return OCEAN_token().address.lower()


def ERC721Template():
Expand All @@ -96,7 +96,7 @@ def ERC20Template():
return _contracts("ERC20Template")


def factoryRouter():
def FactoryRouter():
return _contracts("Router")


Expand Down Expand Up @@ -137,11 +137,11 @@ def VestingWalletV0():


@enforce_types
def createDataNFTWithFRE(from_account, token):
data_NFT = createDataNFT("1", "1", from_account)
DT = createDatatokenFromDataNFT("1", "1", data_NFT, from_account)
def create_data_nft_with_fre(from_account, token):
data_NFT = create_data_nft("1", "1", from_account)
DT = create_datatoken_from_data_nft("1", "1", data_NFT, from_account)

exchangeId = createFREFromDatatoken(DT, token, 10.0, from_account)
exchangeId = create_FRE_from_datatoken(DT, token, 10.0, from_account)
return (data_NFT, DT, exchangeId)


Expand All @@ -157,11 +157,11 @@ def _get_events(tx):


@enforce_types
def createDataNFT(name: str, symbol: str, from_account):
def create_data_nft(name: str, symbol: str, from_account):
erc721_factory = ERC721Factory()
template_index = 1
additional_metadata_updater = ZERO_ADDRESS
additional_erc20_deployer = factoryRouter().address
additional_erc20_deployer = FactoryRouter().address
transferable = True
owner = from_account.address
token_uri = "https://mystorage.com/mytoken.png"
Expand All @@ -184,24 +184,26 @@ def createDataNFT(name: str, symbol: str, from_account):
return data_NFT


def getDataNFT(data_NFT_address):
return B.ERC721Template.at(data_NFT_address)
def get_data_nft(data_nft_address):
return B.ERC721Template.at(data_nft_address)


def getDataField(data_NFT, field_label: str) -> str:
def get_data_field(data_nft, field_label: str) -> str:
field_label_hash = Web3.keccak(text=field_label) # to keccak256 hash
field_value_hex = data_NFT.getData(field_label_hash)
field_value_hex = data_nft.getData(field_label_hash)
field_value = field_value_hex.decode("ascii")

return field_value


@enforce_types
def createDatatokenFromDataNFT(DT_name: str, DT_symbol: str, data_NFT, from_account):
def create_datatoken_from_data_nft(
dt_name: str, dt_symbol: str, data_nft, from_account
):
erc20_template_index = 1
strings = [
DT_name,
DT_symbol,
dt_name,
dt_symbol,
]
addresses = [
from_account.address, # minter
Expand All @@ -215,7 +217,7 @@ def createDatatokenFromDataNFT(DT_name: str, DT_symbol: str, data_NFT, from_acco
]
_bytes: List[Any] = []

tx = data_NFT.createERC20(
tx = data_nft.createERC20(
erc20_template_index, strings, addresses, uints, _bytes, {"from": from_account}
)

Expand All @@ -227,21 +229,21 @@ def createDatatokenFromDataNFT(DT_name: str, DT_symbol: str, data_NFT, from_acco


@enforce_types
def createFREFromDatatoken(
datatoken, base_TOKEN, amount: float, from_account, rate=1.0
def create_FRE_from_datatoken(
datatoken, base_token, amount: float, from_account, rate=1.0
) -> str:
"""Create new fixed-rate exchange. Returns its exchange_id (str)"""
datatoken.approve(FixedPrice().address, to_wei(amount), {"from": from_account})

addresses = [
base_TOKEN.address, # baseToken
base_token.address, # baseToken
from_account.address, # owner
from_account.address, # marketFeeCollector address
ZERO_ADDRESS, # allowed swapper
]

uints = [
base_TOKEN.decimals(), # baseTokenDecimals
base_token.decimals(), # baseTokenDecimals
datatoken.decimals(), # datatokenDecimals
to_wei(rate), # fixedRate : exchange rate of base_TOKEN to datatoken
0, # marketFee
Expand All @@ -268,13 +270,13 @@ def createFREFromDatatoken(


@enforce_types
def set_allocation(amount: int, nft_addr: str, chainID: int, from_account):
veAllocate().setAllocation(amount, nft_addr, chainID, {"from": from_account})
def set_allocation(amount: int, nft_addr: str, chain_id: int, from_account):
veAllocate().setAllocation(amount, nft_addr, chain_id, {"from": from_account})


@enforce_types
def ve_delegate(
from_account, to_account, percentage: float, tokenid: int, expiry: int = 0
from_account, to_account, percentage: float, token_id: int, expiry: int = 0
):
if expiry == 0:
expiry = veOCEAN().locked__end(from_account)
Expand All @@ -284,7 +286,7 @@ def ve_delegate(
int(percentage * 10000),
0,
expiry,
tokenid,
token_id,
{"from": from_account},
)

Expand Down Expand Up @@ -405,7 +407,7 @@ def to_32byte_hex(val: int) -> str:


@enforce_types
def calcDID(nft_addr: str, chainID: int) -> str:
def calc_did(nft_addr: str, chainID: int) -> str:
nft_addr2 = brownie.web3.toChecksumAddress(nft_addr)

# adapted from ocean.py/ocean_lib/ocean/ocean_assets.py
Expand Down
Loading

0 comments on commit d6dd11e

Please sign in to comment.