DePayFi / web3-mock

🤡 JavaScript library to mock web3 responses either by emulating web3 wallets or web3 RPC requests.
https://depay.com
MIT License
81 stars 21 forks source link

Web3-Mock doesn't work with a real application (`MetaMask/test-dapp`) #34

Open matstyler opened 1 month ago

matstyler commented 1 month ago

I was able to setup Web3-Mock using Playwright but I cannot use it properly with Cypress. Lets say I have a very simple use case. I mock the metamask wallet and then I want to test that mock using @metamask/test-dapp. Nothing is working as expected and I get provider errors:

Screenshot 2024-06-02 at 15 59 22

The thing is I am able to use window object in the e2e test code but this is not what I need. I want the mock working in e2e manual test - for example by clicking on the "ETH ACCOUNTS" button.

Screenshot 2024-06-02 at 16 01 00

My code for this simple example:

const accounts = ['0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045']

beforeEach(()=>{
  mock({ blockchain: 'ethereum', accounts: { return: accounts }, wallet: 'metamask' })
})

it("should mock account", () => {
cy.visit("http://localhost:9999");

cy.get("#getAccounts").click();
})
johanneskares commented 3 weeks ago

Yeah same here, I created a new lib to be able to use a mock wallet, not Metamask: https://github.com/johanneskares/wallet-mock