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

dev: Better estimate fee test #1368

Open
LucasLvy opened this issue Jan 12, 2024 · 16 comments · May be fixed by #1526
Open

dev: Better estimate fee test #1368

LucasLvy opened this issue Jan 12, 2024 · 16 comments · May be fixed by #1526
Assignees
Labels
backlog Ready to be picked enhancement New feature or request stale

Comments

@LucasLvy
Copy link
Contributor

Instead of comparing hardcoded values, execute the transaction and compare the actual fees with the estimated fees

@LucasLvy LucasLvy added the enhancement New feature or request label Jan 12, 2024
@kenkomu
Copy link

kenkomu commented Jan 15, 2024

Hello, can I take this?

@tdelabro
Copy link
Collaborator

@kenkomu sure!!

Do you have a clear view on how to do that?

I think @LucasLvy was talking about tests in starknet-rpc-test/estimate_fee.rs but it would certainly be cool if you could also add such a test in the pallet tests.

@tdelabro tdelabro added the backlog Ready to be picked label Jan 19, 2024
@tdelabro
Copy link
Collaborator

@kenkomu you don't seem to be active. Comment again if you want to work on it again

@fishseabowl
Copy link
Contributor

@tdelabro could I take it? Thanks

@kenkomu
Copy link

kenkomu commented Jan 28, 2024

@kenkomu you don't seem to be active. Comment again if you want to work on it again

I want to work on it again.

@tdelabro
Copy link
Collaborator

tdelabro commented Jan 29, 2024

@kenkomu What is your ETA?

@kenkomu
Copy link

kenkomu commented Jan 30, 2024

What do you mean by ETA?
Can you guide me on how to tackle the task?

@tdelabro
Copy link
Collaborator

@kenkomu Estimated Time of Arrival: when do you think you will be finished? We gave you the issue two weeks ago and you haven't started it yet, so this time I would like you to commit to a schedule.

Instead of comparing hardcoded values, execute the transaction and compare the actual fees with the estimated fees

Lucas was referring tho this test:

starknet-rpc-test/estimate_fee.rs

#[rstest]
#[tokio::test]
async fn works_ok(madara: &ThreadSafeMadaraClient) -> Result<(), anyhow::Error> {
    let rpc = madara.get_starknet_client().await;

    let tx = BroadcastedInvokeTransaction {
        max_fee: FieldElement::ZERO,
        signature: vec![],
        nonce: FieldElement::ZERO,
        sender_address: FieldElement::from_hex_be(ACCOUNT_CONTRACT).unwrap(),
        calldata: vec![
            FieldElement::from_hex_be(TEST_CONTRACT_ADDRESS).unwrap(),
            get_selector_from_name("sqrt").unwrap(),
            FieldElement::from_hex_be("1").unwrap(),
            FieldElement::from(81u8),
        ],
        is_query: true,
    };

    let invoke_transaction = BroadcastedTransaction::Invoke(tx.clone());

    let invoke_transaction_2 =
        BroadcastedTransaction::Invoke(BroadcastedInvokeTransaction { nonce: FieldElement::ONE, ..tx });

    let estimates =
        rpc.estimate_fee(&vec![invoke_transaction, invoke_transaction_2], BlockId::Tag(BlockTag::Latest)).await?;

    // TODO: instead execute the tx and check that the actual fee are the same as the estimated ones
    assert_eq!(estimates.len(), 2);
    assert_eq!(estimates[0].overall_fee, 420);
    assert_eq!(estimates[1].overall_fee, 420);
    // https://starkscan.co/block/5
    assert_eq!(estimates[0].gas_consumed, 0);
    assert_eq!(estimates[1].gas_consumed, 0);

    Ok(())
}

As you can see at the end we do assert_eq against hardcoded values. A better approach, as said by lucas would be to execute the transaction and then compare the fee taken during the execution with those estimated by the call to estimate_fee and make sure they match.

Does it sound doable?

@kenkomu
Copy link

kenkomu commented Jan 31, 2024

Yes, it sounds doable. Can you give me a week to complete it? I will be reaching out to you frequently.

Copy link

github-actions bot commented Mar 2, 2024

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.
Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by leaving a 👍
Because this issue is marked as stale, it will be closed and locked in 7 days if no further activity occurs.
Thank you for your contributions!

@github-actions github-actions bot added the stale label Mar 2, 2024
@tdelabro
Copy link
Collaborator

tdelabro commented Mar 2, 2024

@kenkomu are you still working on this?

@github-actions github-actions bot removed the stale label Mar 3, 2024
@kenkomu
Copy link

kenkomu commented Mar 5, 2024

No, sorry for the late reply.

@tdelabro
Copy link
Collaborator

tdelabro commented Mar 5, 2024

Don't worry no problem

@fishseabowl
Copy link
Contributor

@tdelabro could I take it? Thanks

@tdelabro
Copy link
Collaborator

sure. Go ahead @fishseabowl

Copy link

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.
Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by leaving a 👍
Because this issue is marked as stale, it will be closed and locked in 7 days if no further activity occurs.
Thank you for your contributions!

@github-actions github-actions bot added the stale label Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Ready to be picked enhancement New feature or request stale
Projects
Status: 🏗 In progress
Development

Successfully merging a pull request may close this issue.

4 participants