genlayer-test 1.0.0__py3-none-any.whl → 2.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,432 @@
1
+ def test_leader_only_network_config_true(pytester):
2
+ pytester.makepyfile(
3
+ """
4
+ from gltest_cli.config.general import get_general_config
5
+
6
+ def test_leader_only_network_config():
7
+ general_config = get_general_config()
8
+ assert general_config.get_leader_only() == True
9
+ """
10
+ )
11
+
12
+ config_content = """
13
+ networks:
14
+ default: localnet
15
+ localnet:
16
+ url: "http://127.0.0.1:4000/api"
17
+ leader_only: true
18
+
19
+ paths:
20
+ contracts: "contracts"
21
+
22
+ environment: .env
23
+ """
24
+
25
+ pytester.makefile(".config.yaml", **{"gltest": config_content})
26
+
27
+ result = pytester.runpytest("-v")
28
+
29
+ result.stdout.fnmatch_lines(
30
+ [
31
+ "*::test_leader_only_network_config PASSED*",
32
+ ]
33
+ )
34
+ assert result.ret == 0
35
+
36
+
37
+ def test_leader_only_network_config_false(pytester):
38
+ pytester.makepyfile(
39
+ """
40
+ from gltest_cli.config.general import get_general_config
41
+
42
+ def test_leader_only_network_config():
43
+ general_config = get_general_config()
44
+ assert general_config.get_leader_only() == False
45
+ """
46
+ )
47
+
48
+ config_content = """
49
+ networks:
50
+ default: localnet
51
+ localnet:
52
+ url: "http://127.0.0.1:4000/api"
53
+ leader_only: false
54
+
55
+ paths:
56
+ contracts: "contracts"
57
+
58
+ environment: .env
59
+ """
60
+
61
+ pytester.makefile(".config.yaml", **{"gltest": config_content})
62
+
63
+ result = pytester.runpytest("-v")
64
+
65
+ result.stdout.fnmatch_lines(
66
+ [
67
+ "*::test_leader_only_network_config PASSED*",
68
+ ]
69
+ )
70
+ assert result.ret == 0
71
+
72
+
73
+ def test_leader_only_cli_overrides_network_config(pytester):
74
+ pytester.makepyfile(
75
+ """
76
+ from gltest_cli.config.general import get_general_config
77
+
78
+ def test_leader_only_cli_overrides():
79
+ general_config = get_general_config()
80
+ assert general_config.get_leader_only() == True
81
+ """
82
+ )
83
+
84
+ config_content = """
85
+ networks:
86
+ default: localnet
87
+ localnet:
88
+ url: "http://127.0.0.1:4000/api"
89
+ leader_only: false
90
+
91
+ paths:
92
+ contracts: "contracts"
93
+
94
+ environment: .env
95
+ """
96
+
97
+ pytester.makefile(".config.yaml", **{"gltest": config_content})
98
+
99
+ # CLI flag should override network config
100
+ result = pytester.runpytest("--leader-only", "-v")
101
+
102
+ result.stdout.fnmatch_lines(
103
+ [
104
+ "*::test_leader_only_cli_overrides PASSED*",
105
+ ]
106
+ )
107
+ assert result.ret == 0
108
+
109
+
110
+ def test_leader_only_network_config_default(pytester):
111
+ pytester.makepyfile(
112
+ """
113
+ from gltest_cli.config.general import get_general_config
114
+
115
+ def test_leader_only_network_config_default():
116
+ general_config = get_general_config()
117
+ assert general_config.get_leader_only() == False
118
+ """
119
+ )
120
+
121
+ config_content = """
122
+ networks:
123
+ default: localnet
124
+ localnet:
125
+ url: "http://127.0.0.1:4000/api"
126
+
127
+ paths:
128
+ contracts: "contracts"
129
+
130
+ environment: .env
131
+ """
132
+
133
+ pytester.makefile(".config.yaml", **{"gltest": config_content})
134
+
135
+ result = pytester.runpytest("-v")
136
+ result.stdout.fnmatch_lines(
137
+ [
138
+ "*::test_leader_only_network_config_default PASSED*",
139
+ ]
140
+ )
141
+ assert result.ret == 0
142
+
143
+
144
+ def test_custom_accounts_config(pytester):
145
+ """Test custom accounts configuration."""
146
+ pytester.makepyfile(
147
+ """
148
+ from gltest_cli.config.general import get_general_config
149
+
150
+ def test_custom_accounts():
151
+ general_config = get_general_config()
152
+ accounts = general_config.get_accounts_keys()
153
+ assert len(accounts) == 3
154
+ assert accounts[0] == "account1_private_key"
155
+ assert accounts[1] == "account2_private_key"
156
+ assert accounts[2] == "account3_private_key"
157
+ from_account = general_config.get_default_account_key()
158
+ assert from_account == "account1_private_key"
159
+ """
160
+ )
161
+
162
+ config_content = """
163
+ networks:
164
+ default: localnet
165
+ localnet:
166
+ url: "http://127.0.0.1:4000/api"
167
+ accounts:
168
+ - "account1_private_key"
169
+ - "account2_private_key"
170
+ - "account3_private_key"
171
+
172
+ paths:
173
+ contracts: "contracts"
174
+
175
+ environment: .env
176
+ """
177
+
178
+ pytester.makefile(".config.yaml", **{"gltest": config_content})
179
+
180
+ result = pytester.runpytest("-v")
181
+ result.stdout.fnmatch_lines(
182
+ [
183
+ "*::test_custom_accounts PASSED*",
184
+ ]
185
+ )
186
+ assert result.ret == 0
187
+
188
+
189
+ def test_from_account_config(pytester):
190
+ """Test 'from' account configuration."""
191
+ pytester.makepyfile(
192
+ """
193
+ from gltest_cli.config.general import get_general_config
194
+
195
+ def test_from_account():
196
+ general_config = get_general_config()
197
+ from_account = general_config.get_default_account_key()
198
+ assert from_account == "account2_private_key"
199
+ """
200
+ )
201
+
202
+ config_content = """
203
+ networks:
204
+ default: localnet
205
+ localnet:
206
+ url: "http://127.0.0.1:4000/api"
207
+ accounts:
208
+ - "account1_private_key"
209
+ - "account2_private_key"
210
+ - "account3_private_key"
211
+ from: "account2_private_key"
212
+
213
+ paths:
214
+ contracts: "contracts"
215
+
216
+ environment: .env
217
+ """
218
+
219
+ pytester.makefile(".config.yaml", **{"gltest": config_content})
220
+
221
+ result = pytester.runpytest("-v")
222
+ result.stdout.fnmatch_lines(
223
+ [
224
+ "*::test_from_account PASSED*",
225
+ ]
226
+ )
227
+ assert result.ret == 0
228
+
229
+
230
+ def test_multiple_networks_config(pytester):
231
+ """Test multiple networks configuration."""
232
+ pytester.makepyfile(
233
+ """
234
+ from gltest_cli.config.general import get_general_config
235
+
236
+ def test_multiple_networks():
237
+ general_config = get_general_config()
238
+ # Default should be testnet
239
+ assert general_config.get_network_name() == "testnet"
240
+ rpc_url = general_config.get_rpc_url()
241
+ assert rpc_url == "https://testnet.example.com"
242
+ """
243
+ )
244
+
245
+ config_content = """
246
+ networks:
247
+ default: testnet
248
+ localnet:
249
+ id: 61999
250
+ url: "http://127.0.0.1:4000/api"
251
+ accounts:
252
+ - "local_account1"
253
+ - "local_account2"
254
+ testnet:
255
+ id: 5555
256
+ url: "https://testnet.example.com"
257
+ accounts:
258
+ - "testnet_account1"
259
+ - "testnet_account2"
260
+ leader_only: true
261
+
262
+ paths:
263
+ contracts: "contracts"
264
+
265
+ environment: .env
266
+ """
267
+
268
+ pytester.makefile(".config.yaml", **{"gltest": config_content})
269
+
270
+ result = pytester.runpytest("-v")
271
+ result.stdout.fnmatch_lines(
272
+ [
273
+ "*::test_multiple_networks PASSED*",
274
+ ]
275
+ )
276
+ assert result.ret == 0
277
+
278
+
279
+ def test_custom_paths_config(pytester):
280
+ """Test custom paths configuration."""
281
+ pytester.makepyfile(
282
+ """
283
+ from gltest_cli.config.general import get_general_config
284
+ from pathlib import Path
285
+
286
+ def test_custom_paths():
287
+ general_config = get_general_config()
288
+ assert general_config.get_contracts_dir() == Path("src/contracts")
289
+ assert general_config.get_artifacts_dir() == Path("build/artifacts")
290
+ """
291
+ )
292
+
293
+ config_content = """
294
+ networks:
295
+ default: localnet
296
+ localnet:
297
+ url: "http://127.0.0.1:4000/api"
298
+
299
+ paths:
300
+ contracts: "src/contracts"
301
+ artifacts: "build/artifacts"
302
+
303
+ environment: .env
304
+ """
305
+
306
+ pytester.makefile(".config.yaml", **{"gltest": config_content})
307
+
308
+ result = pytester.runpytest("-v")
309
+ result.stdout.fnmatch_lines(
310
+ [
311
+ "*::test_custom_paths PASSED*",
312
+ ]
313
+ )
314
+ assert result.ret == 0
315
+
316
+
317
+ def test_custom_environment_file(pytester):
318
+ """Test custom environment file configuration."""
319
+ pytester.makepyfile(
320
+ """
321
+ from gltest_cli.config.general import get_general_config
322
+
323
+ def test_custom_environment():
324
+ general_config = get_general_config()
325
+ assert general_config.user_config.environment == ".env.test"
326
+ """
327
+ )
328
+
329
+ config_content = """
330
+ networks:
331
+ default: localnet
332
+ localnet:
333
+ url: "http://127.0.0.1:4000/api"
334
+
335
+ paths:
336
+ contracts: "contracts"
337
+
338
+ environment: .env.test
339
+ """
340
+
341
+ pytester.makefile(".config.yaml", **{"gltest": config_content})
342
+
343
+ result = pytester.runpytest("-v")
344
+ result.stdout.fnmatch_lines(
345
+ [
346
+ "*::test_custom_environment PASSED*",
347
+ ]
348
+ )
349
+ assert result.ret == 0
350
+
351
+
352
+ def test_cli_network_override(pytester):
353
+ """Test CLI network override of config file."""
354
+ pytester.makepyfile(
355
+ """
356
+ from gltest_cli.config.general import get_general_config
357
+
358
+ def test_network_override():
359
+ general_config = get_general_config()
360
+ assert general_config.get_network_name() == "testnet"
361
+ rpc_url = general_config.get_rpc_url()
362
+ assert rpc_url == "https://testnet.example.com"
363
+ """
364
+ )
365
+
366
+ config_content = """
367
+ networks:
368
+ default: localnet
369
+ localnet:
370
+ id: 61999
371
+ url: "http://127.0.0.1:4000/api"
372
+ accounts:
373
+ - "local_account1"
374
+ testnet:
375
+ id: 5555
376
+ url: "https://testnet.example.com"
377
+ accounts:
378
+ - "testnet_account1"
379
+
380
+ paths:
381
+ contracts: "contracts"
382
+
383
+ environment: .env
384
+ """
385
+
386
+ pytester.makefile(".config.yaml", **{"gltest": config_content})
387
+
388
+ result = pytester.runpytest("--network=testnet", "-v")
389
+ result.stdout.fnmatch_lines(
390
+ [
391
+ "*::test_network_override PASSED*",
392
+ ]
393
+ )
394
+ assert result.ret == 0
395
+
396
+
397
+ def test_wait_interval_and_retries_config(pytester):
398
+ """Test default wait interval and retries from CLI."""
399
+ pytester.makepyfile(
400
+ """
401
+ from gltest_cli.config.general import get_general_config
402
+
403
+ def test_wait_config():
404
+ general_config = get_general_config()
405
+ assert general_config.get_default_wait_interval() == 3000
406
+ assert general_config.get_default_wait_retries() == 20
407
+ """
408
+ )
409
+
410
+ config_content = """
411
+ networks:
412
+ default: localnet
413
+ localnet:
414
+ url: "http://127.0.0.1:4000/api"
415
+
416
+ paths:
417
+ contracts: "contracts"
418
+
419
+ environment: .env
420
+ """
421
+
422
+ pytester.makefile(".config.yaml", **{"gltest": config_content})
423
+
424
+ result = pytester.runpytest(
425
+ "--default-wait-interval=3000", "--default-wait-retries=20", "-v"
426
+ )
427
+ result.stdout.fnmatch_lines(
428
+ [
429
+ "*::test_wait_config PASSED*",
430
+ ]
431
+ )
432
+ assert result.ret == 0
@@ -147,3 +147,260 @@ def test_general_config_contracts_default():
147
147
 
