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

confirmMetamaskTransaction function fails with the default metamask version 9.7.1 #252

Closed
DimitarTAtanasov opened this issue Oct 26, 2021 · 21 comments

Comments

@DimitarTAtanasov
Copy link

Thanks for the great work on Synpress, this library looks awesome. Anyway I am struggling with something when I try to confirm transactions.

Steps to reproduce:
Leave env variable for metamask version blank (use the hardcoded version 9.7.1)
Execute: synpress run
Metamask is being initialized
The chosen address is visited
The user wallet is connected to the dApp
Button leading to transaction which needs confirmation from metamask is pressed.

Once needed to confirm metamask transaction, it is failed(screenshot attached)

metamask

Note:
Debugged the library and found where the confirmation is failing

cy.confirmMetamaskTransaction is calling -> confirmTransaction in ./commands/metamask.js
which is calling:
await puppeteer.waitClearAndType( newGasFee, confirmPageElements.gasFeeInput, notificationPage, ); - all the params passed to waitClearAndType defined.

The function waitClearAndType is failing on the step:
await input.click({ clickCount: 3 }); Where 'input' is defined.

I tried to replace waitClearAndType with waitAndType when called from confirmTransaction and the transaction is passed successfully ( but the gas fee paid for the transaction is not right of course)
Other workaround I tried is to skip the calling of waitClearAndType it is working as well, but there is possibility for the transaction not to be mined if the gas fee increased from the moment we triggered the transaction.

Also if some of the latest versions of Metamask is used(tried with 10.2.2), confirmMetamaskTransaction is failing as well as in the last versions of Metamask, the confirmation page has no input field for the gas fee at all and it seems that the gas fee is recalculated by Metamask automatically. For these versions of metamask we could skip the steps for manually getting and setting the gas fee.

@ochikov
Copy link

ochikov commented Oct 26, 2021

The same issue on my side.

@RAMTO
Copy link

RAMTO commented Oct 26, 2021

Yep, on my as well

@drptbl
Copy link
Member

drptbl commented Oct 26, 2021

@DimitarTAtanasov @RAMTO @ochikov thanks for reports guys. I will take a look in to this asap (today).

Cheers,
Jakub.

@drptbl
Copy link
Member

drptbl commented Oct 26, 2021

@DimitarTAtanasov @RAMTO @ochikov this issue should be fixed now.
Please use: @synthetixio/synpress@0.9.25-beta.26 and let me know if it works for you now.

It was a quick fix, I will come up with something better until end of the week, but it should be still fine for now.

I'm going to work on Metamask 10+ support in upcoming week and support both versions (<10 also).

Thanks,
Jakub.

@DimitarTAtanasov
Copy link
Author

@drptbl Thanks for the fast response. Using version 0.9.25-beta.26 I am still experiencing the same issue.
I am applying a screenshot with part of the latest fix you provided await puppeteer.metamaskWindow().waitForTimeout(1000); just to be sure I applied the last changes.
Screenshot 2021-10-27 at 10 42 43

@ochikov
Copy link

ochikov commented Oct 27, 2021

@drptbl Can you give us a hand once again? Thank you in advance.

@drptbl
Copy link
Member

drptbl commented Oct 27, 2021

@DimitarTAtanasov @ochikov sure, with pleasure :).

Few questions:

  1. Is there any chance your test code is open sourced, so that I can reproduce the issue on my machine? Since yesterday fixes I can't reproduce it anymore.
  2. Do you run your e2e tests on MacOS/Linux/Windows/inside docker?
  3. Just to make sure, you're using synpress run for the whole time, right?
  4. Do you use your PC while tests are running? They need a focus of browser sometimes (only while confirming transaction in metamask notification window), so at this specific point you shouldn't be interfering with window focus.
  5. Did you reproduce this issue only on 1 machine or does it happen on multiple machines? I can see few people participating in this conversation and I'm wondering if they're also having this issue on their machines?

Thanks for answers in advance, they will help me out with debugging. I will continue investigating this today.

Cheers,
Jakub.

@DimitarTAtanasov
Copy link
Author

DimitarTAtanasov commented Oct 27, 2021

@drptbl

  1. Unfortunately the code is not open sourced, I will try to record a video and will upload it later.
  2. Currently I am executing the tests on MacOS, tried also on Windows machine with the same result (I have plans to execute them in docker in future if possible)
  3. I run the tests using 'synpress run' as described in documentation
  4. Tried not touching anything after started the tests, still the same issue.
  5. Tried on two MacOS machines and one windows machine so far, the result is always the same.

Again when I remove the calling of
await puppeteer.waitClearAndType( newGasFee, confirmPageElements.gasFeeInput, notificationPage, ); the confirmation is successful

I will try to record and upload a video asap. Please let me know if I could help with something else in the investigation.

@DimitarTAtanasov
Copy link
Author

Sorry closed the issue by mistake. Reopening it

