Skip to content

Commit

Permalink
Shahak/pytest with contract deployment test (#41)
Browse files Browse the repository at this point in the history
* add pytest to git actions

* Add python test that deploys the contracts

* Add python test that deploys the contracts

* added test/ethereum directory

* Delete contracts/starknet/__pycache__ directory

* added scripts to package.json

* Update tests.yml

* use yarn in pytest step

Co-authored-by: Orlando <orlandothefraser@gmail.com>
Co-authored-by: Orland0x <37511817+Orland0x@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 28, 2022
1 parent 388d20c commit ec66726
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 2 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,18 @@ jobs:
run: yarn compile

- name: Run unit tests
run: yarn test
run: yarn test:hardhat

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.7"

- name: Install pytest
run: python -m pip install --upgrade pytest

- name: Install cairo lang
run: python -m pip install --upgrade cairo-lang>=0.7.1

- name: Run python unit tests
run: yarn test:pytest
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
**/__pycache__

#Hardhat files
cache
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"compile:l2": "hardhat starknet-compile",
"compile": "yarn compile:l1 && yarn compile:l2",
"deploy:l2:testnet": "hardhat starknet-deploy --starknet-network alpha",
"test": "hardhat test",
"test:hardhat": "hardhat test",
"test:pytest": "py.test",
"test": "yarn test:hardhat && yarn test:pytest",
"start:l1": "hardhat node",
"format:l1": "prettier --write 'contracts/**/*.sol'",
"check-format:l1": "prettier -c 'contracts/**/*.sol'",
Expand Down
File renamed without changes.
File renamed without changes.
49 changes: 49 additions & 0 deletions test/starknet/test_contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import asyncio
import os
import pytest

from starkware.starknet.testing.contract import StarknetContract
from starkware.starknet.testing.starknet import Starknet

COMPILED_CONTRACTS_DIR = os.path.join("starknet-artifacts", "contracts", "starknet")


@pytest.fixture(scope="session")
def event_loop():
loop = asyncio.get_event_loop()
yield loop
loop.close()


@pytest.fixture(scope="session")
async def starknet() -> Starknet:
return await Starknet.empty()


async def load_compiled_contract_and_deploy(
starknet: Starknet, contract_name: str
) -> StarknetContract:
return await starknet.deploy(
constructor_calldata=[],
contract_def=ContractDefinition.loads(
open(
os.path.join(
COMPILED_CONTRACTS_DIR, f"{contract_name}.cairo", f"{contract_name}.json"
)
).read()
),
)


@pytest.fixture
async def l1_auth_mock_contract(starknet: Starknet) -> StarknetContract:
return load_compiled_contract_and_deploy(starknet=starknet, contract_name="L1AuthMock")


@pytest.fixture
async def l2_auth_mock_contract(starknet: Starknet) -> StarknetContract:
return load_compiled_contract_and_deploy(starknet=starknet, contract_name="L2AuthMock")


def test_fixtures(l1_auth_mock_contract: StarknetContract, l2_auth_mock_contract: StarknetContract):
pass

0 comments on commit ec66726

Please sign in to comment.