Skip to content

Commit

Permalink
Try getPublicKey if get_public_key does not exist (kkrt-labs#552)
Browse files Browse the repository at this point in the history
Time spent on this PR: 0.1

## Pull request type

Please check the type of change your PR introduces:

- [x] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, renaming)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] Documentation content changes
- [ ] Other (please describe):

## What is the current behavior?

After removing the hardcoded Account for devnet, `get_account` was
broken as testnet account uses `getPublicKey` case

## What is the new behavior?

Fix `scripts.utils.get_account` for devnet
  • Loading branch information
ClementWalter authored Mar 21, 2023
1 parent ecc216e commit f3010de
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
id: cached-poetry
uses: actions/cache@v3
with:
path: ~/.local # the path depends on the OS.
key: poetry # use new date to reset poetry cache
path: ~/.local
key: self-hosted-poetry
- name: Install Poetry
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
Expand Down Expand Up @@ -62,8 +62,8 @@ jobs:
id: cached-poetry
uses: actions/cache@v3
with:
path: ~/.local # the path depends on the OS.
key: poetry # use new date to reset poetry cache
path: ~/.local
key: self-hosted-poetry
- name: Install Poetry
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
Expand Down Expand Up @@ -107,8 +107,8 @@ jobs:
id: cached-poetry
uses: actions/cache@v3
with:
path: ~/.local # the path depends on the OS.
key: poetry # use new date to reset poetry cache
path: ~/.local
key: self-hosted-poetry
- name: Install Poetry
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/deployments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
id: cached-poetry
uses: actions/cache@v3
with:
path: ~/.local # the path depends on the OS.
key: poetry # use new date to reset poetry cache
path: ~/.local
key: ubuntu-latest-poetry
- name: Install Poetry
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
Expand All @@ -35,7 +35,8 @@ jobs:
with:
path: .venv
key:
self-hosted-venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
ubuntu-latest-venv-${{ runner.os }}-${{
hashFiles('**/poetry.lock')}}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: make setup
Expand Down
28 changes: 22 additions & 6 deletions scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,28 @@ async def get_account(
) -> AccountClient:
address = int(address or ACCOUNT_ADDRESS, 16)
key_pair = KeyPair.from_private_key(int(private_key or PRIVATE_KEY, 16))
call = Call(
to_addr=address,
selector=get_selector_from_name("get_public_key"),
calldata=[],
)
public_key = await GATEWAY_CLIENT.call_contract(call=call, block_hash="pending")
try:
call = Call(
to_addr=address,
selector=get_selector_from_name("get_public_key"),
calldata=[],
)
public_key = await GATEWAY_CLIENT.call_contract(call=call, block_hash="pending")
except Exception as err:
if (
json.loads(re.findall("{.*}", err.args[0], re.DOTALL)[0])["code"]
== "StarknetErrorCode.ENTRY_POINT_NOT_FOUND_IN_CONTRACT"
):
call = Call(
to_addr=address,
selector=get_selector_from_name("getPublicKey"),
calldata=[],
)
public_key = await GATEWAY_CLIENT.call_contract(
call=call, block_hash="pending"
)
else:
raise err
if key_pair.public_key != public_key[0]:
raise ValueError(
f"Public key of account 0x{address:064x} is not consistent with provided private key"
Expand Down
1 change: 0 additions & 1 deletion src/kakarot/library.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ from kakarot.constants import (
contract_account_class_hash,
externally_owned_account_class_hash,
blockhash_registry_address,
Constants,
account_proxy_class_hash,
)
from kakarot.accounts.library import Accounts
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def ec_sign(

def get_multicall_from_evm_txs(
evm_txs: list, private_key: PrivateKey
) -> Tuple[list, str, list]:
) -> Tuple[list, bytes, list]:
calls = []
calldata = b""
expected_result = []
Expand Down

0 comments on commit f3010de

Please sign in to comment.