genlayer-test 0.4.0__py3-none-any.whl → 1.0.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.4.0.dist-info → genlayer_test-1.0.0.dist-info}/METADATA +54 -8
- genlayer_test-1.0.0.dist-info/RECORD +75 -0
- gltest/__init__.py +7 -6
- gltest/{glchain/client.py → clients.py} +1 -1
- gltest/contracts/__init__.py +4 -0
- gltest/contracts/contract.py +193 -0
- gltest/{glchain/contract.py → contracts/contract_factory.py} +17 -135
- gltest/contracts/contract_functions.py +61 -0
- gltest/contracts/method_stats.py +163 -0
- gltest/contracts/stats_collector.py +259 -0
- gltest/contracts/utils.py +12 -0
- gltest/fixtures.py +2 -6
- gltest/helpers/take_snapshot.py +1 -1
- gltest/logging.py +17 -0
- gltest_cli/config/constants.py +1 -0
- gltest_cli/config/plugin.py +37 -0
- gltest_cli/config/pytest_context.py +9 -0
- gltest_cli/config/types.py +16 -0
- gltest_cli/config/user.py +9 -6
- gltest_cli/logging.py +1 -1
- tests/examples/tests/test_football_prediction_market.py +2 -2
- tests/examples/tests/test_intelligent_oracle_factory.py +6 -6
- tests/examples/tests/test_llm_erc20.py +5 -5
- tests/examples/tests/test_llm_erc20_analyze.py +50 -0
- tests/examples/tests/test_log_indexer.py +23 -11
- tests/examples/tests/test_multi_file_contract.py +2 -2
- tests/examples/tests/test_multi_file_contract_legacy.py +2 -2
- tests/examples/tests/test_multi_read_erc20.py +14 -12
- tests/examples/tests/test_multi_tenant_storage.py +11 -7
- tests/examples/tests/test_read_erc20.py +1 -1
- tests/examples/tests/test_storage.py +4 -4
- tests/examples/tests/test_storage_legacy.py +5 -3
- tests/examples/tests/test_user_storage.py +20 -10
- tests/examples/tests/test_wizard_of_coin.py +1 -1
- tests/gltest_cli/config/test_general_config.py +149 -0
- tests/gltest_cli/config/test_plugin.py +78 -0
- tests/gltest_cli/config/test_user.py +51 -1
- genlayer_test-0.4.0.dist-info/RECORD +0 -66
- gltest/glchain/__init__.py +0 -16
- {genlayer_test-0.4.0.dist-info → genlayer_test-1.0.0.dist-info}/WHEEL +0 -0
- {genlayer_test-0.4.0.dist-info → genlayer_test-1.0.0.dist-info}/entry_points.txt +0 -0
- {genlayer_test-0.4.0.dist-info → genlayer_test-1.0.0.dist-info}/licenses/LICENSE +0 -0
- {genlayer_test-0.4.0.dist-info → genlayer_test-1.0.0.dist-info}/top_level.txt +0 -0
- /gltest/{glchain/account.py → accounts.py} +0 -0
gltest_cli/config/user.py
CHANGED
@@ -4,20 +4,21 @@ import re
|
|
4
4
|
from dotenv import load_dotenv
|
5
5
|
from pathlib import Path
|
6
6
|
from functools import lru_cache
|
7
|
-
from gltest.
|
7
|
+
from gltest.accounts import create_accounts
|
8
8
|
from gltest_cli.config.constants import (
|
9
9
|
GLTEST_CONFIG_FILE,
|
10
10
|
DEFAULT_NETWORK,
|
11
11
|
DEFAULT_RPC_URL,
|
12
12
|
DEFAULT_ENVIRONMENT,
|
13
13
|
DEFAULT_CONTRACTS_DIR,
|
14
|
+
DEFAULT_ARTIFACTS_DIR,
|
14
15
|
DEFAULT_NETWORK_ID,
|
15
16
|
)
|
16
17
|
from gltest_cli.config.types import UserConfig, NetworkConfigData, PathConfig
|
17
18
|
|
18
19
|
VALID_ROOT_KEYS = ["networks", "paths", "environment"]
|
19
20
|
VALID_NETWORK_KEYS = ["id", "url", "accounts", "from"]
|
20
|
-
VALID_PATHS_KEYS = ["contracts"]
|
21
|
+
VALID_PATHS_KEYS = ["contracts", "artifacts"]
|
21
22
|
|
22
23
|
|
23
24
|
@lru_cache(maxsize=1)
|
@@ -34,7 +35,9 @@ def get_default_user_config() -> UserConfig:
|
|
34
35
|
from_account=accounts_private_keys[0],
|
35
36
|
),
|
36
37
|
},
|
37
|
-
paths=PathConfig(
|
38
|
+
paths=PathConfig(
|
39
|
+
contracts=DEFAULT_CONTRACTS_DIR, artifacts=DEFAULT_ARTIFACTS_DIR
|
40
|
+
),
|
38
41
|
environment=DEFAULT_ENVIRONMENT,
|
39
42
|
default_network=DEFAULT_NETWORK,
|
40
43
|
)
|
@@ -208,10 +211,10 @@ def _get_overridden_environment(raw_config: dict) -> str:
|
|
208
211
|
def _get_overridden_paths(raw_config: dict) -> PathConfig:
|
209
212
|
default_config = get_default_user_config()
|
210
213
|
if "paths" in raw_config:
|
214
|
+
paths_config = raw_config.get("paths", {})
|
211
215
|
return PathConfig(
|
212
|
-
contracts=Path(
|
213
|
-
|
214
|
-
)
|
216
|
+
contracts=Path(paths_config.get("contracts", DEFAULT_CONTRACTS_DIR)),
|
217
|
+
artifacts=Path(paths_config.get("artifacts", DEFAULT_ARTIFACTS_DIR)),
|
215
218
|
)
|
216
219
|
return default_config.paths
|
217
220
|
|
gltest_cli/logging.py
CHANGED
@@ -27,11 +27,11 @@ def test_football_prediction_market(setup_validators):
|
|
27
27
|
contract = factory.deploy(args=["2024-06-26", "Georgia", "Portugal"])
|
28
28
|
|
29
29
|
# Resolve match
|
30
|
-
transaction_response_call_1 = contract.resolve(args=[])
|
30
|
+
transaction_response_call_1 = contract.resolve(args=[]).transact()
|
31
31
|
assert tx_execution_succeeded(transaction_response_call_1)
|
32
32
|
|
33
33
|
# Get Updated State
|
34
|
-
contract_state_2 = contract.get_resolution_data(args=[])
|
34
|
+
contract_state_2 = contract.get_resolution_data(args=[]).call()
|
35
35
|
|
36
36
|
assert contract_state_2["winner"] == 1
|
37
37
|
assert contract_state_2["score"] == "2:0"
|
@@ -12,7 +12,7 @@ def wait_for_contract_deployment(intelligent_oracle_contract, max_retries=10, de
|
|
12
12
|
"""
|
13
13
|
for _ in range(max_retries):
|
14
14
|
try:
|
15
|
-
intelligent_oracle_contract.get_dict(args=[])
|
15
|
+
intelligent_oracle_contract.get_dict(args=[]).call()
|
16
16
|
return True # If successful, contract is deployed
|
17
17
|
except Exception:
|
18
18
|
time.sleep(delay)
|
@@ -124,11 +124,11 @@ def test_intelligent_oracle_factory_pattern(setup_validators):
|
|
124
124
|
market_data["resolution_urls"],
|
125
125
|
market_data["earliest_resolution_date"],
|
126
126
|
],
|
127
|
-
)
|
127
|
+
).transact()
|
128
128
|
assert tx_execution_succeeded(create_result)
|
129
129
|
|
130
130
|
# Get the latest contract address from factory
|
131
|
-
registered_addresses = registry_contract.get_contract_addresses(args=[])
|
131
|
+
registered_addresses = registry_contract.get_contract_addresses(args=[]).call()
|
132
132
|
new_market_address = registered_addresses[-1]
|
133
133
|
|
134
134
|
# Build a contract object
|
@@ -145,7 +145,7 @@ def test_intelligent_oracle_factory_pattern(setup_validators):
|
|
145
145
|
|
146
146
|
# Verify each market's state
|
147
147
|
for i, market_contract in enumerate(created_market_contracts):
|
148
|
-
market_state = market_contract.get_dict(args=[])
|
148
|
+
market_state = market_contract.get_dict(args=[]).call()
|
149
149
|
expected_data = markets_data[i]
|
150
150
|
|
151
151
|
# Verify key market properties
|
@@ -171,10 +171,10 @@ def test_intelligent_oracle_factory_pattern(setup_validators):
|
|
171
171
|
for i, market_contract in enumerate(created_market_contracts):
|
172
172
|
resolve_result = market_contract.resolve(
|
173
173
|
args=[markets_data[i]["evidence_urls"]],
|
174
|
-
)
|
174
|
+
).transact()
|
175
175
|
assert tx_execution_succeeded(resolve_result)
|
176
176
|
|
177
177
|
# Verify market was resolved and has the correct outcome
|
178
|
-
market_state = market_contract.get_dict(args=[])
|
178
|
+
market_state = market_contract.get_dict(args=[]).call()
|
179
179
|
assert market_state["status"] == "Resolved"
|
180
180
|
assert market_state["outcome"] == markets_data[i]["outcome"]
|
@@ -34,17 +34,17 @@ def test_llm_erc20(setup_validators):
|
|
34
34
|
contract = factory.deploy(args=[TOKEN_TOTAL_SUPPLY])
|
35
35
|
|
36
36
|
# Get Initial State
|
37
|
-
contract_state_1 = contract.get_balances(args=[])
|
37
|
+
contract_state_1 = contract.get_balances(args=[]).call()
|
38
38
|
assert contract_state_1[from_account_a.address] == TOKEN_TOTAL_SUPPLY
|
39
39
|
|
40
40
|
# Transfer from User A to User B
|
41
41
|
transaction_response_call_1 = contract.transfer(
|
42
42
|
args=[TRANSFER_AMOUNT, from_account_b.address]
|
43
|
-
)
|
43
|
+
).transact()
|
44
44
|
assert tx_execution_succeeded(transaction_response_call_1)
|
45
45
|
|
46
46
|
# Get Updated State
|
47
|
-
contract_state_2_1 = contract.get_balances(args=[])
|
47
|
+
contract_state_2_1 = contract.get_balances(args=[]).call()
|
48
48
|
assert (
|
49
49
|
contract_state_2_1[from_account_a.address]
|
50
50
|
== TOKEN_TOTAL_SUPPLY - TRANSFER_AMOUNT
|
@@ -52,9 +52,9 @@ def test_llm_erc20(setup_validators):
|
|
52
52
|
assert contract_state_2_1[from_account_b.address] == TRANSFER_AMOUNT
|
53
53
|
|
54
54
|
# Get Updated State
|
55
|
-
contract_state_2_2 = contract.get_balance_of(args=[from_account_a.address])
|
55
|
+
contract_state_2_2 = contract.get_balance_of(args=[from_account_a.address]).call()
|
56
56
|
assert contract_state_2_2 == TOKEN_TOTAL_SUPPLY - TRANSFER_AMOUNT
|
57
57
|
|
58
58
|
# Get Updated State
|
59
|
-
contract_state_2_3 = contract.get_balance_of(args=[from_account_b.address])
|
59
|
+
contract_state_2_3 = contract.get_balance_of(args=[from_account_b.address]).call()
|
60
60
|
assert contract_state_2_3 == TRANSFER_AMOUNT
|
@@ -0,0 +1,50 @@
|
|
1
|
+
from gltest import get_contract_factory, get_default_account, create_account
|
2
|
+
|
3
|
+
|
4
|
+
TOKEN_TOTAL_SUPPLY = 1000
|
5
|
+
TRANSFER_AMOUNT = 100
|
6
|
+
|
7
|
+
|
8
|
+
def test_llm_erc20_analyze(setup_validators):
|
9
|
+
setup_validators()
|
10
|
+
# Account Setup
|
11
|
+
from_account_a = get_default_account()
|
12
|
+
from_account_b = create_account()
|
13
|
+
|
14
|
+
# Deploy Contract
|
15
|
+
factory = get_contract_factory("LlmErc20")
|
16
|
+
contract = factory.deploy(args=[TOKEN_TOTAL_SUPPLY])
|
17
|
+
|
18
|
+
# Get Initial State
|
19
|
+
contract_state_1 = contract.get_balances(args=[]).call()
|
20
|
+
assert contract_state_1[from_account_a.address] == TOKEN_TOTAL_SUPPLY
|
21
|
+
|
22
|
+
# Transfer from User A to User B
|
23
|
+
stats = contract.transfer(args=[TRANSFER_AMOUNT, from_account_b.address]).analyze(
|
24
|
+
provider="openai", model="gpt-4o", runs=3
|
25
|
+
)
|
26
|
+
|
27
|
+
# Verify it's a MethodStatsSummary object
|
28
|
+
assert hasattr(stats, "method")
|
29
|
+
assert hasattr(stats, "args")
|
30
|
+
assert hasattr(stats, "total_runs")
|
31
|
+
assert hasattr(stats, "execution_time")
|
32
|
+
assert hasattr(stats, "provider")
|
33
|
+
assert hasattr(stats, "model")
|
34
|
+
|
35
|
+
# Check basic properties
|
36
|
+
assert stats.method == "transfer"
|
37
|
+
assert stats.args == [TRANSFER_AMOUNT, from_account_b.address]
|
38
|
+
assert stats.total_runs == 3
|
39
|
+
assert stats.provider == "openai"
|
40
|
+
assert stats.model == "gpt-4o"
|
41
|
+
assert isinstance(stats.execution_time, float)
|
42
|
+
|
43
|
+
# Check string representation
|
44
|
+
stats_str = str(stats)
|
45
|
+
assert "Method analysis summary" in stats_str
|
46
|
+
assert "Method: transfer" in stats_str
|
47
|
+
assert f"Args: [{TRANSFER_AMOUNT}, '{from_account_b.address}']" in stats_str
|
48
|
+
assert f"Total runs: {stats.total_runs}" in stats_str
|
49
|
+
assert f"Provider: {stats.provider}" in stats_str
|
50
|
+
assert f"Model: {stats.model}" in stats_str
|
@@ -9,56 +9,68 @@ def test_log_indexer(setup_validators):
|
|
9
9
|
contract = factory.deploy(args=[])
|
10
10
|
|
11
11
|
# Get closest vector when empty
|
12
|
-
closest_vector_log_0 = contract.get_closest_vector(args=["I like mango"])
|
12
|
+
closest_vector_log_0 = contract.get_closest_vector(args=["I like mango"]).call()
|
13
13
|
assert closest_vector_log_0 is None
|
14
14
|
|
15
15
|
# Add log 0
|
16
|
-
transaction_response_add_log_0 = contract.add_log(
|
16
|
+
transaction_response_add_log_0 = contract.add_log(
|
17
|
+
args=["I like to eat mango", 0]
|
18
|
+
).transact()
|
17
19
|
assert tx_execution_succeeded(transaction_response_add_log_0)
|
18
20
|
|
19
21
|
# Get closest vector to log 0
|
20
|
-
closest_vector_log_0 = contract.get_closest_vector(args=["I like mango"])
|
22
|
+
closest_vector_log_0 = contract.get_closest_vector(args=["I like mango"]).call()
|
21
23
|
closest_vector_log_0 = closest_vector_log_0
|
22
24
|
assert float(closest_vector_log_0["similarity"]) > 0.94
|
23
25
|
assert float(closest_vector_log_0["similarity"]) < 0.95
|
24
26
|
|
25
27
|
# Add log 1
|
26
|
-
transaction_response_add_log_1 = contract.add_log(
|
28
|
+
transaction_response_add_log_1 = contract.add_log(
|
29
|
+
args=["I like carrots", 1]
|
30
|
+
).transact()
|
27
31
|
assert tx_execution_succeeded(transaction_response_add_log_1)
|
28
32
|
|
29
33
|
# Get closest vector to log 1
|
30
|
-
closest_vector_log_1 = contract.get_closest_vector(args=["I like carrots"])
|
34
|
+
closest_vector_log_1 = contract.get_closest_vector(args=["I like carrots"]).call()
|
31
35
|
closest_vector_log_1 = closest_vector_log_1
|
32
36
|
assert float(closest_vector_log_1["similarity"]) == 1
|
33
37
|
|
34
38
|
# Update log 0
|
35
39
|
transaction_response_update_log_0 = contract.update_log(
|
36
40
|
args=[0, "I like to eat a lot of mangoes"]
|
37
|
-
)
|
41
|
+
).transact()
|
38
42
|
assert tx_execution_succeeded(transaction_response_update_log_0)
|
39
43
|
|
40
44
|
# Get closest vector to log 0
|
41
|
-
closest_vector_log_0_2 = contract.get_closest_vector(
|
45
|
+
closest_vector_log_0_2 = contract.get_closest_vector(
|
46
|
+
args=["I like mango a lot"]
|
47
|
+
).call()
|
42
48
|
closest_vector_log_0_2 = closest_vector_log_0_2
|
43
49
|
assert float(closest_vector_log_0_2["similarity"]) > 0.94
|
44
50
|
assert float(closest_vector_log_0_2["similarity"]) < 0.95
|
45
51
|
|
46
52
|
# Remove log 0
|
47
|
-
transaction_response_remove_log_0 = contract.remove_log(args=[0])
|
53
|
+
transaction_response_remove_log_0 = contract.remove_log(args=[0]).transact()
|
48
54
|
assert tx_execution_succeeded(transaction_response_remove_log_0)
|
49
55
|
|
50
56
|
# Get closest vector to log 0
|
51
|
-
closest_vector_log_0_3 = contract.get_closest_vector(
|
57
|
+
closest_vector_log_0_3 = contract.get_closest_vector(
|
58
|
+
args=["I like to eat mango"]
|
59
|
+
).call()
|
52
60
|
closest_vector_log_0_3 = closest_vector_log_0_3
|
53
61
|
assert float(closest_vector_log_0_3["similarity"]) > 0.67
|
54
62
|
assert float(closest_vector_log_0_3["similarity"]) < 0.68
|
55
63
|
|
56
64
|
# Add third log
|
57
|
-
transaction_response_add_log_2 = contract.add_log(
|
65
|
+
transaction_response_add_log_2 = contract.add_log(
|
66
|
+
args=["This is the third log", 3]
|
67
|
+
).transact()
|
58
68
|
assert tx_execution_succeeded(transaction_response_add_log_2)
|
59
69
|
|
60
70
|
# Check if new item got id 2
|
61
|
-
closest_vector_log_2 = contract.get_closest_vector(
|
71
|
+
closest_vector_log_2 = contract.get_closest_vector(
|
72
|
+
args=["This is the third log"]
|
73
|
+
).call()
|
62
74
|
assert float(closest_vector_log_2["similarity"]) > 0.99
|
63
75
|
assert closest_vector_log_2["id"] == 3
|
64
76
|
assert closest_vector_log_2["text"] == "This is the third log"
|
@@ -9,8 +9,8 @@ def test_multi_file_contract(setup_validators):
|
|
9
9
|
factory = get_contract_factory("MultiFileContract")
|
10
10
|
contract = factory.deploy(args=[])
|
11
11
|
|
12
|
-
wait_response = contract.wait(args=[])
|
12
|
+
wait_response = contract.wait(args=[]).transact()
|
13
13
|
assert tx_execution_succeeded(wait_response)
|
14
14
|
|
15
|
-
res = contract.test(args=[])
|
15
|
+
res = contract.test(args=[]).call()
|
16
16
|
assert res == "123"
|
@@ -9,8 +9,8 @@ def test_multi_file_contract_legacy(setup_validators):
|
|
9
9
|
factory = get_contract_factory("MultiFileContractLegacy")
|
10
10
|
contract = factory.deploy(args=[])
|
11
11
|
|
12
|
-
wait_response = contract.wait(args=[])
|
12
|
+
wait_response = contract.wait(args=[]).transact()
|
13
13
|
assert tx_execution_succeeded(wait_response)
|
14
14
|
|
15
|
-
res = contract.test(args=[])
|
15
|
+
res = contract.test(args=[]).call()
|
16
16
|
assert res == "123"
|
@@ -61,11 +61,11 @@ def test_multi_read_erc20(setup_validators):
|
|
61
61
|
from_account_doge.address,
|
62
62
|
[doge_contract.address, shiba_contract.address],
|
63
63
|
]
|
64
|
-
)
|
64
|
+
).transact()
|
65
65
|
assert tx_execution_succeeded(transaction_response_call)
|
66
66
|
|
67
67
|
# check balances
|
68
|
-
call_method_response_get_balances = multi_read_contract.get_balances(args=[])
|
68
|
+
call_method_response_get_balances = multi_read_contract.get_balances(args=[]).call()
|
69
69
|
assert call_method_response_get_balances == {
|
70
70
|
from_account_doge.address: {
|
71
71
|
doge_contract.address: TOKEN_TOTAL_SUPPLY,
|
@@ -74,20 +74,22 @@ def test_multi_read_erc20(setup_validators):
|
|
74
74
|
}
|
75
75
|
|
76
76
|
# update balances for shiba account
|
77
|
-
transaction_response_call =
|
78
|
-
from_account_shiba
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
77
|
+
transaction_response_call = (
|
78
|
+
multi_read_contract.connect(from_account_shiba)
|
79
|
+
.update_token_balances(
|
80
|
+
args=[
|
81
|
+
from_account_shiba.address,
|
82
|
+
[doge_contract.address, shiba_contract.address],
|
83
|
+
]
|
84
|
+
)
|
85
|
+
.transact()
|
84
86
|
)
|
85
87
|
assert tx_execution_succeeded(transaction_response_call)
|
86
88
|
|
87
89
|
# check balances
|
88
|
-
call_method_response_get_balances =
|
89
|
-
from_account_shiba
|
90
|
-
)
|
90
|
+
call_method_response_get_balances = (
|
91
|
+
multi_read_contract.connect(from_account_shiba).get_balances(args=[]).call()
|
92
|
+
)
|
91
93
|
|
92
94
|
assert call_method_response_get_balances == {
|
93
95
|
from_account_doge.address: {
|
@@ -48,19 +48,23 @@ def test_multi_tenant_storage(setup_validators):
|
|
48
48
|
]
|
49
49
|
)
|
50
50
|
# update storage for first contract
|
51
|
-
transaction_response_call =
|
52
|
-
account=user_account_a
|
53
|
-
|
51
|
+
transaction_response_call = (
|
52
|
+
multi_tenant_storage_contract.connect(account=user_account_a)
|
53
|
+
.update_storage(args=["user_a_storage"])
|
54
|
+
.transact()
|
55
|
+
)
|
54
56
|
assert tx_execution_succeeded(transaction_response_call)
|
55
57
|
|
56
58
|
# update storage for second contract
|
57
|
-
transaction_response_call =
|
58
|
-
account=user_account_b
|
59
|
-
|
59
|
+
transaction_response_call = (
|
60
|
+
multi_tenant_storage_contract.connect(account=user_account_b)
|
61
|
+
.update_storage(args=["user_b_storage"])
|
62
|
+
.transact()
|
63
|
+
)
|
60
64
|
assert tx_execution_succeeded(transaction_response_call)
|
61
65
|
|
62
66
|
# get all storages
|
63
|
-
storages = multi_tenant_storage_contract.get_all_storages(args=[])
|
67
|
+
storages = multi_tenant_storage_contract.get_all_storages(args=[]).call()
|
64
68
|
|
65
69
|
assert storages == {
|
66
70
|
second_storage_contract.address: "user_a_storage",
|
@@ -12,15 +12,15 @@ def test_storage(setup_validators):
|
|
12
12
|
contract = factory.deploy(args=[INITIAL_STATE], wait_retries=40)
|
13
13
|
|
14
14
|
# Get initial state
|
15
|
-
contract_state_1 = contract.get_storage(args=[])
|
15
|
+
contract_state_1 = contract.get_storage(args=[]).call()
|
16
16
|
assert contract_state_1 == INITIAL_STATE
|
17
17
|
|
18
18
|
# Update State
|
19
19
|
transaction_response_call_1 = contract.update_storage(
|
20
|
-
args=[UPDATED_STATE]
|
21
|
-
)
|
20
|
+
args=[UPDATED_STATE]
|
21
|
+
).transact(wait_retries=40)
|
22
22
|
assert tx_execution_succeeded(transaction_response_call_1)
|
23
23
|
|
24
24
|
# Get Updated State
|
25
|
-
contract_state_2 = contract.get_storage(args=[])
|
25
|
+
contract_state_2 = contract.get_storage(args=[]).call()
|
26
26
|
assert contract_state_2 == UPDATED_STATE
|
@@ -12,13 +12,15 @@ def test_storage_legacy(setup_validators):
|
|
12
12
|
contract = factory.deploy(args=[INITIAL_STATE])
|
13
13
|
|
14
14
|
# Get initial state
|
15
|
-
contract_state_1 = contract.get_storage(args=[])
|
15
|
+
contract_state_1 = contract.get_storage(args=[]).call()
|
16
16
|
assert contract_state_1 == INITIAL_STATE
|
17
17
|
|
18
18
|
# Update State
|
19
|
-
transaction_response_call_1 = contract.update_storage(
|
19
|
+
transaction_response_call_1 = contract.update_storage(
|
20
|
+
args=[UPDATED_STATE]
|
21
|
+
).transact()
|
20
22
|
assert tx_execution_succeeded(transaction_response_call_1)
|
21
23
|
|
22
24
|
# Get Updated State
|
23
|
-
contract_state_2 = contract.get_storage(args=[])
|
25
|
+
contract_state_2 = contract.get_storage(args=[]).call()
|
24
26
|
assert contract_state_2 == UPDATED_STATE
|
@@ -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(
|
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(
|
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 =
|
57
|
-
|
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(
|
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(
|
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
|
@@ -0,0 +1,149 @@
|
|
1
|
+
import pytest
|
2
|
+
from pathlib import Path
|
3
|
+
from gltest_cli.config.types import (
|
4
|
+
GeneralConfig,
|
5
|
+
UserConfig,
|
6
|
+
PluginConfig,
|
7
|
+
PathConfig,
|
8
|
+
NetworkConfigData,
|
9
|
+
)
|
10
|
+
from gltest_cli.config.constants import DEFAULT_ARTIFACTS_DIR, DEFAULT_CONTRACTS_DIR
|
11
|
+
|
12
|
+
|
13
|
+
def test_general_config_artifacts_methods():
|
14
|
+
"""Test GeneralConfig artifacts directory methods."""
|
15
|
+
user_config = UserConfig(
|
16
|
+
networks={"localnet": NetworkConfigData()},
|
17
|
+
paths=PathConfig(contracts=Path("contracts"), artifacts=Path("user_artifacts")),
|
18
|
+
)
|
19
|
+
|
20
|
+
plugin_config = PluginConfig()
|
21
|
+
general_config = GeneralConfig(user_config=user_config, plugin_config=plugin_config)
|
22
|
+
|
23
|
+
# Test get_artifacts_dir returns user config value when plugin config is not set
|
24
|
+
assert general_config.get_artifacts_dir() == Path("user_artifacts")
|
25
|
+
|
26
|
+
# Test set_artifacts_dir updates plugin config
|
27
|
+
general_config.set_artifacts_dir(Path("plugin_artifacts"))
|
28
|
+
assert general_config.get_artifacts_dir() == Path("plugin_artifacts")
|
29
|
+
|
30
|
+
# Plugin config should take precedence
|
31
|
+
assert general_config.plugin_config.artifacts_dir == Path("plugin_artifacts")
|
32
|
+
|
33
|
+
|
34
|
+
def test_general_config_artifacts_default():
|
35
|
+
"""Test GeneralConfig artifacts directory with default values."""
|
36
|
+
user_config = UserConfig(
|
37
|
+
networks={"localnet": NetworkConfigData()},
|
38
|
+
paths=PathConfig(artifacts=DEFAULT_ARTIFACTS_DIR),
|
39
|
+
)
|
40
|
+
|
41
|
+
plugin_config = PluginConfig()
|
42
|
+
general_config = GeneralConfig(user_config=user_config, plugin_config=plugin_config)
|
43
|
+
|
44
|
+
# Should return default artifacts directory
|
45
|
+
assert general_config.get_artifacts_dir() == DEFAULT_ARTIFACTS_DIR
|
46
|
+
|
47
|
+
|
48
|
+
def test_general_config_artifacts_plugin_precedence():
|
49
|
+
"""Test that plugin config takes precedence over user config for artifacts."""
|
50
|
+
user_config = UserConfig(
|
51
|
+
networks={"localnet": NetworkConfigData()},
|
52
|
+
paths=PathConfig(artifacts=Path("user_artifacts")),
|
53
|
+
)
|
54
|
+
|
55
|
+
plugin_config = PluginConfig(artifacts_dir=Path("plugin_artifacts"))
|
56
|
+
general_config = GeneralConfig(user_config=user_config, plugin_config=plugin_config)
|
57
|
+
|
58
|
+
# Plugin config should take precedence
|
59
|
+
assert general_config.get_artifacts_dir() == Path("plugin_artifacts")
|
60
|
+
|
61
|
+
|
62
|
+
def test_general_config_artifacts_none_values():
|
63
|
+
"""Test GeneralConfig behavior when artifacts paths are None."""
|
64
|
+
user_config = UserConfig(
|
65
|
+
networks={"localnet": NetworkConfigData()}, paths=PathConfig(artifacts=None)
|
66
|
+
)
|
67
|
+
|
68
|
+
plugin_config = PluginConfig(artifacts_dir=None)
|
69
|
+
general_config = GeneralConfig(user_config=user_config, plugin_config=plugin_config)
|
70
|
+
|
71
|
+
# Should return None when both are None
|
72
|
+
assert general_config.get_artifacts_dir() is None
|
73
|
+
|
74
|
+
|
75
|
+
def test_general_config_both_contracts_and_artifacts():
|
76
|
+
"""Test that both contracts and artifacts directories work together."""
|
77
|
+
user_config = UserConfig(
|
78
|
+
networks={"localnet": NetworkConfigData()},
|
79
|
+
paths=PathConfig(
|
80
|
+
contracts=Path("src/contracts"), artifacts=Path("build/artifacts")
|
81
|
+
),
|
82
|
+
)
|
83
|
+
|
84
|
+
plugin_config = PluginConfig(
|
85
|
+
contracts_dir=Path("custom/contracts"), artifacts_dir=Path("custom/artifacts")
|
86
|
+
)
|
87
|
+
|
88
|
+
general_config = GeneralConfig(user_config=user_config, plugin_config=plugin_config)
|
89
|
+
|
90
|
+
# Both should return plugin values (precedence)
|
91
|
+
assert general_config.get_contracts_dir() == Path("custom/contracts")
|
92
|
+
assert general_config.get_artifacts_dir() == Path("custom/artifacts")
|
93
|
+
|
94
|
+
|
95
|
+
def test_general_config_mixed_precedence():
|
96
|
+
"""Test mixed precedence where only one path is overridden in plugin."""
|
97
|
+
user_config = UserConfig(
|
98
|
+
networks={"localnet": NetworkConfigData()},
|
99
|
+
paths=PathConfig(
|
100
|
+
contracts=Path("user/contracts"), artifacts=Path("user/artifacts")
|
101
|
+
),
|
102
|
+
)
|
103
|
+
|
104
|
+
# Only override artifacts in plugin config
|
105
|
+
plugin_config = PluginConfig(artifacts_dir=Path("plugin/artifacts"))
|
106
|
+
general_config = GeneralConfig(user_config=user_config, plugin_config=plugin_config)
|
107
|
+
|
108
|
+
# Contracts should come from user config, artifacts from plugin config
|
109
|
+
assert general_config.get_contracts_dir() == Path("user/contracts")
|
110
|
+
assert general_config.get_artifacts_dir() == Path("plugin/artifacts")
|
111
|
+
|
112
|
+
|
113
|
+
def test_path_config_validation():
|
114
|
+
"""Test PathConfig validation for artifacts."""
|
115
|
+
# Valid path configurations
|
116
|
+
valid_config = PathConfig(contracts=Path("contracts"), artifacts=Path("artifacts"))
|
117
|
+
assert valid_config.contracts == Path("contracts")
|
118
|
+
assert valid_config.artifacts == Path("artifacts")
|
119
|
+
|
120
|
+
# Test with string paths
|
121
|
+
string_config = PathConfig(contracts="contracts", artifacts="artifacts")
|
122
|
+
# PathConfig should handle string conversion in __post_init__
|
123
|
+
assert string_config.contracts == "contracts"
|
124
|
+
assert string_config.artifacts == "artifacts"
|
125
|
+
|
126
|
+
|
127
|
+
def test_path_config_invalid_types():
|
128
|
+
"""Test PathConfig validation with invalid types."""
|
129
|
+
# Test invalid artifacts type
|
130
|
+
with pytest.raises(ValueError, match="artifacts must be a string or Path"):
|
131
|
+
PathConfig(artifacts=123)
|
132
|
+
|
133
|
+
# Test invalid contracts type (existing validation)
|
134
|
+
with pytest.raises(ValueError, match="contracts must be a string or Path"):
|
135
|
+
PathConfig(contracts=123)
|
136
|
+
|
137
|
+
|
138
|
+
def test_general_config_contracts_default():
|
139
|
+
"""Test GeneralConfig contracts directory with default values."""
|
140
|
+
user_config = UserConfig(
|
141
|
+
networks={"localnet": NetworkConfigData()},
|
142
|
+
paths=PathConfig(contracts=DEFAULT_CONTRACTS_DIR),
|
143
|
+
)
|
144
|
+
|
145
|
+
plugin_config = PluginConfig()
|
146
|
+
general_config = GeneralConfig(user_config=user_config, plugin_config=plugin_config)
|
147
|
+
|
148
|
+
# Should return default contracts directory
|
149
|
+
assert general_config.get_contracts_dir() == DEFAULT_CONTRACTS_DIR
|