1- import os
21from unittest .mock import MagicMock , patch , AsyncMock
32
43import pytest as pytest
109 ForgetMessage ,
1110)
1211
12+ from aleph_client .types import StorageEnum , MessageStatus
13+
1314from aleph_client .asynchronous import (
1415 create_post ,
1516 _get_fallback_session ,
1819 create_program ,
1920 forget ,
2021)
21- from aleph_client .chains .common import get_fallback_private_key , delete_private_key_file
22- from aleph_client .chains .ethereum import ETHAccount
23- from aleph_client .conf import settings
24- from aleph_client .types import StorageEnum , MessageStatus
2522
2623
2724def new_mock_session_with_post_success ():
@@ -41,21 +38,15 @@ def new_mock_session_with_post_success():
4138
4239
4340@pytest .mark .asyncio
44- async def test_create_post ():
41+ async def test_create_post (ethereum_account ):
4542 _get_fallback_session .cache_clear ()
4643
47- if os .path .exists (settings .PRIVATE_KEY_FILE ):
48- delete_private_key_file ()
49-
50- private_key = get_fallback_private_key ()
51- account : ETHAccount = ETHAccount (private_key = private_key )
52-
5344 content = {"Hello" : "World" }
5445
5546 mock_session = new_mock_session_with_post_success ()
5647
5748 post_message , message_status = await create_post (
58- account = account ,
49+ account = ethereum_account ,
5950 post_content = content ,
6051 post_type = "TEST" ,
6152 channel = "TEST" ,
@@ -70,29 +61,23 @@ async def test_create_post():
7061
7162
7263@pytest .mark .asyncio
73- async def test_create_aggregate ():
64+ async def test_create_aggregate (ethereum_account ):
7465 _get_fallback_session .cache_clear ()
7566
76- if os .path .exists (settings .PRIVATE_KEY_FILE ):
77- delete_private_key_file ()
78-
79- private_key = get_fallback_private_key ()
80- account : ETHAccount = ETHAccount (private_key = private_key )
81-
8267 content = {"Hello" : "World" }
8368
8469 mock_session = new_mock_session_with_post_success ()
8570
8671 _ = await create_aggregate (
87- account = account ,
72+ account = ethereum_account ,
8873 key = "hello" ,
8974 content = content ,
9075 channel = "TEST" ,
9176 session = mock_session ,
9277 )
9378
9479 aggregate_message , message_status = await create_aggregate (
95- account = account ,
80+ account = ethereum_account ,
9681 key = "hello" ,
9782 content = "world" ,
9883 channel = "TEST" ,
@@ -105,23 +90,17 @@ async def test_create_aggregate():
10590
10691
10792@pytest .mark .asyncio
108- async def test_create_store ():
93+ async def test_create_store (ethereum_account ):
10994 _get_fallback_session .cache_clear ()
11095
111- if os .path .exists (settings .PRIVATE_KEY_FILE ):
112- delete_private_key_file ()
113-
114- private_key = get_fallback_private_key ()
115- account : ETHAccount = ETHAccount (private_key = private_key )
116-
11796 mock_session = new_mock_session_with_post_success ()
11897
11998 mock_ipfs_push_file = AsyncMock ()
12099 mock_ipfs_push_file .return_value = "QmRTV3h1jLcACW4FRfdisokkQAk4E4qDhUzGpgdrd4JAFy"
121100
122101 with patch ("aleph_client.asynchronous.ipfs_push_file" , mock_ipfs_push_file ):
123102 _ = await create_store (
124- account = account ,
103+ account = ethereum_account ,
125104 file_content = b"HELLO" ,
126105 channel = "TEST" ,
127106 storage_engine = StorageEnum .ipfs ,
@@ -130,7 +109,7 @@ async def test_create_store():
130109 )
131110
132111 _ = await create_store (
133- account = account ,
112+ account = ethereum_account ,
134113 file_hash = "QmRTV3h1jLcACW4FRfdisokkQAk4E4qDhUzGpgdrd4JAFy" ,
135114 channel = "TEST" ,
136115 storage_engine = StorageEnum .ipfs ,
@@ -144,8 +123,9 @@ async def test_create_store():
144123 )
145124
146125 with patch ("aleph_client.asynchronous.storage_push_file" , mock_storage_push_file ):
126+
147127 store_message , message_status = await create_store (
148- account = account ,
128+ account = ethereum_account ,
149129 file_content = b"HELLO" ,
150130 channel = "TEST" ,
151131 storage_engine = StorageEnum .storage ,
@@ -158,19 +138,13 @@ async def test_create_store():
158138
159139
160140@pytest .mark .asyncio
161- async def test_create_program ():
141+ async def test_create_program (ethereum_account ):
162142 _get_fallback_session .cache_clear ()
163143
164- if os .path .exists (settings .PRIVATE_KEY_FILE ):
165- delete_private_key_file ()
166-
167- private_key = get_fallback_private_key ()
168- account : ETHAccount = ETHAccount (private_key = private_key )
169-
170144 mock_session = new_mock_session_with_post_success ()
171145
172146 program_message , message_status = await create_program (
173- account = account ,
147+ account = ethereum_account ,
174148 program_ref = "FAKE-HASH" ,
175149 entrypoint = "main:app" ,
176150 runtime = "FAKE-HASH" ,
@@ -184,19 +158,13 @@ async def test_create_program():
184158
185159
186160@pytest .mark .asyncio
187- async def test_forget ():
161+ async def test_forget (ethereum_account ):
188162 _get_fallback_session .cache_clear ()
189163
190- if os .path .exists (settings .PRIVATE_KEY_FILE ):
191- delete_private_key_file ()
192-
193- private_key = get_fallback_private_key ()
194- account : ETHAccount = ETHAccount (private_key = private_key )
195-
196164 mock_session = new_mock_session_with_post_success ()
197165
198166 forget_message , message_status = await forget (
199- account = account ,
167+ account = ethereum_account ,
200168 hashes = ["QmRTV3h1jLcACW4FRfdisokkQAk4E4qDhUzGpgdrd4JAFy" ],
201169 reason = "GDPR" ,
202170 channel = "TEST" ,
0 commit comments