250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- CSS
- JavaScript
- concept
- nextJS
- middleware
- HTML
- solidity
- 삶
- Ethereum
- tailwindcss
- web
- Interface
- hardhat
- Props
- typeScript
- 기준
- useState
- graphQL
- node.js
- evm
- error
- SSR
- REACT
- bitcoin
- express.js
- blockchain
- API
- built in object
- CLASS
- Redux
Archives
- Today
- Total
ReasonJun
Hardhat : loadFixture(), it(), expect() 본문
728x90
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
import { expect } from 'chai';
import { ethers } from 'hardhat';
describe('VendingMachine', function () {
// We define a fixture to reuse the same setup in every test.
// We use loadFixture to run this setup once, snapshot that state,
// and reset Hardhat Network to that snapshot in every test.
async function VendingMachineFixture() {
// Contracts are deployed using the first signer/account by default
const [owner, otherAccount] = await ethers.getSigners();
const VendingMachine = await ethers.getContractFactory('VendingMachine');
const vendingMachine = await VendingMachine.deploy();
return { vendingMachine, owner, otherAccount };
}
describe('VendingMachine', function () {
it('should make 100 cupcake at constructor', async function () {
const { vendingMachine } = await loadFixture(VendingMachineFixture);
expect(
(
await vendingMachine.cupcakeBalances(vendingMachine.address)
).toNumber()
).to.equal(100);
});
});
});
The loadFixture() function is used to load the state that was setup by the VendingMachineFixture() function.
The it() function is used to define a test. In this case, the test is checking that the VendingMachine contract has a correct balance of 100 cupcakes.
The expect() function is used to make assertions about the state of the test. In this case, the expect() function is asserting that the balance of the VendingMachine contract is equal to 100.
728x90
'Blockchain > HardHat' 카테고리의 다른 글
Hardhat : Solidity-coverage (0) | 2023.10.20 |
---|---|
Hardhat : Event filtering (attach, getLogs, topic, Interface, getTransactionReceipt, parseLog) (0) | 2023.10.20 |
Hardhat : .to.emit().withArgs(); (0) | 2023.10.20 |
Hardhat : describe(), Fixture(), ethers.getSigners() (0) | 2023.10.20 |
Hardhat : ethers.getContractFactory() / deploy() / deployed() (1) | 2023.10.20 |
Comments