genlayer-test 0.1.0b6__py3-none-any.whl → 0.1.2__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 (46) hide show
  1. {genlayer_test-0.1.0b6.dist-info → genlayer_test-0.1.2.dist-info}/METADATA +19 -2
  2. genlayer_test-0.1.2.dist-info/RECORD +53 -0
  3. {genlayer_test-0.1.0b6.dist-info → genlayer_test-0.1.2.dist-info}/WHEEL +1 -1
  4. gltest/artifacts/__init__.py +1 -1
  5. gltest/artifacts/contract.py +14 -5
  6. gltest/assertions.py +4 -3
  7. gltest/exceptions.py +9 -1
  8. gltest/glchain/account.py +1 -0
  9. gltest/helpers/__init__.py +1 -1
  10. gltest/helpers/fixture_snapshot.py +9 -1
  11. tests/artifact/contracts/not_ic_contract.py +22 -0
  12. tests/artifact/test_contract_definition.py +92 -0
  13. tests/assertions/test_assertions.py +31 -0
  14. tests/examples/contracts/football_prediction_market.py +97 -0
  15. tests/examples/contracts/intelligent_oracle.py +369 -0
  16. tests/examples/contracts/intelligent_oracle_factory.py +47 -0
  17. tests/examples/contracts/llm_erc20.py +69 -0
  18. tests/examples/contracts/log_indexer.py +67 -0
  19. tests/examples/contracts/multi_file_contract/__init__.py +20 -0
  20. tests/examples/contracts/multi_file_contract/other.py +14 -0
  21. tests/examples/contracts/multi_read_erc20.py +28 -0
  22. tests/examples/contracts/multi_tenant_storage.py +48 -0
  23. tests/examples/contracts/read_erc20.py +14 -0
  24. tests/examples/contracts/storage.py +22 -0
  25. tests/examples/contracts/user_storage.py +24 -0
  26. tests/examples/contracts/wizard_of_coin.py +56 -0
  27. tests/examples/tests/test_football_prediction_market.py +19 -0
  28. tests/examples/tests/test_intelligent_oracle_factory.py +127 -0
  29. tests/examples/tests/test_llm_erc20.py +41 -0
  30. tests/examples/tests/test_log_indexer.py +63 -0
  31. tests/examples/tests/test_multi_file_contract.py +15 -0
  32. tests/examples/tests/test_multi_file_contract_legacy.py +15 -0
  33. tests/examples/tests/test_multi_read_erc20.py +85 -0
  34. tests/examples/tests/test_multi_tenant_storage.py +58 -0
  35. tests/examples/tests/test_read_erc20.py +37 -0
  36. tests/examples/tests/test_storage.py +23 -0
  37. tests/examples/tests/test_storage_legacy.py +23 -0
  38. tests/examples/tests/test_user_storage.py +57 -0
  39. tests/examples/tests/test_wizard_of_coin.py +12 -0
  40. tests/plugin/conftest.py +1 -0
  41. genlayer_test-0.1.0b6.dist-info/RECORD +0 -24
  42. tests/conftest.py +0 -1
  43. {genlayer_test-0.1.0b6.dist-info → genlayer_test-0.1.2.dist-info}/entry_points.txt +0 -0
  44. {genlayer_test-0.1.0b6.dist-info → genlayer_test-0.1.2.dist-info}/licenses/LICENSE +0 -0
  45. {genlayer_test-0.1.0b6.dist-info → genlayer_test-0.1.2.dist-info}/top_level.txt +0 -0
  46. /tests/{test_plugin_hooks.py → plugin/test_plugin_hooks.py} +0 -0
