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

Commit

Permalink
Update goerli2 chain id (#327)
Browse files Browse the repository at this point in the history
* feat: add goerli2 chain id

* feat: improve tests

* feat: fix test
  • Loading branch information
ericnordelo authored Dec 16, 2022
1 parent 5a84329 commit 77ba209
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ install_requires =
importlib-metadata>=4.0
python-dotenv>=0.19.2
starknet-devnet>=0.3.5
cairo-lang>=0.10.1
cairo-lang>=0.10.3
pytest>=7.1.3
pytest-asyncio>=0.19.0
requests>=2.28.1
Expand Down
13 changes: 8 additions & 5 deletions src/nile/signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ def __init__(self, private_key, network="testnet"):
"""Construct a Signer object. Takes a private key."""
self.private_key = private_key
self.public_key = private_to_stark_key(private_key)
self.chain_id = (
StarknetChainId.MAINNET.value
if network == "mainnet"
else StarknetChainId.TESTNET.value
)
if network == "mainnet":
self.chain_id = StarknetChainId.MAINNET.value
else:
self.chain_id = (
StarknetChainId.TESTNET2.value
if network == "goerli2"
else StarknetChainId.TESTNET.value
)

def sign(self, message_hash):
"""Sign a message hash."""
Expand Down
19 changes: 14 additions & 5 deletions tests/test_signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@

PRIVATE_KEY = 12345678987654321
SIGNER = Signer(PRIVATE_KEY)
NETWORKS = ["mainnet", "goerli", "goerli2", "integration", "localhost"]
NETWORK_CHAIN_ID = {
"mainnet": StarknetChainId.MAINNET.value,
"goerli": StarknetChainId.TESTNET.value,
"goerli2": StarknetChainId.TESTNET2.value,
"integration": StarknetChainId.TESTNET.value,
"localhost": StarknetChainId.TESTNET.value,
}


def get_account_definition():
Expand Down Expand Up @@ -108,14 +116,15 @@ async def test_execute():
assert execution_info.result == (3,)


@pytest.mark.parametrize("network", NETWORKS)
@pytest.mark.asyncio
async def test_chain_id():
mainnet = Signer(PRIVATE_KEY, "mainnet")
assert mainnet.chain_id == StarknetChainId.MAINNET.value
async def test_chain_id(network):
signer = Signer(PRIVATE_KEY, network)
assert signer.chain_id == NETWORK_CHAIN_ID[network]

testnet = Signer(PRIVATE_KEY, "testnet")
assert testnet.chain_id == StarknetChainId.TESTNET.value

@pytest.mark.asyncio
async def test_chain_id_no_network():
no_network = Signer(PRIVATE_KEY)
assert no_network.chain_id == StarknetChainId.TESTNET.value

Expand Down

0 comments on commit 77ba209

Please sign in to comment.