Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable deploying contracts without providing abi #1452

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
dd83220
Merge branch 'kkawula/1334-remove-unnecessary-cairo-0-tests'
kkawula Jul 30, 2024
7009e4f
Migrate tests to use cairo 1 ERC20 contract
kkawula Jul 30, 2024
9c1e645
Remove ERC20 contract cairo code and fixtures
kkawula Jul 30, 2024
9a01051
Adapt tests to the cairo 1
kkawula Aug 5, 2024
966f950
Merge 'development'
kkawula Aug 5, 2024
8c4418f
Merge 'development'
kkawula Aug 5, 2024
f43673a
Fix test in Serilization Guide
kkawula Aug 5, 2024
3b1658c
Fix typo in 'test_abi_parsing'
kkawula Aug 5, 2024
2adc084
Fix after merge
kkawula Aug 5, 2024
82e7242
Remove 'constructor_with_arguments.cairo' and 'constructor_without_ar…
kkawula Aug 5, 2024
301a8d4
Add 'constructor_with_arguments.cairo' contract and update test_throw…
kkawula Aug 6, 2024
74e9360
Update 'test_constructor_arguments_contract_deploy'
kkawula Aug 6, 2024
50bad80
Add skiping test while cairo v1 test dir is triggered
kkawula Aug 6, 2024
46f4e6e
Update 'test_create_deployment_call_raw_supports_seed_0' and 'test_cr…
kkawula Aug 6, 2024
ad05ad8
Remove old 'constructor_with_arguments' fixture
kkawula Aug 6, 2024
a0db46f
Update 'test_deploying_with_udc'
kkawula Aug 6, 2024
c735a0d
Update 'constructor_with_arguments_abi' and 'constructor_with_argumen…
kkawula Aug 6, 2024
02c1647
Update docs example
kkawula Aug 6, 2024
c7152f2
Add 'map' contract implementation in cairo 1
kkawula Aug 6, 2024
e1dceb2
Add fixtures for new contract
kkawula Aug 6, 2024
518eafa
Remove 'map_contract_declare_hahs' fixutre
kkawula Aug 6, 2024
a1c69b4
Replace old 'map_contract' fixture
kkawula Aug 6, 2024
e5d6b71
Replace old 'map_class_hash' fixture
kkawula Aug 6, 2024
964a289
Update a few tests
kkawula Aug 6, 2024
a7d664c
Update 'test_deploying_in_multicall'
kkawula Aug 6, 2024
2b8520b
Remove 'Simple declare and deploy' paragraph from docs
kkawula Aug 6, 2024
bf0be0d
Update docs example 'Quickstart - Using Account'
kkawula Aug 6, 2024
dc814a2
Update docs example 'Guide - test_simple_deploy
kkawula Aug 6, 2024
8e9b904
Remove fixtures 'map_source_code' and 'map_compiled_contract'
kkawula Aug 6, 2024
44fb7c2
Fix PriceUnit assertion in 'test_account_estimate_fee_for_declare_tra…
kkawula Aug 6, 2024
a02e663
Add docs test to skip because of redeclaration :(
kkawula Aug 6, 2024
04c5850
Remove map.cairo
kkawula Aug 6, 2024
6f57a8d
Remove 'replace_class.cairo' conatract and fixture
kkawula Aug 6, 2024
7d163b0
Remove unused fixture 'fixture_balance_contract'
kkawula Aug 6, 2024
adfc532
Upadte 'test_estimate_fee_for_multiple_transactions'
kkawula Aug 7, 2024
b01371f
Update 'test_simulate_transactions_declare'
kkawula Aug 7, 2024
7939061
Remove 'test_simulate_transactions_declare'
kkawula Aug 7, 2024
7506f57
Update 'simple_storage_with_event' contract to cairo 1
kkawula Aug 7, 2024
a134d21
Add test to skip reason='Some cairo 1 contracts compiled with v1 comp…
kkawula Aug 7, 2024
c27654a
Merge branch 'development' into kkawula/1334-replace-cairo-0-contracts
kkawula Aug 8, 2024
d4dd60b
Merge 'kkawula/1334-replace-cairo-0-contracts'
kkawula Aug 8, 2024
bc2f6a4
Remove deprecated cairo 0 fixture 'simple_storage_with_event_compiled…
kkawula Aug 8, 2024
823f96c
Remove cairo v1 version of 'simple_storage_with_event.cairo' contract
kkawula Aug 8, 2024
5e0ff7d
Remove cairo v1 contracts that have events
kkawula Aug 8, 2024
f6f15f0
Remove removed contracts from lib.cairo
kkawula Aug 8, 2024
73332dc
Fix 'test_deserialize_abi' v1
kkawula Aug 8, 2024
8995741
Fix 'test_evenet_serialization_v1'
kkawula Aug 8, 2024
1a5db99
Fix 'test_throws_when_cairo1_without_compiled_contract_casm_and_class…
kkawula Aug 8, 2024
dd2785e
Merge branch 'development' into kkawula/1334-replace-cairo-0-contracts
kkawula Aug 8, 2024
3656a44
Merge branch 'kkawula/1334-replace-cairo-0-contracts' into 'kkawula/1…
kkawula Aug 9, 2024
db09b19
Fix 'test_throws_when_cairo1_without_compiled_contract_casm_and_class…
kkawula Aug 9, 2024
a273e9f
Add 'Balance' contract implementation in cairo v1
kkawula Aug 9, 2024
c316414
Update test for new Balance contract
kkawula Aug 9, 2024
b9350b6
Merge branch 'refs/heads/kkawula/replace-cairo-0-contracts-vol2' into…
kkawula Aug 9, 2024
82ac7f6
Fix funny error
kkawula Aug 9, 2024
8cadc5e
Remove cairo 0 'balance' contract
kkawula Aug 9, 2024
ed4a922
Remove cairo 0 'balance_struct_event' contract
kkawula Aug 9, 2024
652e0ec
Add folder with cairo 0 contracs abi; Delete 'balance_struxt_event' a…
kkawula Aug 9, 2024
4a0ea80
Remove unused 'mock_account.cairo' contract
kkawula Aug 19, 2024
e2a5844
Remove unused 'contract.cairo' contract
kkawula Aug 19, 2024
362ac44
Remove unused cairo 0 openzeppelin contracts
kkawula Aug 19, 2024
2fbad1e
Remove unused 'Upgradable.cairo' contract
kkawula Aug 19, 2024
bc9a7f7
Remove usage of cairo 0 account contract; Add cairo 1 account contract
kkawula Aug 19, 2024
4a3c65c
Fix 'test_compute_sierra_class_hash'
kkawula Aug 19, 2024
9c4e3e6
Add 'test_simple_declare_and_deploy' to skip
kkawula Aug 19, 2024
4eb752c
Remove cairo 0 'account_with_validate_deploy' contract
kkawula Aug 19, 2024
67af1cc
Remove cairo 0 contracts compiling script and workflow
kkawula Aug 19, 2024
fd9c3d9
Fix github workflows checks
kkawula Aug 20, 2024
fef6821
Revert "Fix github workflows checks"
kkawula Aug 20, 2024
31e462f
Reapply "Fix github workflows checks"
kkawula Aug 20, 2024
3fd4e7b
Fix github workflows checks
kkawula Aug 20, 2024
fb2dd69
Fix workflows
kkawula Aug 20, 2024
11cf1d7
Revert "Fix github workflows checks"
kkawula Aug 20, 2024
c4dd18b
Add download
kkawula Aug 20, 2024
93554b3
Fix 'test_deploy_account_v1'
kkawula Aug 20, 2024
284e989
Skip 'test_deploy_account_v1' for contract from v1 directory
kkawula Aug 20, 2024
01dff1a
Remove 'test_sign_invoke_v1_for_fee_estimation' (sign_decalre_v1)
kkawula Aug 21, 2024
13699a0
Remove unused fixture 'deployed_balance_contract' (declare_v1)
kkawula Aug 21, 2024
836e6b0
Remove 'declare_v1' method from 'Contract' class
kkawula Aug 21, 2024
68eca27
Remove 'sign_declare_v1' method from 'Account' and 'BaseAccount' class
kkawula Aug 21, 2024
1f1f120
Update docs 'deploying_contracts' (remove declare_v1)
kkawula Aug 21, 2024
eb71ff9
Enable deploying contracts without providing abi
kkawula Aug 22, 2024
0738067
Fix 'test_deploy_contract_v3_without_abi' test
kkawula Aug 22, 2024
4045018
Update vaildating calldata
kkawula Aug 22, 2024
9bfdce4
Remove 'test_throws_when_calldata_provided_without_abi'
kkawula Aug 22, 2024
544d598
Create 'test_constructor_arguments_contract_deploy_without_abi'
kkawula Aug 22, 2024
0071703
Remove 'test_throws_when_calldata_not_provided'
kkawula Aug 23, 2024
d2174a1
Rename 'is_valid_calldata' to '_is_list_of_ints_or_strings'
kkawula Aug 23, 2024
264b447
Add 'test_throws_when_calldata_provided_without_abi'
kkawula Aug 23, 2024
5f953d0
Lint
kkawula Aug 23, 2024
3609c74
Update starknet_py/tests/e2e/docs/code_examples/test_contract.py
kkawula Aug 28, 2024
0a9282f
Update docstring for '_is_list_of_ints_or_strings'
kkawula Aug 28, 2024
c69d4ce
Update starknet_py/tests/e2e/deploy/deployer_test.py
kkawula Aug 28, 2024
168e868
Update starknet_py/net/udc_deployer/deployer.py
kkawula Aug 28, 2024
d054263
Update starknet_py/tests/e2e/deploy/deployer_test.py
kkawula Aug 28, 2024
37d3d43
Fix '_is_list_of_ints_or_strings' docstring
kkawula Aug 28, 2024
b9e790c
Fix abi conditions
kkawula Aug 29, 2024
781ea0b
Merge branch 'development' into kkawula/enable-contract-deploy-withou…
kkawula Aug 29, 2024
54f0f92
Add empty line for readability
kkawula Aug 29, 2024
b315707
Fix after merge
kkawula Aug 29, 2024
553fb8b
Fix 'create_contract_deployment' condition
kkawula Aug 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions starknet_py/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ async def deploy_contract_v1(
async def deploy_contract_v3(
account: BaseAccount,
class_hash: Hash,
abi: List,
abi: Optional[List] = None,
constructor_args: Optional[Union[List, Dict]] = None,
*,
deployer_address: AddressRepresentation = DEFAULT_DEPLOYER_ADDRESS,
Expand Down Expand Up @@ -1012,9 +1012,15 @@ async def deploy_contract_v3(
auto_estimate=auto_estimate,
)

deployed_contract = Contract(
provider=account, address=address, abi=abi, cairo_version=cairo_version
)
if abi is not None:
deployed_contract = Contract(
provider=account, address=address, abi=abi, cairo_version=cairo_version
)
else:
deployed_contract = await Contract.from_address(
address=address, provider=account
)

deploy_result = DeployResult(
hash=res.transaction_hash,
_client=account.client,
Expand Down
30 changes: 24 additions & 6 deletions starknet_py/net/udc_deployer/deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,18 @@ def create_contract_deployment(
:param calldata: Constructor args of the contract to be deployed.
:return: NamedTuple with call and address of the contract to be deployed.
"""
if not abi and calldata:
raise ValueError("Argument calldata was provided without an ABI.")

raw_calldata = translate_constructor_args(
abi=abi or [], constructor_args=calldata, cairo_version=cairo_version
)
raw_calldata = None

if calldata and abi is None:
if not _is_list_of_ints_or_strings(calldata):
raise ValueError(
"Argument calldata was provided without an ABI. It cannot be serialized."
)
raw_calldata = [int_from_hex(x) for x in calldata]
elif calldata and abi is not None:
raw_calldata = translate_constructor_args(
abi=abi or [], constructor_args=calldata, cairo_version=cairo_version
)

return self.create_contract_deployment_raw(
class_hash=class_hash, salt=salt, raw_calldata=raw_calldata
Expand Down Expand Up @@ -176,3 +182,15 @@ def _get_random_salt() -> int:
_deployer_serializer = serializer_for_function(
_deployer_abi.functions["deployContract"]
)


def _is_list_of_ints_or_strings(data: Union[List, dict]) -> bool:
"""
Checks if the given data is a list containing only strings or integers.

:param data: Constructor args (calldata) of the contract to be deployed.
:return: True if the data is a list of strings or integers, False otherwise.
"""
if isinstance(data, list):
return all(isinstance(x, (int, str)) for x in data)
return False
kkawula marked this conversation as resolved.
Show resolved Hide resolved
17 changes: 0 additions & 17 deletions starknet_py/tests/e2e/account/account_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,23 +673,6 @@ async def test_sign_invoke_v3_for_fee_estimation(account, map_contract):
assert estimation.overall_fee > 0


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_sign_declare_v1_for_fee_estimation(account, map_compiled_contract):
transaction = await account.sign_declare_v1(
compiled_contract=map_compiled_contract, max_fee=MAX_FEE
)

estimate_fee_transaction = await account.sign_for_fee_estimate(transaction)
assert estimate_fee_transaction.version == transaction.version + 2**128

estimation = await account.client.estimate_fee(estimate_fee_transaction)
assert isinstance(estimation, EstimatedFee)
assert estimation.unit == PriceUnit.WEI
assert estimation.overall_fee > 0


@pytest.mark.asyncio
async def test_sign_deploy_account_v1_for_fee_estimation(
client, deploy_account_details_factory
Expand Down
86 changes: 63 additions & 23 deletions starknet_py/tests/e2e/deploy/deployer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,41 @@ async def test_default_deploy_with_class_hash(account, map_class_hash):
assert contract_deployment.address != 0


@pytest.mark.asyncio
async def test_throws_when_calldata_provided_without_abi(map_class_hash):
deployer = Deployer()

with pytest.raises(ValueError, match="calldata was provided without an ABI."):
deployer.create_contract_deployment(
class_hash=map_class_hash, calldata=[12, 34]
)


@pytest.mark.skipif(
"--contract_dir=v2" not in sys.argv,
reason="Contract exists only in v2 directory",
)
@pytest.mark.asyncio
async def test_throws_when_calldata_not_provided(constructor_with_arguments_abi):
deployer = Deployer()
@pytest.mark.parametrize("calldata", [[10, 1, 2, 3, 3, 1, 2, 3, 12, 99]])
async def test_constructor_arguments_contract_deploy_without_abi(
account,
constructor_with_arguments_class_hash,
calldata,
):
deployer = Deployer(account_address=account.address)

with pytest.raises(
ValueError,
match="Provided contract has a constructor and no arguments were provided.",
):
deployer.create_contract_deployment(
class_hash=1234, abi=constructor_with_arguments_abi, cairo_version=1
)
deploy_call, contract_address = deployer.create_contract_deployment(
class_hash=constructor_with_arguments_class_hash,
calldata=calldata,
)

deploy_invoke_transaction = await account.sign_invoke_v1(
deploy_call, max_fee=MAX_FEE
)
resp = await account.client.send_transaction(deploy_invoke_transaction)
await account.client.wait_for_tx(resp.transaction_hash)

contract = await Contract.from_address(address=contract_address, provider=account)

result = (await contract.functions["get"].call(block_number="latest"))[0]
unwrapped_result = (result[0], result[1], result[2], dict(result[3]))
expected_result = (
10,
(1, (2, 3)),
sum([1, 2, 3]),
{"value": 12, "nested_struct": {"value": 99}},
)
assert unwrapped_result == expected_result


@pytest.mark.skipif(
Expand Down Expand Up @@ -82,7 +92,6 @@ async def test_constructor_arguments_contract_deploy(
class_hash=constructor_with_arguments_class_hash,
abi=constructor_with_arguments_abi,
calldata=calldata,
cairo_version=1,
)

deploy_invoke_transaction = await account.sign_invoke_v1(
Expand All @@ -95,7 +104,6 @@ async def test_constructor_arguments_contract_deploy(
address=contract_address,
abi=constructor_with_arguments_abi,
provider=account,
cairo_version=1,
)

result = (await contract.functions["get"].call(block_number="latest"))[0]
Expand All @@ -108,6 +116,39 @@ async def test_constructor_arguments_contract_deploy(
)


@pytest.mark.skipif(
"--contract_dir=v1" in sys.argv,
reason="Contract exists only in v2 directory",
)
@pytest.mark.asyncio
@pytest.mark.parametrize(
"calldata",
[
[10, (1, (2, 3)), [1, 2, 3], {"value": 12, "nested_struct": {"value": 99}}],
{
"single_value": 10,
"tuple": (1, (2, 3)),
"arr": [1, 2, 3],
"dict": {"value": 12, "nested_struct": {"value": 99}},
},
],
)
async def test_throws_when_calldata_provided_without_abi(
account,
constructor_with_arguments_class_hash,
calldata,
):
deployer = Deployer(account_address=account.address)

with pytest.raises(
ValueError,
match="Argument calldata was provided without an ABI. It cannot be serialized.",
):
deployer.create_contract_deployment(
class_hash=constructor_with_arguments_class_hash, calldata=calldata
)


@pytest.mark.asyncio
@pytest.mark.parametrize(
"salt, pass_account_address", [(1, True), (2, False), (None, True), (None, False)]
Expand Down Expand Up @@ -161,7 +202,7 @@ async def test_create_deployment_call_raw(
deployer = Deployer(account_address=account.address)

raw_calldata = translate_constructor_args(
abi=constructor_with_arguments_abi, constructor_args=calldata, cairo_version=1
abi=constructor_with_arguments_abi, constructor_args=calldata
)

(
Expand Down Expand Up @@ -204,7 +245,6 @@ async def test_create_deployment_call_raw_supports_seed_0(
raw_calldata = translate_constructor_args(
abi=constructor_with_arguments_abi,
constructor_args=sample_calldata,
cairo_version=1,
)

expected_address = compute_address(
Expand Down
26 changes: 26 additions & 0 deletions starknet_py/tests/e2e/docs/code_examples/test_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,29 @@ async def test_deploy_contract_v3(account, cairo1_hello_starknet_class_hash: int
contract_address=contract.address
)
assert class_hash == cairo1_hello_starknet_class_hash


@pytest.mark.asyncio
async def test_deploy_contract_v3_without_abi(
account, cairo1_hello_starknet_class_hash: int
):
deploy_result = await Contract.deploy_contract_v3(
class_hash=cairo1_hello_starknet_class_hash,
account=account,
l1_resource_bounds=ResourceBounds(
max_amount=int(1e5), max_price_per_unit=int(1e13)
),
)
await deploy_result.wait_for_acceptance()

contract = deploy_result.deployed_contract
assert isinstance(contract.address, int)
assert len(contract.functions) == 2

transaction = await account.client.get_transaction(tx_hash=deploy_result.hash)
assert isinstance(transaction, InvokeTransactionV3)

class_hash = await account.client.get_class_hash_at(
contract_address=contract.address
)
assert class_hash == cairo1_hello_starknet_class_hash

This file was deleted.

Loading
Loading