0

Here is a test file.
ethers.getSigners() works fine ethers.deployContract() works fine for some reason, ethers.utils.solidityKeccak256 keeps breaking the code with this error:

' TypeError: Cannot read properties of undefined (reading 'solidityKeccak256')

const { expect } = require("chai");
const crypto = require('crypto');

describe("Pool claim", function () {
  it("Deployment should claim", async function () {
    const [owner, otherAccount] = await ethers.getSigners();
    const PRIVATE_KEY = "******"
    const wallet = new ethers.Wallet(PRIVATE_KEY);


    const Factory = await ethers.deployContract("RewardRegistry");
    const Pool = await Factory.createContracts("++++");

    const ammount = 1;
    const userAddr = await otherAccount.address
    const nonce =  crypto.randomBytes(32)

    const message = ethers.utils.solidityKeccak256(
        ['address', 'bytes32', 'uint256'],
        [userAddr, nonce, ammount]
      );

    const signature = await wallet.signMessage(message);

    const claimReward = await Pool.claimReward(userAddr, nonce, signature, ammount)

    // expect(await hardhatToken.totalSupply()).to.equal(ownerBalance);
  });
});


1 Answer 1

1

If you are on ethers v6, try this:

  const message = ethers.solidityPackedKeccak256(
    ['address', 'bytes32', 'uint256'],
    [userAddr, nonce, ammount]
  );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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