genlayer-test 0.0.1__tar.gz → 0.1.0__tar.gz

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 (47) hide show
  1. genlayer_test-0.1.0/LICENSE +21 -0
  2. genlayer_test-0.1.0/PKG-INFO +419 -0
  3. genlayer_test-0.1.0/README.md +398 -0
  4. genlayer_test-0.1.0/genlayer_test.egg-info/PKG-INFO +419 -0
  5. genlayer_test-0.1.0/genlayer_test.egg-info/SOURCES.txt +38 -0
  6. genlayer_test-0.1.0/genlayer_test.egg-info/entry_points.txt +5 -0
  7. genlayer_test-0.1.0/genlayer_test.egg-info/requires.txt +2 -0
  8. genlayer_test-0.1.0/genlayer_test.egg-info/top_level.txt +4 -0
  9. genlayer_test-0.1.0/gltest/__init__.py +18 -0
  10. genlayer_test-0.1.0/gltest/artifacts/__init__.py +3 -0
  11. genlayer_test-0.1.0/gltest/artifacts/contract.py +86 -0
  12. genlayer_test-0.1.0/gltest/assertions.py +17 -0
  13. genlayer_test-0.1.0/gltest/exceptions.py +20 -0
  14. genlayer_test-0.1.0/gltest/glchain/__init__.py +16 -0
  15. genlayer_test-0.1.0/gltest/glchain/account.py +17 -0
  16. genlayer_test-0.1.0/gltest/glchain/client.py +23 -0
  17. genlayer_test-0.1.0/gltest/glchain/contract.py +244 -0
  18. genlayer_test-0.1.0/gltest/helpers/__init__.py +8 -0
  19. genlayer_test-0.1.0/gltest/helpers/fixture_snapshot.py +67 -0
  20. genlayer_test-0.1.0/gltest/helpers/take_snapshot.py +41 -0
  21. genlayer_test-0.1.0/gltest/plugin_config.py +42 -0
  22. genlayer_test-0.1.0/gltest/plugin_hooks.py +51 -0
  23. genlayer_test-0.1.0/gltest/types.py +7 -0
  24. genlayer_test-0.1.0/gltest_cli/main.py +5 -0
  25. genlayer_test-0.1.0/pyproject.toml +37 -0
  26. genlayer_test-0.1.0/tests/examples/tests/test_football_prediction_market.py +19 -0
  27. genlayer_test-0.1.0/tests/examples/tests/test_intelligent_oracle_factory.py +129 -0
  28. genlayer_test-0.1.0/tests/examples/tests/test_llm_erc20.py +41 -0
  29. genlayer_test-0.1.0/tests/examples/tests/test_log_indexer.py +64 -0
  30. genlayer_test-0.1.0/tests/examples/tests/test_multi_file_contract.py +15 -0
  31. genlayer_test-0.1.0/tests/examples/tests/test_multi_read_erc20.py +85 -0
  32. genlayer_test-0.1.0/tests/examples/tests/test_multi_tenant_storage.py +58 -0
  33. genlayer_test-0.1.0/tests/examples/tests/test_read_erc20.py +37 -0
  34. genlayer_test-0.1.0/tests/examples/tests/test_storage.py +23 -0
  35. genlayer_test-0.1.0/tests/examples/tests/test_user_storage.py +60 -0
  36. genlayer_test-0.1.0/tests/examples/tests/test_wizard_of_coin.py +12 -0
  37. genlayer_test-0.1.0/tests/plugin/conftest.py +1 -0
  38. genlayer_test-0.1.0/tests/plugin/test_plugin_hooks.py +78 -0
  39. genlayer_test-0.0.1/MANIFEST.in +0 -2
  40. genlayer_test-0.0.1/PKG-INFO +0 -17
  41. genlayer_test-0.0.1/README.md +0 -8
  42. genlayer_test-0.0.1/genlayer_test.egg-info/PKG-INFO +0 -17
  43. genlayer_test-0.0.1/genlayer_test.egg-info/SOURCES.txt +0 -7
  44. genlayer_test-0.0.1/genlayer_test.egg-info/top_level.txt +0 -1
  45. genlayer_test-0.0.1/pyproject.toml +0 -14
  46. {genlayer_test-0.0.1 → genlayer_test-0.1.0}/genlayer_test.egg-info/dependency_links.txt +0 -0
  47. {genlayer_test-0.0.1 → genlayer_test-0.1.0}/setup.cfg +0 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 YeagerAI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,419 @@
