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

Fix panic when MetaMask returns error #549

Merged
merged 4 commits into from Sep 30, 2021
Merged

Fix panic when MetaMask returns error #549

merged 4 commits into from Sep 30, 2021

Conversation

dvec
Copy link
Contributor

@dvec dvec commented Sep 28, 2021

Fix #544

Copy link
Owner

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks! Any chance we can cover this behaviour with a test case?

@dvec
Copy link
Contributor Author

dvec commented Sep 28, 2021

We can't run tests directly in browser, so I think the only solution is to mock window.ethereum, which may be a tricky task

Copy link
Owner

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we extract response parsing to a standalone (rust) function and just unit test that? I.e. that given the expected payload it parses correctly. wdyt?

@dvec
Copy link
Contributor Author

dvec commented Sep 28, 2021

Sounds like a solution, I'll try to commit it today

@dvec
Copy link
Contributor Author

dvec commented Sep 28, 2021

I'm wondering why there is a panic at all in case of invalid response while we have web3::error::Error::InvalidResponse. Especially considering that std::panic::catch_unwind is not available on wasm target (what also means that it's impossible to use #[should_panic] in tests). Can we refuse this behavior and return Err(web3::error::Error::InvalidResponse(...)) instead of panic?

@tomusdrw
Copy link
Owner

Can we refuse this behavior and return Err(web3::error::Error::InvalidResponse(...)) instead of panic?

Yeah, I just looked at the code and indeed we shouldn't be panicking and definitely the code is not unreachable as we can tell. If you want to bundle the fix in the same PR I'm fine with that.

Copy link
Owner

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

@tomusdrw tomusdrw merged commit 2711cd0 into tomusdrw:master Sep 30, 2021
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 this pull request may close these issues.

eip_1193: entered unreachable code when canceling transaction in MetaMask
2 participants