
    %j
                     `    d dl Zd dlmc mZ d dlmZ d dlm	Z	m
Z
 dddZd Zd Zd Zd	 ZdS )
    N)Account)load_hyperliquid_envdiagnose_hyperliquid_env)api_keyc                    d| d| dg}||                     d|            |                     d                    |          dz   d           d S )NHL_WALLET_ADDRESS=zHL_API_PRIVATE_KEY=zAPI Wallet Name=Hermes AgentzAPI Key=
utf-8encoding)append
write_textjoin)pathwalletprivate_keyr   liness        V/home/agent/projects/CryptoTradingBot/Crypto_Agent/tests/test_hyperliquid_env_modes.py
_write_envr      sr    %V%%+k++&E
 )))***OODIIe$$t+gO>>>>>    c                    t          j                    }t          j                    }t          j                    j        }t          | dz  ||j                                        |j                   t          d| fd          }|j        }||k    }|st          j	        d|fd||f          dt          j                    v st          j        |          rt          j        |          ndt          j        |          d	t          j                    v st          j        |          rt          j        |          nd	d
z  }dd|iz  }t          t          j        |                    d x}}|j        }d}	||	u }|st          j	        d|fd||	f          dt          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |	          dz  }
dd|
iz  }t          t          j        |                    d x}x}}	d}|j        }	||	v}|st          j	        d|fd||	f          t          j        |          dt          j                    v st          j        |          rt          j        |          ndt          j        |	          dz  }
dd|
iz  }t          t          j        |                    d x}x}}	d}|j        }	||	v }|st          j	        d|fd||	f          t          j        |          dt          j                    v st          j        |          rt          j        |          ndt          j        |	          dz  }
dd|
iz  }t          t          j        |                    d x}x}}	|j        }d}	||	u }|st          j	        d|fd||	f          dt          j                    v st          j        |          rt          j        |          ndt          j        |          t          j        |	          dz  }
dd|
iz  }t          t          j        |                    d x}x}}	d S )NzMainnet.envr   r   r   mainnetreadonlysearch_dirsvalidation_mode==z7%(py2)s
{%(py2)s = %(py0)s.account_address
} == %(py4)scfgr   py0py2py4assert %(py6)spy6Fis)zJ%(py2)s
{%(py2)s = %(py0)s.api_wallet_key_matches_private_key
} is %(py5)sr#   r$   py5assert %(py7)spy7api_key_private_key_mismatch)not in)z2%(py1)s not in %(py5)s
{%(py5)s = %(py3)s.errors
}py1py3r+   in)z0%(py1)s in %(py5)s
{%(py5)s = %(py3)s.warnings
}Tz9%(py2)s
{%(py2)s = %(py0)s.safe_for_readonly
} is %(py5)s)r   createaddressr   keyhexr   account_address
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanation"api_wallet_key_matches_private_keyerrorswarningssafe_for_readonly)tmp_pathsignerstale_api_keyr   r!   @py_assert1@py_assert3@py_format5@py_format7@py_assert4@py_format6@py_format8@py_assert0@py_assert2s                 r   5test_readonly_mode_allows_api_key_mismatch_as_warningrS      s   ^FN$$M^%Fx-'FJNNDTDT^k^stttt
yxkS]
^
^
^C(&((((((((((&((((((((((((3(((((3(((((((((((((((((&(((((&(((((((((((((((((((((((((((1:U:1U::::::::::1U::::::::::::3:::::3::::::1::::U:::::::::::::::::::::::::::);;);;;;;;;;;;);;;;;);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;)9S\9)\9999999999)\99999)99999999999S99999S999999\999999999999999999999999999 (D( D(((((((((( D((((((((((((3(((((3(((((( ((((D(((((((((((((((((((((((((((((r   c                 
   t          j                    }t          j                    }t          j                    j        }t          | dz  ||j                                        |j                   t          d| fdd          }d}|j        }||v }|st          j	        d|fd	||f          t          j
        |          d
t          j                    v st          j        |          rt          j
        |          nd
t          j
        |          dz  }dd|iz  }	t          t          j        |	                    d x}x}}|j        }
d}|
|u }|st          j	        d|fd|
|f          d
t          j                    v st          j        |          rt          j
        |          nd
t          j
        |
          t          j
        |          dz  }dd|iz  }	t          t          j        |	                    d x}
x}}d S )NTestnet.envr   testnetsignedT)r   r   allow_errorsr.   r3   )z.%(py1)s in %(py5)s
{%(py5)s = %(py3)s.errors
}r!   r0   r,   r-   Fr(   )zB%(py2)s
{%(py2)s = %(py0)s.safe_to_run_testnet_smokes
} is %(py5)sr*   )r   r6   r7   r   r8   r9   r   rD   r;   r<   r@   r=   r>   r?   rA   rB   safe_to_run_testnet_smokes)rG   rH   rI   r   r!   rQ   rN   rR   rO   rP   rJ   rK   s               r   7test_signed_mode_still_fails_closed_on_api_key_mismatchrZ       s9   ^FN$$M^%Fx-'FJNNDTDT^k^stttt
yxkS[jn
o
o
oC)7SZ7)Z7777777777)Z77777)77777777777S77777S777777Z777777777777777777777777777)2U2)U2222222222)U2222222222223222223222222)2222U22222222222222222222222222222r   c                 
   t          j                    j        }| dz                      d| dd           t	          d| fd          }|j        }||k    }|st          j        d	|fd
||f          dt          j	                    v st          j
        |          rt          j        |          ndt          j        |          dt          j	                    v st          j
        |          rt          j        |          nddz  }dd|iz  }t          t          j        |                    d x}}|j        }d }||u }|st          j        d|fd||f          dt          j	                    v st          j
        |          rt          j        |          ndt          j        |          t          j        |          dz  }dd|iz  }	t          t          j        |	                    d x}x}}|j        }d }||u }|st          j        d|fd||f          dt          j	                    v st          j
        |          rt          j        |          ndt          j        |          t          j        |          dz  }dd|iz  }	t          t          j        |	                    d x}x}}|j        }d}||u }|st          j        d|fd||f          dt          j	                    v st          j
        |          rt          j        |          ndt          j        |          t          j        |          dz  }dd|iz  }	t          t          j        |	                    d x}x}}|                                d         }
d }|
|u }|slt          j        d|fd|
|f          t          j        |
          t          j        |          dz  }dd|iz  }t          t          j        |                    d x}
x}}d S )NrU   r   r	   r
   r   rV   r   r   r   r    r!   r   r"   r&   r'   r(   )z7%(py2)s
{%(py2)s = %(py0)s.api_private_key
} is %(py5)sr*   r,   r-   )zB%(py2)s
{%(py2)s = %(py0)s.api_wallet_address_derived
} is %(py5)sTr5   credential_warningz%(py1)s is %(py4)sr1   r%   )r   r6   r7   r   r   r:   r;   r<   r=   r>   r?   r@   rA   rB   api_private_keyapi_wallet_address_derivedrF   masked)rG   r   r!   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   s               r   /test_readonly_mode_requires_only_wallet_addressrb   ,   s   ^%F))*Iv*I*I*IT[)\\\
yxkS]
^
^
^C(&((((((((((&((((((((((((3(((((3(((((((((((((((((&(((((&(((((((((((((((((((((((((((&$&$&&&&&&&&&&$&&&&&&&&&&&&3&&&&&3&&&&&&&&&&$&&&&&&&&&&&&&&&&&&&&&&&&&&&)1T1)T1111111111)T1111111111113111113111111)1111T111111111111111111111111111 (D( D(((((((((( D((((((((((((3(((((3(((((( ((((D(((((((((((((((((((((((((((::<<,-55-5555555555-55555-555555555555555555555555555555555r   c                 R   t          j                    }t          j                    }t          j                    j        }t          | dz  ||j                                        |j                   t          d| fd          }|d         }|j        }d} ||          }|ssdt          j	        |          t          j	        |          t          j	        |          t          j	        |          dz  }	t          t          j        |	                    d x}x}x}}|d	         }d
}
||
k    }|slt          j        d|fd||
f          t          j	        |          t          j	        |
          dz  }dd|iz  }t          t          j        |                    d x}x}}
|d         }g }
||
k    }|slt          j        d|fd||
f          t          j	        |          t          j	        |
          dz  }dd|iz  }t          t          j        |                    d x}x}}
|d         }d}
||
u }|slt          j        d|fd||
f          t          j	        |          t          j	        |
          dz  }dd|iz  }t          t          j        |                    d x}x}}
d S )NrU   r   rV   r   r   env_file_pathzJassert %(py7)s
{%(py7)s = %(py3)s
{%(py3)s = %(py1)s.endswith
}(%(py5)s)
})r1   r2   r+   r-   r\   r.   r   )z%(py1)s == %(py4)sr^   r&   r'   rD   rF   Tr(   r]   )r   r6   r7   r   r8   r9   r   endswithr;   r@   rA   rB   r<   )rG   rH   rI   r   diagrQ   rR   rN   @py_assert6rP   rK   rL   rM   s                r   6test_diagnose_reports_validation_mode_readonly_warningrh   9   s   ^FN$$M^%Fx-'FJNNDTDT^k^stttt#IH;XbcccD 8 )8-8))-88888888 8888)8888-8888888888888888888888888888$%G)GG%)GGGGGGGGGGG%)GGGGGG%GGGG)GGGGGGGGGGGGGGGGGGGGGGGGGGGG>R>R>R>R#$,,$,,,,,,,,,,$,,,,,$,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,r   )builtinsr=   _pytest.assertion.rewrite	assertionrewriter;   eth_accountr   src.config.hyperliquid_envr   r   r   rS   rZ   rb   rh    r   r   <module>rp      s                        U U U U U U U U 6: ? ? ? ? ?) ) )	3 	3 	3
6 
6 
6- - - - -r   