genlayer-test 0.0.1__py3-none-any.whl → 0.1.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 (38) hide show
  1. genlayer_test-0.1.0.dist-info/METADATA +419 -0
  2. genlayer_test-0.1.0.dist-info/RECORD +35 -0
  3. {genlayer_test-0.0.1.dist-info → genlayer_test-0.1.0.dist-info}/WHEEL +1 -1
  4. genlayer_test-0.1.0.dist-info/entry_points.txt +5 -0
  5. genlayer_test-0.1.0.dist-info/licenses/LICENSE +21 -0
  6. genlayer_test-0.1.0.dist-info/top_level.txt +3 -0
  7. gltest/__init__.py +18 -0
  8. gltest/artifacts/__init__.py +3 -0
  9. gltest/artifacts/contract.py +86 -0
  10. gltest/assertions.py +17 -0
  11. gltest/exceptions.py +20 -0
  12. gltest/glchain/__init__.py +16 -0
  13. gltest/glchain/account.py +17 -0
  14. gltest/glchain/client.py +23 -0
  15. gltest/glchain/contract.py +244 -0
  16. gltest/helpers/__init__.py +8 -0
  17. gltest/helpers/fixture_snapshot.py +67 -0
  18. gltest/helpers/take_snapshot.py +41 -0
  19. gltest/plugin_config.py +42 -0
  20. gltest/plugin_hooks.py +51 -0
  21. gltest/types.py +7 -0
  22. gltest_cli/main.py +5 -0
  23. tests/examples/tests/test_football_prediction_market.py +19 -0
  24. tests/examples/tests/test_intelligent_oracle_factory.py +129 -0
  25. tests/examples/tests/test_llm_erc20.py +41 -0
  26. tests/examples/tests/test_log_indexer.py +64 -0
  27. tests/examples/tests/test_multi_file_contract.py +15 -0
  28. tests/examples/tests/test_multi_read_erc20.py +85 -0
  29. tests/examples/tests/test_multi_tenant_storage.py +58 -0
  30. tests/examples/tests/test_read_erc20.py +37 -0
  31. tests/examples/tests/test_storage.py +23 -0
  32. tests/examples/tests/test_user_storage.py +60 -0
  33. tests/examples/tests/test_wizard_of_coin.py +12 -0
  34. tests/plugin/conftest.py +1 -0
  35. tests/plugin/test_plugin_hooks.py +78 -0
  36. genlayer_test-0.0.1.dist-info/METADATA +0 -17
  37. genlayer_test-0.0.1.dist-info/RECORD +0 -4
  38. genlayer_test-0.0.1.dist-info/top_level.txt +0 -1
