hardhat-contract-prompts

hop6·2022년 4월 20일
0

hardhat을 이용해서 smart contarct 테스트를 할 때 사용할만한 라이브러리.
hardhat project directory안 contracts/ 에 Solidity 파일을 넣으면, 해당 smart contract에 대한 메소드를 prompts로 제공해준다.
(현재는 view 태그가 붙은 메소드에 대한 기능만 구현되어 있음)


repo : https://github.com/dbadoy/hardhat-contract-prompts
npm : https://www.npmjs.com/package/hardhat-contract-prompts

Install

Intsall in hardhat project root directory.

npm i hardhat-contract-prompts

Usage

  1. Place solidity code to 'contracts' in hardhat project path.
  2. Import prompt.
import { ViewContractPrompt } from 'hardhat-contract-prompts';
  1. Generate prompt.
const vcp = new ViewContractPrompt();
  1. Set contract name, prompt message.
await vcp.prepare('CONTRACT_NAME', 'my prompts...');
  1. Execute.
// contract -> ethers.Contract
const res = await vcp.executre(contract);
console.log(res);
  1. Run script.
// It doesn't work in 'npx hardhat test'. Use 'hardhat run'.
$ npx hardhat run [script]

Example

Example 1 : Greeter

import { ViewContractPrompt } from './hardhat-prompt';

async function temp() {
    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!");
    await setGreetingTx.wait();

    const vcp = new ViewContractPrompt();
    await vcp.prepare('Greeter', 'greeter test prompts.');

    const res = await vcp.execute(greeter);
    console.log(res);
}

// npx hardhat run test/greeter.ts

Run

스크린샷 2022-04-20 오전 12 55 19 스크린샷 2022-04-20 오전 12 55 36

Example 2 : myERC20

import { ViewContractPrompt } from './hardhat-prompt';

async function temp() {
    const Token = await ethers.getContractFactory("Token");
    const token = await Token.deploy(ethers.utils.parseEther('100000000'), 'MyToken', 'MTK');
    await token.deployed();

    const vcp = new ViewContractPrompt();
    await vcp.prepare('Token', 'Token test prompts.');

    const res = await vcp.execute(token);
    console.log(res);
}

// npx hardhat run test/token.ts

Run

스크린샷 2022-04-20 오전 12 56 00 스크린샷 2022-04-20 오전 12 56 59 스크린샷 2022-04-20 오전 12 57 13 스크린샷 2022-04-20 오전 12 58 01

0개의 댓글