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(starknet_mempool): add case for tx in state #3153

Merged

Conversation

ArniStarkware
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

@ArniStarkware ArniStarkware marked this pull request as ready for review January 7, 2025 09:27
@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/mempool_test/with_state branch from ff90789 to 9423e31 Compare January 7, 2025 14:59
Copy link
Contributor

@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: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @ArniStarkware and @ayeletstarkware)


crates/starknet_mempool/src/mempool_test.rs line 944 at r1 (raw file):

    (mempool_content_builder, deployer_address)
}

I think we should test 3 cases:

  1. we call add_tx and see that we get true for deploy_account_exists
  2. after get_txs we call get_txs, and see that the result is still true
  3. after that we call commit and see that the result is still true

Code quote:

/// Adds the address of an account to the mempool state as part of the tentative state. Returns the
/// mempool content builder and the deployer address.
fn mempool_content_builder_with_account_in_state() -> (MempoolContentBuilder, ContractAddress) {
    let deployer_address = contract_address!(100_u32);
    let mut state = MempoolState::default();
    let _nonce = state.get_or_insert(deployer_address, Nonce(Felt::ONE));
    assert_eq!(_nonce, Nonce(Felt::ONE));

    let mempool_content_builder = MempoolContentBuilder::new().with_state(state);

    (mempool_content_builder, deployer_address)
}

@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/state_test_case branch from f474d74 to f15e5b2 Compare January 7, 2025 15:30
Copy link
Contributor Author

@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: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware and @Yael-Starkware)


crates/starknet_mempool/src/mempool_test.rs line 944 at r1 (raw file):

Previously, Yael-Starkware (YaelD) wrote…

I think we should test 3 cases:

  1. we call add_tx and see that we get true for deploy_account_exists
  2. after get_txs we call get_txs, and see that the result is still true
  3. after that we call commit and see that the result is still true

Done, a simplified version of that.

The issue with my test is that it is not functional.
Tomorrow, I will add a creation for testing for the state.

@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/mempool_test/with_state branch from 9423e31 to f5dc52e Compare January 7, 2025 16:21
@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/state_test_case branch 2 times, most recently from a47d318 to eb7eef1 Compare January 7, 2025 16:28
Copy link
Contributor Author

@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: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @ayeletstarkware and @Yael-Starkware)


crates/starknet_mempool/src/mempool_test.rs line 944 at r1 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

Done, a simplified version of that.

The issue with my test is that it is not functional.
Tomorrow, I will add a creation for testing for the state.

Done.
Now unit test.

@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/mempool_test/with_state branch from f5dc52e to 3e735b3 Compare January 8, 2025 07:59
@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/state_test_case branch from eb7eef1 to 2bdcd0a Compare January 8, 2025 08:00
@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/mempool_test/with_state branch from 3e735b3 to 0470274 Compare January 8, 2025 09:58
@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/state_test_case branch from 2bdcd0a to 17725da Compare January 8, 2025 09:58
@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/mempool_test/with_state branch from 0470274 to bca6521 Compare January 8, 2025 11:30
@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/state_test_case branch from 17725da to 11a90b6 Compare January 8, 2025 11:30
@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/mempool_test/with_state branch from bca6521 to e126e22 Compare January 8, 2025 11:32
@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/state_test_case branch 2 times, most recently from d79dabe to 0e50d4e Compare January 8, 2025 11:34
Copy link
Contributor

@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: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @ArniStarkware and @ayeletstarkware)


crates/starknet_mempool/src/mempool_test.rs line 944 at r1 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

Done.
Now unit test.

I wouldn't want to assume anything about the internal structure of the mempool, I think we should test only external apis here. Meaning, actually call add_tx, get_txs and commit. The test shouldn't depend on the internal mempool implementation.

We can use the MempoolContentBuilder to create an initial non-empty state for the test.

@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/mempool_test/with_state branch from e126e22 to c75adbc Compare January 8, 2025 13:00
@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/state_test_case branch 2 times, most recently from d0aae03 to 21c231a Compare January 8, 2025 14:03
@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/state_test_case branch from 6eb528a to 0c14be2 Compare January 9, 2025 12:12
@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/impl branch from 6e131e2 to 8f9b3c3 Compare January 9, 2025 14:24
@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/state_test_case branch from 0c14be2 to 39f94fd Compare January 9, 2025 14:24
Copy link
Contributor Author

@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: 2 of 4 files reviewed, 2 unresolved discussions (waiting on @alonh5, @ayeletstarkware, and @Yael-Starkware)


crates/starknet_mempool/src/mempool_test.rs line 896 at r6 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

Done.

Now moved to flow tests.

@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/impl branch from 8f9b3c3 to 326cbcb Compare January 9, 2025 16:36
@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/state_test_case branch from 39f94fd to 19059bc Compare January 9, 2025 16:36
@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/impl branch from 326cbcb to 29ea006 Compare January 9, 2025 17:54
@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/state_test_case branch from 19059bc to cd6cd8f Compare January 9, 2025 17:54
Copy link
Contributor

@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.

Reviewed 2 of 2 files at r7, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @alonh5, @ArniStarkware, and @ayeletstarkware)


crates/starknet_mempool/src/mempool_test.rs line 893 at r7 (raw file):

    assert!(!mempool.has_tx_from_address(contract_address!(100_u32)));
}

just for the sake of making the code clear and readable, maybe the two tests should be together.
or otherwise, maybe add a comment that the positive flow is being tested as a flow test?

