From c93d5891dcf22c02aca1ea1440a1d512fd304be7 Mon Sep 17 00:00:00 2001 From: Pedro Yves Fracari Date: Mon, 15 Apr 2024 17:18:57 -0300 Subject: [PATCH 1/3] wip: fix poetry lock --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 902da10..e2c31ef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: python-version: [ - "3.8", "3.9", "3.10", "3.11", "3.12", + "3.10", "3.11", "3.12", ] timeout-minutes: 10 steps: @@ -32,6 +32,10 @@ jobs: cache: poetry cache-dependency-path: poetry.lock + - name: Poetry lock + run: | + poetry lock + - name: Install dependencies run: | poetry install From aaa3d3c16a1d28a9a95bf2485ea82d90dfe1893c Mon Sep 17 00:00:00 2001 From: Pedro Yves Fracari Date: Mon, 15 Apr 2024 18:00:03 -0300 Subject: [PATCH 2/3] fix: pyright types --- .github/workflows/ci.yml | 5 ---- cow_py/codegen/solidity_converter.py | 14 ++------- cow_py/order_book/api.py | 14 ++++++--- examples/order_posting_e2e.py | 38 +++++++++++++----------- pyproject.toml | 5 +++- tests/common/api/test_api_base.py | 3 +- tests/order_book/test_api.py | 39 ++++++++++++++++-------- tests/subgraphs/deployments.py | 44 ---------------------------- 8 files changed, 66 insertions(+), 96 deletions(-) delete mode 100644 tests/subgraphs/deployments.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2c31ef..c285d9a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,11 +30,6 @@ jobs: with: python-version: ${{ matrix.python-version }} cache: poetry - cache-dependency-path: poetry.lock - - - name: Poetry lock - run: | - poetry lock - name: Install dependencies run: | diff --git a/cow_py/codegen/solidity_converter.py b/cow_py/codegen/solidity_converter.py index fa920d6..90766f0 100644 --- a/cow_py/codegen/solidity_converter.py +++ b/cow_py/codegen/solidity_converter.py @@ -10,9 +10,9 @@ "int": "int", } DYNAMIC_SOLIDITY_TYPES = { - f"{prefix}{i*8 if prefix != 'bytes' else i}": "int" - if prefix != "bytes" - else "HexBytes" + f"{prefix}{i*8 if prefix != 'bytes' else i}": ( + "int" if prefix != "bytes" else "HexBytes" + ) for prefix in ["uint", "int", "bytes"] for i in range(1, 33) } @@ -97,11 +97,3 @@ def _convert_array_or_basic_type(solidity_type: str) -> str: return f'Tuple[{", ".join([SOLIDITY_TO_PYTHON_TYPES.get(base_type, "Any")] * size)}]' else: return SOLIDITY_TO_PYTHON_TYPES.get(solidity_type, "Any") - - @staticmethod - def _get_struct_name(internal_type: str) -> str: - if not internal_type or "struct " not in internal_type: - raise SolidityConverterError( - f"Invalid internal type for struct: {internal_type}" - ) - return internal_type.replace("struct ", "").replace(".", "_").replace("[]", "") diff --git a/cow_py/order_book/api.py b/cow_py/order_book/api.py index b33a044..c99b394 100644 --- a/cow_py/order_book/api.py +++ b/cow_py/order_book/api.py @@ -4,6 +4,8 @@ from cow_py.common.api.api_base import ApiBase, Context from cow_py.common.config import SupportedChainId from cow_py.order_book.config import OrderBookAPIConfigFactory +from typing import Union +from cow_py.order_book.generated.model import OrderQuoteSide2, OrderQuoteValidity2 from .generated.model import ( UID, @@ -17,6 +19,8 @@ OrderQuoteRequest, OrderQuoteResponse, OrderQuoteSide, + OrderQuoteSide1, + OrderQuoteSide3, OrderQuoteValidity, OrderQuoteValidity1, SolverCompetitionResponse, @@ -122,7 +126,7 @@ async def get_app_data( ) async def get_solver_competition( - self, action_id: int = "latest", context_override: Context = {} + self, action_id: Union[int, str] = "latest", context_override: Context = {} ) -> SolverCompetitionResponse: response = await self._fetch( path=f"/api/v1/solver_competition/{action_id}", @@ -142,8 +146,10 @@ async def get_solver_competition_by_tx_hash( async def post_quote( self, request: OrderQuoteRequest, - side: OrderQuoteSide, - validity: OrderQuoteValidity = OrderQuoteValidity1(validTo=None), + side: Union[OrderQuoteSide, OrderQuoteSide1, OrderQuoteSide2, OrderQuoteSide3], + validity: Union[ + OrderQuoteValidity, OrderQuoteValidity1, OrderQuoteValidity2 + ] = OrderQuoteValidity1(validTo=None), context_override: Context = {}, ) -> OrderQuoteResponse: response = await self._fetch( @@ -184,7 +190,7 @@ async def delete_order( async def put_app_data( self, app_data: AppDataObject, - app_data_hash: str = None, + app_data_hash: str = "", context_override: Context = {}, ) -> AppDataHash: app_data_hash_url = app_data_hash if app_data_hash else "" diff --git a/examples/order_posting_e2e.py b/examples/order_posting_e2e.py index 2fca57a..5dc9842 100644 --- a/examples/order_posting_e2e.py +++ b/examples/order_posting_e2e.py @@ -18,12 +18,13 @@ from cow_py.contracts.sign import sign_order as _sign_order from cow_py.order_book.api import OrderBookApi from cow_py.order_book.config import OrderBookAPIConfigFactory +from cow_py.order_book.generated.model import OrderQuoteSide1, TokenAmount +from cow_py.order_book.generated.model import OrderQuoteSideKindSell from cow_py.order_book.generated.model import ( UID, OrderCreation, OrderQuoteRequest, OrderQuoteResponse, - OrderQuoteSide, ) BUY_TOKEN = "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14" # WETH @@ -41,7 +42,7 @@ async def get_order_quote( - order_quote_request: OrderQuoteRequest, order_side: OrderQuoteSide + order_quote_request: OrderQuoteRequest, order_side: OrderQuoteSide1 ) -> OrderQuoteResponse: return await ORDER_BOOK_API.post_quote(order_quote_request, order_side) @@ -59,19 +60,21 @@ def sign_order(order: Order) -> EcdsaSignature: async def post_order(order: Order, signature: EcdsaSignature) -> UID: order_creation = OrderCreation( - sellToken=order.sellToken, - buyToken=order.buyToken, - sellAmount=order.sellAmount, - feeAmount=order.feeAmount, - buyAmount=order.buyAmount, - validTo=order.validTo, - kind=order.kind, - partiallyFillable=order.partiallyFillable, - appData=order.appData, - signature=signature.data, - signingScheme="eip712", - receiver=order.receiver, - **{"from": ADDRESS}, + **{ + "from": ADDRESS, + "sellToken": order.sellToken, + "buyToken": order.buyToken, + "sellAmount": order.sellAmount, + "feeAmount": order.feeAmount, + "buyAmount": order.buyAmount, + "validTo": order.validTo, + "kind": order.kind, + "partiallyFillable": order.partiallyFillable, + "appData": order.appData, + "signature": signature.data, + "signingScheme": "eip712", + "receiver": order.receiver, + }, ) return await ORDER_BOOK_API.post_order(order_creation) @@ -84,8 +87,9 @@ async def main(): "from": ADDRESS, } ) - order_side = OrderQuoteSide( - kind=ORDER_KIND, sellAmountBeforeFee=SELL_AMOUNT_BEFORE_FEE + order_side = OrderQuoteSide1( + kind=OrderQuoteSideKindSell.sell, + sellAmountBeforeFee=TokenAmount(SELL_AMOUNT_BEFORE_FEE), ) order_quote = await get_order_quote(order_quote_request, order_side) diff --git a/pyproject.toml b/pyproject.toml index 545f01a..012d3ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,6 +50,9 @@ exclude = [ "**/node_modules", "**/__pycache__", "cow_py/subgraph/client/*.py", - # "cow_py/order_book/generated/*.py" + "cow_py/order_book/generated/*.py", + ".venv/", + "**/__generated__" ] reportIncompatibleVariableOverride = 'warning' +strictParameterNoneValue = false diff --git a/tests/common/api/test_api_base.py b/tests/common/api/test_api_base.py index 3138207..1c3dd9f 100644 --- a/tests/common/api/test_api_base.py +++ b/tests/common/api/test_api_base.py @@ -6,6 +6,7 @@ from cow_py.common.api.api_base import ApiBase, APIConfig from cow_py.common.api.decorators import DEFAULT_BACKOFF_OPTIONS from cow_py.common.config import SupportedChainId +from httpx import Request ERROR_MESSAGE = "💣💥 Booom!" OK_RESPONSE = {"status": 200, "ok": True, "content": {"some": "data"}} @@ -48,7 +49,7 @@ def mock_success_response(): def mock_http_status_error(): return httpx.HTTPStatusError( message=ERROR_MESSAGE, - request=None, + request=Request("GET", "http://example.com"), response=httpx.Response(500), ) diff --git a/tests/order_book/test_api.py b/tests/order_book/test_api.py index 5ac3830..72f5d22 100644 --- a/tests/order_book/test_api.py +++ b/tests/order_book/test_api.py @@ -3,10 +3,12 @@ import pytest from cow_py.order_book.api import OrderBookApi +from cow_py.order_book.generated.model import OrderQuoteSide1 +from cow_py.order_book.generated.model import OrderQuoteSideKindSell +from cow_py.order_book.generated.model import TokenAmount from cow_py.order_book.generated.model import ( OrderQuoteRequest, OrderQuoteResponse, - OrderQuoteSide, Trade, OrderCreation, ) @@ -74,7 +76,10 @@ async def test_post_quote(order_book_api): "onchainOrder": False, } ) - mock_order_quote_side = OrderQuoteSide(sellAmountBeforeFee="0", kind="sell") + + mock_order_quote_side = OrderQuoteSide1( + sellAmountBeforeFee=TokenAmount("0"), kind=OrderQuoteSideKindSell.sell + ) mock_order_quote_response_data = { "quote": { "sellToken": "0x", @@ -112,17 +117,25 @@ async def test_post_quote(order_book_api): async def test_post_order(order_book_api): mock_response = "mock_uid" mock_order_creation = OrderCreation( - sellToken="0x", - buyToken="0x", - sellAmount="0", - buyAmount="0", - validTo=0, - feeAmount="0", - kind="buy", - partiallyFillable=True, - appData="0x", - signingScheme="eip712", - signature="0x", + **{ + "sellToken": "0x", + "buyToken": "0x", + "sellAmount": "0", + "buyAmount": "0", + "validTo": 0, + "feeAmount": "0", + "kind": "buy", + "partiallyFillable": True, + "appData": "0x", + "signingScheme": "eip712", + "signature": "0x", + "receiver": "0x", + "sellTokenBalance": "erc20", + "buyTokenBalance": "erc20", + "quoteId": 0, + "appDataHash": "0x", + "from_": "0x", + } ) with patch("httpx.AsyncClient.request", new_callable=AsyncMock) as mock_request: mock_request.return_value = AsyncMock( diff --git a/tests/subgraphs/deployments.py b/tests/subgraphs/deployments.py deleted file mode 100644 index 4c4bec6..0000000 --- a/tests/subgraphs/deployments.py +++ /dev/null @@ -1,44 +0,0 @@ -import pytest - -from cow_py.common.chains import Chain -from cow_py.subgraphs.deployments import ( - SUBGRAPH_BASE_URL, - SubgraphConfig, - SubgraphEnvironment, - build_subgraph_url, -) - - -def test_build_subgraph_url(): - assert ( - build_subgraph_url(Chain.MAINNET, SubgraphEnvironment.PRODUCTION) - == f"{SUBGRAPH_BASE_URL}/cow" - ) - assert ( - build_subgraph_url(Chain.MAINNET, SubgraphEnvironment.STAGING) - == f"{SUBGRAPH_BASE_URL}/cow-staging" - ) - assert ( - build_subgraph_url(Chain.GNOSIS, SubgraphEnvironment.PRODUCTION) - == f"{SUBGRAPH_BASE_URL}/cow-gc" - ) - assert ( - build_subgraph_url(Chain.GNOSIS, SubgraphEnvironment.STAGING) - == f"{SUBGRAPH_BASE_URL}/cow-gc-staging" - ) - - with pytest.raises(ValueError): - build_subgraph_url(Chain.SEPOLIA, SubgraphEnvironment.PRODUCTION) - - -def test_subgraph_config(): - mainnet_config = SubgraphConfig(Chain.MAINNET) - assert mainnet_config.production == f"{SUBGRAPH_BASE_URL}/cow" - assert mainnet_config.staging == f"{SUBGRAPH_BASE_URL}/cow-staging" - - gnosis_chain_config = SubgraphConfig(Chain.GNOSIS) - assert gnosis_chain_config.production == f"{SUBGRAPH_BASE_URL}/cow-gc" - assert gnosis_chain_config.staging == f"{SUBGRAPH_BASE_URL}/cow-gc-staging" - - with pytest.raises(ValueError): - SubgraphConfig(Chain.SEPOLIA).production From 0f4b0478c718cbba8090012fbde5cb20259089dc Mon Sep 17 00:00:00 2001 From: Pedro Yves Fracari Date: Mon, 15 Apr 2024 18:00:59 -0300 Subject: [PATCH 3/3] wip: fix cache --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c285d9a..e2c31ef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,11 @@ jobs: with: python-version: ${{ matrix.python-version }} cache: poetry + cache-dependency-path: poetry.lock + + - name: Poetry lock + run: | + poetry lock - name: Install dependencies run: |