hicommonwealth / commonwealth

A platform for decentralized communities
https://commonwealth.im
GNU General Public License v3.0
67 stars 42 forks source link

Create metamask mock for e2e tests #4149

Closed jnaviask closed 1 year ago

jnaviask commented 1 year ago

Description

Required to get #4148 off the ground -- we need a way to mock Metamask's various calls, so we can "log in" a user as part of automatic testing.

Engineering Requirements

ianrowan commented 1 year ago

Moving this to a 3 as the recreation of metamasks eth_signedTypedData_v4 is going to take some research effort and building

ianrowan commented 1 year ago

Finding at this point are that the only way to set window.ethereum is using the page.addInitScript() before each page load. The tricky caveat here is this expects vanilla javascript and the complex custom provider I built in TS does not transpile well to a plain script.

I rewrote in JS but external dependencies are hard to manage here, so the inject script has issues using web3.js and the metamask signing utility. There aren't many example usages out there of this feature beyond just simple few line scripts.

ianrowan commented 1 year ago

Additionally it looks like building a chromium extension might be a choice. The tough part here is the access extensions and chrome are given to inject things into the browser context.

As far as playwright, the ability to do this is limited by the browser itself. So building the metamask-like provider into something like an extension might be more straightforward(if the chromium extension process is in general)

ianrowan commented 1 year ago

Now that we're moving forward with the app code approach, a few things to wrap this up.

  1. Do we have an ETH RPC we can use for our provider. The alchemy provider does not have localhost on the whitelist so it currently doesnt work(I was testing with my personal infura before these final steps)?

  2. Ok to use the existing ETH_RPC env var which currently toggles ability to use test net for this with the condition ETH_RPC=e2e-test as the on flag. If so, as mentioned where should I document(packages/commonwealth README?)

@jnaviask