genlayer-test 0.4.1__py3-none-any.whl → 0.5.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.
Files changed (46) hide show
  1. {genlayer_test-0.4.1.dist-info → genlayer_test-0.5.0.dist-info}/METADATA +257 -24
  2. genlayer_test-0.5.0.dist-info/RECORD +76 -0
  3. gltest/__init__.py +7 -6
  4. gltest/{glchain/client.py → clients.py} +1 -1
  5. gltest/contracts/__init__.py +4 -0
  6. gltest/contracts/contract.py +205 -0
  7. gltest/{glchain/contract.py → contracts/contract_factory.py} +47 -144
  8. gltest/contracts/contract_functions.py +62 -0
  9. gltest/contracts/method_stats.py +163 -0
  10. gltest/contracts/stats_collector.py +259 -0
  11. gltest/contracts/utils.py +12 -0
  12. gltest/fixtures.py +2 -6
  13. gltest/helpers/take_snapshot.py +1 -1
  14. gltest/types.py +1 -0
  15. gltest_cli/config/constants.py +2 -0
  16. gltest_cli/config/plugin.py +121 -49
  17. gltest_cli/config/pytest_context.py +9 -0
  18. gltest_cli/config/types.py +73 -8
  19. gltest_cli/config/user.py +71 -28
  20. gltest_cli/logging.py +3 -2
  21. tests/examples/contracts/football_prediction_market.py +1 -1
  22. tests/examples/tests/test_football_prediction_market.py +2 -2
  23. tests/examples/tests/test_intelligent_oracle_factory.py +8 -24
  24. tests/examples/tests/test_llm_erc20.py +5 -5
  25. tests/examples/tests/test_llm_erc20_analyze.py +50 -0
  26. tests/examples/tests/test_log_indexer.py +23 -11
  27. tests/examples/tests/test_multi_file_contract.py +2 -2
  28. tests/examples/tests/test_multi_file_contract_legacy.py +2 -2
  29. tests/examples/tests/test_multi_read_erc20.py +14 -12
  30. tests/examples/tests/test_multi_tenant_storage.py +11 -7
  31. tests/examples/tests/test_read_erc20.py +1 -1
  32. tests/examples/tests/test_storage.py +4 -4
  33. tests/examples/tests/test_storage_legacy.py +5 -3
  34. tests/examples/tests/test_user_storage.py +20 -10
  35. tests/examples/tests/test_wizard_of_coin.py +1 -1
  36. tests/gltest_cli/config/test_config_integration.py +432 -0
  37. tests/gltest_cli/config/test_general_config.py +406 -0
  38. tests/gltest_cli/config/test_plugin.py +164 -1
  39. tests/gltest_cli/config/test_user.py +61 -1
  40. genlayer_test-0.4.1.dist-info/RECORD +0 -67
  41. gltest/glchain/__init__.py +0 -16
  42. {genlayer_test-0.4.1.dist-info → genlayer_test-0.5.0.dist-info}/WHEEL +0 -0
  43. {genlayer_test-0.4.1.dist-info → genlayer_test-0.5.0.dist-info}/entry_points.txt +0 -0
  44. {genlayer_test-0.4.1.dist-info → genlayer_test-0.5.0.dist-info}/licenses/LICENSE +0 -0
  45. {genlayer_test-0.4.1.dist-info → genlayer_test-0.5.0.dist-info}/top_level.txt +0 -0
  46. /gltest/{glchain/account.py → accounts.py} +0 -0
@@ -37,41 +37,51 @@ def test_user_storage(setup_validators):
37
37
  contract = factory.deploy()
38
38
 
39
39
  # GET Initial State
40
- contract_state_1 = contract.get_complete_storage(args=[])
40
+ contract_state_1 = contract.get_complete_storage(args=[]).call()
41
41
  assert contract_state_1 == {}
42
42
 
43
43
  # ADD User A State
44
- transaction_response_call_1 = contract.update_storage(args=[INITIAL_STATE_USER_A])
44
+ transaction_response_call_1 = contract.update_storage(
45
+ args=[INITIAL_STATE_USER_A]
46
+ ).transact()
45
47
  assert tx_execution_succeeded(transaction_response_call_1)
46
48
 
47
49
  # Get Updated State
48
- contract_state_2_1 = contract.get_complete_storage(args=[])
50
+ contract_state_2_1 = contract.get_complete_storage(args=[]).call()
49
51
  assert contract_state_2_1[from_account_a.address] == INITIAL_STATE_USER_A
50
52
 
51
53
  # Get Updated State
52
- contract_state_2_2 = contract.get_account_storage(args=[from_account_a.address])
54
+ contract_state_2_2 = contract.get_account_storage(
55
+ args=[from_account_a.address]
56
+ ).call()
53
57
  assert contract_state_2_2 == INITIAL_STATE_USER_A
54
58
 
55
59
  # ADD User B State
56
- transaction_response_call_2 = contract.connect(from_account_b).update_storage(
57
- args=[INITIAL_STATE_USER_B]
60
+ transaction_response_call_2 = (
61
+ contract.connect(from_account_b)
62
+ .update_storage(args=[INITIAL_STATE_USER_B])
63
+ .transact()
58
64
  )
59
65
  assert tx_execution_succeeded(transaction_response_call_2)
60
66
 
61
67
  # Get Updated State
62
- contract_state_3 = contract.get_complete_storage(args=[])
68
+ contract_state_3 = contract.get_complete_storage(args=[]).call()
63
69
  assert contract_state_3[from_account_a.address] == INITIAL_STATE_USER_A
64
70
  assert contract_state_3[from_account_b.address] == INITIAL_STATE_USER_B
65
71
 
66
72
  # UPDATE User A State
67
- transaction_response_call_3 = contract.update_storage(args=[UPDATED_STATE_USER_A])
73
+ transaction_response_call_3 = contract.update_storage(
74
+ args=[UPDATED_STATE_USER_A]
75
+ ).transact()
68
76
  assert tx_execution_succeeded(transaction_response_call_3)
69
77
 
70
78
  # Get Updated State
71
- contract_state_4_1 = contract.get_complete_storage(args=[])
79
+ contract_state_4_1 = contract.get_complete_storage(args=[]).call()
72
80
  assert contract_state_4_1[from_account_a.address] == UPDATED_STATE_USER_A
73
81
  assert contract_state_4_1[from_account_b.address] == INITIAL_STATE_USER_B
74
82
 
75
83
  # Get Updated State
76
- contract_state_4_2 = contract.get_account_storage(args=[from_account_b.address])
84
+ contract_state_4_2 = contract.get_account_storage(
85
+ args=[from_account_b.address]
86
+ ).call()
77
87
  assert contract_state_4_2 == INITIAL_STATE_USER_B
@@ -23,5 +23,5 @@ def test_wizard_of_coin(setup_validators):
23
23
 
24
24
  transaction_response_call_1 = contract.ask_for_coin(
25
25
  args=["Can you please give me my coin?"]
26
- )
26
+ ).transact()
27
27
  assert tx_execution_succeeded(transaction_response_call_1)
@@ -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