[Solidity] Hardhat 공부 - 2(단위테스트, console.log)

Hardhat Day 2

단위테스트 및 console.log !!


1. 단위테스트

  • hardhat.config.js 파일내에 require("@nomiclabs/hardhat-waffle"); 명령어를 추가하면 단위테스트에 waffle 사용이 가능해집니다.
  • 단위테스트는 chai를 이용합니다.
  • describe 함수로 단위테스트 범위를 설정하고, it 함수로 실제 단위로 테스트 가능합니다.
  • const wallets = waffle.provider.getWallets(); 명령어로 지갑 정보를 가져 올 수 있음
const { expect } = require("chai");

describe("Greeter", function () {

  it("Should return the new greeting once it's changed", async function () {
    const Greeter = await ethers.getContractFactory("Greeter");
    const greeter = await Greeter.deploy("Hello, world!");
    await greeter.deployed();

    expect(await greeter.greet()).to.equal("Hello, world!");

    const setGreetingTx = await greeter.setGreeting("Hola, mundo!");

    // wait until the transaction is mined
    await setGreetingTx.wait();

    expect(await greeter.greet()).to.equal("Hola, mundo!");
  });
});


2. console.log

  • truffle에서는 로그를 볼 수 있는 방법이 없었지만, hardhat에서는 console.log 명령어를 제공합니다.
  • .sol 확장자 파일내부에 hardhat/console.log' 를 추가하면, solidity 내부에서console.log` 사용이 가능해집니다.
  • 단위테스트에서도 console.log 부분에 입력한 값이 나오기 때문에 값 확인에 꽤나 도움이 될 것으로 판단됩니다.
Sort:  

@happyberrysboy transfered 50 KRWP to @krwp.burn. voting percent : 84.64%, voting power : 46.13%, steem power : 1864503.68, STU KRW : 1200.
@happyberrysboy staking status : 13840 KRWP
@happyberrysboy limit for KRWP voting service : 13.84 KRWP (rate : 0.001)
What you sent : 50 KRWP
Refund balance : 36.16 KRWP [58511197 - aefba88c670877cb4c1ab1e389584aa47dd650f9]

Coin Marketplace

STEEM 0.33
TRX 0.11
JST 0.034
BTC 66363.68
ETH 3207.73
USDT 1.00
SBD 4.27