44import pytest
55from consensus_decentralization .helper import INTERIM_DIR
66from consensus_decentralization .aggregate import aggregate , Aggregator , divide_timeframe
7+ from consensus_decentralization .helper import get_clustering_flag , get_aggregated_data_dir_name
78
89
910@pytest .fixture
@@ -15,6 +16,8 @@ def setup_and_cleanup():
1516 """
1617 # Set up
1718 test_io_dir = INTERIM_DIR / "test_output"
19+ # Mock return value of get_clustering_flag
20+ get_clustering_flag .return_value = True
1821 yield test_io_dir
1922 # Clean up
2023 shutil .rmtree (test_io_dir )
@@ -41,7 +44,7 @@ def mock_sample_bitcoin_mapped_data(setup_and_cleanup):
4144 '{"number": "649064", "timestamp": "2020-09-20 11:17:00 UTC", "reward_addresses": "0000000000000000000000000000000000000000", "creator": "TEST2", "mapping_method": "known_identifiers"},' \
4245 '{"number": "682736", "timestamp": "2021-05-09 11:12:32 UTC", "reward_addresses": "18cBEMRxXHqzWWCxZNtU91F5sbUNKhL5PX", "creator": "ViaBTC", "mapping_method": "known_identifiers"}' \
4346 ']'
44- with open (test_bitcoin_dir / 'mapped_data .json' , 'w' ) as f :
47+ with open (test_bitcoin_dir / 'mapped_data_clustered .json' , 'w' ) as f :
4548 f .write (mapped_data )
4649 return json .loads (mapped_data )
4750
@@ -64,7 +67,7 @@ def mock_sample_ethereum_mapped_data(setup_and_cleanup):
6467 '{"number":"11184329","timestamp":"2020-11-03 12:56:41 UTC","reward_addresses":"0x8595dd9e0438640b5e1254f9df579ac12a86865f","creator":"TEST", "mapping_method": "known_identifiers"},' \
6568 '{"number":"11183793","timestamp":"2020-11-03 10:56:07 UTC","reward_addresses":"0x8595dd9e0438640b5e1254f9df579ac12a86865f","creator":"TEST", "mapping_method": "known_identifiers"}' \
6669 ']'
67- with open (test_ethereum_dir / 'mapped_data .json' , 'w' ) as f :
70+ with open (test_ethereum_dir / 'mapped_data_clustered .json' , 'w' ) as f :
6871 f .write (mapped_data )
6972
7073
@@ -81,7 +84,7 @@ def mock_sample_cardano_mapped_data(setup_and_cleanup):
8184 '{"number":"00000000000","timestamp":"2020-12-31T06:42:00","creator":"Arrakis", "mapping_method": "known_identifiers"},' \
8285 '{"number":"55555555555","timestamp":"2020-12-31T06:42:01","creator":"1percentpool", "mapping_method": "known_identifiers"}' \
8386 ']'
84- with open (test_cardano_dir / 'mapped_data .json' , 'w' ) as f :
87+ with open (test_cardano_dir / 'mapped_data_clustered .json' , 'w' ) as f :
8588 f .write (mapped_data )
8689
8790
@@ -99,7 +102,7 @@ def mock_sample_tezos_mapped_data(setup_and_cleanup):
99102 '{"number": "1650474", "timestamp": "2021-08-30 06:11:58 UTC", "reward_addresses": "tz1Vd1rXpV8hTHbFXCXN3c3qzCsgcU5BZw1e", "creator": "TEST", "mapping_method": "known_addresses"},' \
100103 '{"number": "1651794", "timestamp": "2021-08-30 17:41:08 UTC", "reward_addresses": "None", "creator": "----- UNDEFINED BLOCK PRODUCER -----", "mapping_method": "fallback_mapping"}' \
101104 ']'
102- with open (test_tezos_dir / 'mapped_data .json' , 'w' ) as f :
105+ with open (test_tezos_dir / 'mapped_data_clustered .json' , 'w' ) as f :
103106 f .write (mapped_data )
104107
105108
@@ -109,7 +112,7 @@ def test_aggregate(setup_and_cleanup, mock_sample_bitcoin_mapped_data):
109112 timeframe = (datetime .date (2010 , 1 , 1 ), datetime .date (2010 , 12 , 31 ))
110113 aggregate (project = 'sample_bitcoin' , output_dir = test_io_dir , timeframe = timeframe , estimation_window = 31 , frequency = 31 , force_aggregate = True )
111114
112- output_file = test_io_dir / ('sample_bitcoin/blocks_per_entity /31_day_window_from_2010-01-01_to_2010-12'
115+ output_file = test_io_dir / ('sample_bitcoin/blocks_per_entity_clustered /31_day_window_from_2010-01-01_to_2010-12'
113116 '-31_sampled_every_31_days.csv' )
114117 assert output_file .is_file () # there is no data from 2010 in the sample but the aggregator still creates the file when called with this timeframe
115118
@@ -119,20 +122,20 @@ def test_aggregate(setup_and_cleanup, mock_sample_bitcoin_mapped_data):
119122 aggregate (project = 'sample_bitcoin' , output_dir = test_io_dir , timeframe = timeframe , estimation_window = 30 , frequency = 30 ,
120123 force_aggregate = True )
121124
122- output_file = test_io_dir / 'sample_bitcoin/blocks_per_entity /30_day_window_from_2018-02-01_to_2018-02-28_sampled_every_30_days.csv'
125+ output_file = test_io_dir / 'sample_bitcoin/blocks_per_entity_clustered /30_day_window_from_2018-02-01_to_2018-02-28_sampled_every_30_days.csv'
123126 assert not output_file .is_file ()
124127
125128 timeframe = (datetime .date (2018 , 3 , 1 ), datetime .date (2018 , 3 , 31 ))
126129 aggregate (project = 'sample_bitcoin' , output_dir = test_io_dir , timeframe = timeframe , estimation_window = 31 , frequency = 31 ,
127130 force_aggregate = True )
128- output_file = test_io_dir / ('sample_bitcoin/blocks_per_entity /31_day_window_from_2018-03-01_to_2018-03'
131+ output_file = test_io_dir / ('sample_bitcoin/blocks_per_entity_clustered /31_day_window_from_2018-03-01_to_2018-03'
129132 '-31_sampled_every_31_days.csv' )
130133 assert output_file .is_file ()
131134
132135 timeframe = (datetime .date (2021 , 1 , 1 ), datetime .date (2021 , 12 , 31 ))
133136 aggregate (project = 'sample_bitcoin' , output_dir = test_io_dir , timeframe = timeframe , estimation_window = 31 , frequency = 31 ,
134137 force_aggregate = True )
135- output_file = test_io_dir / ('sample_bitcoin/blocks_per_entity /31_day_window_from_2021-01-01_to_2021-12'
138+ output_file = test_io_dir / ('sample_bitcoin/blocks_per_entity_clustered /31_day_window_from_2021-01-01_to_2021-12'
136139 '-31_sampled_every_31_days.csv' )
137140 assert output_file .is_file ()
138141
@@ -172,7 +175,7 @@ def test_bitcoin_aggregation(setup_and_cleanup, mock_sample_bitcoin_mapped_data)
172175 'GBMiners' : '2\n '
173176 }
174177
175- output_file = test_io_dir / ('sample_bitcoin/blocks_per_entity /30_day_window_from_2018-02-01_to_2018-03'
178+ output_file = test_io_dir / ('sample_bitcoin/blocks_per_entity_clustered /30_day_window_from_2018-02-01_to_2018-03'
176179 '-02_sampled_every_30_days.csv' )
177180 with open (output_file ) as f :
178181 for line in f .readlines ():
@@ -194,7 +197,7 @@ def test_bitcoin_aggregation(setup_and_cleanup, mock_sample_bitcoin_mapped_data)
194197 'Bitmain' : '1\n '
195198 }
196199
197- output_file = test_io_dir / ('sample_bitcoin/blocks_per_entity /all_from_2020-01-01_to_2020-12-31.csv' )
200+ output_file = test_io_dir / ('sample_bitcoin/blocks_per_entity_clustered /all_from_2020-01-01_to_2020-12-31.csv' )
198201 with open (output_file ) as f :
199202 for line in f .readlines ():
200203 col_1 , col_2 = line .split (',' )
@@ -220,7 +223,7 @@ def test_ethereum_aggregation(setup_and_cleanup, mock_sample_ethereum_mapped_dat
220223 '0x45133a7e1cc7e18555ae8a4ee632a8a61de90df6' : '1\n '
221224 }
222225
223- output_file = test_io_dir / ('sample_ethereum/blocks_per_entity /30_day_window_from_2020-11-01_to_2020-11'
226+ output_file = test_io_dir / ('sample_ethereum/blocks_per_entity_clustered /30_day_window_from_2020-11-01_to_2020-11'
224227 '-30_sampled_every_30_days.csv' )
225228 with open (output_file ) as f :
226229 for line in f .readlines ():
@@ -241,7 +244,7 @@ def test_ethereum_aggregation(setup_and_cleanup, mock_sample_ethereum_mapped_dat
241244 'MEV Builder: 0x3B...436' : '1\n '
242245 }
243246
244- output_file = test_io_dir / ('sample_ethereum/blocks_per_entity /365_day_window_from_2023-01-01_to_2023-12'
247+ output_file = test_io_dir / ('sample_ethereum/blocks_per_entity_clustered /365_day_window_from_2023-01-01_to_2023-12'
245248 '-31_sampled_every_365_days.csv' )
246249 with open (output_file ) as f :
247250 for line in f .readlines ():
@@ -270,7 +273,7 @@ def test_cardano_aggregation(setup_and_cleanup, mock_sample_cardano_mapped_data)
270273 '1percentpool' : '1\n '
271274 }
272275
273- output_file = test_io_dir / ('sample_cardano/blocks_per_entity /31_day_window_from_2020-12-01_to_2020-12'
276+ output_file = test_io_dir / ('sample_cardano/blocks_per_entity_clustered /31_day_window_from_2020-12-01_to_2020-12'
274277 '-31_sampled_every_31_days.csv' )
275278 with open (output_file ) as f :
276279 for line in f .readlines ():
@@ -298,7 +301,7 @@ def test_tezos_aggregation(setup_and_cleanup, mock_sample_tezos_mapped_data):
298301 '----- UNDEFINED BLOCK PRODUCER -----' : '1\n '
299302 }
300303
301- output_file = test_io_dir / ('sample_tezos/blocks_per_entity /31_day_window_from_2021-08-01_to_2021-08'
304+ output_file = test_io_dir / ('sample_tezos/blocks_per_entity_clustered /31_day_window_from_2021-08-01_to_2021-08'
302305 '-31_sampled_every_31_days.csv' )
303306 with open (output_file ) as f :
304307 for line in f .readlines ():
@@ -319,7 +322,7 @@ def test_tezos_aggregation(setup_and_cleanup, mock_sample_tezos_mapped_data):
319322 'tz0000000000000000000000000000000000' : '1\n '
320323 }
321324
322- output_file = test_io_dir / ('sample_tezos/blocks_per_entity /365_day_window_from_2018-01-01_to_2018-12'
325+ output_file = test_io_dir / ('sample_tezos/blocks_per_entity_clustered /365_day_window_from_2018-01-01_to_2018-12'
323326 '-31_sampled_every_365_days.csv' )
324327 with open (output_file ) as f :
325328 for line in f .readlines ():
0 commit comments