|
| 1 | +# Waffle example |
| 2 | + |
| 3 | +Simple scripts for testing matchers provided by Waffle tool. |
| 4 | + |
| 5 | +## Configuration |
| 6 | + |
| 7 | +Create `.env` file based on `.env.example` |
| 8 | + |
| 9 | +``` |
| 10 | +OPERATOR_PRIVATE_KEY= |
| 11 | +RELAY_ENDPOINT= |
| 12 | +``` |
| 13 | + |
| 14 | + - `OPERATOR_PRIVATE_KEY` is your account ECDSA hex-encoded private key. |
| 15 | + - `RELAY_ENDPOINT` is a path to your JSON RPC Api. `https://testnet.hashio.io/api` for testnet. Remember to start your Hedera local node if you want to use the http://localhost:7546 endpoint. |
| 16 | + |
| 17 | +## Setup & Install |
| 18 | + |
| 19 | +In the project directory: |
| 20 | +1. Run `npm install` |
| 21 | +2. Run `npm run build` |
| 22 | +2. Run `npm run test` |
| 23 | + |
| 24 | +# Waffle |
| 25 | +[Waffle](https://ethereum-waffle.readthedocs.io/) is a library designed for testing Smart Contracts. |
| 26 | + |
| 27 | +#### Features |
| 28 | + |
| 29 | +Waffle provides several features that enhance the testing experience for developers: |
| 30 | + |
| 31 | +- Includes new Chai matchers specifically designed for Smart Contract testing. |
| 32 | +- Enables the use of mocked wallets and Smart Contracts for isolated and controlled testing environments. |
| 33 | +- Allows the use of fixtures to define reusable setups for tests, reducing boilerplate code and simplifying complex test setups. |
| 34 | + |
| 35 | +#### Dependencies |
| 36 | + |
| 37 | +Waffle uses **ethers.js** to perform operations such as deploying Smart Contracts and sending transactions. It leverages **Mocha** and **Chai** as the foundational testing tools, while adding its own custom matchers tailored for Smart Contracts. |
| 38 | + |
| 39 | +## Installation: |
| 40 | +To install Waffle, you need to add the `ethereum-waffle` node module to your project. You can do this using the following command: |
| 41 | + |
| 42 | +```shell |
| 43 | +npm install --save-dev ethereum-waffle |
| 44 | +``` |
| 45 | + |
| 46 | +## Hedera Smart Contracts Development |
| 47 | + |
| 48 | +Waffle utilizes `ethers.js` to communicate with the JSON-RPC API. |
| 49 | + |
| 50 | +A sample usage is documented in this [example](https://github.com/hashgraph/hedera-json-rpc-relay/tree/main/tools/hardhat-example). |
| 51 | + |
| 52 | +Both [contract deployment](https://github.com/hashgraph/hedera-json-rpc-relay/blob/main/tools/hardhat-example/scripts/deployContract.js) and [calls](https://github.com/hashgraph/hedera-json-rpc-relay/blob/main/tools/hardhat-example/scripts/contractCall.js) are performed using `ethers.js` in the same way Waffle does. |
| 53 | + |
| 54 | +The [Chai matchers](https://ethereum-waffle.readthedocs.io/en/latest/matchers.html) provided by Waffle are not dependent on any specific network. They can be used to easily detect common scenarios in Smart Contract testing, such as whether an event was emitted by the Smart Contract or if an operation was reverted. |
| 55 | + |
| 56 | +There are also matchers for Chai that test raw strings such as addresses and keys. These matchers assume that only ECDSA keys are correct. |
| 57 | + |
| 58 | +However, the mocks provided by Waffle are designed to simulate Ethereum network behavior, which means they may not replicate some Hedera-specific traits, such as `ecrecover` behavior for non-ECDSA keys or after private key changes. The wallet mock will only support wallets utilizing ECDSA keys. |
| 59 | + |
| 60 | +The mock Waffle provider allows users to imitate basic ENS operations, such as registering domains and retrieving the address of a domain. The Hedera Name Service (HNS) at its core level provides similar functionalities, so this mock can be used as its replacement. |
| 61 | + |
| 62 | +### Known issues |
| 63 | + |
| 64 | +Waffle fixtures are not supported, more information: https://github.com/hashgraph/hedera-smart-contracts/issues/702 |
0 commit comments