Unable to run meta-tx tests

I cloned the workshop with the basic meta-tx management using oz defender relayer: https://github.com/OpenZeppelin/workshops/tree/master/25-defender-metatx-api

:computer: Environment
Mac OS

:memo:Details
After cloning the repo, i've added a private key to the .env file in the root folder and run "yarn test".
All the tests including the meta-tx are failing with the error
"MethodNotSupportedError: Method eth_signTypedData is not supported"

:1234: Code to reproduce
Clone the repo, build the code with yarn build, add this Private Key to the .env file: PRIVATE_KEY=075546cddad7ce53ac599a1f264cbbe0ba59832b28ee24af7bd168fcfce47802

run yarn test

Hey @sgy0 -

We've had a couple people test this internally in response to your issue and it seems the tests are running green. Best guess is you are not pulling in latest version of the dependencies, but it is hard to tell without further information.

Hello,

this is my .env

PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

The value is the first of the list of the accounts hardhat creates.

Could you share your env file? Probably I'm missing something

Not needed anymore, this solved my issue! https://stackoverflow.com/questions/69692842/error-message-error0308010cdigital-envelope-routinesunsupported

Thanks for the support

Hello there. Sorry to hear this was an issue, but after stumbling my way through the same error, I've got your fix:

  • In the tests, the signer.js script tries to determine which function to use (eth_signTypedData or eth_signTypedData_v4) based on the wallet provider--Hardhat, Metamask, etc. It does this in a roundabout way by checking to see if hardhat's local dev chain is being used by checking the chainId. If it's a local Hardhat test being run, the chainId will be 31337.
  • However, hardhat.config pulls in your PRIVATE_KEY under the networks section (Hardhat is the local network). If your private key came from a Metamask wallet, and the request in signer.js during testing the eth_signTypedData function will be selected instead of the correct function for Metamask wallets, eth_signTypedData_v4.
  • A super quick and dirty fix for this is to set the isHardhat variable to false, and the tests should pass with your Metamask private key.

Thanks @casey.erikson for the help with this! :100: