Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Commit

Permalink
Add support for goerli2 and integration testnets (#272)
Browse files Browse the repository at this point in the history
* add support for goerli2 and integration testnets

* fix linting

* update readme

* Update src/nile/common.py

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* Update src/nile/cli.py

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* Update src/nile/cli.py

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>

* apply review suggestions

* fix tests

Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>
  • Loading branch information
martriay and ericnordelo committed Nov 2, 2022
1 parent 6191128 commit b4c7fc8
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ A few things to notice here:
1. `nile deploy <contract_name>` looks for an artifact with the same name
2. This created a `localhost.deployments.txt` file storing all data related to my deployment
3. The `--alias` parameter lets me create a unique identifier for future interactions, if no alias is set then the contract's address can be used as identifier
4. By default Nile works on local, but you can use the `--network` parameter to interact with `mainnet`, `goerli`, and the default `localhost`.
4. By default Nile works on local, but you can use the `--network` parameter to interact with `mainnet`, `goerli`, `goerli2`, `integration`, and the default `localhost`.
5. By default, the ABI corresponding to the contract will be registered with the deployment. To register a different ABI file, use the `--abi` parameter.

### `setup`
Expand Down Expand Up @@ -194,7 +194,7 @@ A few things to notice here:
1. `nile declare <private_key_alias> <contract_name>` looks for an artifact with name `<contract_name>`
2. This creates or updates a `localhost.declarations.txt` file storing all data related to your declarations
3. The `--alias` parameter lets you create a unique identifier for future interactions, if no alias is set then the contract's address can be used as identifier
4. By default Nile works on local, but you can use the `--network` parameter to interact with `mainnet`, `goerli`, and the default `localhost`.
4. By default Nile works on local, but you can use the `--network` parameter to interact with `mainnet`, `goerli`, `goerli2`, `integration`, and the default `localhost`.

### `call`

Expand Down
12 changes: 6 additions & 6 deletions src/nile/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

logging.basicConfig(level=logging.DEBUG, format="%(message)s")

NETWORKS = ("localhost", "goerli", "mainnet")
NETWORKS = ("localhost", "integration", "goerli", "goerli2", "mainnet")


def network_option(f):
Expand All @@ -42,15 +42,15 @@ def network_option(f):

def _validate_network(_ctx, _param, value):
"""Normalize network values."""
# check if value is known
if value in NETWORKS:
return value
# normalize goerli
if "goerli" in value or "testnet" in value:
if "testnet" == value:
return "goerli"
# normalize localhost
if "localhost" in value or "127.0.0.1" in value:
if "127.0.0.1" == value:
return "localhost"
# check if value is accepted
if value in NETWORKS:
return value
# raise if value is invalid
raise click.BadParameter(f"'{value}'. Use one of {NETWORKS}")

Expand Down
13 changes: 10 additions & 3 deletions src/nile/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
)


def get_gateway():
def get_gateways():
"""Get the StarkNet node details."""
try:
with open(NODE_FILENAME, "r") as f:
Expand All @@ -38,10 +38,17 @@ def get_gateway():

except FileNotFoundError:
with open(NODE_FILENAME, "w") as f:
f.write('{"localhost": "http://127.0.0.1:5050/"}')
networks = {
"localhost": "http://127.0.0.1:5050/",
"goerli2": "https://alpha4-2.starknet.io",
"integration": "https://external.integration.starknet.io",
}
f.write(json.dumps(networks, indent=2))

return networks

GATEWAYS = get_gateway()

GATEWAYS = get_gateways()


