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

test: add deploy_account to integration test #302

Merged

Conversation

Yael-Starkware
Copy link
Contributor

@Yael-Starkware Yael-Starkware commented Jun 27, 2024

This change is Reviewable

@codecov-commenter
Copy link

codecov-commenter commented Jun 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.77%. Comparing base (e78af98) to head (6db50c2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #302      +/-   ##
==========================================
+ Coverage   81.76%   82.77%   +1.01%     
==========================================
  Files          30       30              
  Lines        1431     1469      +38     
  Branches     1431     1469      +38     
==========================================
+ Hits         1170     1216      +46     
+ Misses        201      193       -8     
  Partials       60       60              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@ArniStarkware ArniStarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 5 files at r1.
Reviewable status: 2 of 5 files reviewed, 3 unresolved discussions (waiting on @dafnamatsry, @giladchase, and @Yael-Starkware)


crates/tests-integration/src/state_reader.rs line 60 at r1 (raw file):

            ContractAddress::default(),
        )
        .unwrap()

What do you think about wrapping this into a function as a test util?

Suggestion:

        let deploy_account_tx = assert_matches!(
            deploy_tx,
            RPCTransaction::DeployAccount(deploy_account_tx) => deploy_account_tx
        );
        return deployed_account_contract_address(deploy_account_tx);
        
        
        fn deployed_account_contract_address(deploy_account_tx: RPCDeployAccountTransaction) -> ContractAddress {
            let RPCDeployAccountTransaction::V3(tx) = deploy_account_tx;
            calculate_contract_address(
            tx.contract_address_salt,
            tx.class_hash,
            &tx.constructor_calldata,
            ContractAddress::default(),
        )
        .unwrap()
            }

crates/tests-integration/src/state_reader.rs line 62 at r1 (raw file):

        .unwrap()
    };
}

Do we have other examples for this? Is there something I can look for a reference?
(Nice!)

Code quote:

lazy_static! {
    static ref DEPLOY_ACCCOUNT_TX_CONTRACT_ADDRESS: ContractAddress = {
        let deploy_tx = deploy_account_tx();
        let tx = assert_matches!(
            deploy_tx,
            RPCTransaction::DeployAccount(RPCDeployAccountTransaction::V3(tx)) => tx
        );
        calculate_contract_address(
            tx.contract_address_salt,
            tx.class_hash,
            &tx.constructor_calldata,
            ContractAddress::default(),
        )
        .unwrap()
    };
}

crates/tests-integration/src/state_reader.rs line 295 at r1 (raw file):

            .extend(key_value.clone());
    }
}

IIUC.

Suggestion:

fn fund_feature_account_contract(
    storage_diffs: &mut IndexMap<ContractAddress, IndexMap<StorageKey, StarkFelt>>,
    contract: &FeatureContract,
    instance: u16,
    initial_balances: u128,
    chain_info: &ChainInfo,
) {
    match contract {
        FeatureContract::AccountWithLongValidate(_)
        | FeatureContract::AccountWithoutValidations(_)
        | FeatureContract::FaultyAccount(_) => {
            fund_account(
                storage_diffs,
                &contract.get_instance_address(instance),
                initial_balances,
                chain_info,
            );
        }
        _ => (),
    }
}

fn fund_account(
    storage_diffs: &mut IndexMap<ContractAddress, IndexMap<StorageKey, StarkFelt>>,
    account_address: &ContractAddress,
    initial_balances: u128,
    chain_info: &ChainInfo,
) {
    let key_value = indexmap! {
        get_fee_token_var_address(*account_address) => stark_felt!(initial_balances),
    };
    for fee_type in FeeType::iter() {
        storage_diffs
            .entry(chain_info.fee_token_address(&fee_type))
            .or_default()
            .extend(key_value.clone());
    }
}

Copy link
Contributor

@ArniStarkware ArniStarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 5 files at r1.
Reviewable status: 3 of 5 files reviewed, 3 unresolved discussions (waiting on @dafnamatsry, @giladchase, and @Yael-Starkware)

Copy link
Collaborator

@dafnamatsry dafnamatsry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 5 of 5 files at r1, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @giladchase and @Yael-Starkware)


