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

Panic Message Substring fails when using a proxy contract #1550

Open
bitzoic opened this issue Dec 2, 2024 · 0 comments
Open

Panic Message Substring fails when using a proxy contract #1550

bitzoic opened this issue Dec 2, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@bitzoic
Copy link
Member

bitzoic commented Dec 2, 2024

If a contract is expected to revert with a message after going through a proxy contract that uses the run_external function, the SDK does not catch the expected substring and instead fails.

Example:

Calling Contract

This contract calls the proxy with the TargetContract abi, triggering the fallback function in the proxy.

contract;

use target_abi::TargetContract;

abi CallerContract {
    fn call_proxy_contract(proxy_contract: ContractId);
}

impl CallerContract for Contract {
    fn call_proxy_contract(proxy_contract: ContractId) {
        abi(TargetContract, proxy_contract.bits()).target_function();
    }
}

Proxy Contract

The following is called in the proxy contract:

#[fallback]
fn fallback() {
    run_external(_proxy_target().expect("FallbackError::TargetNotSet"))
}

Target Contract

The following is the target contract:

contract;

use target_abi::TargetContract;

impl TargetContract for Contract {
    fn target_function() {
        log("called through proxy");
        revert(0);
    }
}

Rust Tests

If the test is expected to panic with the message "called through proxy", it will fail to catch the correct substring.

#[tokio::test]
#[should_panic(expected = "called through proxy")]
async fn can_get_contract_id() {
    let (
        // called_instance,
        // called_id,
        proxy_instance,
        proxy_id,
        caller_instance,
        caller_id,
        target_instance,
        target_id,
    ) = get_contract_instances().await;
    proxy_instance
        .methods()
        .initialize_proxy()
        .call()
        .await
        .unwrap();

    let _response = caller_instance
        .methods()
        .call_proxy_contract(proxy_id)
        .with_contracts(&[&proxy_instance, &target_instance])
        .call()
        .await
        .unwrap();
}
@bitzoic bitzoic added the bug Something isn't working label Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant