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

Simplify paths for fetching contract classes in tests #377

Merged
merged 9 commits into from
Jul 12, 2022

Conversation

andrew-fleming
Copy link
Collaborator

@andrew-fleming andrew-fleming commented Jul 4, 2022

This PR proposes to simplify getting contract classes in the test environment. Instead of passing the entire path as an argument to get_contract_class, this PR proposes to pass just the contract name. For example:

account_cls = get_contract_class('Account')
erc20_cls = get_contract_class('ERC20')

as opposed to:

account_cls = get_contract_class('openzeppelin/account/Account.cairo')
erc20_cls = get_contract_class('openzeppelin/token/erc20/ERC20.cairo')

In the event that multiple preset contracts share the same name, get_contract_class includes the optional param is_path. The syntax looks like this:

account_cls = get_contract_class('openzeppelin/account/Account.cairo', is_path=True)

Resolves #379.

Copy link
Contributor

@JulissaDantes JulissaDantes left a comment

Choose a reason for hiding this comment

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

Looks good!

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.

Left small comments, great improvement!

docs/Utilities.md Outdated Show resolved Hide resolved

signer = MockSigner(12345678987654321)
Copy link
Contributor

Choose a reason for hiding this comment

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

why was this needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah it's not!

@@ -11,7 +11,7 @@
async def reentrancy_mock():
starknet = await Starknet.empty()
contract = await starknet.deploy(
"tests/mocks/reentrancy_mock.cairo",
contract_class=get_contract_class("reentrancy_mock"),
Copy link
Contributor

Choose a reason for hiding this comment

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

how was this working?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Without the contract_class kwarg, you mean?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes

account_cls = get_contract_class('Account')
erc721_cls = get_contract_class('ERC721_Mintable_Burnable')
erc721_holder_cls = get_contract_class('ERC721_Holder')
unsupported_cls = get_contract_class('Initializable')
Copy link
Contributor

Choose a reason for hiding this comment

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

image

andrew-fleming and others added 2 commits July 12, 2022 17:58
Co-authored-by: Martín Triay <martriay@gmail.com>
@martriay martriay merged commit 5b616cf into OpenZeppelin:main Jul 12, 2022
@andrew-fleming andrew-fleming deleted the get-path branch July 15, 2022 19: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.

Simplify getting contract paths for testing
3 participants