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

= not implemented for anchor_lang::error::Error #1538

Closed
guibescos opened this issue Mar 1, 2022 · 3 comments · Fixed by #1544
Closed

= not implemented for anchor_lang::error::Error #1538

guibescos opened this issue Mar 1, 2022 · 3 comments · Fixed by #1544

Comments

@guibescos
Copy link
Contributor

guibescos commented Mar 1, 2022

I've been struggling to cargo test my code.
Basically I want to create a unit test that runs a function and checks the returned error against an Anchor Error.

When I run :
assert_eq!(returns_error(), Err(error!(ErrorCode::MyError)))
I get :
error[E0369]: binary operation `==` cannot be applied to type `Result<(), anchor_lang::error::Error>
Reproducible example : https://github.com/guibescos/anchor-issue-error-equals
Run : cargo test

@guibescos
Copy link
Contributor Author

I seems to me like the equal operation might need to get implemented. Wanted to get some thoughts from the community on how easy this is to PR.

@callensm
Copy link
Member

callensm commented Mar 2, 2022

This would be a very simple pull request, but what is the use case for equating two errors within the contract code?

@guibescos
Copy link
Contributor Author

guibescos commented Mar 2, 2022

rust tests, check my minimal example in the shared repo

#[test]
fn test_error_2() {
    fn returns_error() -> Result<()> {
        return Err(error!(ErrorCode::MyError));
    }

    assert_eq!(returns_error(), Err(error!(ErrorCode::MyError)))
}

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 a pull request may close this issue.

2 participants