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
Intsall in hardhat project root directory.
npm i hardhat-contract-prompts
import { ViewContractPrompt } from 'hardhat-contract-prompts';
const vcp = new ViewContractPrompt();
await vcp.prepare('CONTRACT_NAME', 'my prompts...');
// contract -> ethers.Contract
const res = await vcp.executre(contract);
console.log(res);
// It doesn't work in 'npx hardhat test'. Use 'hardhat run'.
$ npx hardhat run [script]
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
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