1
+ Metadata-Version: 2.4
2
+ Name: genlayer-test
3
+ Version: 0.1.0
4
+ Summary: GenLayer Testing Suite
5
+ Author: GenLayer
6
+ License-Expression: MIT
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.8
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Topic :: Software Development :: Testing
15
+ Requires-Python: >=3.8
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: pytest
19
+ Requires-Dist: genlayer-py==0.1.0
20
+ Dynamic: license-file
21
+
22
+ # GenLayer Testing Suite
23
+
24
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/license/mit/)
25
+ [![Discord](https://dcbadge.vercel.app/api/server/8Jm4v89VAu?compact=true&style=flat)](https://discord.gg/VpfmXEMN66)
26
+ [![Twitter](https://img.shields.io/twitter/url/https/twitter.com/yeagerai.svg?style=social&label=Follow%20%40GenLayer)](https://x.com/GenLayer)
27
+ [![PyPI version](https://badge.fury.io/py/genlayer-test.svg)](https://badge.fury.io/py/genlayer-test)
28
+ [![Documentation](https://img.shields.io/badge/docs-genlayer-blue)](https://docs.genlayer.com/api-references/genlayer-test)
29
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
30
+
31
+ ## About
32
+
33
+ The GenLayer Testing Suite is a powerful testing framework designed to streamline the development and validation of intelligent contracts within the GenLayer ecosystem. Built on top of [pytest](https://docs.pytest.org/en/stable/) and [genlayer-py](https://docs.genlayer.com/api-references/genlayer-py), this suite provides developers with a comprehensive set of tools for deploying, interacting with, and testing intelligent contracts efficiently in a simulated GenLayer environment.
34
+
35
+ ## 🚀 Quick Start
36
+
37
+ ### Installation
38
+
39
+ ```bash
40
+ pip install genlayer-test
41
+ ```
42
+
43
+ ### Basic Usage
44
+
45
+ ```python
46
+ from gltest import get_contract_factory, default_account, create_account
47
+ from gltest.assertions import tx_execution_succeeded
48
+
49
+ factory = get_contract_factory("MyContract")
50
+ # Deploy a contract with default account
51
+ contract = factory.deploy() # This will be deployed with default_account
52
+ assert contract.account == default_account
53
+
54
+ # Deploy a contract with other account
55
+ other_account = create_account()
56
+ contract = factory.deploy(account=other_account)
57
+ assert contract.account == other_account
58
+
59
+ # Interact with the contract
60
+ result = contract.get_value() # Read method
61
+ tx_receipt = contract.set_value(args=["new_value"]) # Write method
62
+
63
+ assert tx_execution_succeeded(tx_receipt)
64
+ ```
65
+
66
+ ## 📋 Table of Contents
67
+
68
+ - [About](#about)
69
+ - [Quick Start](#-quick-start)
70
+ - [Prerequisites](#prerequisites)
71
+ - [Installation and Usage](#installation-and-usage)
72
+ - [Key Features](#-key-features)
73
+ - [Examples](#-examples)
74
+ - [Best Practices](#-best-practices)
75
+ - [Troubleshooting](#-troubleshooting)
76
+ - [Contributing](#-contributing)
77
+ - [License](#-license)
78
+ - [Support](#-support)
79
+
80
+ ## Prerequisites
81
+
82
+ Before installing GenLayer Testing Suite, ensure you have the following prerequisites installed:
83
+
84
+ - Python (>=3.12)
85
+ - GenLayer Studio (Docker deployment)
86
+ - pip (Python package installer)
87
+
88
+ ## Installation and Usage
89
+
90
+ ### Installation Options
91
+
92
+ 1. Install from PyPI (recommended):
93
+ ```bash
94
+ $ pip install genlayer-test
95
+ ```
96
+
97
+ 2. Install from source:
98
+ ```bash
99
+ $ git clone https://github.com/yeagerai/genlayer-testing-suite
100
+ $ cd genlayer-testing-suite
101
+ $ pip install -e .
102
+ ```
103
+
104
+ ### Running Tests
105
+
106
+ 1. Run all tests:
107
+ ```bash
108
+ $ gltest
109
+ ```
110
+
111
+ 2. Run specific test file:
112
+ ```bash
113
+ $ gltest tests/test_mycontract.py
114
+ ```
115
+
116
+ 3. Run tests with specific markers:
117
+ ```bash
118
+ $ gltest -m "integration"
119
+ ```
120
+
121
+ 4. Run tests with verbose output:
122
+ ```bash
123
+ $ gltest -v
124
+ ```
125
+
126
+ 5. Run tests in specific contracts directories, by default `<path_to_contracts>` is set to `contracts/`
127
+ ```bash
128
+ $ gltest --contracts-dir <path_to_contracts>
129
+ ```
130
+
131
+ 6. Run tests with a custom RPC url
132
+ ```bash
133
+ $ gltest --rpc-url <custom_rpc_url>
134
+ ```
135
+
136
+ 6. Run tests with a default wait interval for waiting transaction receipts
137
+ ```bash
138
+ $ gltest --default-wait-interval <default_wait_interval>
139
+ ```
140
+
141
+ 6. Run tests with a default wait retries for waiting transaction receipts
142
+ ```bash
143
+ $ gltest --default-wait-retries <default_wait_retries>
144
+ ```
145
+
146
+ ## 🚀 Key Features
147
+
148
+ - **Pytest Integration** – Extends pytest to support intelligent contract testing, making it familiar and easy to adopt.
149
+ - **Account & Transaction Management** – Create, fund, and track accounts and transactions within the GenLayer Simulator.
150
+ - **Contract Deployment & Interaction** – Deploy contracts, call methods, and monitor events seamlessly.
151
+ - **CLI Compatibility** – Run tests directly from the command line, ensuring smooth integration with the GenLayer CLI.
152
+ - **State Injection & Consensus Simulation** – Modify contract states dynamically and simulate consensus scenarios for advanced testing.
153
+ - **Prompt Testing & Statistical Analysis** – Evaluate and statistically test prompts for AI-driven contract execution.
154
+ - **Scalability to Security & Audit Tools** – Designed to extend into security testing and smart contract auditing.
155
+
156
+ ## 📚 Examples
157
+
158
+ ### Project Structure
159
+
160
+ Before diving into the examples, let's understand the basic project structure:
161
+
162
+ ```
163
+ genlayer-example/
164
+ ├── contracts/ # Contract definitions
165
+ │ └── storage.gpy # Example storage contract
166
+ └── test/ # Test files
167
+ └── test_contract.py # Contract test cases
168
+ ```
169
+
170
+ ### Storage Contract Example
171
+
172
+ Let's examine a simple Storage contract that demonstrates basic read and write operations:
173
+
174
+ ```python
175
+ # { "Depends": "py-genlayer:test" }
176
+
177
+ from genlayer import *
178
+
179
+
180
+ # contract class
181
+ class Storage(gl.Contract):
182
+ # State variable to store data
183
+ storage: str
184
+
185
+ # Constructor - initializes the contract state
186
+ def __init__(self, initial_storage: str):
187
+ self.storage = initial_storage
188
+
189
+ # Read method - marked with @gl.public.view decorator
190
+ # Returns the current storage value
191
+ @gl.public.view
192
+ def get_storage(self) -> str:
193
+ return self.storage
194
+
195
+ # Write method - marked with @gl.public.write decorator
196
+ # Updates the storage value
197
+ @gl.public.write
198
+ def update_storage(self, new_storage: str) -> None:
199
+ self.storage = new_storage
200
+ ```
201
+
202
+ Key features demonstrated in this contract:
203
+ - State variable declaration
204
+ - Constructor with initialization
205
+ - Read-only method with `@gl.public.view` decorator
206
+ - State-modifying method with `@gl.public.write` decorator
207
+ - Type hints for better code clarity
208
+
209
+ ### Contract Deployment
210
+
211
+ Here's how to deploy the Storage contract:
212
+
213
+ ```python
214
+ from gltest import get_contract_factory, default_account
215
+
216
+ def test_deployment():
217
+ # Get the contract factory for your contract
218
+ # it will search in the contracts directory
219
+ factory = get_contract_factory("Storage")
220
+
221
+ # Deploy the contract with constructor arguments
222
+ contract = factory.deploy(
223
+ args=["initial_value"], # Constructor arguments
224
+ account=default_account, # Account to deploy from
225
+ consensus_max_rotations=3, # Optional: max consensus rotations
226
+ leader_only=False, # Optional: whether to run only on leader
227
+ )
228
+
229
+ # Contract is now deployed and ready to use
230
+ assert contract.address is not None
231
+ ```
232
+
233
+ ### Read Methods
234
+
235
+ Reading from the contract is straightforward:
236
+
237
+ ```python
238
+ from gltest import get_contract_factory, default_account
239
+
240
+ def test_read_methods():
241
+ # Get the contract factory and deploy the contract
242
+ factory = get_contract_factory("Storage")
243
+ contract = factory.deploy(account=default_account)
244
+
245
+ # Call a read-only method
246
+ result = contract.get_value(args=[])
247
+
248
+ # Assert the result matches the initial value
249
+ assert result == "initial_value"
250
+ ```
251
+
252
+ ### Write Methods
253
+
254
+ Writing to the contract requires transaction handling:
255
+
256
+ ```python
257
+ from gltest import get_contract_factory
258
+ from gltest.assertions import tx_execution_succeeded
259
+
260
+ def test_write_methods():
261
+ # Get the contract factory and deploy the contract
262
+ factory = get_contract_factory("Storage")
263
+ contract = factory.deploy()
264
+
265
+ # Call a write method with arguments
266
+ tx_receipt = contract.update_storage(
267
+ args=["new_value"], # Method arguments
268
+ value=0, # Optional: amount of native currency to send
269
+ consensus_max_rotations=3, # Optional: max consensus rotations
270
+ leader_only=False, # Optional: whether to run only on leader
271
+ wait_interval=1, # Optional: seconds between status checks
272
+ wait_retries=10, # Optional: max number of retries
273
+ )
274
+
275
+ # Verify the transaction was successful
276
+ assert tx_execution_succeeded(tx_receipt)
277
+
278
+ # Verify the value was updated
279
+ assert contract.get_storage() == "new_value"
280
+ ```
281
+
282
+ For more example contracts, check out the [contracts directory](tests/examples/contracts) which contains various sample contracts demonstrating different features and use cases.
283
+
284
+ ## 📝 Best Practices
285
+
286
+ 1. **Test Organization**
287
+ - Keep tests in a dedicated `tests` directory
288
+ - Use descriptive test names
289
+ - Group related tests using pytest markers
290
+
291
+ 2. **Contract Deployment**
292
+ - Always verify deployment success
293
+ - Use appropriate consensus parameters
294
+ - Handle deployment errors gracefully
295
+
296
+ 3. **Transaction Handling**
297
+ - Always wait for transaction finalization
298
+ - Verify transaction status
299
+ - Handle transaction failures appropriately
300
+
301
+ 4. **State Management**
302
+ - Reset state between tests
303
+ - Use fixtures for common setup
304
+ - Avoid test dependencies
305
+
306
+ ## 🔧 Troubleshooting
307
+
308
+ ### Common Issues
309
+
310
+ 1. **Deployment Failures**
311
+ - **Problem**: Contract deployment fails due to various reasons like insufficient funds, invalid contract code, or network issues.
312
+ - **Solution**: Implement proper error handling
313
+ ```python
314
+ try:
315
+ contract = factory.deploy(args=["initial_value"])
316
+ except DeploymentError as e:
317
+ print(f"Deployment failed: {e}")
318
+ ```
319
+
320
+ 2. **Transaction Timeouts**
321
+ - **Problem**: Transactions take too long to complete or fail due to network congestion or consensus delays.
322
+ - **Solution**: Adjust timeout parameters and implement retry logic:
323
+ ```python
324
+ tx_receipt = contract.set_value(
325
+ args=["new_value"],
326
+ wait_interval=2, # Increase wait interval between status checks
327
+ wait_retries=20, # Increase number of retry attempts
328
+ )
329
+ ```
330
+
331
+ 3. **Consensus Issues**
332
+ - **Problem**: Transactions fail due to consensus-related problems like network partitions or slow consensus.
333
+ - **Solution**: Adjust consensus parameters and try different modes:
334
+ ```python
335
+ # Try with increased consensus parameters
336
+ contract = factory.deploy(
337
+ consensus_max_rotations=5, # Increase number of consensus rotations
338
+ leader_only=True, # Try leader-only mode for faster execution
339
+ )
340
+
341
+ # For critical operations, use more conservative settings
342
+ contract = factory.deploy(
343
+ consensus_max_rotations=10, # More rotations for better reliability
344
+ leader_only=False, # Full consensus for better security
345
+ wait_interval=3, # Longer wait between checks
346
+ wait_retries=30 # More retries for consensus
347
+ )
348
+ ```
349
+
350
+ 4. **Contracts Directory Issues**
351
+ - **Problem**: `get_contract_factory` can't find your contract files.
352
+ - **Solution**: Ensure proper directory structure and configuration:
353
+ ```bash
354
+ # Default structure
355
+ your_project/
356
+ ├── contracts/ # Default contracts directory
357
+ │ └── my_contract.gpy # Your contract file
358
+ └── tests/
359
+ └── test_contract.py # Your test file
360
+
361
+ # If using a different directory structure
362
+ gltest --contracts-dir /path/to/your/contracts
363
+ ```
364
+
365
+ 5. **Contract File Naming and Structure**
366
+ - **Problem**: Contracts aren't being recognized or loaded properly.
367
+ - **Solution**: Follow the correct naming and structure conventions:
368
+ ```python
369
+ # Correct file: contracts/my_contract.gpy
370
+ # Correct structure:
371
+ from genlayer import *
372
+
373
+ class MyContract(gl.Contract):
374
+ # Contract code here
375
+ pass
376
+
377
+ # Incorrect file: contracts/my_contract.py # Wrong extension
378
+ # Incorrect structure:
379
+ class MyContract: # Missing gl.Contract inheritance
380
+ pass
381
+ ```
382
+
383
+ 6. **Environment Setup Issues**
384
+ - **Problem**: Tests fail due to missing or incorrect environment setup.
385
+ - **Solution**: Verify your environment:
386
+ ```bash
387
+ # Check Python version
388
+ python --version # Should be >= 3.8
389
+
390
+ # Check GenLayer Studio status
391
+ docker ps # Should show GenLayer Studio running
392
+
393
+ # Verify package installation
394
+ pip list | grep genlayer-test # Should show installed version
395
+ ```
396
+
397
+ ## 🤝 Contributing
398
+
399
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
400
+
401
+ 1. Fork the repository
402
+ 2. Create your feature branch
403
+ 3. Commit your changes
404
+ 4. Push to the branch
405
+ 5. Create a Pull Request
406
+
407
+ ## 📄 License
408
+
409
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
410
+
411
+ ## 💬 Support
412
+
413
+ - [Documentation](https://docs.genlayer.com/api-references/genlayer-test)
414
+ - [Discord Community](https://discord.gg/VpfmXEMN66)
415
+ - [GitHub Issues](https://github.com/yeagerai/genlayer-testing-suite/issues)
416
+ - [Twitter](https://x.com/GenLayer)
417
+
418
+
419
+