Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Nile's Signer #283

Merged
merged 16 commits into from
May 6, 2022
Merged

Use Nile's Signer #283

merged 16 commits into from
May 6, 2022

Conversation

andrew-fleming
Copy link
Collaborator

This PR removes the local Signer in utils.py and instead imports/uses Nile's Signer class. This PR proposes to include the ActivatedSigner class. ActivatedSigner performs the following:

  • manage nonces
  • format and pass data to Nile's Signer
  • invoke __execute__ with the tx signature returned from Nile's Signer

Further, this PR includes updated documentation regarding how ActivatedSigner works with Nile's Signer. This resolves #221.

@andrew-fleming andrew-fleming marked this pull request as draft April 22, 2022 17:30
@andrew-fleming andrew-fleming marked this pull request as ready for review April 22, 2022 18:40
Copy link
Contributor

@martriay martriay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry that it took me so long to review this! I think we're on the right track, opened a few discussions.

tests/utils.py Outdated
@@ -128,7 +125,7 @@ def cached_contract(state, definition, deployed):
return contract


class Signer():
class ActivatedSigner():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me what the right name for this is. I was considering moving the transaction functionality upstream to Nile, but the reason we had this split in the first time is that Nile's should be generic enough while this is tied to StarkNet's testing framework -- which is not good to send transactions to public chains.

We could either abstract the provider (testing fw / starknet.py / public net?) on Nile's side and just provision the testing fw from each test and not have this intermediate abstraction, or maybe rename this one to TestSigner or something like that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm yeah, I struggled a little bit with naming this (SignerWithAccount, ExtendedSigner, and this). I think renaming to TestSigner is perfectly fine. We're just using it here to test the contracts anyway.

tox.ini Outdated
@@ -16,6 +16,7 @@ passenv =
PYTHONPATH
deps =
cairo-lang==0.8.1
cairo-nile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we fix versions in here to avoid breaking changes impacting this repo's development?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good idea

@@ -1,11 +1,12 @@
import pytest
from starkware.starknet.testing.starknet import Starknet
from utils import (
Signer, str_to_felt, TRUE, FALSE, get_contract_def, cached_contract, assert_revert, to_uint
ActivatedSigner, str_to_felt, TRUE, FALSE, get_contract_def, cached_contract,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this PR is old, but would that TRUE and FALSE end up in main if we merge this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that TRUE and FALSE end up in main as a duplicate you mean? If that's the question, I'll rebase first and make sure there are no duplicates

docs/Utilities.md Outdated Show resolved Hide resolved
docs/Account.md Outdated Show resolved Hide resolved
docs/Account.md Outdated Show resolved Hide resolved
docs/Account.md Outdated

To use Signer, pass a private key when instantiating the class:
* reformats callarray
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should "callarray" be formatted somehow? has been defined before? reformat how?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good questions. It's really just converting callarray[0] to hex so "reformat" isn't correct. I'll better explain this and include where it's first defined as well.

docs/Account.md Outdated

To use Signer, pass a private key when instantiating the class:
* reformats callarray
* a necessary process to convert the `to` contract address to hexadecimal format
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Nile converts to to base-16 which requires the to address to be a string. Converting the address with str() creates an integer that exceeds Cairo's FIELD_PRIME...I'll add this to the docs :)

docs/Account.md Outdated Show resolved Hide resolved
docs/Account.md Outdated Show resolved Hide resolved
@andrew-fleming andrew-fleming marked this pull request as draft April 30, 2022 01:20
@andrew-fleming andrew-fleming marked this pull request as ready for review May 1, 2022 05:25
@andrew-fleming andrew-fleming marked this pull request as draft May 1, 2022 17:03
@andrew-fleming andrew-fleming marked this pull request as ready for review May 1, 2022 17:57
Copy link
Contributor

@martriay martriay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking very good now! Great work

@martriay martriay merged commit 5a9a7f1 into OpenZeppelin:main May 6, 2022
@andrew-fleming andrew-fleming deleted the update-signer branch May 18, 2022 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Nile's Signer.py
2 participants