genlayer-test 0.1.0b3__tar.gz → 0.1.0b5__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 (36) hide show
  1. genlayer_test-0.1.0b5/LICENSE +21 -0
  2. genlayer_test-0.1.0b5/PKG-INFO +402 -0
  3. genlayer_test-0.1.0b5/README.md +381 -0
  4. genlayer_test-0.1.0b5/genlayer_test.egg-info/PKG-INFO +402 -0
  5. {genlayer_test-0.1.0b3 → genlayer_test-0.1.0b5}/genlayer_test.egg-info/SOURCES.txt +7 -1
  6. {genlayer_test-0.1.0b3 → genlayer_test-0.1.0b5}/genlayer_test.egg-info/top_level.txt +0 -1
  7. genlayer_test-0.1.0b5/gltest/exceptions.py +20 -0
  8. {genlayer_test-0.1.0b3 → genlayer_test-0.1.0b5}/gltest/glchain/__init__.py +2 -2
  9. genlayer_test-0.1.0b5/gltest/glchain/client.py +23 -0
  10. {genlayer_test-0.1.0b3 → genlayer_test-0.1.0b5}/gltest/glchain/contract.py +13 -17
  11. genlayer_test-0.1.0b5/gltest/helpers/__init__.py +8 -0
  12. genlayer_test-0.1.0b5/gltest/helpers/fixture_snapshot.py +67 -0
  13. genlayer_test-0.1.0b5/gltest/helpers/take_snapshot.py +41 -0
  14. genlayer_test-0.1.0b5/gltest/plugin_config.py +42 -0
  15. genlayer_test-0.1.0b5/gltest/plugin_hooks.py +51 -0
  16. {genlayer_test-0.1.0b3 → genlayer_test-0.1.0b5}/pyproject.toml +1 -1
  17. genlayer_test-0.1.0b5/tests/conftest.py +1 -0
  18. genlayer_test-0.1.0b5/tests/test_plugin_hooks.py +78 -0
  19. genlayer_test-0.1.0b3/PKG-INFO +0 -97
  20. genlayer_test-0.1.0b3/README.md +0 -78
  21. genlayer_test-0.1.0b3/genlayer_test.egg-info/PKG-INFO +0 -97
  22. genlayer_test-0.1.0b3/gltest/exceptions.py +0 -4
  23. genlayer_test-0.1.0b3/gltest/glchain/client.py +0 -15
  24. genlayer_test-0.1.0b3/gltest/plugin_config.py +0 -12
  25. genlayer_test-0.1.0b3/gltest/plugin_hooks.py +0 -16
  26. {genlayer_test-0.1.0b3 → genlayer_test-0.1.0b5}/genlayer_test.egg-info/dependency_links.txt +0 -0
  27. {genlayer_test-0.1.0b3 → genlayer_test-0.1.0b5}/genlayer_test.egg-info/entry_points.txt +0 -0
  28. {genlayer_test-0.1.0b3 → genlayer_test-0.1.0b5}/genlayer_test.egg-info/requires.txt +0 -0
  29. {genlayer_test-0.1.0b3 → genlayer_test-0.1.0b5}/gltest/__init__.py +0 -0
  30. {genlayer_test-0.1.0b3 → genlayer_test-0.1.0b5}/gltest/artifacts/__init__.py +0 -0
  31. {genlayer_test-0.1.0b3 → genlayer_test-0.1.0b5}/gltest/artifacts/contract.py +0 -0
  32. {genlayer_test-0.1.0b3 → genlayer_test-0.1.0b5}/gltest/assertions.py +0 -0
  33. {genlayer_test-0.1.0b3 → genlayer_test-0.1.0b5}/gltest/glchain/account.py +0 -0
  34. {genlayer_test-0.1.0b3 → genlayer_test-0.1.0b5}/gltest/types.py +0 -0
  35. {genlayer_test-0.1.0b3 → genlayer_test-0.1.0b5}/gltest_cli/main.py +0 -0
  36. {genlayer_test-0.1.0b3 → genlayer_test-0.1.0b5}/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,402 @@