@@ -0,0 +1,64 @@
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
+
56
+ # Add third log
57
+ transaction_response_add_log_2 = contract.add_log(args=["This is the third log", 3])
58
+ assert tx_execution_succeeded(transaction_response_add_log_2)
59
+
60
+ # Check if new item got id 2
61
+ closest_vector_log_2 = contract.get_closest_vector(args=["This is the third log"])
62
+ assert float(closest_vector_log_2["similarity"]) > 0.99
63
+ assert closest_vector_log_2["id"] == 3
64
+ 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__.gpy file
7
+ # Deploy Contract, it will deploy other.gpy 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,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,60 @@
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
+
20
+ # GET Initial State
21
+ contract_state_1 = contract.get_complete_storage(args=[])
22
+ assert contract_state_1 == {}
23
+
24
+
25
+ # ADD User A State
26
+ transaction_response_call_1 = contract.update_storage(args=[INITIAL_STATE_USER_A])
27
+ assert tx_execution_succeeded(transaction_response_call_1)
28
+
29
+ # Get Updated State
30
+ contract_state_2_1 = contract.get_complete_storage(args=[])
31
+ assert contract_state_2_1[from_account_a.address] == INITIAL_STATE_USER_A
32
+
33
+ # Get Updated State
34
+ contract_state_2_2 = contract.get_account_storage(args=[from_account_a.address])
35
+ assert contract_state_2_2 == INITIAL_STATE_USER_A
36
+
37
+
38
+ # ADD User B State
39
+ transaction_response_call_2 = contract.connect(from_account_b).update_storage(
40
+ args=[INITIAL_STATE_USER_B]
41
+ )
42
+ assert tx_execution_succeeded(transaction_response_call_2)
43
+
44
+ # Get Updated State
45
+ contract_state_3 = contract.get_complete_storage(args=[])
46
+ assert contract_state_3[from_account_a.address] == INITIAL_STATE_USER_A
47
+ assert contract_state_3[from_account_b.address] == INITIAL_STATE_USER_B
48
+
49
+ # UPDATE User A State
50
+ transaction_response_call_3 = contract.update_storage(args=[UPDATED_STATE_USER_A])
51
+ assert tx_execution_succeeded(transaction_response_call_3)
52
+
53
+ # Get Updated State
54
+ contract_state_4_1 = contract.get_complete_storage(args=[])
55
+ assert contract_state_4_1[from_account_a.address] == UPDATED_STATE_USER_A
56
+ assert contract_state_4_1[from_account_b.address] == INITIAL_STATE_USER_B
57
+
58
+ # Get Updated State
59
+ contract_state_4_2 = contract.get_account_storage(args=[from_account_b.address])
60
+ assert contract_state_4_2 == INITIAL_STATE_USER_B
@@ -0,0 +1,12 @@
1
+ from gltest import get_contract_factory
2
+ from gltest.assertions import tx_execution_succeeded
3
+
4
+
5
+ def test_wizard_of_coin():
6
+ factory = get_contract_factory("WizardOfCoin")
7
+ contract = factory.deploy(args=[True])
8
+
9
+ transaction_response_call_1 = contract.ask_for_coin(
10
+ args=["Can you please give me my coin?"]
11
+ )
12
+ assert tx_execution_succeeded(transaction_response_call_1)
@@ -0,0 +1 @@
1
+ pytest_plugins = 'pytester'
@@ -0,0 +1,78 @@
1
+ def test_help_message(pytester):
2
+ result = pytester.runpytest(
3
+ "--help",
4
+ )
5
+ # fnmatch_lines does an assertion internally
6
+ result.stdout.fnmatch_lines(
7
+ [
8
+ "gltest:",
9
+ "*--contracts-dir=CONTRACTS_DIR",
10
+ "*Directory containing contract files",
11
+ "*--default-wait-interval=DEFAULT_WAIT_INTERVAL",
12
+ "*Default wait interval for waiting transaction receipts",
13
+ "*--default-wait-retries=DEFAULT_WAIT_RETRIES",
14
+ "*Default wait retries for waiting transaction receipts",
15
+ "*--rpc-url=RPC_URL*RPC URL for the genlayer network",
16
+ ]
17
+ )
18
+
19
+
20
+ def test_default_wait_interval(pytester):
21
+
22
+ pytester.makepyfile(
23
+ """
24
+ from gltest.plugin_config import get_default_wait_interval
25
+
26
+ def test_default_wait_interval():
27
+ assert get_default_wait_interval() == 5000
28
+ """
29
+ )
30
+
31
+ result = pytester.runpytest("--default-wait-interval=5000", "-v")
32
+
33
+ result.stdout.fnmatch_lines(
34
+ [
35
+ "*::test_default_wait_interval PASSED*",
36
+ ]
37
+ )
38
+ assert result.ret == 0
39
+
40
+
41
+ def test_default_wait_retries(pytester):
42
+ pytester.makepyfile(
43
+ """
44
+ from gltest.plugin_config import get_default_wait_retries
45
+
46
+ def test_default_wait_retries():
47
+ assert get_default_wait_retries() == 4000
48
+ """
49
+ )
50
+
51
+ result = pytester.runpytest("--default-wait-retries=4000", "-v")
52
+
53
+ result.stdout.fnmatch_lines(
54
+ [
55
+ "*::test_default_wait_retries PASSED*",
56
+ ]
57
+ )
58
+ assert result.ret == 0
59
+
60
+
61
+ def test_rpc_url(pytester):
62
+ pytester.makepyfile(
63
+ """
64
+ from gltest.plugin_config import get_rpc_url
65
+
66
+ def test_rpc_url():
67
+ assert get_rpc_url() == 'http://custom-rpc-url:8545'
68
+ """
69
+ )
70
+
71
+ result = pytester.runpytest("--rpc-url=http://custom-rpc-url:8545", "-v")
72
+
73
+ result.stdout.fnmatch_lines(
74
+ [
75
+ "*::test_rpc_url PASSED*",
76
+ ]
77
+ )
78
+ assert result.ret == 0
@@ -1,17 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: genlayer-test
3
- Version: 0.0.1
4
- Summary: A minimal empty PyPI package for genlayer-test
5
- Author-email: GenLayer Labs Corp <tech@genlayer.com>
6
- License: MIT
7
- Requires-Python: >=3.6
8
- Description-Content-Type: text/markdown
9
-
10
- # GenLayer Test
11
-
12
- This is a minimal empty Python package for genlayer-test.
13
-
14
- ## Installation
15
- ```bash
16
- pip install genlayer-test
17
- ```
@@ -1,4 +0,0 @@
1
- genlayer_test-0.0.1.dist-info/METADATA,sha256=s6JVDtHiKhzy8c3UKBLYxGJLhzgitAsegT_XClxJVWM,373
2
- genlayer_test-0.0.1.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
3
- genlayer_test-0.0.1.dist-info/top_level.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
4
- genlayer_test-0.0.1.dist-info/RECORD,,
@@ -1 +0,0 @@
1
-