La primera pregunta es tan clara conmigo si no está muy clara, pero haré lo mejor que pueda.
Actualmente estoy viendo un video de YouTube para probar mi contrato con hardhat, ethers y waffle ( https://www.youtube.com/watch?v=oTpmNEYV8iQ&list=PLw-9a9yL-pt3sEhicr6gmuOQdcmWXhCx4&index=6 ).
Aquí está el contrato:
// SPDX-License-Identifier: MIT pragma solidity ^0.8.9; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; contract MyContract is ERC721 { constructor(string memory name, string memory symbol) ERC721(name, symbol) { } }Y aquí está test.js:
const { expect } = require('chai'); describe("MyContract", function() { it("should return correct name", async function() { const MyContract = hre.ethers.getContractFactory("MyContract"); const myContractDeployed = await MyContract.deploy("MyContractName", "MCN"); await myContractDeployed.deployed(); expect(await myContractDeployed.name()).to.equal("MyContractName"); }); });cuando ejecuto "npx hardhat test" en la terminal, devuelve:
MyContract 1) should return correct name 0 passing (7ms) 1 failing 1) MyContract should return correct name: TypeError: Cannot read properties of undefined (reading 'getContractFactory') at Context.<anonymous> (test\test.js:7:35) at processImmediate (node:internal/timers:464:21)Mi código coincide con el del video, y me está costando entender por qué obtengo un TypeError aquí. ¡Cualquier orientación es muy apreciada!
EDITAR:
De alguna manera lo arreglé, no entiendo cómo lo arregló exactamente, pero lo hizo. En lugar de simplemente instalar
npm install @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers etherslo instalé
npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethersEntonces la terminal imprimió
npm WARN idealTree Removing dependencies.@nomiclabs/hardhat-waffle in favor of devDependencies.@nomiclabs/hardhat-waffle npm WARN idealTree Removing dependencies.ethereum-waffle in favor of devDependencies.ethereum-waffle npm WARN idealTree Removing dependencies.@nomiclabs/hardhat-ethers in favor of devDependencies.@nomiclabs/hardhat-ethers npm WARN idealTree Removing dependencies.ethers in favor of devDependencies.ethersluego eliminé el hre frente a ethers.getContractFactory("MyContract") ¡y funcionó! Si alguien quisiera explicar por qué esto podría haberlo solucionado, estaría feliz de leerlo, de lo contrario, seguiré adelante.