1
+ Metadata-Version: 2.4
2
+ Name: genlayer-test
3
+ Version: 0.1.0b5
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.0b1
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
+ ## 🚀 Key Features
132
+
133
+ - **Pytest Integration** – Extends pytest to support intelligent contract testing, making it familiar and easy to adopt.
134
+ - **Account & Transaction Management** – Create, fund, and track accounts and transactions within the GenLayer Simulator.
135
+ - **Contract Deployment & Interaction** – Deploy contracts, call methods, and monitor events seamlessly.
136
+ - **CLI Compatibility** – Run tests directly from the command line, ensuring smooth integration with the GenLayer CLI.
137
+ - **State Injection & Consensus Simulation** – Modify contract states dynamically and simulate consensus scenarios for advanced testing.
138
+ - **Prompt Testing & Statistical Analysis** – Evaluate and statistically test prompts for AI-driven contract execution.
139
+ - **Scalability to Security & Audit Tools** – Designed to extend into security testing and smart contract auditing.
140
+
141
+ ## 📚 Examples
142
+
143
+ ### Project Structure
144
+
145
+ Before diving into the examples, let's understand the basic project structure:
146
+
147
+ ```
148
+ genlayer-example/
149
+ ├── contracts/ # Contract definitions
150
+ │ └── storage.gpy # Example storage contract
151
+ └── test/ # Test files
152
+ └── test_contract.py # Contract test cases
153
+ ```
154
+
155
+ ### Storage Contract Example
156
+
157
+ Let's examine a simple Storage contract that demonstrates basic read and write operations:
158
+
159
+ ```python
160
+ # { "Depends": "py-genlayer:test" }
161
+
162
+ from genlayer import *
163
+
164
+
165
+ # contract class
166
+ class Storage(gl.Contract):
167
+ # State variable to store data
168
+ storage: str
169
+
170
+ # Constructor - initializes the contract state
171
+ def __init__(self, initial_storage: str):
172
+ self.storage = initial_storage
173
+
174
+ # Read method - marked with @gl.public.view decorator
175
+ # Returns the current storage value
176
+ @gl.public.view
177
+ def get_storage(self) -> str:
178
+ return self.storage
179
+
180
+ # Write method - marked with @gl.public.write decorator
181
+ # Updates the storage value
182
+ @gl.public.write
183
+ def update_storage(self, new_storage: str) -> None:
184
+ self.storage = new_storage
185
+ ```
186
+
187
+ Key features demonstrated in this contract:
188
+ - State variable declaration
189
+ - Constructor with initialization
190
+ - Read-only method with `@gl.public.view` decorator
191
+ - State-modifying method with `@gl.public.write` decorator
192
+ - Type hints for better code clarity
193
+
194
+ ### Contract Deployment
195
+
196
+ Here's how to deploy the Storage contract:
197
+
198
+ ```python
199
+ from gltest import get_contract_factory, default_account
200
+
201
+ def test_deployment():
202
+ # Get the contract factory for your contract
203
+ # it will search in the contracts directory
204
+ factory = get_contract_factory("Storage")
205
+
206
+ # Deploy the contract with constructor arguments
207
+ contract = factory.deploy(
208
+ args=["initial_value"], # Constructor arguments
209
+ account=default_account, # Account to deploy from
210
+ consensus_max_rotations=3, # Optional: max consensus rotations
211
+ leader_only=False, # Optional: whether to run only on leader
212
+ )
213
+
214
+ # Contract is now deployed and ready to use
215
+ assert contract.address is not None
216
+ ```
217
+
218
+ ### Read Methods
219
+
220
+ Reading from the contract is straightforward:
221
+
222
+ ```python
223
+ from gltest import get_contract_factory, default_account
224
+
225
+ def test_read_methods():
226
+ # Get the contract factory and deploy the contract
227
+ factory = get_contract_factory("Storage")
228
+ contract = factory.deploy(account=default_account)
229
+
230
+ # Call a read-only method
231
+ result = contract.get_value(args=[])
232
+
233
+ # Assert the result matches the initial value
234
+ assert result == "initial_value"
235
+ ```
236
+
237
+ ### Write Methods
238
+
239
+ Writing to the contract requires transaction handling:
240
+
241
+ ```python
242
+ from gltest import get_contract_factory
243
+ from gltest.assertions import tx_execution_succeeded
244
+
245
+ def test_write_methods():
246
+ # Get the contract factory and deploy the contract
247
+ factory = get_contract_factory("Storage")
248
+ contract = factory.deploy()
249
+
250
+ # Call a write method with arguments
251
+ tx_receipt = contract.update_storage(
252
+ args=["new_value"], # Method arguments
253
+ value=0, # Optional: amount of native currency to send
254
+ consensus_max_rotations=3, # Optional: max consensus rotations
255
+ leader_only=False, # Optional: whether to run only on leader
256
+ wait_interval=1, # Optional: seconds between status checks
257
+ wait_retries=10, # Optional: max number of retries
258
+ )
259
+
260
+ # Verify the transaction was successful
261
+ assert tx_execution_succeeded(tx_receipt)
262
+
263
+ # Verify the value was updated
264
+ assert contract.get_storage() == "new_value"
265
+ ```
266
+
267
+ ## 📝 Best Practices
268
+
269
+ 1. **Test Organization**
270
+ - Keep tests in a dedicated `tests` directory
271
+ - Use descriptive test names
272
+ - Group related tests using pytest markers
273
+
274
+ 2. **Contract Deployment**
275
+ - Always verify deployment success
276
+ - Use appropriate consensus parameters
277
+ - Handle deployment errors gracefully
278
+
279
+ 3. **Transaction Handling**
280
+ - Always wait for transaction finalization
281
+ - Verify transaction status
282
+ - Handle transaction failures appropriately
283
+
284
+ 4. **State Management**
285
+ - Reset state between tests
286
+ - Use fixtures for common setup
287
+ - Avoid test dependencies
288
+
289
+ ## 🔧 Troubleshooting
290
+
291
+ ### Common Issues
292
+
293
+ 1. **Deployment Failures**
294
+ - **Problem**: Contract deployment fails due to various reasons like insufficient funds, invalid contract code, or network issues.
295
+ - **Solution**: Implement proper error handling
296
+ ```python
297
+ try:
298
+ contract = factory.deploy(args=["initial_value"])
299
+ except DeploymentError as e:
300
+ print(f"Deployment failed: {e}")
301
+ ```
302
+
303
+ 2. **Transaction Timeouts**
304
+ - **Problem**: Transactions take too long to complete or fail due to network congestion or consensus delays.
305
+ - **Solution**: Adjust timeout parameters and implement retry logic:
306
+ ```python
307
+ tx_receipt = contract.set_value(
308
+ args=["new_value"],
309
+ wait_interval=2, # Increase wait interval between status checks
310
+ wait_retries=20, # Increase number of retry attempts
311
+ )
312
+ ```
313
+
314
+ 3. **Consensus Issues**
315
+ - **Problem**: Transactions fail due to consensus-related problems like network partitions or slow consensus.
316
+ - **Solution**: Adjust consensus parameters and try different modes:
317
+ ```python
318
+ # Try with increased consensus parameters
319
+ contract = factory.deploy(
320
+ consensus_max_rotations=5, # Increase number of consensus rotations
321
+ leader_only=True, # Try leader-only mode for faster execution
322
+ )
323
+
324
+ # For critical operations, use more conservative settings
325
+ contract = factory.deploy(
326
+ consensus_max_rotations=10, # More rotations for better reliability
327
+ leader_only=False, # Full consensus for better security
328
+ wait_interval=3, # Longer wait between checks
329
+ wait_retries=30 # More retries for consensus
330
+ )
331
+ ```
332
+
333
+ 4. **Contracts Directory Issues**
334
+ - **Problem**: `get_contract_factory` can't find your contract files.
335
+ - **Solution**: Ensure proper directory structure and configuration:
336
+ ```bash
337
+ # Default structure
338
+ your_project/
339
+ ├── contracts/ # Default contracts directory
340
+ │ └── my_contract.gpy # Your contract file
341
+ └── tests/
342
+ └── test_contract.py # Your test file
343
+
344
+ # If using a different directory structure
345
+ gltest --contracts-dir /path/to/your/contracts
346
+ ```
347
+
348
+ 5. **Contract File Naming and Structure**
349
+ - **Problem**: Contracts aren't being recognized or loaded properly.
350
+ - **Solution**: Follow the correct naming and structure conventions:
351
+ ```python
352
+ # Correct file: contracts/my_contract.gpy
353
+ # Correct structure:
354
+ from genlayer import *
355
+
356
+ class MyContract(gl.Contract):
357
+ # Contract code here
358
+ pass
359
+
360
+ # Incorrect file: contracts/my_contract.py # Wrong extension
361
+ # Incorrect structure:
362
+ class MyContract: # Missing gl.Contract inheritance
363
+ pass
364
+ ```
365
+
366
+ 6. **Environment Setup Issues**
367
+ - **Problem**: Tests fail due to missing or incorrect environment setup.
368
+ - **Solution**: Verify your environment:
369
+ ```bash
370
+ # Check Python version
371
+ python --version # Should be >= 3.8
372
+
373
+ # Check GenLayer Studio status
374
+ docker ps # Should show GenLayer Studio running
375
+
376
+ # Verify package installation
377
+ pip list | grep genlayer-test # Should show installed version
378
+ ```
379
+
380
+ ## 🤝 Contributing
381
+
382
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
383
+
384
+ 1. Fork the repository
385
+ 2. Create your feature branch
386
+ 3. Commit your changes
387
+ 4. Push to the branch
388
+ 5. Create a Pull Request
389
+
390
+ ## 📄 License
391
+
392
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
393
+
394
+ ## 💬 Support
395
+
396
+ - [Documentation](https://docs.genlayer.com/api-references/genlayer-test)
397
+ - [Discord Community](https://discord.gg/VpfmXEMN66)
398
+ - [GitHub Issues](https://github.com/yeagerai/genlayer-testing-suite/issues)
399
+ - [Twitter](https://x.com/GenLayer)
400
+
401
+
402
+