Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

374
Vistas
TypeError: Cannot read properties of undefined (reading 'equal')

I have created 2 TESTS --

In 2nd TEST, I have enclosed owner, addr1, addr2 in [] as per the Official Hardhat Documentation, like this const [owner,addr1,addr2] = await ethers.getSigners();, But the problem is when I use [] bracket, it shows me the error TypeError: Cannot read properties of undefined (reading 'equal') and the test also failed,

Here is the Code --->

const { expect } = require('chai');
// const { ethers } = require('hardhat');


describe('Token contract', function () {
    //1st TEST

    it('Deployment should assign the total supply of the tokens to the owner', async function () {
        const [owner] = await ethers.getSigners();
        

        const Token = await ethers.getContractFactory('Token');

        const hardhatToken = await Token.deploy();

        const ownerBalance = await hardhatToken.balanceOf(owner.address);
        
        expect(await hardhatToken.totalSupply()).to.equal(ownerBalance);
    });

    //2nd TEST

    it('Should Transfer Tokens between accounts', async function () {
        
        const [owner,addr1,addr2] = await ethers.getSigners();
        

        const Token = await ethers.getContractFactory('Token');

        const hardhatToken = await Token.deploy();

        //Transfer 10 tokens from Owner to addr1
        await hardhatToken.transfer(addr1.address,10);
        expect(await hardhatToken.balanceOf(addr1.address).to.equal(10));

        //Transfer 5 tokens from addr1 to addr2
        await hardhatToken.connect(addr1).transfer(addr2.address,5);
        expect(await hardhatToken.balanceOf(addr2.address).to.equal(5))
    });
});

But if U see in the 1st TEST, I haven't used [], for owner, so the test passed. Below is the Official Hardhat documentation if U want to check the code --->

https://hardhat.org/tutorial/testing-contracts.html

Please help me to solve this Problem Thanks

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You didn't close the parenthesis around the expect calls in the second test correctly. You're accessing .to on the number returned by .balanceOf.

Replace with:

expect(await hardhatToken.balanceOf(addr1.address)).to.equal(10);
// ...
expect(await hardhatToken.balanceOf(addr2.address)).to.equal(5);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda