Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
Created constants for declare tx versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekryba committed May 18, 2023
1 parent 608621d commit fddeb2d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
19 changes: 9 additions & 10 deletions test/rpc/test_rpc_estimate_fee.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
from test.rpc.rpc_utils import rpc_call_background_devnet
from test.rpc.test_rpc_transactions import pad_zero_entry_points
from test.shared import (
DEPRECATED_RPC_DECLARE_TX_VERSION,
PREDEPLOY_ACCOUNT_CLI_ARGS,
PREDEPLOYED_ACCOUNT_ADDRESS,
PREDEPLOYED_ACCOUNT_PRIVATE_KEY,
SUPPORTED_RPC_DECLARE_TX_VERSION,
SUPPORTED_RPC_TX_VERSION,
)
from test.test_account import deploy_empty_contract
Expand Down Expand Up @@ -181,14 +183,14 @@ def test_estimate_fee_declare_v1(declare_content):
sender_address=int(PREDEPLOYED_ACCOUNT_ADDRESS, 16),
max_fee=0,
nonce=nonce,
version=SUPPORTED_RPC_TX_VERSION,
version=DEPRECATED_RPC_DECLARE_TX_VERSION,
)
signature = _get_signature(tx_hash, PREDEPLOYED_ACCOUNT_PRIVATE_KEY)

declare_transaction = RpcBroadcastedDeclareTxnV1(
type=declare_content["type"],
max_fee=rpc_felt(0),
version=hex(SUPPORTED_RPC_TX_VERSION),
version=hex(DEPRECATED_RPC_DECLARE_TX_VERSION),
signature=[rpc_felt(sig) for sig in signature],
nonce=rpc_felt(nonce),
contract_class=_rpc_contract_class,
Expand All @@ -209,7 +211,6 @@ def test_estimate_fee_declare_v2():
"""
contract_class, _, compiled_class_hash = load_cairo1_contract()

version = 2
nonce = get_nonce(PREDEPLOYED_ACCOUNT_ADDRESS)

tx_hash = calculate_declare_transaction_hash(
Expand All @@ -218,7 +219,7 @@ def test_estimate_fee_declare_v2():
chain_id=StarknetChainId.TESTNET.value,
sender_address=int(PREDEPLOYED_ACCOUNT_ADDRESS, 16),
max_fee=0,
version=version,
version=SUPPORTED_RPC_DECLARE_TX_VERSION,
nonce=nonce,
)

Expand All @@ -229,7 +230,7 @@ def test_estimate_fee_declare_v2():
sender_address=PREDEPLOYED_ACCOUNT_ADDRESS,
compiled_class_hash=rpc_felt(compiled_class_hash),
type="DECLARE",
version=rpc_felt(version),
version=rpc_felt(SUPPORTED_RPC_DECLARE_TX_VERSION),

This comment has been minimized.

Copy link
@FabijanC

FabijanC May 18, 2023

Collaborator

shouldn't it stay version?

This comment has been minimized.

Copy link
@FabijanC

FabijanC May 18, 2023

Collaborator

ah sorry, I thought version was a function parameter, now I see it's not; although it could still be a good idea to just replace version = 2 with version = <NEW_CONSTANT>

nonce=rpc_felt(nonce),
max_fee=rpc_felt(0),
signature=list(map(rpc_felt, signature)),
Expand All @@ -254,16 +255,14 @@ def test_estimate_multiple_transactions():
invoke_transaction = RpcBroadcastedInvokeTxnV1(
type="INVOKE",
max_fee=rpc_felt(0),
version=hex(SUPPORTED_RPC_TX_VERSION),
version=hex(DEPRECATED_RPC_DECLARE_TX_VERSION),
signature=[rpc_felt(sig) for sig in signature],
nonce=rpc_felt(nonce),
sender_address=rpc_felt(PREDEPLOYED_ACCOUNT_ADDRESS),
calldata=[rpc_felt(data) for data in execute_calldata],
)

contract_class, _, compiled_class_hash = load_cairo1_contract()

version = 2
nonce += 1

tx_hash = calculate_declare_transaction_hash(
Expand All @@ -272,7 +271,7 @@ def test_estimate_multiple_transactions():
chain_id=StarknetChainId.TESTNET.value,
sender_address=int(PREDEPLOYED_ACCOUNT_ADDRESS, 16),
max_fee=0,
version=version,
version=SUPPORTED_RPC_DECLARE_TX_VERSION,
nonce=nonce,
)

Expand All @@ -283,7 +282,7 @@ def test_estimate_multiple_transactions():
sender_address=PREDEPLOYED_ACCOUNT_ADDRESS,
compiled_class_hash=rpc_felt(compiled_class_hash),
type="DECLARE",
version=rpc_felt(version),
version=rpc_felt(SUPPORTED_RPC_DECLARE_TX_VERSION),
nonce=rpc_felt(nonce),
max_fee=rpc_felt(0),
signature=list(map(rpc_felt, signature)),
Expand Down
11 changes: 6 additions & 5 deletions test/rpc/test_rpc_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
from test.shared import (
ABI_PATH,
CONTRACT_PATH,
DEPRECATED_RPC_DECLARE_TX_VERSION,
EXPECTED_UDC_ADDRESS,
INCORRECT_GENESIS_BLOCK_HASH,
PREDEPLOYED_ACCOUNT_ADDRESS,
PREDEPLOYED_ACCOUNT_PRIVATE_KEY,
STARKNET_CLI_ACCOUNT_ABI_PATH,
SUPPORTED_RPC_DECLARE_TX_VERSION,
SUPPORTED_RPC_TX_VERSION,
)
from test.test_declare_v2 import load_cairo1_contract
Expand Down Expand Up @@ -549,7 +551,7 @@ def test_add_declare_transaction_on_incorrect_contract(declare_content):
declare_transaction = RpcBroadcastedDeclareTxnV1(
type=declare_content["type"],
max_fee=rpc_felt(declare_content["max_fee"]),
version=hex(SUPPORTED_RPC_TX_VERSION),
version=hex(DEPRECATED_RPC_DECLARE_TX_VERSION),
signature=[rpc_felt(sig) for sig in declare_content["signature"]],
nonce=rpc_felt(declare_content["nonce"]),
contract_class=contract_class,
Expand All @@ -570,7 +572,6 @@ def test_add_declare_transaction_v2():
contract_class, _, compiled_class_hash = load_cairo1_contract()

max_fee = int(4e16)
version = 2
nonce = get_nonce(PREDEPLOYED_ACCOUNT_ADDRESS)

tx_hash = calculate_declare_transaction_hash(
Expand All @@ -579,7 +580,7 @@ def test_add_declare_transaction_v2():
chain_id=StarknetChainId.TESTNET.value,
sender_address=int(PREDEPLOYED_ACCOUNT_ADDRESS, 16),
max_fee=max_fee,
version=version,
version=SUPPORTED_RPC_DECLARE_TX_VERSION,
nonce=nonce,
)

Expand All @@ -590,7 +591,7 @@ def test_add_declare_transaction_v2():
sender_address=PREDEPLOYED_ACCOUNT_ADDRESS,
compiled_class_hash=rpc_felt(compiled_class_hash),
type="DECLARE",
version=rpc_felt(version),
version=rpc_felt(SUPPORTED_RPC_DECLARE_TX_VERSION),
nonce=rpc_felt(nonce),
max_fee=rpc_felt(max_fee),
signature=list(map(rpc_felt, signature)),
Expand Down Expand Up @@ -635,7 +636,7 @@ def _add_declare_transaction():
declare_transaction = RpcBroadcastedDeclareTxnV1(
type="DECLARE",
max_fee=rpc_felt(max_fee),
version=hex(SUPPORTED_RPC_TX_VERSION),
version=hex(DEPRECATED_RPC_DECLARE_TX_VERSION),
signature=[rpc_felt(sig) for sig in signature],
nonce=rpc_felt(nonce),
contract_class=_rpc_contract_class,
Expand Down
3 changes: 3 additions & 0 deletions test/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
SUPPORTED_TX_VERSION = 1
SUPPORTED_RPC_TX_VERSION = 1

SUPPORTED_RPC_DECLARE_TX_VERSION = 2
DEPRECATED_RPC_DECLARE_TX_VERSION = 1

PREDEPLOY_ACCOUNT_CLI_ARGS = ("--seed", "42", "--accounts", "1")
PREDEPLOYED_ACCOUNT_ADDRESS = (
"0x347be35996a21f6bf0623e75dbce52baba918ad5ae8d83b6f416045ab22961a"
Expand Down

0 comments on commit fddeb2d

Please sign in to comment.