genlayer-test 0.7.0__py3-none-any.whl → 0.8.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.
- {genlayer_test-0.7.0.dist-info → genlayer_test-0.8.0.dist-info}/METADATA +217 -3
- {genlayer_test-0.7.0.dist-info → genlayer_test-0.8.0.dist-info}/RECORD +11 -8
- gltest/__init__.py +3 -0
- gltest/types.py +12 -1
- gltest/validators/__init__.py +3 -0
- gltest/validators/validator_factory.py +136 -0
- tests/examples/tests/test_custom_validators.py +65 -0
- {genlayer_test-0.7.0.dist-info → genlayer_test-0.8.0.dist-info}/WHEEL +0 -0
- {genlayer_test-0.7.0.dist-info → genlayer_test-0.8.0.dist-info}/entry_points.txt +0 -0
- {genlayer_test-0.7.0.dist-info → genlayer_test-0.8.0.dist-info}/licenses/LICENSE +0 -0
- {genlayer_test-0.7.0.dist-info → genlayer_test-0.8.0.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: genlayer-test
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.8.0
|
4
4
|
Summary: GenLayer Testing Suite
|
5
5
|
Author: GenLayer
|
6
6
|
License-Expression: MIT
|
@@ -15,7 +15,7 @@ Description-Content-Type: text/markdown
|
|
15
15
|
License-File: LICENSE
|
16
16
|
Requires-Dist: pytest
|
17
17
|
Requires-Dist: setuptools>=77.0
|
18
|
-
Requires-Dist: genlayer-py==0.
|
18
|
+
Requires-Dist: genlayer-py==0.9.0
|
19
19
|
Requires-Dist: colorama>=0.4.6
|
20
20
|
Requires-Dist: pyyaml
|
21
21
|
Requires-Dist: python-dotenv
|
@@ -308,6 +308,7 @@ When this flag is enabled, all contracts deployed and all write transactions wil
|
|
308
308
|
- **State Injection & Consensus Simulation** – Modify contract states dynamically and simulate consensus scenarios for advanced testing.
|
309
309
|
- **Prompt Testing & Statistical Analysis** – Evaluate and statistically test prompts for AI-driven contract execution.
|
310
310
|
- **Scalability to Security & Audit Tools** – Designed to extend into security testing and smart contract auditing.
|
311
|
+
- **Custom Transaction Context** – Set custom validators with specific LLM providers and models, and configure GenVM datetime for deterministic testing scenarios.
|
311
312
|
|
312
313
|
## 📚 Examples
|
313
314
|
|
@@ -387,6 +388,7 @@ def test_deployment():
|
|
387
388
|
args=["initial_value"], # Constructor arguments
|
388
389
|
account=get_default_account(), # Account to deploy from
|
389
390
|
consensus_max_rotations=3, # Optional: max consensus rotations
|
391
|
+
transaction_context=None, # Optional: custom transaction context
|
390
392
|
)
|
391
393
|
|
392
394
|
# Contract is now deployed and ready to use
|
@@ -419,7 +421,9 @@ def test_read_methods():
|
|
419
421
|
contract = factory.deploy()
|
420
422
|
|
421
423
|
# Call a read-only method
|
422
|
-
result = contract.get_storage(args=[]).call(
|
424
|
+
result = contract.get_storage(args=[]).call(
|
425
|
+
transaction_context=None, # Optional: custom transaction context
|
426
|
+
)
|
423
427
|
|
424
428
|
# Assert the result matches the initial value
|
425
429
|
assert result == "initial_value"
|
@@ -446,6 +450,7 @@ def test_write_methods():
|
|
446
450
|
consensus_max_rotations=3, # Optional: max consensus rotations
|
447
451
|
wait_interval=1, # Optional: seconds between status checks
|
448
452
|
wait_retries=10, # Optional: max number of retries
|
453
|
+
transaction_context=None, # Optional: custom transaction context
|
449
454
|
)
|
450
455
|
|
451
456
|
# Verify the transaction was successful
|
@@ -609,6 +614,7 @@ def test_analyze_method():
|
|
609
614
|
config=None, # Optional: provider-specific config
|
610
615
|
plugin=None, # Optional: plugin name
|
611
616
|
plugin_config=None, # Optional: plugin configuration
|
617
|
+
genvm_datetime="2024-01-15T10:30:00Z", # Optional: GenVM datetime in ISO format
|
612
618
|
)
|
613
619
|
|
614
620
|
# Access analysis results
|
@@ -757,6 +763,214 @@ def test_with_mocked_llm(setup_validators):
|
|
757
763
|
- The `setup_validators` fixture handles the mock setup when provided with a mock_response
|
758
764
|
- Mocking is particularly useful for CI/CD pipelines where deterministic results are required
|
759
765
|
|
766
|
+
### Custom Transaction Context
|
767
|
+
|
768
|
+
The GenLayer Testing Suite allows you to customize the transaction execution environment by providing a `transaction_context` parameter with custom validators and GenVM datetime settings.
|
769
|
+
|
770
|
+
#### Using Transaction Context
|
771
|
+
|
772
|
+
Set custom validators and GenVM datetime for deterministic testing:
|
773
|
+
|
774
|
+
```python
|
775
|
+
from gltest import get_contract_factory, get_validator_factory
|
776
|
+
|
777
|
+
def test_with_custom_transaction_context():
|
778
|
+
factory = get_contract_factory("MyContract")
|
779
|
+
validator_factory = get_validator_factory()
|
780
|
+
|
781
|
+
# Create custom validators
|
782
|
+
validators = validator_factory.batch_create_validators(
|
783
|
+
count=3,
|
784
|
+
stake=10,
|
785
|
+
provider="openai",
|
786
|
+
model="gpt-4o",
|
787
|
+
config={"temperature": 0.7, "max_tokens": 1000},
|
788
|
+
plugin="openai-compatible",
|
789
|
+
plugin_config={"api_key_env_var": "OPENAI_API_KEY"}
|
790
|
+
)
|
791
|
+
|
792
|
+
# Create transaction context with custom validators and datetime
|
793
|
+
transaction_context = {
|
794
|
+
"validators": [v.to_dict() for v in validators],
|
795
|
+
"genvm_datetime": "2024-03-15T14:30:00Z" # ISO format datetime
|
796
|
+
}
|
797
|
+
|
798
|
+
# Deploy with custom context
|
799
|
+
contract = factory.deploy(
|
800
|
+
args=["initial_value"],
|
801
|
+
transaction_context=transaction_context
|
802
|
+
)
|
803
|
+
|
804
|
+
# Call methods with custom context
|
805
|
+
result = contract.read_method().call(
|
806
|
+
transaction_context=transaction_context
|
807
|
+
)
|
808
|
+
|
809
|
+
# Write operations with custom context
|
810
|
+
tx_receipt = contract.write_method(args=["value"]).transact(
|
811
|
+
transaction_context=transaction_context
|
812
|
+
)
|
813
|
+
```
|
814
|
+
|
815
|
+
#### Mock Validators with Transaction Context
|
816
|
+
|
817
|
+
Combine mock validators with custom datetime for fully deterministic tests:
|
818
|
+
|
819
|
+
```python
|
820
|
+
def test_with_mocked_context():
|
821
|
+
factory = get_contract_factory("LLMContract")
|
822
|
+
validator_factory = get_validator_factory()
|
823
|
+
|
824
|
+
# Define mock LLM responses
|
825
|
+
mock_response = {
|
826
|
+
"nondet_exec_prompt": {
|
827
|
+
"analyze this": "positive sentiment"
|
828
|
+
},
|
829
|
+
"eq_principle_prompt_comparative": {
|
830
|
+
"values match": True
|
831
|
+
}
|
832
|
+
}
|
833
|
+
|
834
|
+
# Create mock validators
|
835
|
+
mock_validators = validator_factory.batch_create_mock_validators(
|
836
|
+
count=5,
|
837
|
+
mock_llm_response=mock_response
|
838
|
+
)
|
839
|
+
|
840
|
+
# Set up deterministic context
|
841
|
+
transaction_context = {
|
842
|
+
"validators": [v.to_dict() for v in mock_validators],
|
843
|
+
"genvm_datetime": "2024-01-01T00:00:00Z" # Fixed datetime for reproducibility
|
844
|
+
}
|
845
|
+
|
846
|
+
# Deploy and test with deterministic context
|
847
|
+
contract = factory.deploy(transaction_context=transaction_context)
|
848
|
+
|
849
|
+
# All operations will use the same mocked validators and datetime
|
850
|
+
result = contract.analyze_text(args=["analyze this"]).transact(
|
851
|
+
transaction_context=transaction_context
|
852
|
+
)
|
853
|
+
# Result will consistently return "positive sentiment"
|
854
|
+
```
|
855
|
+
|
856
|
+
### Custom Validators
|
857
|
+
|
858
|
+
The GenLayer Testing Suite includes a `get_validator_factory()` function that allows you to create custom validators with specific configurations for testing different LLM providers and consensus scenarios.
|
859
|
+
|
860
|
+
#### Creating Custom Validators
|
861
|
+
|
862
|
+
```python
|
863
|
+
from gltest import get_validator_factory
|
864
|
+
|
865
|
+
def test_with_custom_validators():
|
866
|
+
factory = get_validator_factory()
|
867
|
+
|
868
|
+
# Create validators with different LLM providers
|
869
|
+
openai_validator = factory.create_validator(
|
870
|
+
stake=10,
|
871
|
+
provider="openai",
|
872
|
+
model="gpt-4o",
|
873
|
+
config={"temperature": 0.8, "max_tokens": 2000},
|
874
|
+
plugin="openai-compatible",
|
875
|
+
plugin_config={"api_key_env_var": "OPENAI_API_KEY"}
|
876
|
+
)
|
877
|
+
|
878
|
+
ollama_validator = factory.create_validator(
|
879
|
+
stake=8,
|
880
|
+
provider="ollama",
|
881
|
+
model="mistral",
|
882
|
+
config={"temperature": 0.5},
|
883
|
+
plugin="ollama",
|
884
|
+
plugin_config={"api_url": "http://localhost:11434"}
|
885
|
+
)
|
886
|
+
|
887
|
+
# Use validators in your tests
|
888
|
+
validators = [openai_validator, ollama_validator]
|
889
|
+
# Configure your test environment with these validators
|
890
|
+
```
|
891
|
+
|
892
|
+
#### Batch Creation
|
893
|
+
|
894
|
+
Create multiple validators with the same configuration:
|
895
|
+
|
896
|
+
```python
|
897
|
+
def test_batch_validators():
|
898
|
+
factory = get_validator_factory()
|
899
|
+
|
900
|
+
# Create 5 validators with identical configuration
|
901
|
+
validators = factory.batch_create_validators(
|
902
|
+
count=5,
|
903
|
+
stake=8,
|
904
|
+
provider="openai",
|
905
|
+
model="gpt-4o",
|
906
|
+
config={"temperature": 0.7, "max_tokens": 1000},
|
907
|
+
plugin="openai-compatible",
|
908
|
+
plugin_config={"api_key_env_var": "OPENAI_API_KEY"}
|
909
|
+
)
|
910
|
+
```
|
911
|
+
|
912
|
+
#### Mock Validators
|
913
|
+
|
914
|
+
For deterministic testing, create mock validators that return predefined responses:
|
915
|
+
|
916
|
+
```python
|
917
|
+
def test_with_mock_validators():
|
918
|
+
factory = get_validator_factory()
|
919
|
+
|
920
|
+
# Define mock responses
|
921
|
+
mock_response = {
|
922
|
+
"nondet_exec_prompt": {
|
923
|
+
"What is 2+2?": "4",
|
924
|
+
"Explain quantum physics": "It's complicated"
|
925
|
+
},
|
926
|
+
"eq_principle_prompt_comparative": {
|
927
|
+
"values must match": True
|
928
|
+
},
|
929
|
+
"eq_principle_prompt_non_comparative": {
|
930
|
+
"Is this valid?": True
|
931
|
+
}
|
932
|
+
}
|
933
|
+
|
934
|
+
# Create a single mock validator
|
935
|
+
mock_validator = factory.create_mock_validator(mock_response)
|
936
|
+
|
937
|
+
# Create multiple mock validators
|
938
|
+
mock_validators = factory.batch_create_mock_validators(
|
939
|
+
count=5,
|
940
|
+
mock_llm_response=mock_response
|
941
|
+
)
|
942
|
+
```
|
943
|
+
|
944
|
+
#### Validator Methods
|
945
|
+
|
946
|
+
Each validator object provides useful methods:
|
947
|
+
- `to_dict()`: Convert validator to dictionary format for API calls
|
948
|
+
- `clone()`: Create an identical copy of the validator
|
949
|
+
- `batch_clone(count)`: Create multiple identical copies
|
950
|
+
|
951
|
+
Example:
|
952
|
+
```python
|
953
|
+
def test_validator_cloning():
|
954
|
+
factory = get_validator_factory()
|
955
|
+
|
956
|
+
# Create a base validator
|
957
|
+
base_validator = factory.create_validator(
|
958
|
+
stake=10,
|
959
|
+
provider="openai",
|
960
|
+
model="gpt-4o",
|
961
|
+
config={"temperature": 0.7},
|
962
|
+
plugin="openai-compatible",
|
963
|
+
plugin_config={"api_key_env_var": "OPENAI_API_KEY"}
|
964
|
+
)
|
965
|
+
|
966
|
+
# Clone it to create identical validators
|
967
|
+
cloned = base_validator.clone()
|
968
|
+
multiple_clones = base_validator.batch_clone(3)
|
969
|
+
|
970
|
+
# Convert to dictionary for API usage
|
971
|
+
validator_dict = base_validator.to_dict()
|
972
|
+
```
|
973
|
+
|
760
974
|
## 📝 Best Practices
|
761
975
|
|
762
976
|
1. **Test Organization**
|
@@ -1,12 +1,12 @@
|
|
1
|
-
genlayer_test-0.
|
2
|
-
gltest/__init__.py,sha256=
|
1
|
+
genlayer_test-0.8.0.dist-info/licenses/LICENSE,sha256=che_H4vE0QUx3HvWrAa1_jDEVInift0U6VO15-QqEls,1064
|
2
|
+
gltest/__init__.py,sha256=49112x2CLdYwvCbBZ1laJmMk0NQ7S3u5YUbxPefqhrk,454
|
3
3
|
gltest/accounts.py,sha256=HUmWguJMolggQaZNRPw-LGlRlQCjLLdUanKRowMv6pI,812
|
4
4
|
gltest/assertions.py,sha256=0dEk0VxcHK4I7GZPHxJmz-2jaA60V499gOSR74rZbfM,1748
|
5
5
|
gltest/clients.py,sha256=1dX6wmG3QCevQRLbSaFlHymZSb-sJ5aYwet1IoX2nbA,1554
|
6
6
|
gltest/exceptions.py,sha256=deJPmrTe5gF33qkkKF2IVJY7lc_knI7Ql3N7jZ8aLZs,510
|
7
7
|
gltest/fixtures.py,sha256=EJXmqcC3LD03v07mepacFl58lAdhbLj6bP5rtALYISk,2507
|
8
8
|
gltest/logging.py,sha256=jAkHsuMm-AEx1Xu1srU6W-0YzTwXJB48mCK-OVzAiN4,342
|
9
|
-
gltest/types.py,sha256=
|
9
|
+
gltest/types.py,sha256=H32fHrU5aFMaPHXgEWcHAmLWOZ9pBFVp8PK_ncpVOgM,940
|
10
10
|
gltest/utils.py,sha256=-gHhjrS7i_GhDG3sKOq2qsTtYBt4HHgXHEXh-3RB_rI,573
|
11
11
|
gltest/artifacts/__init__.py,sha256=qTt3TE19gVNWnQLUlt5aDe4nNvJ2YJ1jzDkMmYIsCG0,194
|
12
12
|
gltest/artifacts/contract.py,sha256=KChpmfjZod_0dVB8y-dvWz6IVm7QlIJsgG2ArtvVDaU,6457
|
@@ -20,6 +20,8 @@ gltest/contracts/utils.py,sha256=TTXgcXn9BuRIlKJrjwmU7R3l1IgXsXk2luM-r3lfbbg,296
|
|
20
20
|
gltest/helpers/__init__.py,sha256=I7HiTu_H7_hP65zY6Wl02r-5eAMr2eZvqBVmusuQLX4,180
|
21
21
|
gltest/helpers/fixture_snapshot.py,sha256=bMgvlEVQBGIQzj7NOyosXWlphI1H2C1o75Zo0C-kGfQ,1931
|
22
22
|
gltest/helpers/take_snapshot.py,sha256=-QkaBvFG4ZsNKv_nCSEsy5Ze1pICOHxVhReSeQmZUlY,1276
|
23
|
+
gltest/validators/__init__.py,sha256=AXboXORF5a8MVtG7jWMT1fJcwGXNzcX6txXQstwX2EU,152
|
24
|
+
gltest/validators/validator_factory.py,sha256=fpb-YyAKuWo4-pXBjrZ_TApYLsm6HHa6kGpbFByRucs,3886
|
23
25
|
gltest_cli/logging.py,sha256=WXVhfq9vT6FtV_jxDqGEGia1ZWSIUKAfmWRnZd_gWQk,1266
|
24
26
|
gltest_cli/main.py,sha256=Ti2-0Ev1x5_cM0D1UKqdgaDt80CDHEQGtdRne2qLm4M,53
|
25
27
|
gltest_cli/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -46,6 +48,7 @@ tests/examples/contracts/user_storage.py,sha256=2W2Iv-hQZMkAaPl2RY_F-OeJpD4IlPxg
|
|
46
48
|
tests/examples/contracts/wizard_of_coin.py,sha256=Y8daPpoSKdM8wfbCPOIgEdpkLIA1ZMmeg6Hu5fBB-kU,1624
|
47
49
|
tests/examples/contracts/multi_file_contract/__init__.py,sha256=xDn_wS62GhCmnYoI6xIqlic2i882SoPnR2TEauKc9tQ,575
|
48
50
|
tests/examples/contracts/multi_file_contract/other.py,sha256=jHDtjUL3eAUgE6yOYKFw_RfAH7kIwk8CvxUjbWHNruk,236
|
51
|
+
tests/examples/tests/test_custom_validators.py,sha256=ounk3fBqDexAI3eRUqscMqKf5vz77tbSxW4Cz8tzfF0,2172
|
49
52
|
tests/examples/tests/test_football_prediction_market.py,sha256=f2hfDK76WrNJZtFkTPKoPRR6bkmFLEssnlwwltSnU9A,1111
|
50
53
|
tests/examples/tests/test_intelligent_oracle_factory.py,sha256=sL26aeb84XpJPCSUSIX3yrbwQE8GZtvNcsaKTpngFmY,7611
|
51
54
|
tests/examples/tests/test_invalid_deploy.py,sha256=pppM8_Vn4DXcWq9iyJXb0SpZnKXkIyJxoIDW5ApCS94,814
|
@@ -72,8 +75,8 @@ tests/gltest_cli/config/test_config_integration.py,sha256=vPTzr3_h9UMw7m72HogBJE
|
|
72
75
|
tests/gltest_cli/config/test_general_config.py,sha256=UHtSwVnso-ZwNtYM0Z4v2sCLKwyrVbHlk6b1leVfV84,14703
|
73
76
|
tests/gltest_cli/config/test_plugin.py,sha256=COrEK5tHP1BSzanWbZHmN3EQgE9VuTcPvB95pgOvKS4,7974
|
74
77
|
tests/gltest_cli/config/test_user.py,sha256=JxR655oUFoM9quWQO68CVPKRpT0TMpzS3bF6j6NWyT4,14401
|
75
|
-
genlayer_test-0.
|
76
|
-
genlayer_test-0.
|
77
|
-
genlayer_test-0.
|
78
|
-
genlayer_test-0.
|
79
|
-
genlayer_test-0.
|
78
|
+
genlayer_test-0.8.0.dist-info/METADATA,sha256=6LQF4o37U3qg9rmmLLoZps0XpC0T5gFsg_l4NZr7z4g,39178
|
79
|
+
genlayer_test-0.8.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
80
|
+
genlayer_test-0.8.0.dist-info/entry_points.txt,sha256=RWPcSArBpz_G4BYioh5L8Q8hyClRbSgzLimjcWMp-BQ,94
|
81
|
+
genlayer_test-0.8.0.dist-info/top_level.txt,sha256=-qiGZxTRBytujzgVcKpxjvQ-WNeUDjXa59ceGMwMpko,24
|
82
|
+
genlayer_test-0.8.0.dist-info/RECORD,,
|
gltest/__init__.py
CHANGED
@@ -8,6 +8,8 @@ from gltest.clients import (
|
|
8
8
|
get_gl_client,
|
9
9
|
)
|
10
10
|
from gltest.contracts import get_contract_factory
|
11
|
+
from gltest.validators import get_validator_factory
|
12
|
+
|
11
13
|
|
12
14
|
__all__ = [
|
13
15
|
"create_account",
|
@@ -16,4 +18,5 @@ __all__ = [
|
|
16
18
|
"get_gl_client",
|
17
19
|
"get_accounts",
|
18
20
|
"get_default_account",
|
21
|
+
"get_validator_factory",
|
19
22
|
]
|
gltest/types.py
CHANGED
@@ -9,6 +9,17 @@ from genlayer_py.types import (
|
|
9
9
|
from typing import List, TypedDict, Dict, Any
|
10
10
|
|
11
11
|
|
12
|
+
class MockedLLMResponse(TypedDict):
|
13
|
+
"""Maps prompts to responses"""
|
14
|
+
|
15
|
+
# Prompt -> raw JSON string response
|
16
|
+
nondet_exec_prompt: Dict[str, str]
|
17
|
+
|
18
|
+
# Principle -> expected boolean
|
19
|
+
eq_principle_prompt_comparative: Dict[str, bool]
|
20
|
+
eq_principle_prompt_non_comparative: Dict[str, bool]
|
21
|
+
|
22
|
+
|
12
23
|
class ValidatorConfig(TypedDict):
|
13
24
|
"""Validator information."""
|
14
25
|
|
@@ -20,7 +31,7 @@ class ValidatorConfig(TypedDict):
|
|
20
31
|
|
21
32
|
|
22
33
|
class TransactionContext(TypedDict, total=False):
|
23
|
-
"""Context for
|
34
|
+
"""Context for transaction operations."""
|
24
35
|
|
25
36
|
validators: List[ValidatorConfig] # List to create virtual validators
|
26
37
|
genvm_datetime: str # ISO format datetime string
|
@@ -0,0 +1,136 @@
|
|
1
|
+
from gltest.types import MockedLLMResponse
|
2
|
+
from dataclasses import dataclass
|
3
|
+
from typing import Dict, Any, Optional, List
|
4
|
+
from copy import deepcopy
|
5
|
+
|
6
|
+
|
7
|
+
@dataclass
|
8
|
+
class Validator:
|
9
|
+
stake: int
|
10
|
+
provider: str
|
11
|
+
model: str
|
12
|
+
config: Dict[str, Any]
|
13
|
+
plugin: str
|
14
|
+
plugin_config: Dict[str, Any]
|
15
|
+
|
16
|
+
# Mock configuration
|
17
|
+
mock_enabled: bool
|
18
|
+
mock_llm_response: Optional[MockedLLMResponse]
|
19
|
+
|
20
|
+
def to_dict(self) -> Dict[str, Any]:
|
21
|
+
normal_config = {
|
22
|
+
"stake": self.stake,
|
23
|
+
"provider": self.provider,
|
24
|
+
"model": self.model,
|
25
|
+
"config": deepcopy(self.config),
|
26
|
+
"plugin": self.plugin,
|
27
|
+
"plugin_config": deepcopy(self.plugin_config),
|
28
|
+
}
|
29
|
+
if not self.mock_enabled:
|
30
|
+
return normal_config
|
31
|
+
|
32
|
+
mock = self.mock_llm_response or {}
|
33
|
+
mock_config = {
|
34
|
+
"response": mock.get("nondet_exec_prompt", {}),
|
35
|
+
"eq_principle_prompt_comparative": mock.get(
|
36
|
+
"eq_principle_prompt_comparative", {}
|
37
|
+
),
|
38
|
+
"eq_principle_prompt_non_comparative": mock.get(
|
39
|
+
"eq_principle_prompt_non_comparative", {}
|
40
|
+
),
|
41
|
+
}
|
42
|
+
return {
|
43
|
+
**normal_config,
|
44
|
+
"plugin_config": {
|
45
|
+
**self.plugin_config,
|
46
|
+
"mock_response": mock_config,
|
47
|
+
},
|
48
|
+
}
|
49
|
+
|
50
|
+
def batch_clone(self, count: int) -> List["Validator"]:
|
51
|
+
return [self.clone() for _ in range(count)]
|
52
|
+
|
53
|
+
def clone(self) -> "Validator":
|
54
|
+
return Validator(
|
55
|
+
stake=self.stake,
|
56
|
+
provider=self.provider,
|
57
|
+
model=self.model,
|
58
|
+
config=deepcopy(self.config),
|
59
|
+
plugin=self.plugin,
|
60
|
+
plugin_config=deepcopy(self.plugin_config),
|
61
|
+
mock_enabled=self.mock_enabled,
|
62
|
+
mock_llm_response=deepcopy(self.mock_llm_response),
|
63
|
+
)
|
64
|
+
|
65
|
+
|
66
|
+
class ValidatorFactory:
|
67
|
+
def __init__(self):
|
68
|
+
pass
|
69
|
+
|
70
|
+
def create_validator(
|
71
|
+
self,
|
72
|
+
stake: int,
|
73
|
+
provider: str,
|
74
|
+
model: str,
|
75
|
+
config: Dict[str, Any],
|
76
|
+
plugin: str,
|
77
|
+
plugin_config: Dict[str, Any],
|
78
|
+
) -> Validator:
|
79
|
+
return Validator(
|
80
|
+
stake=stake,
|
81
|
+
provider=provider,
|
82
|
+
model=model,
|
83
|
+
config=deepcopy(config),
|
84
|
+
plugin=plugin,
|
85
|
+
plugin_config=deepcopy(plugin_config),
|
86
|
+
mock_enabled=False,
|
87
|
+
mock_llm_response=None,
|
88
|
+
)
|
89
|
+
|
90
|
+
def batch_create_validators(
|
91
|
+
self,
|
92
|
+
count: int,
|
93
|
+
stake: int,
|
94
|
+
provider: str,
|
95
|
+
model: str,
|
96
|
+
config: Dict[str, Any],
|
97
|
+
plugin: str,
|
98
|
+
plugin_config: Dict[str, Any],
|
99
|
+
) -> List[Validator]:
|
100
|
+
return [
|
101
|
+
self.create_validator(
|
102
|
+
stake=stake,
|
103
|
+
provider=provider,
|
104
|
+
model=model,
|
105
|
+
config=config,
|
106
|
+
plugin=plugin,
|
107
|
+
plugin_config=plugin_config,
|
108
|
+
)
|
109
|
+
for _ in range(count)
|
110
|
+
]
|
111
|
+
|
112
|
+
def create_mock_validator(self, mock_llm_response: MockedLLMResponse) -> Validator:
|
113
|
+
return Validator(
|
114
|
+
stake=8,
|
115
|
+
provider="openai",
|
116
|
+
model="gpt-4o",
|
117
|
+
config={"temperature": 0.75, "max_tokens": 500},
|
118
|
+
plugin="openai-compatible",
|
119
|
+
plugin_config={
|
120
|
+
"api_key_env_var": "OPENAIKEY",
|
121
|
+
"api_url": "https://api.openai.com",
|
122
|
+
},
|
123
|
+
mock_enabled=True,
|
124
|
+
mock_llm_response=deepcopy(mock_llm_response),
|
125
|
+
)
|
126
|
+
|
127
|
+
def batch_create_mock_validators(
|
128
|
+
self,
|
129
|
+
count: int,
|
130
|
+
mock_llm_response: MockedLLMResponse,
|
131
|
+
) -> List[Validator]:
|
132
|
+
return [self.create_mock_validator(mock_llm_response) for _ in range(count)]
|
133
|
+
|
134
|
+
|
135
|
+
def get_validator_factory() -> ValidatorFactory:
|
136
|
+
return ValidatorFactory()
|
@@ -0,0 +1,65 @@
|
|
1
|
+
from gltest import get_contract_factory
|
2
|
+
from gltest.assertions import tx_execution_succeeded
|
3
|
+
from gltest import get_validator_factory
|
4
|
+
from gltest.types import MockedLLMResponse
|
5
|
+
import json
|
6
|
+
|
7
|
+
|
8
|
+
def test_custom_validators():
|
9
|
+
|
10
|
+
validator_factory = get_validator_factory()
|
11
|
+
validators = validator_factory.batch_create_validators(
|
12
|
+
count=5,
|
13
|
+
stake=8,
|
14
|
+
provider="openai",
|
15
|
+
model="gpt-4o",
|
16
|
+
config={"temperature": 0.75, "max_tokens": 500},
|
17
|
+
plugin="openai-compatible",
|
18
|
+
plugin_config={
|
19
|
+
"api_key_env_var": "OPENAIKEY",
|
20
|
+
"api_url": "https://api.openai.com",
|
21
|
+
},
|
22
|
+
)
|
23
|
+
|
24
|
+
factory = get_contract_factory("WizardOfCoin")
|
25
|
+
contract = factory.deploy(
|
26
|
+
args=[True],
|
27
|
+
transaction_context={"validators": [v.to_dict() for v in validators]},
|
28
|
+
)
|
29
|
+
|
30
|
+
transaction_response_call_1 = contract.ask_for_coin(
|
31
|
+
args=["Can you please give me my coin?"]
|
32
|
+
).transact(transaction_context={"validators": [v.to_dict() for v in validators]})
|
33
|
+
assert tx_execution_succeeded(transaction_response_call_1)
|
34
|
+
|
35
|
+
|
36
|
+
def test_custom_mocked_validators():
|
37
|
+
mock_llm_response: MockedLLMResponse = {
|
38
|
+
"nondet_exec_prompt": {
|
39
|
+
"wizard": json.dumps(
|
40
|
+
{
|
41
|
+
"reasoning": "I am a grumpy wizard and I never give away my coins!",
|
42
|
+
"give_coin": False,
|
43
|
+
}
|
44
|
+
),
|
45
|
+
},
|
46
|
+
"eq_principle_prompt_comparative": {
|
47
|
+
"The value of give_coin has to match": True
|
48
|
+
},
|
49
|
+
}
|
50
|
+
validator_factory = get_validator_factory()
|
51
|
+
validators = validator_factory.batch_create_mock_validators(
|
52
|
+
count=5,
|
53
|
+
mock_llm_response=mock_llm_response,
|
54
|
+
)
|
55
|
+
|
56
|
+
factory = get_contract_factory("WizardOfCoin")
|
57
|
+
contract = factory.deploy(
|
58
|
+
args=[True],
|
59
|
+
transaction_context={"validators": [v.to_dict() for v in validators]},
|
60
|
+
)
|
61
|
+
|
62
|
+
transaction_response_call_1 = contract.ask_for_coin(
|
63
|
+
args=["Can you please give me my coin?"]
|
64
|
+
).transact(transaction_context={"validators": [v.to_dict() for v in validators]})
|
65
|
+
assert tx_execution_succeeded(transaction_response_call_1)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|