Skip to content

Commit 26290d5

Browse files
committed
Added docs
1 parent 6299bfa commit 26290d5

File tree

3 files changed

+91
-7
lines changed

3 files changed

+91
-7
lines changed

docs/guide/account_and_client.rst

+9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ Account also provides a way of creating signed transaction without sending them.
4646
:language: python
4747
:dedent: 4
4848

49+
Creating "Outside transaction" and executing it. (SNIP-9)[https://github.com/starknet-io/SNIPs/blob/main/SNIPS/snip-9.md]
50+
--------------------------------------------
51+
52+
Account also provides a way of creating a call and signing to allow for another account (caller) to execute it later on original account behalf. This will also allow caller to execute calls encoded in that transaction for free (signer will pay the fee).
53+
54+
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_account_sign_outside_transaction.py
55+
:language: python
56+
:dedent: 4
57+
4958
Multicall
5059
---------
5160

pyproject.toml

+6-7
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,15 @@ setuptools = "^70.3.0"
5656
test = [
5757
"clean_coverage",
5858
"test_ci_v1 --disable-warnings -qq",
59-
# "test_ci_v2 --disable-warnings -qq",
60-
# "test_ci_on_networks --disable-warnings -qq",
61-
# "test_ci_docs_v1 --disable-warnings -qq",
62-
# "test_ci_docs_v2 --disable-warnings -qq",
63-
# "test_report --skip-covered"
59+
"test_ci_v2 --disable-warnings -qq",
60+
"test_ci_on_networks --disable-warnings -qq",
61+
"test_ci_docs_v1 --disable-warnings -qq",
62+
"test_ci_docs_v2 --disable-warnings -qq",
63+
"test_report --skip-covered"
6464
]
6565

6666
test_ci = ["test_ci_v1", "test_ci_v2"]
67-
test_ci_v1 = "coverage run -a -m pytest --contract_dir=v1 starknet_py --ignore=starknet_py/tests/e2e/docs --ignore=starknet_py/tests/e2e/tests_on_networks starknet_py/tests/e2e/account"
68-
# test_ci_v1 = "coverage run -a -m pytest --contract_dir=v1 starknet_py --ignore=starknet_py/tests/e2e/docs --ignore=starknet_py/tests/e2e/tests_on_networks"
67+
test_ci_v1 = "coverage run -a -m pytest --contract_dir=v1 starknet_py --ignore=starknet_py/tests/e2e/docs --ignore=starknet_py/tests/e2e/tests_on_networks"
6968
test_ci_v2 = "coverage run -a -m pytest --contract_dir=v2 starknet_py --ignore=starknet_py/tests/e2e/docs --ignore=starknet_py/tests/e2e/tests_on_networks"
7069

7170
test_ci_on_networks = "coverage run -a -m pytest --contract_dir=v2 starknet_py/tests/e2e/tests_on_networks"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
2+
import pytest
3+
4+
from starknet_py.net.account.account import Account
5+
from starknet_py.net.client_models import (
6+
TransactionFinalityStatus
7+
)
8+
9+
@pytest.mark.asyncio
10+
async def test_account_outside_execution_any_caller(
11+
client,
12+
argent_account_class_hash,
13+
deployed_balance_contract,
14+
deploy_account_details_factory,
15+
):
16+
# pylint: disable=import-outside-toplevel,too-many-locals
17+
address, key_pair, salt, class_hash = await deploy_account_details_factory.get(
18+
class_hash=argent_account_class_hash, argent_calldata=True
19+
)
20+
21+
deploy_result = await Account.deploy_account_v1(
22+
address=address,
23+
class_hash=class_hash,
24+
salt=salt,
25+
key_pair=key_pair,
26+
client=client,
27+
constructor_calldata=[key_pair.public_key, 0],
28+
max_fee=int(1e18),
29+
)
30+
await deploy_result.wait_for_acceptance()
31+
account = deploy_result.account
32+
33+
# docs: start
34+
import datetime
35+
36+
from starknet_py.constants import ANY_CALLER
37+
from starknet_py.hash.selector import get_selector_from_name
38+
from starknet_py.net.client_models import (
39+
Call,
40+
ExecutionTimeBounds,
41+
)
42+
43+
# Create a call to increase the balance by 100. That will be executed
44+
# as part of external execution
45+
46+
increase_balance_call = Call(
47+
to_addr=deployed_balance_contract.address,
48+
selector=get_selector_from_name("increase_balance"),
49+
calldata=[100],
50+
)
51+
52+
# Create a special signed execution call. This call now be executed by
53+
# caller specified. In this case, it is ANY_CALLER, a special constant
54+
# that allows any caller to execute the call.
55+
call = await account.sign_outside_execution_call(
56+
calls=[
57+
increase_balance_call,
58+
],
59+
execution_time_bounds=ExecutionTimeBounds(
60+
execute_after=datetime.datetime.now() - datetime.timedelta(hours=1),
61+
execute_before=datetime.datetime.now() + datetime.timedelta(hours=1),
62+
),
63+
caller=ANY_CALLER,
64+
)
65+
66+
# Execute the call as a normal invoke transaction
67+
tx = await account.execute_v1(calls=[call], max_fee=int(1e18))
68+
await account.client.wait_for_tx(tx.transaction_hash)
69+
70+
# docs: end
71+
72+
receipt = await account.client.get_transaction_receipt(
73+
tx_hash=tx.transaction_hash
74+
)
75+
76+
assert receipt.finality_status == TransactionFinalityStatus.ACCEPTED_ON_L2

0 commit comments

Comments
 (0)