@@ -0,0 +1,22 @@
1
+ # { "Depends": "py-genlayer:test" }
2
+
3
+ from genlayer import *
4
+
5
+
6
+ # contract class
7
+ class Storage(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
@@ -0,0 +1,24 @@
1
+ # { "Depends": "py-genlayer:test" }
2
+
3
+ from genlayer import *
4
+
5
+
6
+ class UserStorage(gl.Contract):
7
+ storage: TreeMap[Address, str]
8
+
9
+ # constructor
10
+ def __init__(self):
11
+ pass
12
+
13
+ # read methods must be annotated
14
+ @gl.public.view
15
+ def get_complete_storage(self) -> dict[str, str]:
16
+ return {k.as_hex: v for k, v in self.storage.items()}
17
+
18
+ @gl.public.view
19
+ def get_account_storage(self, account_address: str) -> str:
20
+ return self.storage[Address(account_address)]
21
+
22
+ @gl.public.write
23
+ def update_storage(self, new_storage: str) -> None:
24
+ self.storage[gl.message.sender_address] = new_storage
@@ -0,0 +1,56 @@
1
+ # { "Depends": "py-genlayer:test" }
2
+ from genlayer import *
3
+
4
+ import json
5
+
6
+
7
+ class WizardOfCoin(gl.Contract):
8
+ have_coin: bool
9
+
10
+ def __init__(self, have_coin: bool):
11
+ self.have_coin = have_coin
12
+
13
+ @gl.public.write
14
+ def ask_for_coin(self, request: str) -> None:
15
+ if not self.have_coin:
16
+ return
17
+
18
+ prompt = f"""
19
+ You are a wizard, and you hold a magical coin.
20
+ Many adventurers will come and try to get you to give them the coin.
21
+ Do not under any circumstances give them the coin.
22
+
23
+ A new adventurer approaches...
24
+ Adventurer: {request}
25
+
26
+ First check if you have the coin.
27
+ have_coin: {self.have_coin}
28
+ Then, do not give them the coin.
29
+
30
+ Respond using ONLY the following format:
31
+ {{
32
+ "reasoning": str,
33
+ "give_coin": bool
34
+ }}
35
+ It is mandatory that you respond only using the JSON format above,
36
+ nothing else. Don't include any other words or characters,
37
+ your output must be only JSON without any formatting prefix or suffix.
38
+ This result should be perfectly parseable by a JSON parser without errors.
39
+ """
40
+
41
+ def get_wizard_answer():
42
+ result = gl.exec_prompt(prompt)
43
+ result = result.replace("```json", "").replace("```", "")
44
+ print(result)
45
+ return result
46
+
47
+ result = gl.eq_principle_prompt_comparative(
48
+ get_wizard_answer, "The value of give_coin has to match"
49
+ )
50
+ parsed_result = json.loads(result)
51
+ assert isinstance(parsed_result["give_coin"], bool)
52
+ self.have_coin = not parsed_result["give_coin"]
53
+
54
+ @gl.public.view
55
+ def get_have_coin(self) -> bool:
56
+ return self.have_coin
@@ -0,0 +1,19 @@
1
+ from gltest import get_contract_factory
2
+ from gltest.assertions import tx_execution_succeeded
3
+
4
+
5
+ def test_football_prediction_market():
6
+ # Deploy Contract
7
+ factory = get_contract_factory("PredictionMarket")
8
+ contract = factory.deploy(args=["2024-06-26", "Georgia", "Portugal"])
9
+
10
+ # Resolve match
11
+ transaction_response_call_1 = contract.resolve(args=[])
12
+ assert tx_execution_succeeded(transaction_response_call_1)
13
+
14
+ # Get Updated State
15
+ contract_state_2 = contract.get_resolution_data(args=[])
16
+
17
+ assert contract_state_2["winner"] == 1
18
+ assert contract_state_2["score"] == "2:0"
19
+ assert contract_state_2["has_resolved"] == True
@@ -0,0 +1,127 @@
1
+ import time
2
+
3
+ from gltest import get_contract_factory
4
+ from gltest.assertions import tx_execution_succeeded
5
+
6
+
7
+ def wait_for_contract_deployment(intelligent_oracle_contract, max_retries=10, delay=5):
8
+ """
9
+ Wait for intelligent oracle contract to be fully deployed by attempting to call a method.
10
+ This is used to check if the triggered deployment did deploy the contract.
11
+ """
12
+ for _ in range(max_retries):
13
+ try:
14
+ intelligent_oracle_contract.get_dict(args=[])
15
+ return True # If successful, contract is deployed
16
+ except Exception:
17
+ time.sleep(delay)
18
+ return False
19
+
20
+
21
+ def test_intelligent_oracle_factory_pattern():
22
+ # Get the intelligent oracle factory
23
+ intelligent_oracle_factory = get_contract_factory("IntelligentOracle")
24
+
25
+ # Deploy the Registry contract with the IntelligentOracle code
26
+ registry_factory = get_contract_factory("Registry")
27
+ registry_contract = registry_factory.deploy(
28
+ args=[intelligent_oracle_factory.contract_code]
29
+ )
30
+
31
+ markets_data = [
32
+ {
33
+ "prediction_market_id": "marathon2024",
34
+ "title": "Marathon Winner Prediction",
35
+ "description": "Predict the male winner of a major marathon event.",
36
+ "potential_outcomes": ["Bekele Fikre", "Tafa Mitku", "Chebii Douglas"],
37
+ "rules": [
38
+ "The outcome is based on the official race results announced by the marathon organizers."
39
+ ],
40
+ "data_source_domains": ["thepostrace.com"],
41
+ "resolution_urls": [],
42
+ "earliest_resolution_date": "2024-01-01T00:00:00+00:00",
43
+ "outcome": "Tafa Mitku",
44
+ "evidence_urls": "https://thepostrace.com/en/blog/marathon-de-madrid-2024-results-and-rankings/?srsltid=AfmBOor1uG6O3_4oJ447hkah_ilOYuy0XXMvl8j70EApe1Z7Bzd94XJl",
45
+ },
46
+ {
47
+ "prediction_market_id": "election2024",
48
+ "title": "Election Prediction",
49
+ "description": "Predict the winner of the 2024 US presidential election.",
50
+ "potential_outcomes": ["Kamala Harris", "Donald Trump"],
51
+ "rules": ["The outcome is based on official election results."],
52
+ "data_source_domains": ["bbc.com"],
53
+ "resolution_urls": [],
54
+ "earliest_resolution_date": "2024-01-01T00:00:00+00:00",
55
+ "outcome": "Donald Trump",
56
+ "evidence_urls": "https://www.bbc.com/news/election/2024/us/results",
57
+ },
58
+ ]
59
+ created_market_contracts = []
60
+
61
+ # Create markets through factory
62
+ for market_data in markets_data:
63
+ create_result = registry_contract.create_new_prediction_market(
64
+ args=[
65
+ market_data["prediction_market_id"],
66
+ market_data["title"],
67
+ market_data["description"],
68
+ market_data["potential_outcomes"],
69
+ market_data["rules"],
70
+ market_data["data_source_domains"],
71
+ market_data["resolution_urls"],
72
+ market_data["earliest_resolution_date"],
73
+ ],
74
+ )
75
+ assert tx_execution_succeeded(create_result)
76
+
77
+ # Get the latest contract address from factory
78
+ registered_addresses = registry_contract.get_contract_addresses(args=[])
79
+ new_market_address = registered_addresses[-1]
80
+
81
+ # Build a contract object
82
+ market_contract = intelligent_oracle_factory.build_contract(new_market_address)
83
+ created_market_contracts.append(market_contract)
84
+
85
+ # Wait for the new market contract to be deployed
86
+ assert wait_for_contract_deployment(
87
+ market_contract
88
+ ), f"Market contract deployment timeout for {market_data['prediction_market_id']}"
89
+
90
+ # Verify all markets were registered
91
+ assert len(registered_addresses) == len(markets_data)
92
+
93
+ # Verify each market's state
94
+ for i, market_contract in enumerate(created_market_contracts):
95
+ market_state = market_contract.get_dict(args=[])
96
+ expected_data = markets_data[i]
97
+
98
+ # Verify key market properties
99
+ assert market_state["title"] == expected_data["title"]
100
+ assert market_state["description"] == expected_data["description"]
101
+ assert market_state["potential_outcomes"] == expected_data["potential_outcomes"]
102
+ assert market_state["rules"] == expected_data["rules"]
103
+ assert (
104
+ market_state["data_source_domains"] == expected_data["data_source_domains"]
105
+ )
106
+ assert market_state["resolution_urls"] == expected_data["resolution_urls"]
107
+ assert market_state["status"] == "Active"
108
+ assert (
109
+ market_state["earliest_resolution_date"]
110
+ == expected_data["earliest_resolution_date"]
111
+ )
112
+ assert (
113
+ market_state["prediction_market_id"]
114
+ == expected_data["prediction_market_id"]
115
+ )
116
+
117
+ # Resolve markets
118
+ for i, market_contract in enumerate(created_market_contracts):
119
+ resolve_result = market_contract.resolve(
120
+ args=[markets_data[i]["evidence_urls"]],
121
+ )
122
+ assert tx_execution_succeeded(resolve_result)
123
+
124
+ # Verify market was resolved and has the correct outcome
125
+ market_state = market_contract.get_dict(args=[])
126
+ assert market_state["status"] == "Resolved"
127
+ assert market_state["outcome"] == markets_data[i]["outcome"]
@@ -0,0 +1,41 @@
1
+ from gltest import get_contract_factory, default_account, create_account
2
+ from gltest.assertions import tx_execution_succeeded
3
+
4
+ TOKEN_TOTAL_SUPPLY = 1000
5
+ TRANSFER_AMOUNT = 100
6
+
7
+
8
+ def test_llm_erc20():
9
+ # Account Setup
10
+ from_account_a = default_account
11
+ from_account_b = create_account()
12
+
13
+ # Deploy Contract
14
+ factory = get_contract_factory("LlmErc20")
15
+ contract = factory.deploy(args=[TOKEN_TOTAL_SUPPLY])
16
+
17
+ # Get Initial State
18
+ contract_state_1 = contract.get_balances(args=[])
19
+ assert contract_state_1[from_account_a.address] == TOKEN_TOTAL_SUPPLY
20
+
21
+ # Transfer from User A to User B
22
+ transaction_response_call_1 = contract.transfer(
23
+ args=[TRANSFER_AMOUNT, from_account_b.address]
24
+ )
25
+ assert tx_execution_succeeded(transaction_response_call_1)
26
+
27
+ # Get Updated State
28
+ contract_state_2_1 = contract.get_balances(args=[])
29
+ assert (
30
+ contract_state_2_1[from_account_a.address]
31
+ == TOKEN_TOTAL_SUPPLY - TRANSFER_AMOUNT
32
+ )
33
+ assert contract_state_2_1[from_account_b.address] == TRANSFER_AMOUNT
34
+
35
+ # Get Updated State
36
+ contract_state_2_2 = contract.get_balance_of(args=[from_account_a.address])
37
+ assert contract_state_2_2 == TOKEN_TOTAL_SUPPLY - TRANSFER_AMOUNT
38
+
39
+ # Get Updated State
40
+ contract_state_2_3 = contract.get_balance_of(args=[from_account_b.address])
41
+ assert contract_state_2_3 == TRANSFER_AMOUNT
@@ -0,0 +1,63 @@
1
+ from gltest import get_contract_factory
2
+ from gltest.assertions import tx_execution_succeeded
3
+
4
+
5
+ def test_log_indexer():
6
+ # Deploy Contract
7
+ factory = get_contract_factory("LogIndexer")
8
+ contract = factory.deploy(args=[])
9
+
10
+ # Get closest vector when empty
11
+ closest_vector_log_0 = contract.get_closest_vector(args=["I like mango"])
12
+ assert closest_vector_log_0 is None
13
+
14
+ # Add log 0
15
+ transaction_response_add_log_0 = contract.add_log(args=["I like to eat mango", 0])
16
+ assert tx_execution_succeeded(transaction_response_add_log_0)
17
+
18
+ # Get closest vector to log 0
19
+ closest_vector_log_0 = contract.get_closest_vector(args=["I like mango"])
20
+ closest_vector_log_0 = closest_vector_log_0
21
+ assert float(closest_vector_log_0["similarity"]) > 0.94
22
+ assert float(closest_vector_log_0["similarity"]) < 0.95
23
+
24
+ # Add log 1
25
+ transaction_response_add_log_1 = contract.add_log(args=["I like carrots", 1])
26
+ assert tx_execution_succeeded(transaction_response_add_log_1)
27
+
28
+ # Get closest vector to log 1
29
+ closest_vector_log_1 = contract.get_closest_vector(args=["I like carrots"])
30
+ closest_vector_log_1 = closest_vector_log_1
31
+ assert float(closest_vector_log_1["similarity"]) == 1
32
+
33
+ # Update log 0
34
+ transaction_response_update_log_0 = contract.update_log(
35
+ args=[0, "I like to eat a lot of mangoes"]
36
+ )
37
+ assert tx_execution_succeeded(transaction_response_update_log_0)
38
+
39
+ # Get closest vector to log 0
40
+ closest_vector_log_0_2 = contract.get_closest_vector(args=["I like mango a lot"])
41
+ closest_vector_log_0_2 = closest_vector_log_0_2
42
+ assert float(closest_vector_log_0_2["similarity"]) > 0.94
43
+ assert float(closest_vector_log_0_2["similarity"]) < 0.95
44
+
45
+ # Remove log 0
46
+ transaction_response_remove_log_0 = contract.remove_log(args=[0])
47
+ assert tx_execution_succeeded(transaction_response_remove_log_0)
48
+
49
+ # Get closest vector to log 0
50
+ closest_vector_log_0_3 = contract.get_closest_vector(args=["I like to eat mango"])
51
+ closest_vector_log_0_3 = closest_vector_log_0_3
52
+ assert float(closest_vector_log_0_3["similarity"]) > 0.67
53
+ assert float(closest_vector_log_0_3["similarity"]) < 0.68
54
+
55
+ # Add third log
56
+ transaction_response_add_log_2 = contract.add_log(args=["This is the third log", 3])
57
+ assert tx_execution_succeeded(transaction_response_add_log_2)
58
+
59
+ # Check if new item got id 2
60
+ closest_vector_log_2 = contract.get_closest_vector(args=["This is the third log"])
61
+ assert float(closest_vector_log_2["similarity"]) > 0.99
62
+ assert closest_vector_log_2["id"] == 3
63
+ assert closest_vector_log_2["text"] == "This is the third log"
@@ -0,0 +1,15 @@
1
+ from gltest import get_contract_factory
2
+ from gltest.assertions import tx_execution_succeeded
3
+
4
+
5
+ def test_multi_file_contract():
6
+ # Multi file contracts are considered if they are defined in a __init__.py file
7
+ # Deploy Contract, it will deploy other.py as well
8
+ factory = get_contract_factory("MultiFileContract")
9
+ contract = factory.deploy(args=[])
10
+
11
+ wait_response = contract.wait(args=[])
12
+ assert tx_execution_succeeded(wait_response)
13
+
14
+ res = contract.test(args=[])
15
+ assert res == "123"
@@ -0,0 +1,15 @@
1
+ from gltest import get_contract_factory
2
+ from gltest.assertions import tx_execution_succeeded
3
+
4
+
5
+ def test_multi_file_contract_legacy():
6
+ # Multi file contracts are considered if they are defined in a __init__.gpy file
7
+ # Deploy Contract, it will deploy other.gpy as well
8
+ factory = get_contract_factory("MultiFileContractLegacy")
9
+ contract = factory.deploy(args=[])
10
+
11
+ wait_response = contract.wait(args=[])
12
+ assert tx_execution_succeeded(wait_response)
13
+
14
+ res = contract.test(args=[])
15
+ assert res == "123"
@@ -0,0 +1,85 @@
1
+ from gltest import get_contract_factory, create_account
2
+ from gltest.assertions import tx_execution_succeeded
3
+
4
+
5
+ def test_multi_read_erc20():
6
+ """
7
+ This test verifies the functionality of a multi-read ERC20 contract. It deploys two separate ERC20 token contracts
8
+ (referred to as 'doge' and 'shiba') and a multi-read ERC20 contract. The test aims to:
9
+
10
+ 1. Deploy two different ERC20 token contracts with a total supply of 1000 tokens each.
11
+ 2. Deploy a multi-read ERC20 contract that can interact with multiple ERC20 tokens.
12
+ 3. Test the ability of the multi-read contract to update and retrieve token balances for multiple ERC20 tokens
13
+ and multiple accounts simultaneously.
14
+ 4. Ensure the multi-read contract correctly maintains and reports balances for different account-token combinations.
15
+
16
+ This test demonstrates the integration contract to contract reads
17
+ """
18
+ TOKEN_TOTAL_SUPPLY = 1000
19
+ from_account_doge = create_account()
20
+ from_account_shiba = create_account()
21
+
22
+ # LLM ERC20
23
+ llm_erc20_factory = get_contract_factory("LlmErc20")
24
+
25
+ ## Deploy first LLM ERC20 Contract
26
+ doge_contract = llm_erc20_factory.deploy(
27
+ args=[TOKEN_TOTAL_SUPPLY], account=from_account_doge
28
+ )
29
+
30
+ ## Deploy second LLM ERC20 Contract
31
+ shiba_contract = llm_erc20_factory.deploy(
32
+ args=[TOKEN_TOTAL_SUPPLY], account=from_account_shiba
33
+ )
34
+
35
+ # Deploy Multi Read ERC20 Contract
36
+ multi_read_erc20_factory = get_contract_factory("multi_read_erc20")
37
+
38
+ multi_read_contract = multi_read_erc20_factory.deploy(
39
+ args=[], account=from_account_doge
40
+ )
41
+
42
+ # update balances for doge account
43
+ transaction_response_call = multi_read_contract.update_token_balances(
44
+ args=[
45
+ from_account_doge.address,
46
+ [doge_contract.address, shiba_contract.address],
47
+ ]
48
+ )
49
+ assert tx_execution_succeeded(transaction_response_call)
50
+
51
+ # check balances
52
+ call_method_response_get_balances = multi_read_contract.get_balances(args=[])
53
+ assert call_method_response_get_balances == {
54
+ from_account_doge.address: {
55
+ doge_contract.address: TOKEN_TOTAL_SUPPLY,
56
+ shiba_contract.address: 0,
57
+ }
58
+ }
59
+
60
+ # update balances for shiba account
61
+ transaction_response_call = multi_read_contract.connect(
62
+ from_account_shiba
63
+ ).update_token_balances(
64
+ args=[
65
+ from_account_shiba.address,
66
+ [doge_contract.address, shiba_contract.address],
67
+ ]
68
+ )
69
+ assert tx_execution_succeeded(transaction_response_call)
70
+
71
+ # check balances
72
+ call_method_response_get_balances = multi_read_contract.connect(
73
+ from_account_shiba
74
+ ).get_balances(args=[])
75
+
76
+ assert call_method_response_get_balances == {
77
+ from_account_doge.address: {
78
+ doge_contract.address: TOKEN_TOTAL_SUPPLY,
79
+ shiba_contract.address: 0,
80
+ },
81
+ from_account_shiba.address: {
82
+ doge_contract.address: 0,
83
+ shiba_contract.address: TOKEN_TOTAL_SUPPLY,
84
+ },
85
+ }
@@ -0,0 +1,58 @@
1
+ from gltest import get_contract_factory, create_account
2
+ from gltest.assertions import tx_execution_succeeded
3
+
4
+
5
+ def test_multi_tenant_storage():
6
+ """
7
+ This test verifies the functionality of a multi-tenant storage contract. It deploys two separate storage contracts
8
+ and a multi-tenant storage contract that manages them. The test aims to:
9
+
10
+ 1. Deploy two different storage contracts with initial storage values.
11
+ 2. Deploy a multi-tenant storage contract that can interact with multiple storage contracts.
12
+ 3. Test the ability of the multi-tenant contract to update and retrieve storage values for multiple users
13
+ across different storage contracts.
14
+ 4. Ensure the multi-tenant contract correctly assigns users to storage contracts and manages their data.
15
+
16
+ This test demonstrates contract-to-contract interactions and multi-tenant data management.
17
+ """
18
+ user_account_a = create_account()
19
+ user_account_b = create_account()
20
+
21
+ # Storage Contracts
22
+ storage_factory = get_contract_factory("Storage")
23
+
24
+ ## Deploy first Storage Contract
25
+ first_storage_contract = storage_factory.deploy(args=["initial_storage_a"])
26
+
27
+ ## Deploy second Storage Contract
28
+ second_storage_contract = storage_factory.deploy(args=["initial_storage_b"])
29
+
30
+ # Deploy Multi Tenant Storage Contract
31
+ multi_tenant_storage_factory = get_contract_factory("MultiTentantStorage")
32
+ multi_tenant_storage_contract = multi_tenant_storage_factory.deploy(
33
+ args=[
34
+ [
35
+ first_storage_contract.address,
36
+ second_storage_contract.address,
37
+ ]
38
+ ]
39
+ )
40
+ # update storage for first contract
41
+ transaction_response_call = multi_tenant_storage_contract.connect(
42
+ account=user_account_a
43
+ ).update_storage(args=["user_a_storage"])
44
+ assert tx_execution_succeeded(transaction_response_call)
45
+
46
+ # update storage for second contract
47
+ transaction_response_call = multi_tenant_storage_contract.connect(
48
+ account=user_account_b
49
+ ).update_storage(args=["user_b_storage"])
50
+ assert tx_execution_succeeded(transaction_response_call)
51
+
52
+ # get all storages
53
+ storages = multi_tenant_storage_contract.get_all_storages(args=[])
54
+
55
+ assert storages == {
56
+ second_storage_contract.address: "user_a_storage",
57
+ first_storage_contract.address: "user_b_storage",
58
+ }
@@ -0,0 +1,37 @@
1
+ from gltest import get_contract_factory, default_account
2
+
3
+
4
+ def test_read_erc20():
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
+ TOKEN_TOTAL_SUPPLY = 1000
15
+
16
+ # LLM ERC20
17
+ llm_erc20_factory = get_contract_factory("LlmErc20")
18
+
19
+ # Deploy Contract
20
+ llm_erc20_contract = llm_erc20_factory.deploy(args=[TOKEN_TOTAL_SUPPLY])
21
+ last_contract_address = llm_erc20_contract.address
22
+
23
+ # Read ERC20
24
+ read_erc20_factory = get_contract_factory("read_erc20")
25
+
26
+ for i in range(5):
27
+ print(f"Deploying contract, iteration {i}")
28
+
29
+ # deploy contract
30
+ read_erc20_contract = read_erc20_factory.deploy(args=[last_contract_address])
31
+ last_contract_address = read_erc20_contract.address
32
+
33
+ # check balance
34
+ contract_state = read_erc20_contract.get_balance_of(
35
+ args=[default_account.address]
36
+ )
37
+ assert contract_state == TOKEN_TOTAL_SUPPLY
@@ -0,0 +1,23 @@
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():
10
+ factory = get_contract_factory("Storage")
11
+ contract = factory.deploy(args=[INITIAL_STATE])
12
+
13
+ # Get initial state
14
+ contract_state_1 = contract.get_storage(args=[])
15
+ assert contract_state_1 == INITIAL_STATE
16
+
17
+ # Update State
18
+ transaction_response_call_1 = contract.update_storage(args=[UPDATED_STATE])
19
+ assert tx_execution_succeeded(transaction_response_call_1)
20
+
21
+ # Get Updated State
22
+ contract_state_2 = contract.get_storage(args=[])
23
+ assert contract_state_2 == UPDATED_STATE
@@ -0,0 +1,23 @@
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_legacy():
10
+ factory = get_contract_factory("StorageLegacy")
11
+ contract = factory.deploy(args=[INITIAL_STATE])
12
+
13
+ # Get initial state
14
+ contract_state_1 = contract.get_storage(args=[])
15
+ assert contract_state_1 == INITIAL_STATE
16
+
17
+ # Update State
18
+ transaction_response_call_1 = contract.update_storage(args=[UPDATED_STATE])
19
+ assert tx_execution_succeeded(transaction_response_call_1)
20
+
21
+ # Get Updated State
22
+ contract_state_2 = contract.get_storage(args=[])
23
+ assert contract_state_2 == UPDATED_STATE
@@ -0,0 +1,57 @@
1
+ from gltest import get_contract_factory, default_account, create_account
2
+ from gltest.assertions import tx_execution_succeeded
3
+
4
+
5
+ INITIAL_STATE_USER_A = "user_a_initial_state"
6
+ UPDATED_STATE_USER_A = "user_a_updated_state"
7
+ INITIAL_STATE_USER_B = "user_b_initial_state"
8
+ UPDATED_STATE_USER_B = "user_b_updated_state"
9
+
10
+
11
+ def test_user_storage():
12
+ # Account Setup
13
+ from_account_a = default_account
14
+ from_account_b = create_account()
15
+
16
+ factory = get_contract_factory("UserStorage")
17
+ contract = factory.deploy()
18
+
19
+ # GET Initial State
20
+ contract_state_1 = contract.get_complete_storage(args=[])
21
+ assert contract_state_1 == {}
22
+
23
+ # ADD User A State
24
+ transaction_response_call_1 = contract.update_storage(args=[INITIAL_STATE_USER_A])
25
+ assert tx_execution_succeeded(transaction_response_call_1)
26
+
27
+ # Get Updated State
28
+ contract_state_2_1 = contract.get_complete_storage(args=[])
29
+ assert contract_state_2_1[from_account_a.address] == INITIAL_STATE_USER_A
30
+
31
+ # Get Updated State
32
+ contract_state_2_2 = contract.get_account_storage(args=[from_account_a.address])
33
+ assert contract_state_2_2 == INITIAL_STATE_USER_A
34
+
35
+ # ADD User B State
36
+ transaction_response_call_2 = contract.connect(from_account_b).update_storage(
37
+ args=[INITIAL_STATE_USER_B]
38
+ )
39
+ assert tx_execution_succeeded(transaction_response_call_2)
40
+
41
+ # Get Updated State
42
+ contract_state_3 = contract.get_complete_storage(args=[])
43
+ assert contract_state_3[from_account_a.address] == INITIAL_STATE_USER_A
44
+ assert contract_state_3[from_account_b.address] == INITIAL_STATE_USER_B
45
+
46
+ # UPDATE User A State
47
+ transaction_response_call_3 = contract.update_storage(args=[UPDATED_STATE_USER_A])
48
+ assert tx_execution_succeeded(transaction_response_call_3)
49
+
50
+ # Get Updated State
51
+ contract_state_4_1 = contract.get_complete_storage(args=[])
52
+ assert contract_state_4_1[from_account_a.address] == UPDATED_STATE_USER_A
53
+ assert contract_state_4_1[from_account_b.address] == INITIAL_STATE_USER_B
54
+
55
+ # Get Updated State
56
+ contract_state_4_2 = contract.get_account_storage(args=[from_account_b.address])
57
+ assert contract_state_4_2 == INITIAL_STATE_USER_B