@DimitarTAtanasov

This comment has been minimized.

@drptbl
Copy link
Member

drptbl commented Oct 27, 2021

Thanks for everything @DimitarTAtanasov, gonna dig in to this today, hopefully will have some solution until tonight.

@DimitarTAtanasov
Copy link
Author

DimitarTAtanasov commented Oct 27, 2021

One more thing which is probably not for this discussion, but in the "changeMetamaskNetwork" if we have network set from the .env, we will not able to change the network as no matter what we pass to the function it will be replaced with the value from the env.

changeMetamaskNetwork: async network => { if (process.env.NETWORK_NAME) { network = process.env.NETWORK_NAME; } else { network = 'kovan'; } const networkChanged = await metamask.changeNetwork(network); return networkChanged; },

If "changeMetamaskNetwork" is made like this on purpose can we have another one for example:
changeMetamaskToSpecificNetwork: async network => { let networkChanged = false; if(network) { networkChanged = await metamask.changeNetwork(network); } return networkChanged; },
This way the user will be able to change the metamask network even if there is a network set in the .env.
Sorry if I am missing something :)

If you agree with this I could make a PR for this one.

Thanks again

@Synthetixio Synthetixio deleted a comment from DimitarTAtanasov Oct 27, 2021
@drptbl
Copy link
Member

drptbl commented Oct 27, 2021

Hey @DimitarTAtanasov, could you please try to run this test on your machine?
https://gist.github.com/drptbl/223e869a7954c393702a3f9d73470412
Just copy content and create new example-spec.js file inside specs folder.

Command to run:
SECRET_WORDS='fill, your, secret, words' BASE_URL=https://rinkeby.gnosis-safe.io/app/\#/welcome NETWORK_NAME=rinkeby npx synpress run

It creates a new gnosis safe on rinkeby, it's ugly but I wanted to do it as fast as possible as it will go to trash anyway.

Can you let me know if it works for you? Or do you have same issues as above?

I'm really trying to figure out what's going on, there is no way for me to reproduce the issue. I was thinking that maybe it's OS-related, but I'm also on macOS.

side-note:
I will also fix the issue with changeMetamaskNetwork that you've mentioned above using occasion after I get the idea where the main issue is.

Thanks again and sorry for taking your time. I'm still investigating in the meantime.

This is how it works on my macOS, just fine:
2021-10-27 23 03 03

@DimitarTAtanasov
Copy link
Author

This example works on my end as well. This is so confusing as I am using the confirmation the same way as in the example you gave me. I will try to dig more in this as well and will get back to you as soon as I have any result.
Thanks again for the time spent on this.

@DimitarTAtanasov
Copy link
Author

DimitarTAtanasov commented Oct 27, 2021

Sorry just realized that the example worked for me as I removed the call of await puppeteer.waitClearAndType( newGasFee, confirmPageElements.gasFeeInput, notificationPage, ); in confirmTransaction

Still have the same issue when execute it with the original code...

@drptbl
Copy link
Member

drptbl commented Oct 27, 2021

@DimitarTAtanasov Thanks for confirming! I'm currently trying to find another solution for waitClearAndType behind the scenes. I should have something ready in ~1h.

@DimitarTAtanasov
Copy link
Author

Sure, thanks again, it is really strange why await input.click({ clickCount: 3 }); in waitClearAndType is failing for me and working for you.

@drptbl
Copy link
Member

drptbl commented Oct 27, 2021

@DimitarTAtanasov Pushed a new update, confirmTransaction is now using waitAndSetValue instead of waitClearAndType.

Please try this version:
"@synthetixio/synpress": "0.9.25-beta.30"

And let me know if it has changed anything. If not, I will keep digging.

Sorry for inconvenience. It's really hard to fix an issue when you're not able to reproduce it.

Thanks,
Jakub.

@drptbl
Copy link
Member

drptbl commented Oct 27, 2021

Damn.. I think that I've actually found related issue that we're experiencing:
puppeteer/puppeteer#3347

confirmTransaction is the only place in the code which uses click() directly from puppeteer, so it makes sense.

@DimitarTAtanasov
Copy link
Author

@drptbl seems to be working with 0.9.25-beta.30 with waitAndSetValue . I think you are right, It seems this could be puppeter related issue. Thanks for the help @drptbl really appreciate it.
I think we could close this issue.
If you find time to include the changes for changeMetamaskNetwork in some of the next releases I will be extremely grateful.

Thanks again and have a nice evening :)

@drptbl
Copy link
Member

drptbl commented Oct 27, 2021

Thanks for confirming @DimitarTAtanasov and thanks for helping me out to solve this one.

I will fix changeMetamaskNetwork tomorrow morning. It's an easy fix.

Related issue:
#253

All best,
Jakub.

@drptbl drptbl closed this as completed Oct 27, 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

No branches or pull requests

4 participants