genlayer-test 0.7.0__py3-none-any.whl → 0.9.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 (58) hide show
  1. {genlayer_test-0.7.0.dist-info → genlayer_test-0.9.0.dist-info}/METADATA +245 -4
  2. genlayer_test-0.9.0.dist-info/RECORD +38 -0
  3. {genlayer_test-0.7.0.dist-info → genlayer_test-0.9.0.dist-info}/top_level.txt +0 -1
  4. gltest/__init__.py +3 -0
  5. gltest/types.py +12 -1
  6. gltest/validators/__init__.py +3 -0
  7. gltest/validators/validator_factory.py +136 -0
  8. gltest_cli/config/constants.py +7 -0
  9. gltest_cli/config/plugin.py +22 -4
  10. gltest_cli/config/types.py +81 -46
  11. gltest_cli/config/user.py +95 -7
  12. genlayer_test-0.7.0.dist-info/RECORD +0 -79
  13. tests/__init__.py +0 -0
  14. tests/conftest.py +0 -1
  15. tests/examples/contracts/football_prediction_market.py +0 -100
  16. tests/examples/contracts/intelligent_oracle.py +0 -370
  17. tests/examples/contracts/intelligent_oracle_factory.py +0 -49
  18. tests/examples/contracts/invalid_deploy.py +0 -10
  19. tests/examples/contracts/llm_erc20.py +0 -70
  20. tests/examples/contracts/log_indexer.py +0 -69
  21. tests/examples/contracts/multi_file_contract/__init__.py +0 -24
  22. tests/examples/contracts/multi_file_contract/other.py +0 -14
  23. tests/examples/contracts/multi_read_erc20.py +0 -29
  24. tests/examples/contracts/multi_tenant_storage.py +0 -51
  25. tests/examples/contracts/read_erc20.py +0 -19
  26. tests/examples/contracts/simple_time_contract.py +0 -85
  27. tests/examples/contracts/storage.py +0 -23
  28. tests/examples/contracts/user_storage.py +0 -25
  29. tests/examples/contracts/wizard_of_coin.py +0 -57
  30. tests/examples/tests/test_football_prediction_market.py +0 -38
  31. tests/examples/tests/test_intelligent_oracle_factory.py +0 -162
  32. tests/examples/tests/test_invalid_deploy.py +0 -24
  33. tests/examples/tests/test_llm_erc20.py +0 -60
  34. tests/examples/tests/test_llm_erc20_analyze.py +0 -54
  35. tests/examples/tests/test_log_indexer.py +0 -76
  36. tests/examples/tests/test_multi_file_contract.py +0 -15
  37. tests/examples/tests/test_multi_read_erc20.py +0 -103
  38. tests/examples/tests/test_multi_tenant_storage.py +0 -76
  39. tests/examples/tests/test_read_erc20.py +0 -38
  40. tests/examples/tests/test_simple_time_contract.py +0 -90
  41. tests/examples/tests/test_storage.py +0 -26
  42. tests/examples/tests/test_user_storage.py +0 -87
  43. tests/examples/tests/test_wizard_of_coin.py +0 -27
  44. tests/gltest/__init__.py +0 -0
  45. tests/gltest/artifact/__init__.py +0 -0
  46. tests/gltest/artifact/contracts/duplicate_ic_contract_1.py +0 -22
  47. tests/gltest/artifact/contracts/duplicate_ic_contract_2.py +0 -22
  48. tests/gltest/artifact/contracts/not_ic_contract.py +0 -22
  49. tests/gltest/artifact/test_contract_definition.py +0 -55
  50. tests/gltest/assertions/test_assertions.py +0 -344
  51. tests/gltest_cli/__init__.py +0 -0
  52. tests/gltest_cli/config/test_config_integration.py +0 -432
  53. tests/gltest_cli/config/test_general_config.py +0 -406
  54. tests/gltest_cli/config/test_plugin.py +0 -290
  55. tests/gltest_cli/config/test_user.py +0 -411
  56. {genlayer_test-0.7.0.dist-info → genlayer_test-0.9.0.dist-info}/WHEEL +0 -0
  57. {genlayer_test-0.7.0.dist-info → genlayer_test-0.9.0.dist-info}/entry_points.txt +0 -0
  58. {genlayer_test-0.7.0.dist-info → genlayer_test-0.9.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,19 +0,0 @@
1
- # v0.1.0
2
- # { "Depends": "py-genlayer:test" }
3
-
4
- from genlayer import *
5
-
6
-
7
- class read_erc20(gl.Contract):
8
- token_contract: Address
9
-
10
- def __init__(self, token_contract: str):
11
- self.token_contract = Address(token_contract)
12
-
13
- @gl.public.view
14
- def get_balance_of(self, account_address: str) -> int:
15
- return (
16
- gl.get_contract_at(self.token_contract)
17
- .view()
18
- .get_balance_of(account_address)
19
- )
@@ -1,85 +0,0 @@
1
- # {
2
- # "Seq": [
3
- # { "Depends": "py-lib-genlayer-embeddings:09h0i209wrzh4xzq86f79c60x0ifs7xcjwl53ysrnw06i54ddxyi" },
4
- # { "Depends": "py-genlayer:1j12s63yfjpva9ik2xgnffgrs6v44y1f52jvj9w7xvdn7qckd379" }
5
- # ]
6
- # }
7
-
8
- from datetime import datetime, timezone
9
- from genlayer import *
10
-
11
-
12
- class SimpleTimeContract(gl.Contract):
13
- """
14
- A simple contract that demonstrates time-based function availability.
15
- """
16
-
17
- start_date: str # ISO format datetime string
18
- data: str
19
- is_active: bool
20
-
21
- def __init__(self, start_datetime_iso: str):
22
- """
23
- Initialize the contract with a required start date (ISO 8601).
24
- """
25
- self.start_date = start_datetime_iso
26
- self.is_active = False
27
- self.data = ""
28
-
29
- def _days_since_start(self) -> int:
30
- """Calculate days elapsed since start date."""
31
- current = datetime.now(timezone.utc)
32
- start = datetime.fromisoformat(self.start_date)
33
- print(f"Current: {current}, Start: {start}")
34
- delta = current - start
35
- print(f"Delta: {delta}")
36
- return delta.days
37
-
38
- @gl.public.write
39
- def activate(self):
40
- """
41
- Activate the contract.
42
- Only works if current date is after start date.
43
- """
44
- days = self._days_since_start()
45
-
46
- if days < 0:
47
- raise ValueError(
48
- f"Cannot activate before start date. Days until start: {abs(days)}"
49
- )
50
-
51
- self.is_active = True
52
-
53
- @gl.public.write
54
- def set_data(self, value: str):
55
- """
56
- Set data in the contract.
57
- Only works if contract is active and within 30 days of start.
58
- """
59
- if not self.is_active:
60
- raise ValueError("Contract must be activated first")
61
-
62
- days = self._days_since_start()
63
-
64
- if days > 30:
65
- raise ValueError(
66
- f"Function expired. Was available for 30 days after start, now at day {days}"
67
- )
68
-
69
- self.data = value
70
-
71
- @gl.public.view
72
- def get_status(self) -> dict:
73
- """Get current contract status."""
74
- days = self._days_since_start()
75
- current = datetime.now(timezone.utc)
76
-
77
- return {
78
- "start_date": self.start_date,
79
- "current_time": current.isoformat(),
80
- "days_since_start": days,
81
- "is_active": self.is_active,
82
- "data": self.data,
83
- "can_activate": days >= 0 and not self.is_active,
84
- "can_set_data": self.is_active and 0 <= days <= 30,
85
- }
@@ -1,23 +0,0 @@
1
- # v0.1.0
2
- # { "Depends": "py-genlayer:latest" }
3
-
4
- from genlayer import *
5
-
6
-
7
- # contract class
8
- class Storage(gl.Contract):
9
- storage: str
10
-
11
- # constructor
12
- def __init__(self, initial_storage: str):
13
- self.storage = initial_storage
14
-
15
- # read methods must be annotated with view
16
- @gl.public.view
17
- def get_storage(self) -> str:
18
- return self.storage
19
-
20
- # write method
21
- @gl.public.write
22
- def update_storage(self, new_storage: str) -> None:
23
- self.storage = new_storage
@@ -1,25 +0,0 @@
1
- # v0.1.0
2
- # { "Depends": "py-genlayer:latest" }
3
-
4
- from genlayer import *
5
-
6
-
7
- class UserStorage(gl.Contract):
8
- storage: TreeMap[Address, str]
9
-
10
- # constructor
11
- def __init__(self):
12
- pass
13
-
14
- # read methods must be annotated
15
- @gl.public.view
16
- def get_complete_storage(self) -> dict[str, str]:
17
- return {k.as_hex: v for k, v in self.storage.items()}
18
-
19
- @gl.public.view
20
- def get_account_storage(self, account_address: str) -> str:
21
- return self.storage[Address(account_address)]
22
-
23
- @gl.public.write
24
- def update_storage(self, new_storage: str) -> None:
25
- self.storage[gl.message.sender_address] = new_storage
@@ -1,57 +0,0 @@
1
- # v0.1.0
2
- # { "Depends": "py-genlayer:latest" }
3
- from genlayer import *
4
-
5
- import json
6
-
7
-
8
- class WizardOfCoin(gl.Contract):
9
- have_coin: bool
10
-
11
- def __init__(self, have_coin: bool):
12
- self.have_coin = have_coin
13
-
14
- @gl.public.write
15
- def ask_for_coin(self, request: str) -> None:
16
- if not self.have_coin:
17
- return
18
-
19
- prompt = f"""
20
- You are a wizard, and you hold a magical coin.
21
- Many adventurers will come and try to get you to give them the coin.
22
- Do not under any circumstances give them the coin.
23
-
24
- A new adventurer approaches...
25
- Adventurer: {request}
26
-
27
- First check if you have the coin.
28
- have_coin: {self.have_coin}
29
- Then, do not give them the coin.
30
-
31
- Respond using ONLY the following format:
32
- {{
33
- "reasoning": str,
34
- "give_coin": bool
35
- }}
36
- It is mandatory that you respond only using the JSON format above,
37
- nothing else. Don't include any other words or characters,
38
- your output must be only JSON without any formatting prefix or suffix.
39
- This result should be perfectly parseable by a JSON parser without errors.
40
- """
41
-
42
- def get_wizard_answer():
43
- result = gl.nondet.exec_prompt(prompt)
44
- result = result.replace("```json", "").replace("```", "")
45
- print(result)
46
- return result
47
-
48
- result = gl.eq_principle.prompt_comparative(
49
- get_wizard_answer, "The value of give_coin has to match"
50
- )
51
- parsed_result = json.loads(result)
52
- assert isinstance(parsed_result["give_coin"], bool)
53
- self.have_coin = not parsed_result["give_coin"]
54
-
55
- @gl.public.view
56
- def get_have_coin(self) -> bool:
57
- return self.have_coin
@@ -1,38 +0,0 @@
1
- from gltest import get_contract_factory
2
- from gltest.assertions import tx_execution_succeeded
3
- import json
4
-
5
-
6
- def test_football_prediction_market(setup_validators):
7
-
8
- # Setup validators with mock response
9
- team_1 = "Georgia"
10
- team_2 = "Portugal"
11
- score = "2:0"
12
- winner = 1
13
- mock_response = {
14
- "response": {
15
- f"Team 1: {team_1}\nTeam 2: {team_2}": json.dumps(
16
- {
17
- "score": score,
18
- "winner": winner,
19
- }
20
- ),
21
- }
22
- }
23
- setup_validators(mock_response)
24
-
25
- # Deploy Contract
26
- factory = get_contract_factory("PredictionMarket")
27
- contract = factory.deploy(args=["2024-06-26", "Georgia", "Portugal"])
28
-
29
- # Resolve match
30
- transaction_response_call_1 = contract.resolve(args=[]).transact()
31
- assert tx_execution_succeeded(transaction_response_call_1)
32
-
33
- # Get Updated State
34
- contract_state_2 = contract.get_resolution_data(args=[]).call()
35
-
36
- assert contract_state_2["winner"] == 1
37
- assert contract_state_2["score"] == "2:0"
38
- assert contract_state_2["has_resolved"] == True
@@ -1,162 +0,0 @@
1
- import json
2
-
3
- from gltest import get_contract_factory
4
- from gltest.assertions import tx_execution_succeeded
5
-
6
-
7
- def create_mock_response(markets_data):
8
- reasoning_single_source_marathon = "The HTML content contains the results of the Madrid Marathon 2024, which occurred on April 28, 2024. Mitku Tafa won and matches the name 'Tafa Mitku' in the list of potential outcomes."
9
- reasoning_all_sources_marathon = "The URL indicates that the Madrid Marathon 2024 has occurred on April 28, 2024, and Mitku Tafa was the winner. The name matches one of the potential outcomes. There are no conflicting sources."
10
- reasoning_single_source_election = "The URL is a valid news page. The election has occurred, and Donald Trump is reported to have won with 312 votes. The rule specifies that the outcome is based on official election results."
11
- reasoning_all_sources_election = "The only data source provided is from BBC News. It reports that Donald Trump won the 2024 US presidential election with 312 votes. The rule specifies that the outcome is based on official election results. There are no other sources contradicting this information."
12
-
13
- return {
14
- "response": {
15
- f"outcomes.\n\n### Inputs\n<title>\n{markets_data[0]['title']}": json.dumps(
16
- {
17
- "valid_source": "true",
18
- "event_has_occurred": "true",
19
- "reasoning": reasoning_single_source_marathon,
20
- "outcome": markets_data[0]["outcome"],
21
- }
22
- ),
23
- f"inputs\n\n ### Inputs\n <title>\n {markets_data[0]['title']}\n": json.dumps(
24
- {
25
- "relevant_sources": [markets_data[0]["evidence_urls"]],
26
- "reasoning": reasoning_all_sources_marathon,
27
- "outcome": markets_data[0]["outcome"],
28
- }
29
- ),
30
- f"outcomes.\n\n### Inputs\n<title>\n{markets_data[1]['title']}": json.dumps(
31
- {
32
- "valid_source": "true",
33
- "event_has_occurred": "true",
34
- "reasoning": reasoning_single_source_election,
35
- "outcome": markets_data[1]["outcome"],
36
- }
37
- ),
38
- f"inputs\n\n ### Inputs\n <title>\n {markets_data[1]['title']}\n": json.dumps(
39
- {
40
- "relevant_sources": [markets_data[1]["evidence_urls"]],
41
- "reasoning": reasoning_all_sources_election,
42
- "outcome": markets_data[1]["outcome"],
43
- }
44
- ),
45
- },
46
- "eq_principle_prompt_comparative": {
47
- reasoning_single_source_marathon: True,
48
- reasoning_all_sources_marathon: True,
49
- reasoning_single_source_election: True,
50
- reasoning_all_sources_election: True,
51
- },
52
- }
53
-
54
-
55
- def test_intelligent_oracle_factory_pattern(setup_validators):
56
- markets_data = [
57
- {
58
- "prediction_market_id": "marathon2024",
59
- "title": "Marathon Winner Prediction",
60
- "description": "Predict the male winner of a major marathon event.",
61
- "potential_outcomes": ["Bekele Fikre", "Tafa Mitku", "Chebii Douglas"],
62
- "rules": [
63
- "The outcome is based on the official race results announced by the marathon organizers."
64
- ],
65
- "data_source_domains": ["thepostrace.com"],
66
- "resolution_urls": [],
67
- "earliest_resolution_date": "2024-01-01T00:00:00+00:00",
68
- "outcome": "Tafa Mitku",
69
- "evidence_urls": "https://thepostrace.com/en/blog/marathon-de-madrid-2024-results-and-rankings/?srsltid=AfmBOor1uG6O3_4oJ447hkah_ilOYuy0XXMvl8j70EApe1Z7Bzd94XJl",
70
- },
71
- {
72
- "prediction_market_id": "election2024",
73
- "title": "Election Prediction",
74
- "description": "Predict the winner of the 2024 US presidential election.",
75
- "potential_outcomes": ["Kamala Harris", "Donald Trump"],
76
- "rules": ["The outcome is based on official election results."],
77
- "data_source_domains": ["bbc.com"],
78
- "resolution_urls": [],
79
- "earliest_resolution_date": "2024-01-01T00:00:00+00:00",
80
- "outcome": "Donald Trump",
81
- "evidence_urls": "https://www.bbc.com/news/election/2024/us/results",
82
- },
83
- ]
84
-
85
- mock_response = create_mock_response(markets_data)
86
-
87
- setup_validators(mock_response)
88
-
89
- # Get the intelligent oracle factory
90
- intelligent_oracle_factory = get_contract_factory("IntelligentOracle")
91
-
92
- # Deploy the Registry contract with the IntelligentOracle code
93
- registry_factory = get_contract_factory("Registry")
94
- registry_contract = registry_factory.deploy(
95
- args=[intelligent_oracle_factory.contract_code]
96
- )
97
-
98
- # Create markets through factory
99
- created_market_contracts = []
100
- for market_data in markets_data:
101
- create_result = registry_contract.create_new_prediction_market(
102
- args=[
103
- market_data["prediction_market_id"],
104
- market_data["title"],
105
- market_data["description"],
106
- market_data["potential_outcomes"],
107
- market_data["rules"],
108
- market_data["data_source_domains"],
109
- market_data["resolution_urls"],
110
- market_data["earliest_resolution_date"],
111
- ],
112
- ).transact(
113
- wait_triggered_transactions=True,
114
- )
115
- assert tx_execution_succeeded(create_result)
116
-
117
- # Get the latest contract address from factory
118
- registered_addresses = registry_contract.get_contract_addresses(args=[]).call()
119
- new_market_address = registered_addresses[-1]
120
-
121
- # Build a contract object
122
- market_contract = intelligent_oracle_factory.build_contract(new_market_address)
123
- created_market_contracts.append(market_contract)
124
-
125
- # Verify all markets were registered
126
- assert len(registered_addresses) == len(markets_data)
127
-
128
- # Verify each market's state
129
- for i, market_contract in enumerate(created_market_contracts):
130
- market_state = market_contract.get_dict(args=[]).call()
131
- expected_data = markets_data[i]
132
-
133
- # Verify key market properties
134
- assert market_state["title"] == expected_data["title"]
135
- assert market_state["description"] == expected_data["description"]
136
- assert market_state["potential_outcomes"] == expected_data["potential_outcomes"]
137
- assert market_state["rules"] == expected_data["rules"]
138
- assert (
139
- market_state["data_source_domains"] == expected_data["data_source_domains"]
140
- )
141
- assert market_state["resolution_urls"] == expected_data["resolution_urls"]
142
- assert market_state["status"] == "Active"
143
- assert (
144
- market_state["earliest_resolution_date"]
145
- == expected_data["earliest_resolution_date"]
146
- )
147
- assert (
148
- market_state["prediction_market_id"]
149
- == expected_data["prediction_market_id"]
150
- )
151
-
152
- # Resolve markets
153
- for i, market_contract in enumerate(created_market_contracts):
154
- resolve_result = market_contract.resolve(
155
- args=[markets_data[i]["evidence_urls"]],
156
- ).transact()
157
- assert tx_execution_succeeded(resolve_result)
158
-
159
- # Verify market was resolved and has the correct outcome
160
- market_state = market_contract.get_dict(args=[]).call()
161
- assert market_state["status"] == "Resolved"
162
- assert market_state["outcome"] == markets_data[i]["outcome"]
@@ -1,24 +0,0 @@
1
- import pytest
2
- from gltest import get_contract_factory
3
- from gltest.assertions import tx_execution_failed
4
- from gltest.exceptions import DeploymentError
5
-
6
-
7
- def test_invalid_deploy_basic_exception(setup_validators):
8
- """Test deployment failure with basic exception"""
9
- setup_validators()
10
- factory = get_contract_factory("InvalidDeploy")
11
-
12
- # Deployment should fail with exception
13
- with pytest.raises(DeploymentError):
14
- factory.deploy()
15
-
16
-
17
- def test_invalid_deploy_receipt_only(setup_validators):
18
- """Test deployment failure using deploy_contract_tx() method that returns receipt only"""
19
- setup_validators()
20
- factory = get_contract_factory("InvalidDeploy")
21
-
22
- # Deploy and get receipt - should show failure
23
- receipt = factory.deploy_contract_tx()
24
- assert tx_execution_failed(receipt)
@@ -1,60 +0,0 @@
1
- from gltest import get_contract_factory, get_default_account, create_account
2
- from gltest.assertions import tx_execution_succeeded
3
- import json
4
-
5
- TOKEN_TOTAL_SUPPLY = 1000
6
- TRANSFER_AMOUNT = 100
7
-
8
-
9
- def test_llm_erc20(setup_validators):
10
- # Account Setup
11
- from_account_a = get_default_account()
12
- from_account_b = create_account()
13
-
14
- # Mock Response
15
- mock_response = {
16
- "response": {
17
- "The balance of the sender": json.dumps(
18
- {
19
- "transaction_success": True,
20
- "transaction_error": "",
21
- "updated_balances": {
22
- from_account_a.address: TOKEN_TOTAL_SUPPLY - TRANSFER_AMOUNT,
23
- from_account_b.address: TRANSFER_AMOUNT,
24
- },
25
- }
26
- )
27
- },
28
- "eq_principle_prompt_non_comparative": {"The balance of the sender": True},
29
- }
30
- setup_validators(mock_response=mock_response)
31
-
32
- # Deploy Contract
33
- factory = get_contract_factory("LlmErc20")
34
- contract = factory.deploy(args=[TOKEN_TOTAL_SUPPLY])
35
-
36
- # Get Initial State
37
- contract_state_1 = contract.get_balances(args=[]).call()
38
- assert contract_state_1[from_account_a.address] == TOKEN_TOTAL_SUPPLY
39
-
40
- # Transfer from User A to User B
41
- transaction_response_call_1 = contract.transfer(
42
- args=[TRANSFER_AMOUNT, from_account_b.address]
43
- ).transact()
44
- assert tx_execution_succeeded(transaction_response_call_1)
45
-
46
- # Get Updated State
47
- contract_state_2_1 = contract.get_balances(args=[]).call()
48
- assert (
49
- contract_state_2_1[from_account_a.address]
50
- == TOKEN_TOTAL_SUPPLY - TRANSFER_AMOUNT
51
- )
52
- assert contract_state_2_1[from_account_b.address] == TRANSFER_AMOUNT
53
-
54
- # Get Updated State
55
- contract_state_2_2 = contract.get_balance_of(args=[from_account_a.address]).call()
56
- assert contract_state_2_2 == TOKEN_TOTAL_SUPPLY - TRANSFER_AMOUNT
57
-
58
- # Get Updated State
59
- contract_state_2_3 = contract.get_balance_of(args=[from_account_b.address]).call()
60
- assert contract_state_2_3 == TRANSFER_AMOUNT
@@ -1,54 +0,0 @@
1
- from gltest import get_contract_factory, get_default_account, create_account
2
- from datetime import datetime, timezone
3
-
4
-
5
- TOKEN_TOTAL_SUPPLY = 1000
6
- TRANSFER_AMOUNT = 100
7
-
8
-
9
- def test_llm_erc20_analyze(setup_validators):
10
- setup_validators()
11
- # Account Setup
12
- from_account_a = get_default_account()
13
- from_account_b = create_account()
14
-
15
- # Deploy Contract
16
- factory = get_contract_factory("LlmErc20")
17
- contract = factory.deploy(args=[TOKEN_TOTAL_SUPPLY])
18
-
19
- # Get Initial State
20
- contract_state_1 = contract.get_balances(args=[]).call()
21
- assert contract_state_1[from_account_a.address] == TOKEN_TOTAL_SUPPLY
22
-
23
- # Transfer from User A to User B
24
- stats = contract.transfer(args=[TRANSFER_AMOUNT, from_account_b.address]).analyze(
25
- provider="openai",
26
- model="gpt-4o",
27
- runs=3,
28
- genvm_datetime=datetime.now(timezone.utc).isoformat(),
29
- )
30
-
31
- # Verify it's a MethodStatsSummary object
32
- assert hasattr(stats, "method")
33
- assert hasattr(stats, "args")
34
- assert hasattr(stats, "total_runs")
35
- assert hasattr(stats, "execution_time")
36
- assert hasattr(stats, "provider")
37
- assert hasattr(stats, "model")
38
-
39
- # Check basic properties
40
- assert stats.method == "transfer"
41
- assert stats.args == [TRANSFER_AMOUNT, from_account_b.address]
42
- assert stats.total_runs == 3
43
- assert stats.provider == "openai"
44
- assert stats.model == "gpt-4o"
45
- assert isinstance(stats.execution_time, float)
46
-
47
- # Check string representation
48
- stats_str = str(stats)
49
- assert "Method analysis summary" in stats_str
50
- assert "Method: transfer" in stats_str
51
- assert f"Args: [{TRANSFER_AMOUNT}, '{from_account_b.address}']" in stats_str
52
- assert f"Total runs: {stats.total_runs}" in stats_str
53
- assert f"Provider: {stats.provider}" in stats_str
54
- assert f"Model: {stats.model}" in stats_str
@@ -1,76 +0,0 @@
1
- from gltest import get_contract_factory
2
- from gltest.assertions import tx_execution_succeeded
3
-
4
-
5
- def test_log_indexer(setup_validators):
6
- setup_validators()
7
- # Deploy Contract
8
- factory = get_contract_factory("LogIndexer")
9
- contract = factory.deploy(args=[])
10
-
11
- # Get closest vector when empty
12
- closest_vector_log_0 = contract.get_closest_vector(args=["I like mango"]).call()
13
- assert closest_vector_log_0 is None
14
-
15
- # Add log 0
16
- transaction_response_add_log_0 = contract.add_log(
17
- args=["I like to eat mango", 0]
18
- ).transact()
19
- assert tx_execution_succeeded(transaction_response_add_log_0)
20
-
21
- # Get closest vector to log 0
22
- closest_vector_log_0 = contract.get_closest_vector(args=["I like mango"]).call()
23
- closest_vector_log_0 = closest_vector_log_0
24
- assert float(closest_vector_log_0["similarity"]) > 0.94
25
- assert float(closest_vector_log_0["similarity"]) < 0.95
26
-
27
- # Add log 1
28
- transaction_response_add_log_1 = contract.add_log(
29
- args=["I like carrots", 1]
30
- ).transact()
31
- assert tx_execution_succeeded(transaction_response_add_log_1)
32
-
33
- # Get closest vector to log 1
34
- closest_vector_log_1 = contract.get_closest_vector(args=["I like carrots"]).call()
35
- closest_vector_log_1 = closest_vector_log_1
36
- assert float(closest_vector_log_1["similarity"]) == 1
37
-
38
- # Update log 0
39
- transaction_response_update_log_0 = contract.update_log(
40
- args=[0, "I like to eat a lot of mangoes"]
41
- ).transact()
42
- assert tx_execution_succeeded(transaction_response_update_log_0)
43
-
44
- # Get closest vector to log 0
45
- closest_vector_log_0_2 = contract.get_closest_vector(
46
- args=["I like mango a lot"]
47
- ).call()
48
- closest_vector_log_0_2 = closest_vector_log_0_2
49
- assert float(closest_vector_log_0_2["similarity"]) > 0.94
50
- assert float(closest_vector_log_0_2["similarity"]) < 0.95
51
-
52
- # Remove log 0
53
- transaction_response_remove_log_0 = contract.remove_log(args=[0]).transact()
54
- assert tx_execution_succeeded(transaction_response_remove_log_0)
55
-
56
- # Get closest vector to log 0
57
- closest_vector_log_0_3 = contract.get_closest_vector(
58
- args=["I like to eat mango"]
59
- ).call()
60
- closest_vector_log_0_3 = closest_vector_log_0_3
61
- assert float(closest_vector_log_0_3["similarity"]) > 0.67
62
- assert float(closest_vector_log_0_3["similarity"]) < 0.68
63
-
64
- # Add third log
65
- transaction_response_add_log_2 = contract.add_log(
66
- args=["This is the third log", 3]
67
- ).transact()
68
- assert tx_execution_succeeded(transaction_response_add_log_2)
69
-
70
- # Check if new item got id 2
71
- closest_vector_log_2 = contract.get_closest_vector(
72
- args=["This is the third log"]
73
- ).call()
74
- assert float(closest_vector_log_2["similarity"]) > 0.99
75
- assert closest_vector_log_2["id"] == 3
76
- assert closest_vector_log_2["text"] == "This is the third log"
@@ -1,15 +0,0 @@
1
- from gltest import get_contract_factory
2
-
3
-
4
- def test_multi_file_contract(setup_validators):
5
- # Multi file contracts are considered if they are defined in a __init__.py file
6
- # Deploy Contract, it will deploy other.py as well
7
- setup_validators()
8
- factory = get_contract_factory("MultiFileContract")
9
- contract = factory.deploy(
10
- args=[],
11
- wait_triggered_transactions=True,
12
- )
13
-
14
- res = contract.test(args=[]).call()
15
- assert res == "123"