genlayer-test 0.8.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.
- {genlayer_test-0.8.0.dist-info → genlayer_test-0.9.0.dist-info}/METADATA +29 -2
- genlayer_test-0.9.0.dist-info/RECORD +38 -0
- {genlayer_test-0.8.0.dist-info → genlayer_test-0.9.0.dist-info}/top_level.txt +0 -1
- gltest_cli/config/constants.py +7 -0
- gltest_cli/config/plugin.py +22 -4
- gltest_cli/config/types.py +81 -46
- gltest_cli/config/user.py +95 -7
- genlayer_test-0.8.0.dist-info/RECORD +0 -82
- tests/__init__.py +0 -0
- tests/conftest.py +0 -1
- tests/examples/contracts/football_prediction_market.py +0 -100
- tests/examples/contracts/intelligent_oracle.py +0 -370
- tests/examples/contracts/intelligent_oracle_factory.py +0 -49
- tests/examples/contracts/invalid_deploy.py +0 -10
- tests/examples/contracts/llm_erc20.py +0 -70
- tests/examples/contracts/log_indexer.py +0 -69
- tests/examples/contracts/multi_file_contract/__init__.py +0 -24
- tests/examples/contracts/multi_file_contract/other.py +0 -14
- tests/examples/contracts/multi_read_erc20.py +0 -29
- tests/examples/contracts/multi_tenant_storage.py +0 -51
- tests/examples/contracts/read_erc20.py +0 -19
- tests/examples/contracts/simple_time_contract.py +0 -85
- tests/examples/contracts/storage.py +0 -23
- tests/examples/contracts/user_storage.py +0 -25
- tests/examples/contracts/wizard_of_coin.py +0 -57
- tests/examples/tests/test_custom_validators.py +0 -65
- tests/examples/tests/test_football_prediction_market.py +0 -38
- tests/examples/tests/test_intelligent_oracle_factory.py +0 -162
- tests/examples/tests/test_invalid_deploy.py +0 -24
- tests/examples/tests/test_llm_erc20.py +0 -60
- tests/examples/tests/test_llm_erc20_analyze.py +0 -54
- tests/examples/tests/test_log_indexer.py +0 -76
- tests/examples/tests/test_multi_file_contract.py +0 -15
- tests/examples/tests/test_multi_read_erc20.py +0 -103
- tests/examples/tests/test_multi_tenant_storage.py +0 -76
- tests/examples/tests/test_read_erc20.py +0 -38
- tests/examples/tests/test_simple_time_contract.py +0 -90
- tests/examples/tests/test_storage.py +0 -26
- tests/examples/tests/test_user_storage.py +0 -87
- tests/examples/tests/test_wizard_of_coin.py +0 -27
- tests/gltest/__init__.py +0 -0
- tests/gltest/artifact/__init__.py +0 -0
- tests/gltest/artifact/contracts/duplicate_ic_contract_1.py +0 -22
- tests/gltest/artifact/contracts/duplicate_ic_contract_2.py +0 -22
- tests/gltest/artifact/contracts/not_ic_contract.py +0 -22
- tests/gltest/artifact/test_contract_definition.py +0 -55
- tests/gltest/assertions/test_assertions.py +0 -344
- tests/gltest_cli/__init__.py +0 -0
- tests/gltest_cli/config/test_config_integration.py +0 -432
- tests/gltest_cli/config/test_general_config.py +0 -406
- tests/gltest_cli/config/test_plugin.py +0 -290
- tests/gltest_cli/config/test_user.py +0 -411
- {genlayer_test-0.8.0.dist-info → genlayer_test-0.9.0.dist-info}/WHEEL +0 -0
- {genlayer_test-0.8.0.dist-info → genlayer_test-0.9.0.dist-info}/entry_points.txt +0 -0
- {genlayer_test-0.8.0.dist-info → genlayer_test-0.9.0.dist-info}/licenses/LICENSE +0 -0
@@ -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"
|
@@ -1,103 +0,0 @@
|
|
1
|
-
from gltest import get_contract_factory, create_account, get_accounts
|
2
|
-
from gltest.assertions import tx_execution_succeeded
|
3
|
-
from gltest_cli.config.general import get_general_config
|
4
|
-
from genlayer_py.chains import testnet_asimov
|
5
|
-
|
6
|
-
|
7
|
-
def test_multi_read_erc20(setup_validators):
|
8
|
-
"""
|
9
|
-
This test verifies the functionality of a multi-read ERC20 contract. It deploys two separate ERC20 token contracts
|
10
|
-
(referred to as 'doge' and 'shiba') and a multi-read ERC20 contract. The test aims to:
|
11
|
-
|
12
|
-
1. Deploy two different ERC20 token contracts with a total supply of 1000 tokens each.
|
13
|
-
2. Deploy a multi-read ERC20 contract that can interact with multiple ERC20 tokens.
|
14
|
-
3. Test the ability of the multi-read contract to update and retrieve token balances for multiple ERC20 tokens
|
15
|
-
and multiple accounts simultaneously.
|
16
|
-
4. Ensure the multi-read contract correctly maintains and reports balances for different account-token combinations.
|
17
|
-
|
18
|
-
This test demonstrates the integration contract to contract reads
|
19
|
-
"""
|
20
|
-
setup_validators()
|
21
|
-
general_config = get_general_config()
|
22
|
-
chain = general_config.get_chain()
|
23
|
-
|
24
|
-
TOKEN_TOTAL_SUPPLY = 1000
|
25
|
-
|
26
|
-
if chain.id == testnet_asimov.id:
|
27
|
-
accounts = get_accounts()
|
28
|
-
if len(accounts) < 2:
|
29
|
-
raise ValueError(
|
30
|
-
f"Test requires at least 2 accounts, but only {len(accounts)} available"
|
31
|
-
)
|
32
|
-
from_account_doge = accounts[0]
|
33
|
-
from_account_shiba = accounts[1]
|
34
|
-
else:
|
35
|
-
from_account_doge = create_account()
|
36
|
-
from_account_shiba = create_account()
|
37
|
-
|
38
|
-
# LLM ERC20
|
39
|
-
llm_erc20_factory = get_contract_factory("LlmErc20")
|
40
|
-
|
41
|
-
## Deploy first LLM ERC20 Contract
|
42
|
-
doge_contract = llm_erc20_factory.deploy(
|
43
|
-
args=[TOKEN_TOTAL_SUPPLY], account=from_account_doge
|
44
|
-
)
|
45
|
-
|
46
|
-
## Deploy second LLM ERC20 Contract
|
47
|
-
shiba_contract = llm_erc20_factory.deploy(
|
48
|
-
args=[TOKEN_TOTAL_SUPPLY], account=from_account_shiba
|
49
|
-
)
|
50
|
-
|
51
|
-
# Deploy Multi Read ERC20 Contract
|
52
|
-
multi_read_erc20_factory = get_contract_factory("multi_read_erc20")
|
53
|
-
|
54
|
-
multi_read_contract = multi_read_erc20_factory.deploy(
|
55
|
-
args=[], account=from_account_doge
|
56
|
-
)
|
57
|
-
|
58
|
-
# update balances for doge account
|
59
|
-
transaction_response_call = multi_read_contract.update_token_balances(
|
60
|
-
args=[
|
61
|
-
from_account_doge.address,
|
62
|
-
[doge_contract.address, shiba_contract.address],
|
63
|
-
]
|
64
|
-
).transact()
|
65
|
-
assert tx_execution_succeeded(transaction_response_call)
|
66
|
-
|
67
|
-
# check balances
|
68
|
-
call_method_response_get_balances = multi_read_contract.get_balances(args=[]).call()
|
69
|
-
assert call_method_response_get_balances == {
|
70
|
-
from_account_doge.address: {
|
71
|
-
doge_contract.address: TOKEN_TOTAL_SUPPLY,
|
72
|
-
shiba_contract.address: 0,
|
73
|
-
}
|
74
|
-
}
|
75
|
-
|
76
|
-
# update balances for shiba account
|
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()
|
86
|
-
)
|
87
|
-
assert tx_execution_succeeded(transaction_response_call)
|
88
|
-
|
89
|
-
# check balances
|
90
|
-
call_method_response_get_balances = (
|
91
|
-
multi_read_contract.connect(from_account_shiba).get_balances(args=[]).call()
|
92
|
-
)
|
93
|
-
|
94
|
-
assert call_method_response_get_balances == {
|
95
|
-
from_account_doge.address: {
|
96
|
-
doge_contract.address: TOKEN_TOTAL_SUPPLY,
|
97
|
-
shiba_contract.address: 0,
|
98
|
-
},
|
99
|
-
from_account_shiba.address: {
|
100
|
-
doge_contract.address: 0,
|
101
|
-
shiba_contract.address: TOKEN_TOTAL_SUPPLY,
|
102
|
-
},
|
103
|
-
}
|
@@ -1,76 +0,0 @@
|
|
1
|
-
from gltest import get_contract_factory, create_account, get_accounts
|
2
|
-
from gltest.assertions import tx_execution_succeeded
|
3
|
-
from gltest_cli.config.general import get_general_config
|
4
|
-
from genlayer_py.chains import testnet_asimov
|
5
|
-
|
6
|
-
|
7
|
-
def test_multi_tenant_storage(setup_validators):
|
8
|
-
"""
|
9
|
-
This test verifies the functionality of a multi-tenant storage contract. It deploys two separate storage contracts
|
10
|
-
and a multi-tenant storage contract that manages them. The test aims to:
|
11
|
-
|
12
|
-
1. Deploy two different storage contracts with initial storage values.
|
13
|
-
2. Deploy a multi-tenant storage contract that can interact with multiple storage contracts.
|
14
|
-
3. Test the ability of the multi-tenant contract to update and retrieve storage values for multiple users
|
15
|
-
across different storage contracts.
|
16
|
-
4. Ensure the multi-tenant contract correctly assigns users to storage contracts and manages their data.
|
17
|
-
|
18
|
-
This test demonstrates contract-to-contract interactions and multi-tenant data management.
|
19
|
-
"""
|
20
|
-
setup_validators()
|
21
|
-
general_config = get_general_config()
|
22
|
-
chain = general_config.get_chain()
|
23
|
-
|
24
|
-
if chain.id == testnet_asimov.id:
|
25
|
-
user_account_a = get_accounts()[0]
|
26
|
-
user_account_b = get_accounts()[1]
|
27
|
-
else:
|
28
|
-
user_account_a = create_account()
|
29
|
-
user_account_b = create_account()
|
30
|
-
|
31
|
-
# Storage Contracts
|
32
|
-
storage_factory = get_contract_factory("Storage")
|
33
|
-
|
34
|
-
## Deploy first Storage Contract
|
35
|
-
first_storage_contract = storage_factory.deploy(args=["initial_storage_a"])
|
36
|
-
|
37
|
-
## Deploy second Storage Contract
|
38
|
-
second_storage_contract = storage_factory.deploy(args=["initial_storage_b"])
|
39
|
-
|
40
|
-
# Deploy Multi Tenant Storage Contract
|
41
|
-
multi_tenant_storage_factory = get_contract_factory("MultiTentantStorage")
|
42
|
-
multi_tenant_storage_contract = multi_tenant_storage_factory.deploy(
|
43
|
-
args=[
|
44
|
-
[
|
45
|
-
first_storage_contract.address,
|
46
|
-
second_storage_contract.address,
|
47
|
-
]
|
48
|
-
]
|
49
|
-
)
|
50
|
-
# update storage for first contract
|
51
|
-
transaction_response_call = (
|
52
|
-
multi_tenant_storage_contract.connect(account=user_account_a)
|
53
|
-
.update_storage(args=["user_a_storage"])
|
54
|
-
.transact(
|
55
|
-
wait_triggered_transactions=True,
|
56
|
-
)
|
57
|
-
)
|
58
|
-
assert tx_execution_succeeded(transaction_response_call)
|
59
|
-
|
60
|
-
# update storage for second contract
|
61
|
-
transaction_response_call = (
|
62
|
-
multi_tenant_storage_contract.connect(account=user_account_b)
|
63
|
-
.update_storage(args=["user_b_storage"])
|
64
|
-
.transact(
|
65
|
-
wait_triggered_transactions=True,
|
66
|
-
)
|
67
|
-
)
|
68
|
-
assert tx_execution_succeeded(transaction_response_call)
|
69
|
-
|
70
|
-
# get all storages
|
71
|
-
storages = multi_tenant_storage_contract.get_all_storages(args=[]).call()
|
72
|
-
|
73
|
-
assert storages == {
|
74
|
-
second_storage_contract.address: "user_a_storage",
|
75
|
-
first_storage_contract.address: "user_b_storage",
|
76
|
-
}
|
@@ -1,38 +0,0 @@
|
|
1
|
-
from gltest import get_contract_factory, get_default_account
|
2
|
-
|
3
|
-
|
4
|
-
def test_read_erc20(setup_validators):
|
5
|
-
"""
|
6
|
-
Tests that recursive contract calls work by:
|
7
|
-
1. creating an LLM ERC20 contract
|
8
|
-
2. creating a read_erc20 contract that reads the LLM ERC20 contract
|
9
|
-
3. creating a read_erc20 contract that reads the previous read_erc20 contract
|
10
|
-
Repeats step 3 a few times.
|
11
|
-
|
12
|
-
It's like a linked list, but with contracts.
|
13
|
-
"""
|
14
|
-
setup_validators()
|
15
|
-
TOKEN_TOTAL_SUPPLY = 1000
|
16
|
-
|
17
|
-
# LLM ERC20
|
18
|
-
llm_erc20_factory = get_contract_factory("LlmErc20")
|
19
|
-
|
20
|
-
# Deploy Contract
|
21
|
-
llm_erc20_contract = llm_erc20_factory.deploy(args=[TOKEN_TOTAL_SUPPLY])
|
22
|
-
last_contract_address = llm_erc20_contract.address
|
23
|
-
|
24
|
-
# Read ERC20
|
25
|
-
read_erc20_factory = get_contract_factory("read_erc20")
|
26
|
-
|
27
|
-
for i in range(5):
|
28
|
-
print(f"Deploying contract, iteration {i}")
|
29
|
-
|
30
|
-
# deploy contract
|
31
|
-
read_erc20_contract = read_erc20_factory.deploy(args=[last_contract_address])
|
32
|
-
last_contract_address = read_erc20_contract.address
|
33
|
-
|
34
|
-
# check balance
|
35
|
-
contract_state = read_erc20_contract.get_balance_of(
|
36
|
-
args=[get_default_account().address]
|
37
|
-
).call()
|
38
|
-
assert contract_state == TOKEN_TOTAL_SUPPLY
|
@@ -1,90 +0,0 @@
|
|
1
|
-
from gltest import get_contract_factory
|
2
|
-
from datetime import datetime, timedelta, timezone
|
3
|
-
from gltest.assertions import tx_execution_succeeded, tx_execution_failed
|
4
|
-
|
5
|
-
|
6
|
-
def test_simple_time_contract():
|
7
|
-
"""Test all time-based functionality in a single comprehensive test."""
|
8
|
-
|
9
|
-
factory = get_contract_factory("SimpleTimeContract")
|
10
|
-
|
11
|
-
# Test 1: Deploy with past start date (10 days ago)
|
12
|
-
now = datetime.now(timezone.utc)
|
13
|
-
past_date = (now - timedelta(days=10)).isoformat()
|
14
|
-
contract = factory.deploy(args=[past_date])
|
15
|
-
|
16
|
-
# Test 1: Check initial status (10 days after start)
|
17
|
-
status = contract.get_status().call()
|
18
|
-
assert status["is_active"] == False
|
19
|
-
assert status["days_since_start"] == 10
|
20
|
-
assert status["can_activate"] == True
|
21
|
-
|
22
|
-
# Test 2: Try to activate before start date (simulate going back in time)
|
23
|
-
before_start_date = now - timedelta(days=15) # 5 days before start
|
24
|
-
before_start_date_receipt = contract.activate().transact(
|
25
|
-
transaction_context={
|
26
|
-
"genvm_datetime": before_start_date.isoformat(),
|
27
|
-
},
|
28
|
-
)
|
29
|
-
assert tx_execution_failed(before_start_date_receipt)
|
30
|
-
|
31
|
-
# Test 3: Activate after start date
|
32
|
-
activate_date = now - timedelta(days=5) # 5 days after start (15 days ago + 10)
|
33
|
-
activate_receipt = contract.activate().transact(
|
34
|
-
transaction_context={
|
35
|
-
"genvm_datetime": activate_date.isoformat(),
|
36
|
-
},
|
37
|
-
)
|
38
|
-
assert tx_execution_succeeded(activate_receipt)
|
39
|
-
|
40
|
-
# Test 4: Verify activation and check status
|
41
|
-
status = contract.get_status().call(
|
42
|
-
transaction_context={
|
43
|
-
"genvm_datetime": activate_date.isoformat(),
|
44
|
-
},
|
45
|
-
)
|
46
|
-
assert status["is_active"] == True
|
47
|
-
assert status["days_since_start"] == 5
|
48
|
-
assert status["can_set_data"] == True
|
49
|
-
|
50
|
-
# Test 5: Set data within valid period (within 30 days)
|
51
|
-
set_data_date = now - timedelta(days=2) # 8 days after start
|
52
|
-
test_data = "Test data within valid period"
|
53
|
-
set_data_receipt = contract.set_data(
|
54
|
-
args=[test_data],
|
55
|
-
).transact(
|
56
|
-
transaction_context={
|
57
|
-
"genvm_datetime": set_data_date.isoformat(),
|
58
|
-
}
|
59
|
-
)
|
60
|
-
assert tx_execution_succeeded(set_data_receipt)
|
61
|
-
|
62
|
-
# Test 6: Verify data was set
|
63
|
-
status = contract.get_status().call(
|
64
|
-
transaction_context={
|
65
|
-
"genvm_datetime": set_data_date.isoformat(),
|
66
|
-
},
|
67
|
-
)
|
68
|
-
assert status["data"] == test_data
|
69
|
-
assert status["days_since_start"] == 8
|
70
|
-
|
71
|
-
# Test 7: Try to set data after 30 days (should fail)
|
72
|
-
expired_date = now + timedelta(days=25) # 35 days after start
|
73
|
-
expired_date_receipt = contract.set_data(
|
74
|
-
args=["Should fail - expired"],
|
75
|
-
).transact(
|
76
|
-
transaction_context={
|
77
|
-
"genvm_datetime": expired_date.isoformat(),
|
78
|
-
}
|
79
|
-
)
|
80
|
-
assert tx_execution_failed(expired_date_receipt)
|
81
|
-
|
82
|
-
# Test 8: Check status shows expired
|
83
|
-
status = contract.get_status().call(
|
84
|
-
transaction_context={
|
85
|
-
"genvm_datetime": expired_date.isoformat(),
|
86
|
-
},
|
87
|
-
)
|
88
|
-
assert status["is_active"] == True # Still active
|
89
|
-
assert status["can_set_data"] == False # But can't set data
|
90
|
-
assert status["days_since_start"] == 35
|
@@ -1,26 +0,0 @@
|
|
1
|
-
from gltest import get_contract_factory
|
2
|
-
from gltest.assertions import tx_execution_succeeded
|
3
|
-
|
4
|
-
|
5
|
-
INITIAL_STATE = "a"
|
6
|
-
UPDATED_STATE = "b"
|
7
|
-
|
8
|
-
|
9
|
-
def test_storage(setup_validators):
|
10
|
-
setup_validators()
|
11
|
-
factory = get_contract_factory("Storage")
|
12
|
-
contract = factory.deploy(args=[INITIAL_STATE], wait_retries=40)
|
13
|
-
|
14
|
-
# Get initial state
|
15
|
-
contract_state_1 = contract.get_storage(args=[]).call()
|
16
|
-
assert contract_state_1 == INITIAL_STATE
|
17
|
-
|
18
|
-
# Update State
|
19
|
-
transaction_response_call_1 = contract.update_storage(
|
20
|
-
args=[UPDATED_STATE]
|
21
|
-
).transact(wait_retries=40)
|
22
|
-
assert tx_execution_succeeded(transaction_response_call_1)
|
23
|
-
|
24
|
-
# Get Updated State
|
25
|
-
contract_state_2 = contract.get_storage(args=[]).call()
|
26
|
-
assert contract_state_2 == UPDATED_STATE
|
@@ -1,87 +0,0 @@
|
|
1
|
-
from gltest import (
|
2
|
-
get_contract_factory,
|
3
|
-
get_default_account,
|
4
|
-
create_account,
|
5
|
-
get_accounts,
|
6
|
-
)
|
7
|
-
from gltest.assertions import tx_execution_succeeded
|
8
|
-
from gltest_cli.config.general import get_general_config
|
9
|
-
from genlayer_py.chains import testnet_asimov
|
10
|
-
|
11
|
-
|
12
|
-
INITIAL_STATE_USER_A = "user_a_initial_state"
|
13
|
-
UPDATED_STATE_USER_A = "user_a_updated_state"
|
14
|
-
INITIAL_STATE_USER_B = "user_b_initial_state"
|
15
|
-
UPDATED_STATE_USER_B = "user_b_updated_state"
|
16
|
-
|
17
|
-
|
18
|
-
def test_user_storage(setup_validators):
|
19
|
-
setup_validators()
|
20
|
-
general_config = get_general_config()
|
21
|
-
chain = general_config.get_chain()
|
22
|
-
|
23
|
-
# Account Setup
|
24
|
-
if chain.id == testnet_asimov.id:
|
25
|
-
accounts = get_accounts()
|
26
|
-
if len(accounts) < 2:
|
27
|
-
raise ValueError(
|
28
|
-
f"Test requires at least 2 accounts, but only {len(accounts)} available"
|
29
|
-
)
|
30
|
-
from_account_a = accounts[0]
|
31
|
-
from_account_b = accounts[1]
|
32
|
-
else:
|
33
|
-
from_account_a = get_default_account()
|
34
|
-
from_account_b = create_account()
|
35
|
-
|
36
|
-
factory = get_contract_factory("UserStorage")
|
37
|
-
contract = factory.deploy()
|
38
|
-
|
39
|
-
# GET Initial State
|
40
|
-
contract_state_1 = contract.get_complete_storage(args=[]).call()
|
41
|
-
assert contract_state_1 == {}
|
42
|
-
|
43
|
-
# ADD User A State
|
44
|
-
transaction_response_call_1 = contract.update_storage(
|
45
|
-
args=[INITIAL_STATE_USER_A]
|
46
|
-
).transact()
|
47
|
-
assert tx_execution_succeeded(transaction_response_call_1)
|
48
|
-
|
49
|
-
# Get Updated State
|
50
|
-
contract_state_2_1 = contract.get_complete_storage(args=[]).call()
|
51
|
-
assert contract_state_2_1[from_account_a.address] == INITIAL_STATE_USER_A
|
52
|
-
|
53
|
-
# Get Updated State
|
54
|
-
contract_state_2_2 = contract.get_account_storage(
|
55
|
-
args=[from_account_a.address]
|
56
|
-
).call()
|
57
|
-
assert contract_state_2_2 == INITIAL_STATE_USER_A
|
58
|
-
|
59
|
-
# ADD User B State
|
60
|
-
transaction_response_call_2 = (
|
61
|
-
contract.connect(from_account_b)
|
62
|
-
.update_storage(args=[INITIAL_STATE_USER_B])
|
63
|
-
.transact()
|
64
|
-
)
|
65
|
-
assert tx_execution_succeeded(transaction_response_call_2)
|
66
|
-
|
67
|
-
# Get Updated State
|
68
|
-
contract_state_3 = contract.get_complete_storage(args=[]).call()
|
69
|
-
assert contract_state_3[from_account_a.address] == INITIAL_STATE_USER_A
|
70
|
-
assert contract_state_3[from_account_b.address] == INITIAL_STATE_USER_B
|
71
|
-
|
72
|
-
# UPDATE User A State
|
73
|
-
transaction_response_call_3 = contract.update_storage(
|
74
|
-
args=[UPDATED_STATE_USER_A]
|
75
|
-
).transact()
|
76
|
-
assert tx_execution_succeeded(transaction_response_call_3)
|
77
|
-
|
78
|
-
# Get Updated State
|
79
|
-
contract_state_4_1 = contract.get_complete_storage(args=[]).call()
|
80
|
-
assert contract_state_4_1[from_account_a.address] == UPDATED_STATE_USER_A
|
81
|
-
assert contract_state_4_1[from_account_b.address] == INITIAL_STATE_USER_B
|
82
|
-
|
83
|
-
# Get Updated State
|
84
|
-
contract_state_4_2 = contract.get_account_storage(
|
85
|
-
args=[from_account_b.address]
|
86
|
-
).call()
|
87
|
-
assert contract_state_4_2 == INITIAL_STATE_USER_B
|
@@ -1,27 +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_wizard_of_coin(setup_validators):
|
7
|
-
mock_response = {
|
8
|
-
"response": {
|
9
|
-
"wizard": json.dumps(
|
10
|
-
{
|
11
|
-
"reasoning": "I am a grumpy wizard and I never give away my coins!",
|
12
|
-
"give_coin": False,
|
13
|
-
}
|
14
|
-
),
|
15
|
-
},
|
16
|
-
"eq_principle_prompt_comparative": {
|
17
|
-
"The value of give_coin has to match": True
|
18
|
-
},
|
19
|
-
}
|
20
|
-
setup_validators(mock_response)
|
21
|
-
factory = get_contract_factory("WizardOfCoin")
|
22
|
-
contract = factory.deploy(args=[True])
|
23
|
-
|
24
|
-
transaction_response_call_1 = contract.ask_for_coin(
|
25
|
-
args=["Can you please give me my coin?"]
|
26
|
-
).transact()
|
27
|
-
assert tx_execution_succeeded(transaction_response_call_1)
|
tests/gltest/__init__.py
DELETED
File without changes
|
File without changes
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# { "Depends": "py-genlayer:test" }
|
2
|
-
|
3
|
-
from genlayer import *
|
4
|
-
|
5
|
-
|
6
|
-
# contract class
|
7
|
-
class DuplicateContract(gl.Contract):
|
8
|
-
storage: str
|
9
|
-
|
10
|
-
# constructor
|
11
|
-
def __init__(self, initial_storage: str):
|
12
|
-
self.storage = initial_storage
|
13
|
-
|
14
|
-
# read methods must be annotated with view
|
15
|
-
@gl.public.view
|
16
|
-
def get_storage(self) -> str:
|
17
|
-
return self.storage
|
18
|
-
|
19
|
-
# write method
|
20
|
-
@gl.public.write
|
21
|
-
def update_storage(self, new_storage: str) -> None:
|
22
|
-
self.storage = new_storage
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# { "Depends": "py-genlayer:test" }
|
2
|
-
|
3
|
-
from genlayer import *
|
4
|
-
|
5
|
-
|
6
|
-
# contract class
|
7
|
-
class DuplicateContract(gl.Contract):
|
8
|
-
storage: str
|
9
|
-
|
10
|
-
# constructor
|
11
|
-
def __init__(self, initial_storage: str):
|
12
|
-
self.storage = initial_storage
|
13
|
-
|
14
|
-
# read methods must be annotated with view
|
15
|
-
@gl.public.view
|
16
|
-
def get_storage(self) -> str:
|
17
|
-
return self.storage
|
18
|
-
|
19
|
-
# write method
|
20
|
-
@gl.public.write
|
21
|
-
def update_storage(self, new_storage: str) -> None:
|
22
|
-
self.storage = new_storage
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# { "Depends": "py-genlayer:test" }
|
2
|
-
|
3
|
-
from genlayer import *
|
4
|
-
|
5
|
-
|
6
|
-
# contract class that is not an IC contract
|
7
|
-
class NotICContract:
|
8
|
-
storage: str
|
9
|
-
|
10
|
-
# constructor
|
11
|
-
def __init__(self, initial_storage: str):
|
12
|
-
self.storage = initial_storage
|
13
|
-
|
14
|
-
# read methods must be annotated with view
|
15
|
-
@gl.public.view
|
16
|
-
def get_storage(self) -> str:
|
17
|
-
return self.storage
|
18
|
-
|
19
|
-
# write method
|
20
|
-
@gl.public.write
|
21
|
-
def update_storage(self, new_storage: str) -> None:
|
22
|
-
self.storage = new_storage
|