Skip to content

Commit 3aa6d3b

Browse files
committed
wip: working http calls and signing (w/ serialize error)
1 parent b151b71 commit 3aa6d3b

File tree

3 files changed

+63
-16
lines changed

3 files changed

+63
-16
lines changed

packages/python/algokit_utils/poetry.lock

Lines changed: 21 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/python/algokit_utils/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ patchelf = { version = "^0.17.2.2", markers = "sys_platform == 'linux'" }
3838
[tool.poetry.group.dev.dependencies]
3939
algosdk = "^2.7.0"
4040
pytest = "^8.4.1"
41+
requests = "^2.32.5"
42+
types-requests = "^2.32.4.20250809"
4143

packages/python/algokit_utils/tests/test_utils.py

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import override
22
import typing
33
from algokit_utils.algokit_http_client import HttpClient, HttpMethod, HttpResponse
4-
from algokit_utils.algokit_transact_ffi import SignedTransaction, Transaction
4+
from algokit_utils.algokit_transact_ffi import SignedTransaction, Transaction, encode_transaction
55
from algokit_utils import AlgodClient, TransactionSigner
66
from algokit_utils.algokit_utils_ffi import (
77
CommonParams,
@@ -13,26 +13,33 @@
1313
from nacl.signing import SigningKey
1414
import base64
1515
import pytest
16+
import requests
17+
import msgpack
1618

17-
MN = "limb estate enhance elegant merry worry spell trophy elegant lab truly step enter destroy split leave beach chalk slight they ignore square tower abandon rough"
19+
MN = "gas net tragic valid celery want good neglect maid nuclear core false chunk place asthma three acoustic moon box million finish bargain onion ability shallow"
1820
SEED_B64: str = to_private_key(MN) # type: ignore
1921
SEED_BYTES = base64.b64decode(SEED_B64)
2022
KEY = SigningKey(SEED_BYTES[:32])
21-
ADDR = "BEMJKX676TZOOWJYMJPOMGIW4UT6S7UDTUUDCUQNKFC42TY6HVKOIWFOYA"
23+
ADDR = "ON6AOPBATSSEL47ML7EPXATHGH7INOWONHWITMQEDRPXHTMDJYMPQXROMA"
2224

2325

2426
class TestSigner(TransactionSigner):
2527
@override
26-
def sign_transactions( # type: ignore
28+
async def sign_transactions( # type: ignore
2729
self, transactions: list[Transaction], indices: list[int]
2830
) -> list[SignedTransaction]:
29-
print("Signing transactions")
30-
return []
31+
stxns = []
32+
for transaction in transactions:
33+
tx_for_signing = encode_transaction(transaction)
34+
sig = KEY.sign(tx_for_signing)
35+
stxns.append(SignedTransaction(transaction=transaction, signature=sig.signature))
36+
37+
return stxns
3138

3239
@override
33-
def sign_transaction(self, transaction: Transaction) -> SignedTransaction: # type: ignore
40+
async def sign_transaction(self, transaction: Transaction) -> SignedTransaction: # type: ignore
3441
print("Signing single transaction")
35-
return self.sign_transactions([transaction], [0])[0]
42+
return (await self.sign_transactions([transaction], [0]))[0]
3643

3744

3845
class SignerGetter(TransactionSignerGetter):
@@ -53,7 +60,29 @@ async def request( # type: ignore
5360
headers: typing.Optional[dict[str, str]],
5461
) -> HttpResponse:
5562
print(f"HTTP {method} {path} {query} {headers}")
56-
return HttpResponse(body=b"", headers={})
63+
64+
headers = headers or {}
65+
headers["X-Algo-API-Token"] = "a" * 64
66+
67+
if method == HttpMethod.GET:
68+
res = requests.get(f"http://localhost:4001/{path}", params=query, headers=headers)
69+
elif method == HttpMethod.POST:
70+
res = requests.post(f"http://localhost:4001/{path}", params=query, data=body, headers=headers)
71+
else:
72+
raise NotImplementedError(f"HTTP method {method} not implemented in test client")
73+
74+
if res.status_code != 200:
75+
raise Exception(f"HTTP request failed: {res.status_code} {res.text}")
76+
77+
if res.headers.get("Content-Type") == "application/msgpack":
78+
print(msgpack.unpackb(res.content, raw=False, strict_map_key=False))
79+
else:
80+
print(res.text)
81+
82+
return HttpResponse(
83+
body=res.content,
84+
headers=res.headers # type: ignore
85+
)
5786

5887

5988
@pytest.mark.asyncio
@@ -77,4 +106,5 @@ async def test_composer():
77106
)
78107
)
79108

80-
await composer.build() # <-- Error here
109+
await composer.build()
110+
await composer.send()

0 commit comments

Comments
 (0)