148
148
  # Should return default contracts directory
149
149
  assert general_config.get_contracts_dir() == DEFAULT_CONTRACTS_DIR
150
+
151
+
152
+ def test_general_config_leader_only_default():
153
+ """Test GeneralConfig leader_only with default values."""
154
+ user_config = UserConfig(
155
+ networks={"localnet": NetworkConfigData()},
156
+ )
157
+
158
+ plugin_config = PluginConfig()
159
+ general_config = GeneralConfig(user_config=user_config, plugin_config=plugin_config)
160
+
161
+ # Should return False by default
162
+ assert general_config.get_leader_only() is False
163
+
164
+
165
+ def test_general_config_leader_only_network_config():
166
+ """Test GeneralConfig leader_only from network configuration."""
167
+ user_config = UserConfig(
168
+ networks={"localnet": NetworkConfigData(leader_only=True)},
169
+ default_network="localnet",
170
+ )
171
+
172
+ plugin_config = PluginConfig()
173
+ general_config = GeneralConfig(user_config=user_config, plugin_config=plugin_config)
174
+
175
+ # Should return True from network config
176
+ assert general_config.get_leader_only() is True
177
+
178
+
179
+ def test_general_config_leader_only_plugin_precedence():
180
+ """Test that plugin config takes precedence over network config for leader_only."""
181
+ user_config = UserConfig(
182
+ networks={"localnet": NetworkConfigData(leader_only=False)},
183
+ default_network="localnet",
184
+ )
185
+
186
+ plugin_config = PluginConfig(leader_only=True)
187
+ general_config = GeneralConfig(user_config=user_config, plugin_config=plugin_config)
188
+
189
+ # Plugin config should take precedence
190
+ assert general_config.get_leader_only() is True
191
+
192
+
193
+ def test_general_config_leader_only_multiple_networks():
194
+ """Test leader_only with multiple networks."""
195
+ user_config = UserConfig(
196
+ networks={
197
+ "localnet": NetworkConfigData(leader_only=False),
198
+ "testnet": NetworkConfigData(leader_only=True),
199
+ },
200
+ default_network="testnet",
201
+ )
202
+
203
+ plugin_config = PluginConfig()
204
+ general_config = GeneralConfig(user_config=user_config, plugin_config=plugin_config)
205
+
206
+ # Should use the default network's leader_only value
207
+ assert general_config.get_leader_only() is True
208
+
209
+ # Change network via plugin config
210
+ plugin_config.network_name = "localnet"
211
+ general_config = GeneralConfig(user_config=user_config, plugin_config=plugin_config)
212
+ assert general_config.get_leader_only() is False
213
+
214
+
215
+ def test_general_config_leader_only_network_not_found():
216
+ """Test leader_only when selected network is not found."""
217
+ user_config = UserConfig(
218
+ networks={"localnet": NetworkConfigData(leader_only=True)},
219
+ default_network="localnet",
220
+ )
221
+
222
+ plugin_config = PluginConfig(network_name="nonexistent")
223
+ general_config = GeneralConfig(user_config=user_config, plugin_config=plugin_config)
224
+
225
+ # Should return False when network is not found
226
+ assert general_config.get_leader_only() is False
227
+
228
+
229
+ def test_check_local_rpc_with_localhost():
230
+ """Test check_local_rpc with localhost URL."""
231
+ user_config = UserConfig(
232
+ networks={"localnet": NetworkConfigData(url="http://localhost:8545")},
233
+ default_network="localnet",
234
+ )
235
+
236
+ plugin_config = PluginConfig()
237
+ general_config = GeneralConfig(user_config=user_config, plugin_config=plugin_config)
238
+
239
+ assert general_config.check_local_rpc() is True
240
+
241
+
242
+ def test_check_local_rpc_with_127_0_0_1():
243
+ """Test check_local_rpc with 127.0.0.1 URL."""
244
+ user_config = UserConfig(
245
+ networks={"localnet": NetworkConfigData(url="http://127.0.0.1:8545")},
246
+ default_network="localnet",
247
+ )
248
+
249
+ plugin_config = PluginConfig()
250
+ general_config = GeneralConfig(user_config=user_config, plugin_config=plugin_config)
251
+
252
+ assert general_config.check_local_rpc() is True
253
+
254
+
255
+ def test_check_local_rpc_with_external_url():
256
+ """Test check_local_rpc with external URL."""
257
+ user_config = UserConfig(
258
+ networks={"testnet": NetworkConfigData(url="https://api.genlayer.com:8545")},
259
+ default_network="testnet",
260
+ )
261
+
262
+ plugin_config = PluginConfig()
263
+ general_config = GeneralConfig(user_config=user_config, plugin_config=plugin_config)
264
+
265
+ assert general_config.check_local_rpc() is False
266
+
267
+
268
+ def test_check_local_rpc_with_plugin_override():
269
+ """Test check_local_rpc with plugin config RPC URL override."""
270
+ user_config = UserConfig(
271
+ networks={"localnet": NetworkConfigData(url="https://external.com")},
272
+ default_network="localnet",
273
+ )
274
+
275
+ plugin_config = PluginConfig(rpc_url="http://localhost:9000")
276
+ general_config = GeneralConfig(user_config=user_config, plugin_config=plugin_config)
277
+
278
+ # Plugin config should take precedence
279
+ assert general_config.check_local_rpc() is True
280
+
281
+
282
+ def test_check_studio_based_rpc_with_localhost():
283
+ """Test check_studio_based_rpc with localhost URL."""
284
+ user_config = UserConfig(
285
+ networks={"localnet": NetworkConfigData(url="http://localhost:8545")},
286
+ default_network="localnet",
287
+ )
288
+
289
+ plugin_config = PluginConfig()
290
+ general_config = GeneralConfig(user_config=user_config, plugin_config=plugin_config)
291
+
292
+ assert general_config.check_studio_based_rpc() is True
293
+
294
+
295
+ def test_check_studio_based_rpc_with_127_0_0_1():
296
+ """Test check_studio_based_rpc with 127.0.0.1 URL."""
297
+ user_config = UserConfig(
298
+ networks={"localnet": NetworkConfigData(url="http://127.0.0.1:8545")},
299
+ default_network="localnet",
300
+ )
301
+
302
+ plugin_config = PluginConfig()
303
+ general_config = GeneralConfig(user_config=user_config, plugin_config=plugin_config)
304
+
305
+ assert general_config.check_studio_based_rpc() is True
306
+
307
+
308
+ def test_check_studio_based_rpc_with_genlayer_subdomain():
309
+ """Test check_studio_based_rpc with .genlayer.com subdomains."""
310
+ test_cases = [
311
+ "https://api.genlayer.com:8545",
312
+ "https://test.genlayer.com",
313
+ "http://staging.api.genlayer.com:9000",
314
+ "https://dev.test.genlayer.com",
315
+ ]
316
+
317
+ for url in test_cases:
318
+ user_config = UserConfig(
319
+ networks={"testnet": NetworkConfigData(url=url)},
320
+ default_network="testnet",
321
+ )
322
+
323
+ plugin_config = PluginConfig()
324
+ general_config = GeneralConfig(
325
+ user_config=user_config, plugin_config=plugin_config
326
+ )
327
+
328
+ assert general_config.check_studio_based_rpc() is True, f"Failed for URL: {url}"
329
+
330
+
331
+ def test_check_studio_based_rpc_with_genlayerlabs_subdomain():
332
+ """Test check_studio_based_rpc with .genlayerlabs.com subdomains."""
333
+ test_cases = [
334
+ "https://api.genlayerlabs.com:8545",
335
+ "https://test.genlayerlabs.com",
336
+ "http://staging.api.genlayerlabs.com:9000",
337
+ "https://dev.test.genlayerlabs.com",
338
+ ]
339
+
340
+ for url in test_cases:
341
+ user_config = UserConfig(
342
+ networks={"testnet": NetworkConfigData(url=url)},
343
+ default_network="testnet",
344
+ )
345
+
346
+ plugin_config = PluginConfig()
347
+ general_config = GeneralConfig(
348
+ user_config=user_config, plugin_config=plugin_config
349
+ )
350
+
351
+ assert general_config.check_studio_based_rpc() is True, f"Failed for URL: {url}"
352
+
353
+
354
+ def test_check_studio_based_rpc_with_non_genlayer_domain():
355
+ """Test check_studio_based_rpc with non-GenLayer domains."""
356
+ test_cases = [
357
+ "https://api.example.com:8545",
358
+ "https://test.otherdomain.com",
359
+ "http://staging.api.random.org:9000",
360
+ "https://genlayer.example.com", # Not a subdomain of .genlayer.com
361
+ "https://genlayerlabs.example.com", # Not a subdomain of .genlayerlabs.com
362
+ ]
363
+
364
+ for url in test_cases:
365
+ user_config = UserConfig(
366
+ networks={"testnet": NetworkConfigData(url=url)},
367
+ default_network="testnet",
368
+ )
369
+
370
+ plugin_config = PluginConfig()
371
+ general_config = GeneralConfig(
372
+ user_config=user_config, plugin_config=plugin_config
373
+ )
374
+
375
+ assert (
376
+ general_config.check_studio_based_rpc() is False
377
+ ), f"Failed for URL: {url}"
378
+
379
+
380
+ def test_check_studio_based_rpc_with_plugin_override():
381
+ """Test check_studio_based_rpc with plugin config RPC URL override."""
382
+ # User config has external URL, but plugin overrides with GenLayer domain
383
+ user_config = UserConfig(
384
+ networks={"localnet": NetworkConfigData(url="https://external.com")},
385
+ default_network="localnet",
386
+ )
387
+
388
+ plugin_config = PluginConfig(rpc_url="https://api.genlayer.com:9000")
389
+ general_config = GeneralConfig(user_config=user_config, plugin_config=plugin_config)
390
+
391
+ # Plugin config should take precedence
392
+ assert general_config.check_studio_based_rpc() is True
393
+
394
+ # Test opposite case: user has GenLayer domain, plugin overrides with external
395
+ user_config2 = UserConfig(
396
+ networks={"localnet": NetworkConfigData(url="https://api.genlayer.com")},
397
+ default_network="localnet",
398
+ )
399
+
400
+ plugin_config2 = PluginConfig(rpc_url="https://external.com:9000")
401
+ general_config2 = GeneralConfig(
402
+ user_config=user_config2, plugin_config=plugin_config2
403
+ )
404
+
405
+ # Plugin config should take precedence
406
+ assert general_config2.check_studio_based_rpc() is False