crates/tests-integration/src/state_reader.rs line 173 at r1 (raw file):

    let erc20 = FeatureContract::ERC20;
    let mut cairo0_contract_classes: Vec<(ClassHash, DeprecatedContractClass)> =
        vec![(erc20.get_class_hash(), serde_json::from_str(&erc20.get_raw_class()).unwrap())];

Maybe pass the erc20 contract as an input as part of contract_instances?

Code quote:

    let erc20 = FeatureContract::ERC20;
    let mut cairo0_contract_classes: Vec<(ClassHash, DeprecatedContractClass)> =
        vec![(erc20.get_class_hash(), serde_json::from_str(&erc20.get_raw_class()).unwrap())];

@Yael-Starkware Yael-Starkware force-pushed the yael/add_deploy_account_to_integration_test_new branch from 94e9014 to 8b4d292 Compare June 30, 2024 11:13
Copy link
Contributor Author

@Yael-Starkware Yael-Starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ArniStarkware, @dafnamatsry, and @giladchase)


crates/tests-integration/src/state_reader.rs line 60 at r1 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

What do you think about wrapping this into a function as a test util?

done.


crates/tests-integration/src/state_reader.rs line 62 at r1 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

Do we have other examples for this? Is there something I can look for a reference?
(Nice!)

Papyrus is using it:
https://github.com/starkware-libs/papyrus/blob/c4d829c978d45a6d49be50da76ebde68e019ccd5/crates/papyrus_rpc/src/v0_7/transaction_test.rs#L35


crates/tests-integration/src/state_reader.rs line 173 at r1 (raw file):

Previously, dafnamatsry wrote…

Maybe pass the erc20 contract as an input as part of contract_instances?

Done.


crates/tests-integration/src/state_reader.rs line 295 at r1 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

IIUC.

Done.

Copy link
Collaborator

@dafnamatsry dafnamatsry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 of 4 files at r2, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ArniStarkware, @giladchase, and @Yael-Starkware)


crates/gateway/Cargo.toml line 16 at r2 (raw file):

[dependencies]
axum.workspace = true
assert_matches.workspace = true

I think there is a way to define the starknet_api_test_utils.rs for tests? and then keep this as dev-dependency.

Take a look at #[cfg(test)] in lib.rs.

Code quote:

assert_matches.workspace = true

Copy link
Contributor Author

@Yael-Starkware Yael-Starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ArniStarkware, @dafnamatsry, and @giladchase)


crates/gateway/Cargo.toml line 16 at r2 (raw file):

Previously, dafnamatsry wrote…

I think there is a way to define the starknet_api_test_utils.rs for tests? and then keep this as dev-dependency.

Take a look at #[cfg(test)] in lib.rs.

yes, I was thinking the same thing exactly and was planning to fix in a the next PR. There is one function in this file that is being used by the gateway so I couldn't make it a test file instantly, will open a separate PR to move the function and then solve this.

Copy link
Contributor Author

@Yael-Starkware Yael-Starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ArniStarkware, @dafnamatsry, and @giladchase)


crates/gateway/Cargo.toml line 16 at r2 (raw file):

Previously, Yael-Starkware (YaelD) wrote…

yes, I was thinking the same thing exactly and was planning to fix in a the next PR. There is one function in this file that is being used by the gateway so I couldn't make it a test file instantly, will open a separate PR to move the function and then solve this.

here is the PR: https://reviewable.io/reviews/starkware-libs/mempool/329

Copy link
Collaborator

@dafnamatsry dafnamatsry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ArniStarkware and @giladchase)

Copy link
Contributor

@ArniStarkware ArniStarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @giladchase)

@Yael-Starkware Yael-Starkware force-pushed the yael/add_deploy_account_to_integration_test_new branch from 8b4d292 to 1f55f90 Compare July 1, 2024 11:12
@Yael-Starkware Yael-Starkware force-pushed the yael/add_deploy_account_to_integration_test_new branch from 1f55f90 to 6db50c2 Compare July 1, 2024 11:15
Copy link
Contributor

@ArniStarkware ArniStarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 3 files at r3, 2 of 2 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @giladchase)

@Yael-Starkware Yael-Starkware merged commit 9456a55 into main Jul 1, 2024
8 checks passed
@Yael-Starkware Yael-Starkware deleted the yael/add_deploy_account_to_integration_test_new branch July 1, 2024 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants