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

Can't use synpress with custom chain #764

Closed
georgi-l95 opened this issue May 22, 2023 · 11 comments
Closed

Can't use synpress with custom chain #764

georgi-l95 opened this issue May 22, 2023 · 11 comments
Labels
bug 🐛 Something isn't working

Comments

@georgi-l95
Copy link

Describe the bug
I'm trying to setup a test, while using custom chain not present here: https://github.com/wagmi-dev/references/tree/main/packages/chains#chains
This flow was working prior version 3.0.5.

To Reproduce
Steps to reproduce the behavior:

  1. Create some simple test and add following network in .env file.
HEDERA_NETWORK={"0.testnet.hedera.com:50211":"0.0.3"}
OPERATOR_ID_MAIN=0.0.1322
OPERATOR_KEY_MAIN=302e020100300506032b6570042204206bb5ca5c9a33b8a12e2d962fe14587fa40e92306e9c39bcd2bb62951100d7248
CHAIN_ID=0x128
MIRROR_NODE_URL=https://testnet.mirrornode.hedera.com
MIRROR_NODE_URL_WEB3=https://testnet.mirrornode.hedera.com
LOCAL_NODE=true
SERVER_PORT=7546
# cypress metamask config
NETWORK_NAME='local hedera'
RPC_URL='http://localhost:7546'
SYMBOL='HBAR'
IS_TESTNET=true
PRIVATE_KEY='0xb46751179bc8aa9e129d34463e46cd924055112eb30b31637b5081b56ad96129'
RECEIVER_PRIVATE_KEY='0x484961ec6c67c270dc5659ea8bb61489967c6acc574d81b1e046e072d5d2436d'
STABLE_MODE=true
  1. Or use the tests from this repo, but bump the version of synpress before that.

Related repository
https://github.com/hashgraph/hedera-json-rpc-relay/tree/main/dapp-example

Expected behavior
To be able to run with chain not present in the wagmi repo.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: macOS
  • Synpress version: All versions after 3.1.0 . Last working version is 3.0.5
  • CI platform (if applicable): GitHub Actions

Additional context
Add any other context about the problem here.

@georgi-l95 georgi-l95 added the bug 🐛 Something isn't working label May 22, 2023
@drptbl
Copy link
Collaborator

drptbl commented May 22, 2023

Thanks for reporting! Will take a look in to this asap.

@georgi-l95
Copy link
Author

Thank you, my setup could be wrong, but I've looked at all available documentation and couldn't find a way to make it work. If this is the case i would be super grateful for a workaround. Thank you for the quick response.

@sloonzz
Copy link

sloonzz commented May 31, 2023

Can confirm this happens to me too. I checked the logic of the package and it seems like the addNetwork command from metamask.js is the culprit. setupMetamask seems to pass in the network as a string instead of an object. Then inside initialSetup, module.exports.addNetwork actually receives a string network instead of an object.

EDIT: This happens even if the correct .env variables are defined, as they are ignored and instead only the NETWORK_NAME is used.

    setupMetamask: async ({
      secretWordsOrPrivateKey,
      network,
      password,
      enableAdvancedSettings,
      enableExperimentalSettings,
    }) => {
      if (process.env.NETWORK_NAME) {
        network = process.env.NETWORK_NAME;
      }
      if (process.env.PRIVATE_KEY) {
        secretWordsOrPrivateKey = process.env.PRIVATE_KEY;
      }
      if (process.env.SECRET_WORDS) {
        secretWordsOrPrivateKey = process.env.SECRET_WORDS;
      }
      await metamask.initialSetup(null, {
        secretWordsOrPrivateKey,
        network,
        password,
        enableAdvancedSettings,
        enableExperimentalSettings,
      });
      return true;
    },

@georgi-l95
Copy link
Author

Nice catch @sloonzz . Are you aware of any workaround for the time being ?

@sloonzz
Copy link

sloonzz commented May 31, 2023

Nice catch @sloonzz . Are you aware of any workaround for the time being ?

Currently trying to manually setupMetamask and addMetamaskNetwork but having trouble with using env variables for some reason.

EDIT: This should(?) be an easy fix though? Just check if the rest of the variables exist then pass in the whole object instead of just the string inside setupMetamask. The logic already exists for other parts of the code.

@georgi-l95
Copy link
Author

georgi-l95 commented May 31, 2023

That's what I though as well, but it again gave me error that it couldn't get the network (same error that I get when i try the .env variables method), when I tried it.

@sloonzz
Copy link

sloonzz commented May 31, 2023

@georgi-l95 You can use my fork in the meantime. Haven't tested it yet because power went out. But I tested an earlier iteration of this and seems to work fine. https://github.com/sloonzz/synpress

@YakovL
Copy link
Contributor

YakovL commented Jun 4, 2023

@georgi-l95 what error do you get? Is it the one below?

tasksetupMetamask, Object{5}
CypressError
Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.

The command that returned the promise was:

cy.task()

The cy command you invoked inside the promise was:

cy.then()

Because Cypress commands are already promise-like, you don't need to wrap them or return your own promise.

Cypress will resolve your command with whatever the final Cypress command yields.

The reason this is an error instead of a warning is because Cypress internally queues commands serially whereas Promises execute as soon as they are invoked. Attempting to reconcile this would prevent Cypress from ever resolving. Learn more

I'm asking because it seems that I've run into the same issue, but I'm not quite sure yet. My test env is:

NETWORK_NAME='Mumbai'
# NETWORK_NAME=polygonMumbai
SECRET_WORDS='spell rally panda picture extra expect arch pond middle eyebrow indicate segment'
CHAIN_ID=80001
RPC_URL='https://matic-mumbai.chainstacklabs.com'
SYMBOL="MATIC"
IS_TESTNET=true

The only issue that I've found mentioning this error is #417, but that one is about watch mode, while I'm having troubles with the ordinary mode.

PS The Stack Trace is minimal:

    at cy.<computed> [as then] (http://localhost:54472/__cypress/runner/cypress_runner.js:160660:72)
From Your Spec Code:
    at Context.eval (http://localhost:54472/__cypress/tests?p=cypress\support\e2e.ts:17078:21)

and cypress\support\e2e.ts is as simple as

import './commands';
import '@synthetixio/synpress/support/index';

Created a new issue to make it fully reproducible: #775

@YakovL
Copy link
Contributor

YakovL commented Jun 5, 2023

I've take several steps further, and added some debugging into synpress/commands/metamask.js → initialSetup:

  async initialSetup(
    playwrightInstance,
    {
      secretWordsOrPrivateKey,
      network,
      password,
      enableAdvancedSettings,
      enableExperimentalSettings,
    },
  ) {
    console.log(`YL debug point 1, process.env.NETWORK_NAME is ${process.env.NETWORK_NAME}`)
    const isCustomNetwork =
      (process.env.NETWORK_NAME &&
        process.env.RPC_URL &&
        process.env.CHAIN_ID &&
        process.env.SYMBOL) ||
      typeof network == 'object';
    console.log(`YL debug point 1.1: isCustomNetwork is ${isCustomNetwork}`)

Suprisingly, it reports that process.env.NETWORK_NAME is undefined. Any idea how comes (it is set in .env)? Is it true in your case?

@r3kt-eth
Copy link
Contributor

r3kt-eth commented Jun 6, 2023

@georgi-l95 @sloonzz @YakovL
Hi,
this should be fixed with latest release which is @synthetixio/[email protected].

Please let me know. Thx.

@r3kt-eth r3kt-eth closed this as completed Jun 6, 2023
@georgi-l95
Copy link
Author

Hey @r3kt-eth, just to confirm that latest version is working now. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants