11from typing import override
22import typing
33from 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
55from algokit_utils import AlgodClient , TransactionSigner
66from algokit_utils .algokit_utils_ffi import (
77 CommonParams ,
1313from nacl .signing import SigningKey
1414import base64
1515import 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 "
1820SEED_B64 : str = to_private_key (MN ) # type: ignore
1921SEED_BYTES = base64 .b64decode (SEED_B64 )
2022KEY = SigningKey (SEED_BYTES [:32 ])
21- ADDR = "BEMJKX676TZOOWJYMJPOMGIW4UT6S7UDTUUDCUQNKFC42TY6HVKOIWFOYA "
23+ ADDR = "ON6AOPBATSSEL47ML7EPXATHGH7INOWONHWITMQEDRPXHTMDJYMPQXROMA "
2224
2325
2426class 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
3845class 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