or maybe the best solution is to start the flow test by checking that the tx doesn't exist?

wdyt?

Code quote:

#[rstest]
fn has_tx_from_address_negative_flow() {
    let mempool = MempoolContentBuilder::new().build_into_mempool();

    assert!(!mempool.has_tx_from_address(contract_address!(100_u32)));
}

Copy link
Contributor

@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 @alonh5, @ArniStarkware, and @ayeletstarkware)


crates/starknet_mempool/src/mempool_test.rs line 893 at r7 (raw file):

Previously, Yael-Starkware (YaelD) wrote…

just for the sake of making the code clear and readable, maybe the two tests should be together.
or otherwise, maybe add a comment that the positive flow is being tested as a flow test?

or maybe the best solution is to start the flow test by checking that the tx doesn't exist?

wdyt?

ok, now that I see the next PR , I retract this comment.

Copy link
Contributor

@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, 2 unresolved discussions (waiting on @alonh5 and @ayeletstarkware)

@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/state_test_case branch from cd6cd8f to 68c0282 Compare January 12, 2025 07:37
@ArniStarkware ArniStarkware changed the base branch from arni/skip_validate/deploy_account_exists/impl to main January 12, 2025 07:37
@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/state_test_case branch from 68c0282 to 762a7a1 Compare January 12, 2025 10:32
Copy link
Contributor

@ayeletstarkware ayeletstarkware 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 2 files at r7, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @alonh5 and @ArniStarkware)


crates/starknet_mempool/tests/flow_test.rs line 311 at r8 (raw file):

#[rstest]
fn has_tx_from_address(mut mempool: Mempool) {

Maybe something with "test_mempool_state_retains_address_across_api_calls`?

Code quote:

fn has_tx_from_address(mut mempool: Mempool)

crates/starknet_mempool/tests/flow_test.rs line 328 at r8 (raw file):

    let nonces = [(address, 1)];
    commit_block(&mut mempool, nonces, []);
    assert!(mempool.has_tx_from_address(contract_address!(address)));

I'm updating the test's documentation based on the mempool tests.

Suggestion:

    // Setup.
    let address = "0x64";
    let input_address_64 = add_tx_input!(address: address);

    // Test.
    add_tx(&mut mempool, &add_tx_args);
    // Assert: Mempool state includes the address of the added transaction.
    assert!(mempool.has_tx_from_address(contract_address!(address)));

    // Test.
    mempool.get_txs(1).unwrap();
    // Assert: The Mempool state still contains the address, even after it was sent to the batcher.
    assert!(mempool.has_tx_from_address(contract_address!(address)));

    // Test.
    let nonces = [(address, 1)];
    commit_block(&mut mempool, nonces, []);
    // Assert: Mempool state still contains the address, even though the transaction was committed.
    // Note that in the future, the Mempool's state may be periodically cleared from records of old
    // committed transactions. Mirroring this behavior may require a modification of this test.
    assert!(mempool.has_tx_from_address(contract_address!(address)));

@ArniStarkware ArniStarkware force-pushed the arni/skip_validate/deploy_account_exists/state_test_case branch from 762a7a1 to 897120d Compare January 12, 2025 12:10
Copy link
Contributor Author

@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: 3 of 4 files reviewed, 2 unresolved discussions (waiting on @alonh5, @ayeletstarkware, and @Yael-Starkware)


crates/starknet_mempool/tests/flow_test.rs line 311 at r8 (raw file):

Previously, ayeletstarkware (Ayelet Zilber) wrote…

Maybe something with "test_mempool_state_retains_address_across_api_calls`?

Done. Also added a comment.


crates/starknet_mempool/tests/flow_test.rs line 328 at r8 (raw file):

Previously, ayeletstarkware (Ayelet Zilber) wrote…

I'm updating the test's documentation based on the mempool tests.

Done.

Copy link
Contributor

@ayeletstarkware ayeletstarkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 3 files at r3, 1 of 1 files at r9, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @alonh5 and @Yael-Starkware)

@ArniStarkware ArniStarkware added this pull request to the merge queue Jan 12, 2025
Merged via the queue into main with commit b89df0e Jan 12, 2025
8 checks passed
Copy link
Collaborator

@alonh5 alonh5 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, 1 unresolved discussion


crates/starknet_mempool/src/test_utils.rs line 216 at r9 (raw file):

        )
    };
    (address: $address:expr) => {

Can't we use an arm that already exists? I don't really understand why we have so many arms in the first place.

@ArniStarkware
Copy link
Contributor Author

crates/starknet_mempool/src/test_utils.rs line 216 at r9 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

Can't we use an arm that already exists? I don't really understand why we have so many arms in the first place.

Dori tried simplifying this test util, to no avail. (Exactly to have as few branches as possible.

Copy link
Collaborator

@alonh5 alonh5 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, 1 unresolved discussion


crates/starknet_mempool/src/test_utils.rs line 216 at r9 (raw file):

Previously, ArniStarkware (Arnon Hod) wrote…

Dori tried simplifying this test util, to no avail. (Exactly to have as few branches as possible.

Still, can you use an existing arm? Some arms receive an address.
Even if we can't simplify it, at least let's not make it more complicated

Copy link
Collaborator

@alonh5 alonh5 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


crates/starknet_mempool/src/test_utils.rs line 216 at r9 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

Still, can you use an existing arm? Some arms receive an address.
Even if we can't simplify it, at least let's not make it more complicated

Ayelet explained offline. This is also fine.

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.

5 participants