madara icon indicating copy to clipboard operation
madara copied to clipboard

dev: Better estimate fee test

Open 0xLucqs opened this issue 1 year ago • 16 comments

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

0xLucqs avatar Jan 12 '24 14:01 0xLucqs

Hello, can I take this?

kenkomu avatar Jan 15 '24 16:01 kenkomu

@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 avatar Jan 19 '24 11:01 tdelabro

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

tdelabro avatar Jan 28 '24 12:01 tdelabro

@tdelabro could I take it? Thanks

fishseabowl avatar Jan 28 '24 19:01 fishseabowl

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

kenkomu avatar Jan 28 '24 20:01 kenkomu

@kenkomu What is your ETA?

tdelabro avatar Jan 29 '24 08:01 tdelabro

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

kenkomu avatar Jan 30 '24 07:01 kenkomu

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

tdelabro avatar Jan 30 '24 09:01 tdelabro

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

kenkomu avatar Jan 31 '24 11:01 kenkomu

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[bot] avatar Mar 02 '24 00:03 github-actions[bot]

@kenkomu are you still working on this?

tdelabro avatar Mar 02 '24 22:03 tdelabro

No, sorry for the late reply.

kenkomu avatar Mar 05 '24 07:03 kenkomu

Don't worry no problem

tdelabro avatar Mar 05 '24 20:03 tdelabro

@tdelabro could I take it? Thanks

fishseabowl avatar Mar 19 '24 20:03 fishseabowl

sure. Go ahead @fishseabowl

tdelabro avatar Mar 19 '24 20:03 tdelabro

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[bot] avatar Apr 19 '24 00:04 github-actions[bot]

repository archived in favor of https://github.com/madara-alliance/madara

tdelabro avatar Aug 02 '24 18:08 tdelabro