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

Automate account flag during compilation #112

Merged
merged 1 commit into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ nile compile contracts/MyContract.cairo # compiles single contract
nile compile contracts/MyContract.cairo --disable-hint-validation # compiles single contract with unwhitelisted hints
```

As of cairo-lang v0.8.0, account contracts (contracts with the `__execute__` method) must be compiled with the `--account_contract` flag.
As of cairo-lang v0.8.0, account contracts (contracts with the `__execute__` method) must be compiled with the `--account_contract` flag. Nile automatically inserts the flag if the contract's name ends with `Account` i.e. Account.cairo, EthAccount.cairo. Otherwise, the flag must be included by the user.

```sh
nile compile contracts/MyAccount.cairo --account_contract # compiles account contract
nile compile contracts/NewAccountType.cairo --account_contract # compiles account contract
```

Example output:
Expand Down
2 changes: 1 addition & 1 deletion src/nile/core/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _compile_contract(
--abi {ABIS_DIRECTORY}/{filename}.json
"""

if account_contract:
if account_contract or filename.endswith("Account"):
cmd = cmd + "--account_contract"

if disable_hint_validation:
Expand Down
36 changes: 36 additions & 0 deletions tests/commands/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,42 @@ def test__compile_account_contract(mock_subprocess):
mock_process.communicate.assert_called_once()


@pytest.mark.parametrize(
"contract_name, flag",
[
("Account", "--account_contract"),
("mock_Account", "--account_contract"),
("Account_Manager", False),
],
)
def test__compile_auto_account_flag(mock_subprocess, contract_name, flag):
path = f"path/to/{contract_name}.cairo"

mock_process = Mock()
mock_subprocess.Popen.return_value = mock_process

_compile_contract(path)

returned_subprocess = [
"starknet-compile",
path,
f"--cairo_path={CONTRACTS_DIRECTORY}",
"--output",
f"artifacts/{contract_name}.json",
"--abi",
f"artifacts/abis/{contract_name}.json",
]

if flag is not False:
returned_subprocess.append(flag)

mock_subprocess.Popen.assert_called_once_with(
returned_subprocess,
stdout=mock_subprocess.PIPE,
)
mock_process.communicate.assert_called_once()


def test__compile_contract_without_hint_validation(mock_subprocess):
contract_name_root = "contract_with_unwhitelisted_hints"
path = f"path/to/{contract_name_root}.cairo"
Expand Down