huff-language / huff-project-template

Foundry Repository Template that supports writing contracts in Huff using the foundry-huff library.
The Unlicense
212 stars 45 forks source link

Test failing after running `npm hardhat test`. #1

Closed johnnymatthews closed 2 years ago

johnnymatthews commented 2 years ago

I've been following the Hardhat Quickstart in the Huffc docs and ran into this problem with the Numbers.t.js test. I'm not too familiar with Hardhat, so I'm not sure which part of the error output is relevant. Here's the whole thing:

$ npx hardhat test

Compiling ../contracts/Number.huff

  Greeter

    1) "before each" hook for "Number is deployed"

·-----------------------|----------------------------|-------------|-----------------------------·
|  Solc version: 0.8.0  ·  Optimizer enabled: false  ·  Runs: 200  ·  Block limit: 30000000 gas  │
························|····························|·············|······························
|  Methods                                                                                       │
·············|··········|··············|·············|·············|·············|················
|  Contract  ·  Method  ·  Min         ·  Max        ·  Avg        ·  # calls    ·  eur (avg)    │
·------------|----------|--------------|-------------|-------------|-------------|---------------·

  0 passing (161ms)
  1 failing

  1) Greeter
       "before each" hook for "Number is deployed":
     Error: error:0308010C:digital envelope routines::unsupported
      at new Hash (node:internal/crypto/hash:67:19)
      at Object.createHash (node:crypto:133:10)
      at hash160 (/Users/johnny/Temp/huff-project/node_modules/ethereum-cryptography/vendor/hdkey-without-crypto.js:249:21)
      at HDKey.set (/Users/johnny/Temp/huff-project/node_modules/ethereum-cryptography/vendor/hdkey-without-crypto.js:50:24)
      at Function.HDKey.fromMasterSeed (/Users/johnny/Temp/huff-project/node_modules/ethereum-cryptography/vendor/hdkey-without-crypto.js:194:20)
      at deriveKeyFromMnemonicAndPath (/Users/johnny/Temp/huff-project/node_modules/hardhat/src/internal/util/keys-derivation.ts:21:27)
      at derivePrivateKeys (/Users/johnny/Temp/huff-project/node_modules/hardhat/src/internal/core/providers/util.ts:29:52)
      at normalizeHardhatNetworkAccountsConfig (/Users/johnny/Temp/huff-project/node_modules/hardhat/src/internal/core/providers/util.ts:56:10)
      at createProvider (/Users/johnny/Temp/huff-project/node_modules/hardhat/src/internal/core/providers/construction.ts:78:59)
      at /Users/johnny/Temp/huff-project/node_modules/hardhat/src/internal/core/runtime-environment.ts:80:28

An unexpected error occurred:

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:133:10)
    at hash160 (/Users/johnny/Temp/huff-project/node_modules/ethereum-cryptography/vendor/hdkey-without-crypto.js:249:21)
    at HDKey.set (/Users/johnny/Temp/huff-project/node_modules/ethereum-cryptography/vendor/hdkey-without-crypto.js:50:24)
    at Function.HDKey.fromMasterSeed (/Users/johnny/Temp/huff-project/node_modules/ethereum-cryptography/vendor/hdkey-without-crypto.js:194:20)
    at deriveKeyFromMnemonicAndPath (/Users/johnny/Temp/huff-project/node_modules/hardhat/src/internal/util/keys-derivation.ts:21:27)
    at derivePrivateKeys (/Users/johnny/Temp/huff-project/node_modules/hardhat/src/internal/core/providers/util.ts:29:52)
    at normalizeHardhatNetworkAccountsConfig (/Users/johnny/Temp/huff-project/node_modules/hardhat/src/internal/core/providers/util.ts:56:10)
    at createProvider (/Users/johnny/Temp/huff-project/node_modules/hardhat/src/internal/core/providers/construction.ts:78:59)
    at /Users/johnny/Temp/huff-project/node_modules/hardhat/src/internal/core/runtime-environment.ts:80:28 {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

I ran into this error after making a new repo using this template, installing packages with npm install, and then compiling and testing with npx hardhat compile and npx hardhat test. The compile command seemed to work fine:

$ npx hardhat compile

Nothing to compile
Pulling Huff version 0.0.17
Compiling contracts/Number.huff
johnnymatthews commented 2 years ago

Just brain dumping here: I'm starting to think that there's something wrong with how Hardhat is set up in this project. Running npx hardhat accounts outputs a similar error:

$ npx hardhat accounts

An unexpected error occurred:

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:133:10)
    at hash160 (/Users/johnny/Temp/huff-project/node_modules/ethereum-cryptography/vendor/hdkey-without-crypto.js:249:21)
    at HDKey.set (/Users/johnny/Temp/huff-project/node_modules/ethereum-cryptography/vendor/hdkey-without-crypto.js:50:24)
    at Function.HDKey.fromMasterSeed (/Users/johnny/Temp/huff-project/node_modules/ethereum-cryptography/vendor/hdkey-without-crypto.js:194:20)
    at deriveKeyFromMnemonicAndPath (/Users/johnny/Temp/huff-project/node_modules/hardhat/src/internal/util/keys-derivation.ts:21:27)
    at derivePrivateKeys (/Users/johnny/Temp/huff-project/node_modules/hardhat/src/internal/core/providers/util.ts:29:52)
    at normalizeHardhatNetworkAccountsConfig (/Users/johnny/Temp/huff-project/node_modules/hardhat/src/internal/core/providers/util.ts:56:10)
    at createProvider (/Users/johnny/Temp/huff-project/node_modules/hardhat/src/internal/core/providers/construction.ts:78:59)
    at /Users/johnny/Temp/huff-project/node_modules/hardhat/src/internal/core/runtime-environment.ts:80:28 {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

I'll keep digging.

johnnymatthews commented 2 years ago

Never mind! The problem was that I was using the latest version of NPM, but Hardhat requires users to use the latest LTS version of NPM (currently 16.15.0). I downgraded to that version and everything worked fine!