İçeriğe geç

Haşimoğlu Tarım Makineleri

Ethereum: How to mock smart contract with hardhat and ethers v6

Spott intelligent contractors with Hardhat and Ethers V6: a guide

If thee of Ethereum intelligent contracts contracts to grow, it is becoming increasingly important to the mock theese contractors. With the latest of the versions of Hardhat (verage 4) and Ethers.js V6, it is it to possible to mock intelligent contracts. In this article we will give exame both opt-step instructions for a.

Nomiclabs/Hardhat waffle: a poplar option

The first is it the Hardhat of Nomiclabs, it is an an-way to tot and the mock intelligent contracts wth Ethers V6. With wth wuffle yu can it tests for the functions of your broadcasting without the act of the contact. This approach is an individual functions or small contractors.

Here is an example of the us of nomiclabs/hardhat waffle:

`Js

Const {Ethers} = demands ('Hardhat');

Async function test martcontraction () {

Const Waffle = Waits Ethers.GetContractory ('MysmartContractor');

Const mockcontraction = Waiting waffle.deploy ();

// Test a certain function

Const Result = expect mockcontraction.myfunction ();

Expect (result) .Be.true;

}

TestMartContract ();

Defi-Wonderland/Smock: A more advanced option

Ethereum: How to mock smart contract with hardhat and ethers v6

The second is Defi-Wonderland/Smock, where offrs a more advanced possibility to the intelligent contracies of Ethers V6. With SMOCK you can create false instance of yours and control your behavior.

Gere is an example of the consume of Defi-Wonderland/Smock:

`Js

Const {Ethers} = demands ('Hardhat');

Const {smock} = request ('@defi-Wonderland/smock');

Async function test martcontraction () {

Const smock = new smock ({{{

Contractdress: '0xmysmartContractdadress',

Network: 'Mainnet', // or 'Wasmbs'

Gasprice: 20,

Gas limit: 200000,

});

Const Contractinstance = expected from Ethers.GetContractory ('MysmartContract'). Deployming ();

Const mockcontraction = waiting smock.createmock (contract instance);

// Test a certain function

Const Result = expect mockcontraction.myfunction ();

Expect (result) .Be.true;

}

TestMartContract ();

Diploma

*

In this article we examined two optings to mock intelligent contracts wth Hardhat and Ethers.js V6. While Nomiclabs/Hardhat-Waffle is a popular solution, Defi-Wonderland/Smock offrs advanced functions to controacter.

When choosing a mocking solution, consister the focusing factors:

  • User -friendlines: How easy is it to set up and use the mock solution?

  • Adaptability: Can you control the behavior of youror contraction use the Mock?

  • Performance: Does the Mock soulk out the performance?

Ultimatly, the choice between noomiclabs/hardhat wuffle and Defi-Wonderland/Smock depends on yours and preferens.

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir