1

I'm running a test on a very simple pool contract. I am using Mocha to write the tests, but Hardhat's network to run them. After firing up my Hardhat node I get the 10 test accounts per usual with their test ETH, and I then try to reference a handful of those accounts in the test using Mocha's contract() function. However, my terminal reads the following when running the test itself:

Error: This method only supports Buffer but input was: <private key>

...where <private key> was the private key of my first test account I was looking to reference. Whenever I have this exact same testing setup when working with Truffle/Ganache exclusively this never came up, so I'm wondering if there is something breaking because I am using both Hardhat & Truffle concurrently; does Hardhat pass back a different value than Truffle does? I was always under the impression that the conversion from the private key to the buffer happened under the hood when using Truffle/Hardhat. Is there an explanation and a workaround for this?

For reference, here is my test file as well:

const { assert } = require('chai');
const Pool = artifacts.require('Pool.sol');

contract('Pool', ([accounts]) => {
    const [admin, user1, user2, user3, _] = accounts;

    it('should accept deposits and read correct balances for contract and users', async () => {
        const pool = await Pool.new('Pool', true);

        await pool.makeDeposit({
            from: user1,
            value: web3.utils.toWei('1'),
        });

        await pool.makeDeposit({
            from: user2,
            value: web3.utils.toWei('1'),
        });

        await pool.makeDeposit({
            from: user3,
            value: web3.utils.toWei('2'),
        });

        await pool.getPoolBalance();
    });
});

Thank you!

1

1 Answer 1

3

I received the same error after upgrading @nomiclabs/hardhat-truffle5 to version ^2.0.1. I believe there is a breaking change in that release.

Revert to version 2.0.0 using this command, and this error will go away.

npm install "@nomiclabs/hardhat-truffle5"@"2.0.0
1
  • You can also upgrade to 2.0.2, which fixes this problem. Oct 5, 2021 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.