def get_all_contracts(ext=None, directory=None):
Expand Down
2 changes: 1 addition & 1 deletion src/nile/core/call_or_invoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def call_or_invoke(
@param type: can be either call or invoke.
@param method: the targeted function.
@param params: the targeted function arguments.
@param network: goerli, mainnet, or predefined networks file.
@param network: goerli, goerli2, integration, mainnet, or predefined networks file.
@param signature: optional signature for invoke transactions.
@param max_fee: optional max fee for invoke transactions.
@param query_flag: either simulate or estimate_fee
Expand Down
4 changes: 2 additions & 2 deletions src/nile/utils/get_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import requests

from nile.accounts import current_index
from nile.common import get_gateway
from nile.common import get_gateways
from nile.core.account import Account
from nile.utils import hex_address, normalize_number

GATEWAYS = get_gateway()
GATEWAYS = get_gateways()

# remove requests info logs coming from urllib3
logging.getLogger("urllib3").setLevel(logging.WARNING)
Expand Down
4 changes: 2 additions & 2 deletions src/nile/utils/get_nonce.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import os
import subprocess

from nile.common import get_gateway
from nile.common import get_gateways

GATEWAYS = get_gateway()
GATEWAYS = get_gateways()


def get_nonce(contract_address, network):
Expand Down
4 changes: 2 additions & 2 deletions tests/commands/test_get_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_get_accounts_with_keys(mock_deploy):
assert len(result) == len(PUBKEYS)


@patch("nile.common.get_gateway", return_value=GATEWAYS)
@patch("nile.common.get_gateways", return_value=GATEWAYS)
@patch("nile.utils.get_accounts._check_and_return_account")
@patch("requests.get", return_value=MockResponse(JSON_DATA, 200))
def test_get_predeployed_accounts(mock_response, mock_return_account, mock_gateways):
Expand Down Expand Up @@ -193,7 +193,7 @@ def test_get_predeployed_accounts(mock_response, mock_return_account, mock_gatew


@patch("nile.core.account.Account.deploy", return_value=(MOCK_ADDRESS, MOCK_INDEX))
@patch("nile.common.get_gateway", return_value=GATEWAYS)
@patch("nile.common.get_gateways", return_value=GATEWAYS)
@patch("nile.utils.get_accounts._check_and_return_account")
@patch("requests.get", return_value=MockResponse(JSON_DATA, 200))
def test_get_predeployed_accounts_logging(
Expand Down
6 changes: 3 additions & 3 deletions tests/commands/test_get_nonce.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[("0xffff", "localhost"), ("0xffff", "goerli"), ("0xffff", "mainnet")],
)
@patch("nile.core.node.subprocess.check_output")
@patch("nile.common.get_gateway", return_value=GATEWAYS)
@patch("nile.common.get_gateways", return_value=GATEWAYS)
def test_call_format(mock_gateway, mock_subprocess, contract_address, network):
get_nonce(contract_address, network)

Expand All @@ -29,7 +29,7 @@ def test_call_format(mock_gateway, mock_subprocess, contract_address, network):


@patch("nile.core.node.subprocess.check_output", return_value="5")
@patch("nile.common.get_gateway", return_value=GATEWAYS)
@patch("nile.common.get_gateways", return_value=GATEWAYS)
def test_get_nonce(mock_gateway, mock_subprocess, caplog):
logging.getLogger().setLevel(logging.INFO)

Expand All @@ -46,7 +46,7 @@ def test_get_nonce(mock_gateway, mock_subprocess, caplog):
["0x4d2", "1234", 1234],
)
@patch("nile.core.node.subprocess.check_output")
@patch("nile.common.get_gateway", return_value=GATEWAYS)
@patch("nile.common.get_gateways", return_value=GATEWAYS)
def test_contract_address_formats(mock_gateway, mock_subprocess, contract_address):
get_nonce(contract_address, "goerli")

Expand Down
7 changes: 7 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ABIS_DIRECTORY,
BUILD_DIRECTORY,
CONTRACTS_DIRECTORY,
GATEWAYS,
NODE_FILENAME,
)

Expand Down Expand Up @@ -181,6 +182,8 @@ def test_node_runs_gateway(opts, expected):
"args",
[
([MOCK_HASH, "--network", "goerli"]),
([MOCK_HASH, "--network", "goerli2"]),
([MOCK_HASH, "--network", "integration"]),
([MOCK_HASH, "--network", "mainnet", "--contracts_file", "example.txt"]),
],
)
Expand All @@ -197,4 +200,8 @@ def test_debug(mock_subprocess, args):
# Setup and assert expected output
expected = ["starknet", "tx_status", "--hash", MOCK_HASH]

network = args[2]
if network in ["goerli2", "integration"]:
expected.append(f"--feeder_gateway_url={GATEWAYS.get(network)}")

mock_subprocess.check_output.assert_called_once_with(expected)

0 comments on commit b4c7fc8

Please sign in to comment.