genlayer-test 0.5.1__py3-none-any.whl → 0.6.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.5.1.dist-info → genlayer_test-0.6.0.dist-info}/METADATA +21 -2
- {genlayer_test-0.5.1.dist-info → genlayer_test-0.6.0.dist-info}/RECORD +10 -7
- gltest/contracts/contract_factory.py +39 -28
- gltest/utils.py +14 -0
- tests/examples/contracts/invalid_deploy.py +10 -0
- tests/examples/tests/test_invalid_deploy.py +24 -0
- {genlayer_test-0.5.1.dist-info → genlayer_test-0.6.0.dist-info}/WHEEL +0 -0
- {genlayer_test-0.5.1.dist-info → genlayer_test-0.6.0.dist-info}/entry_points.txt +0 -0
- {genlayer_test-0.5.1.dist-info → genlayer_test-0.6.0.dist-info}/licenses/LICENSE +0 -0
- {genlayer_test-0.5.1.dist-info → genlayer_test-0.6.0.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: genlayer-test
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.6.0
|
4
4
|
Summary: GenLayer Testing Suite
|
5
5
|
Author: GenLayer
|
6
6
|
License-Expression: MIT
|
@@ -365,17 +365,24 @@ Key features demonstrated in this contract:
|
|
365
365
|
|
366
366
|
### Contract Deployment
|
367
367
|
|
368
|
+
The GenLayer Testing Suite provides two methods for deploying contracts:
|
369
|
+
|
370
|
+
1. **`deploy()`** - Returns the deployed contract instance (recommended for most use cases)
|
371
|
+
2. **`deploy_contract_tx()`** - Returns only the transaction receipt
|
372
|
+
|
368
373
|
Here's how to deploy the Storage contract:
|
369
374
|
|
370
375
|
```python
|
371
376
|
from gltest import get_contract_factory, get_default_account
|
377
|
+
from gltest.assertions import tx_execution_succeeded
|
378
|
+
from gltest.utils import extract_contract_address
|
372
379
|
|
373
380
|
def test_deployment():
|
374
381
|
# Get the contract factory for your contract
|
375
382
|
# it will search in the contracts directory
|
376
383
|
factory = get_contract_factory("Storage")
|
377
384
|
|
378
|
-
# Deploy the contract with constructor arguments
|
385
|
+
# Method 1: Deploy the contract with constructor arguments (recommended)
|
379
386
|
contract = factory.deploy(
|
380
387
|
args=["initial_value"], # Constructor arguments
|
381
388
|
account=get_default_account(), # Account to deploy from
|
@@ -384,6 +391,18 @@ def test_deployment():
|
|
384
391
|
|
385
392
|
# Contract is now deployed and ready to use
|
386
393
|
assert contract.address is not None
|
394
|
+
|
395
|
+
# Method 2: Deploy and get only the receipt
|
396
|
+
receipt = factory.deploy_contract_tx(
|
397
|
+
args=["initial_value"],
|
398
|
+
account=get_default_account(),
|
399
|
+
)
|
400
|
+
|
401
|
+
# Verify deployment succeeded
|
402
|
+
assert tx_execution_succeeded(receipt)
|
403
|
+
|
404
|
+
# Get the contract address
|
405
|
+
contract_address = extract_contract_address(receipt)
|
387
406
|
```
|
388
407
|
|
389
408
|
### Read Methods
|
@@ -1,4 +1,4 @@
|
|
1
|
-
genlayer_test-0.
|
1
|
+
genlayer_test-0.6.0.dist-info/licenses/LICENSE,sha256=che_H4vE0QUx3HvWrAa1_jDEVInift0U6VO15-QqEls,1064
|
2
2
|
gltest/__init__.py,sha256=qoBV3IgDJr8uh9262XsWNMhi-ilkSgMqKVC9FVMk7cw,372
|
3
3
|
gltest/accounts.py,sha256=HUmWguJMolggQaZNRPw-LGlRlQCjLLdUanKRowMv6pI,812
|
4
4
|
gltest/assertions.py,sha256=0dEk0VxcHK4I7GZPHxJmz-2jaA60V499gOSR74rZbfM,1748
|
@@ -7,11 +7,12 @@ gltest/exceptions.py,sha256=deJPmrTe5gF33qkkKF2IVJY7lc_knI7Ql3N7jZ8aLZs,510
|
|
7
7
|
gltest/fixtures.py,sha256=EJXmqcC3LD03v07mepacFl58lAdhbLj6bP5rtALYISk,2507
|
8
8
|
gltest/logging.py,sha256=jAkHsuMm-AEx1Xu1srU6W-0YzTwXJB48mCK-OVzAiN4,342
|
9
9
|
gltest/types.py,sha256=Kj6UuTpRXkA4c5ystKfwgXuCiRJ1VMkbgvP7Auvznhw,184
|
10
|
+
gltest/utils.py,sha256=-gHhjrS7i_GhDG3sKOq2qsTtYBt4HHgXHEXh-3RB_rI,573
|
10
11
|
gltest/artifacts/__init__.py,sha256=qTt3TE19gVNWnQLUlt5aDe4nNvJ2YJ1jzDkMmYIsCG0,194
|
11
12
|
gltest/artifacts/contract.py,sha256=KChpmfjZod_0dVB8y-dvWz6IVm7QlIJsgG2ArtvVDaU,6457
|
12
13
|
gltest/contracts/__init__.py,sha256=A9bvEtYOoqoHS8TLlFBfmNOnfwdsJPEf-AZuikagCHM,166
|
13
14
|
gltest/contracts/contract.py,sha256=hYuugaV_gNFk58mGyLRPKkKVKIjsCDlVpKLvwRBf7sM,6743
|
14
|
-
gltest/contracts/contract_factory.py,sha256=
|
15
|
+
gltest/contracts/contract_factory.py,sha256=SCmhp2DRfD8FRejOqa6-_UF-yJaJr0ShB9lDkLLBzU0,8264
|
15
16
|
gltest/contracts/contract_functions.py,sha256=5gNQYzN47rCJtmcMtUkl4ZK-yDifdZup2YhtlFlrx7E,2203
|
16
17
|
gltest/contracts/method_stats.py,sha256=zWWjvf7K5VC4yrHpDIR717VF7LYp1RaZ1Hr_RZvWxJA,5150
|
17
18
|
gltest/contracts/stats_collector.py,sha256=fuCc8L8hd0tsVGzH4adtZWwPa7ORf0A0zR5Dt1w92Qk,9033
|
@@ -33,6 +34,7 @@ tests/conftest.py,sha256=RKdoE5_zcMimeojAoA_GSFI9du4pMzMi1vZ1njtfoAs,28
|
|
33
34
|
tests/examples/contracts/football_prediction_market.py,sha256=9xwU8f3q73Hae-ByHy_wauhMPLRnLZd4XKNrClnjOJM,3248
|
34
35
|
tests/examples/contracts/intelligent_oracle.py,sha256=cZNGbjKMXY-pimVmPIKIlS963Gd3L1JAipq0VBR1J5Q,12360
|
35
36
|
tests/examples/contracts/intelligent_oracle_factory.py,sha256=6UApEdPzcUXR18wMpaQXtWpEKeQjU0zDkI5ezghuJUo,1526
|
37
|
+
tests/examples/contracts/invalid_deploy.py,sha256=cHXV0aq8gfbWdvjchnjSeoZDCCC-5iNdLGUkJi-tQfo,228
|
36
38
|
tests/examples/contracts/llm_erc20.py,sha256=pOvSUszCtC_f5yDX0tZnj494Ce10uESZ09JLLE8V67o,2534
|
37
39
|
tests/examples/contracts/log_indexer.py,sha256=Nlf8XUt13ujam3k6hbbVrPHK-KJ366Csz1TBjc4P07g,1901
|
38
40
|
tests/examples/contracts/multi_read_erc20.py,sha256=28qYqn191Ro3rP7YJtZwL6Sc7JDXTeh8_QoqvdVPdqM,864
|
@@ -45,6 +47,7 @@ tests/examples/contracts/multi_file_contract/__init__.py,sha256=xDn_wS62GhCmnYoI
|
|
45
47
|
tests/examples/contracts/multi_file_contract/other.py,sha256=jHDtjUL3eAUgE6yOYKFw_RfAH7kIwk8CvxUjbWHNruk,236
|
46
48
|
tests/examples/tests/test_football_prediction_market.py,sha256=f2hfDK76WrNJZtFkTPKoPRR6bkmFLEssnlwwltSnU9A,1111
|
47
49
|
tests/examples/tests/test_intelligent_oracle_factory.py,sha256=sL26aeb84XpJPCSUSIX3yrbwQE8GZtvNcsaKTpngFmY,7611
|
50
|
+
tests/examples/tests/test_invalid_deploy.py,sha256=pppM8_Vn4DXcWq9iyJXb0SpZnKXkIyJxoIDW5ApCS94,814
|
48
51
|
tests/examples/tests/test_llm_erc20.py,sha256=zb5F_7NgvZXhvqL2nULwzuTT6LGDprSy0WgrdjY7pZc,2096
|
49
52
|
tests/examples/tests/test_llm_erc20_analyze.py,sha256=ccWQenEOG-U4TJdu-0i-3qNM4xRRCHSr3Iwz7pxknws,1729
|
50
53
|
tests/examples/tests/test_log_indexer.py,sha256=46AqL7qquNc9GX2wxFxVcQXLqruMnPmxXl1yeB0-KZ4,2869
|
@@ -67,8 +70,8 @@ tests/gltest_cli/config/test_config_integration.py,sha256=vPTzr3_h9UMw7m72HogBJE
|
|
67
70
|
tests/gltest_cli/config/test_general_config.py,sha256=UHtSwVnso-ZwNtYM0Z4v2sCLKwyrVbHlk6b1leVfV84,14703
|
68
71
|
tests/gltest_cli/config/test_plugin.py,sha256=COrEK5tHP1BSzanWbZHmN3EQgE9VuTcPvB95pgOvKS4,7974
|
69
72
|
tests/gltest_cli/config/test_user.py,sha256=JxR655oUFoM9quWQO68CVPKRpT0TMpzS3bF6j6NWyT4,14401
|
70
|
-
genlayer_test-0.
|
71
|
-
genlayer_test-0.
|
72
|
-
genlayer_test-0.
|
73
|
-
genlayer_test-0.
|
74
|
-
genlayer_test-0.
|
73
|
+
genlayer_test-0.6.0.dist-info/METADATA,sha256=uHgafSUvII1G16UbdZ-26QwmtaV86EX1Pk-VwXsZAxs,32466
|
74
|
+
genlayer_test-0.6.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
75
|
+
genlayer_test-0.6.0.dist-info/entry_points.txt,sha256=RWPcSArBpz_G4BYioh5L8Q8hyClRbSgzLimjcWMp-BQ,94
|
76
|
+
genlayer_test-0.6.0.dist-info/top_level.txt,sha256=-qiGZxTRBytujzgVcKpxjvQ-WNeUDjXa59ceGMwMpko,24
|
77
|
+
genlayer_test-0.6.0.dist-info/RECORD,,
|
@@ -17,10 +17,11 @@ from gltest.clients import (
|
|
17
17
|
)
|
18
18
|
from .contract import Contract
|
19
19
|
from gltest.logging import logger
|
20
|
-
from gltest.types import TransactionStatus
|
20
|
+
from gltest.types import TransactionStatus, GenLayerTransaction, CalldataEncodable
|
21
21
|
from gltest.assertions import tx_execution_failed
|
22
22
|
from gltest.exceptions import DeploymentError
|
23
23
|
from gltest_cli.config.general import get_general_config
|
24
|
+
from gltest.utils import extract_contract_address
|
24
25
|
|
25
26
|
|
26
27
|
@dataclass
|
@@ -104,7 +105,7 @@ class ContractFactory:
|
|
104
105
|
|
105
106
|
def deploy(
|
106
107
|
self,
|
107
|
-
args: List[
|
108
|
+
args: Optional[List[CalldataEncodable]] = None,
|
108
109
|
account: Optional[LocalAccount] = None,
|
109
110
|
consensus_max_rotations: Optional[int] = None,
|
110
111
|
wait_interval: Optional[int] = None,
|
@@ -114,7 +115,41 @@ class ContractFactory:
|
|
114
115
|
wait_triggered_transactions_status: TransactionStatus = TransactionStatus.ACCEPTED,
|
115
116
|
) -> Contract:
|
116
117
|
"""
|
117
|
-
Deploy the contract
|
118
|
+
Deploy the contract and return a Contract instance (convenience method).
|
119
|
+
|
120
|
+
This is a convenience method that handles receipt validation
|
121
|
+
and contract instantiation automatically.
|
122
|
+
"""
|
123
|
+
receipt = self.deploy_contract_tx(
|
124
|
+
args=args,
|
125
|
+
account=account,
|
126
|
+
consensus_max_rotations=consensus_max_rotations,
|
127
|
+
wait_interval=wait_interval,
|
128
|
+
wait_retries=wait_retries,
|
129
|
+
wait_transaction_status=wait_transaction_status,
|
130
|
+
wait_triggered_transactions=wait_triggered_transactions,
|
131
|
+
wait_triggered_transactions_status=wait_triggered_transactions_status,
|
132
|
+
)
|
133
|
+
|
134
|
+
if tx_execution_failed(receipt):
|
135
|
+
raise DeploymentError(f"Deployment transaction failed: {receipt}")
|
136
|
+
|
137
|
+
contract_address = extract_contract_address(receipt)
|
138
|
+
return self.build_contract(contract_address=contract_address, account=account)
|
139
|
+
|
140
|
+
def deploy_contract_tx(
|
141
|
+
self,
|
142
|
+
args: Optional[List[CalldataEncodable]] = None,
|
143
|
+
account: Optional[LocalAccount] = None,
|
144
|
+
consensus_max_rotations: Optional[int] = None,
|
145
|
+
wait_interval: Optional[int] = None,
|
146
|
+
wait_retries: Optional[int] = None,
|
147
|
+
wait_transaction_status: TransactionStatus = TransactionStatus.ACCEPTED,
|
148
|
+
wait_triggered_transactions: bool = False,
|
149
|
+
wait_triggered_transactions_status: TransactionStatus = TransactionStatus.ACCEPTED,
|
150
|
+
) -> GenLayerTransaction:
|
151
|
+
"""
|
152
|
+
Deploy the contract and return the transaction receipt.
|
118
153
|
"""
|
119
154
|
general_config = get_general_config()
|
120
155
|
actual_wait_interval = (
|
@@ -148,11 +183,6 @@ class ContractFactory:
|
|
148
183
|
interval=actual_wait_interval,
|
149
184
|
retries=actual_wait_retries,
|
150
185
|
)
|
151
|
-
if tx_execution_failed(tx_receipt):
|
152
|
-
raise ValueError(
|
153
|
-
f"Deployment transaction finalized with error: {tx_receipt}"
|
154
|
-
)
|
155
|
-
|
156
186
|
if wait_triggered_transactions:
|
157
187
|
triggered_transactions = tx_receipt.get("triggered_transactions", [])
|
158
188
|
for triggered_transaction in triggered_transactions:
|
@@ -162,26 +192,7 @@ class ContractFactory:
|
|
162
192
|
interval=actual_wait_interval,
|
163
193
|
retries=actual_wait_retries,
|
164
194
|
)
|
165
|
-
|
166
|
-
if (
|
167
|
-
"tx_data_decoded" in tx_receipt
|
168
|
-
and "contract_address" in tx_receipt["tx_data_decoded"]
|
169
|
-
):
|
170
|
-
contract_address = tx_receipt["tx_data_decoded"]["contract_address"]
|
171
|
-
elif "data" in tx_receipt and "contract_address" in tx_receipt["data"]:
|
172
|
-
contract_address = tx_receipt["data"]["contract_address"]
|
173
|
-
else:
|
174
|
-
raise ValueError("Transaction receipt missing contract address")
|
175
|
-
|
176
|
-
schema = self._get_schema_with_fallback()
|
177
|
-
if schema is None:
|
178
|
-
raise ValueError(
|
179
|
-
"Failed to get schema from all clients (default, hosted studio, and local)"
|
180
|
-
)
|
181
|
-
|
182
|
-
return Contract.new(
|
183
|
-
address=contract_address, schema=schema, account=account
|
184
|
-
)
|
195
|
+
return tx_receipt
|
185
196
|
except Exception as e:
|
186
197
|
raise DeploymentError(
|
187
198
|
f"Failed to deploy contract {self.contract_name}: {str(e)}"
|
gltest/utils.py
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
from genlayer_py.types import GenLayerTransaction
|
2
|
+
|
3
|
+
|
4
|
+
def extract_contract_address(receipt: GenLayerTransaction) -> str:
|
5
|
+
"""Extract contract address from a deployment transaction receipt."""
|
6
|
+
if (
|
7
|
+
"tx_data_decoded" in receipt
|
8
|
+
and "contract_address" in receipt["tx_data_decoded"]
|
9
|
+
):
|
10
|
+
return receipt["tx_data_decoded"]["contract_address"]
|
11
|
+
elif "data" in receipt and "contract_address" in receipt["data"]:
|
12
|
+
return receipt["data"]["contract_address"]
|
13
|
+
else:
|
14
|
+
raise ValueError("Transaction receipt missing contract address")
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import pytest
|
2
|
+
from gltest import get_contract_factory
|
3
|
+
from gltest.assertions import tx_execution_failed
|
4
|
+
from gltest.exceptions import DeploymentError
|
5
|
+
|
6
|
+
|
7
|
+
def test_invalid_deploy_basic_exception(setup_validators):
|
8
|
+
"""Test deployment failure with basic exception"""
|
9
|
+
setup_validators()
|
10
|
+
factory = get_contract_factory("InvalidDeploy")
|
11
|
+
|
12
|
+
# Deployment should fail with exception
|
13
|
+
with pytest.raises(DeploymentError):
|
14
|
+
factory.deploy()
|
15
|
+
|
16
|
+
|
17
|
+
def test_invalid_deploy_receipt_only(setup_validators):
|
18
|
+
"""Test deployment failure using deploy_contract_tx() method that returns receipt only"""
|
19
|
+
setup_validators()
|
20
|
+
factory = get_contract_factory("InvalidDeploy")
|
21
|
+
|
22
|
+
# Deploy and get receipt - should show failure
|
23
|
+
receipt = factory.deploy_contract_tx()
|
24
|
+
assert tx_execution_failed(receipt)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|