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

bug: catch panic in tests #161

Open
AbdelStark opened this issue Aug 18, 2023 · 1 comment
Open

bug: catch panic in tests #161

AbdelStark opened this issue Aug 18, 2023 · 1 comment
Assignees
Labels
bug Something isn't working test

Comments

@AbdelStark
Copy link
Contributor

AbdelStark commented Aug 18, 2023

Description

For now it seems we cannot catch panics triggered by a call that triggers another smart call inside tests.

Example test: given_bad_params_when_create_market_then_fail.

    // Create a market.
    let market_token = contract_address_const::<'market_token'>();
    // We use an invalid address as the index token.
    let index_token = contract_address_const::<0>();
    let long_token = contract_address_const::<'long_token'>();
    let short_token = contract_address_const::<'short_token'>();
    let market_type = 'market_type';

    let new_market = Market { market_token, index_token, long_token, short_token, };

    // Try to create a market.
    // This must fail because the index token is invalid.
    // For now it seems we cannot catch the panic handling the result.
    // TODO: Find a way to catch the panic.
    // let result = market_factory.create_market(index_token, long_token, short_token, market_type);
    // match result {
    //     // If the result is ok, then the test failed.
    //     Result::Ok(_) => assert(false, 'bad_result'),
    //     // If the result is err, then the test passed.
    //     Result::Err(_) => {}
    // }

We should use Starknet Foundry should_panic when available in the release.

#[test]
#[should_panic(expected: ('panic message', ))]
fn should_panic_check_data() {
    panic_with_felt252('panic message');
}
@AbdelStark AbdelStark added bug Something isn't working test labels Aug 18, 2023
@Oshioke-Salaki
Copy link

Hello, Please can i handle this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working test
Projects
Status: 🔖 Ready
Development

No branches or pull requests

3 participants