{"id":13421656,"url":"https://github.com/TrueFiEng/Waffle","last_synced_at":"2025-03-15T10:31:17.245Z","repository":{"id":37649535,"uuid":"141097234","full_name":"TrueFiEng/Waffle","owner":"TrueFiEng","description":"Library for writing and testing smart contracts.","archived":false,"fork":false,"pushed_at":"2023-11-22T21:36:56.000Z","size":20342,"stargazers_count":965,"open_issues_count":73,"forks_count":164,"subscribers_count":18,"default_branch":"master","last_synced_at":"2024-12-13T09:37:06.417Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://getwaffle.io","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TrueFiEng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-07-16T06:42:41.000Z","updated_at":"2024-12-06T01:39:28.000Z","dependencies_parsed_at":"2024-01-25T18:06:46.563Z","dependency_job_id":"0dcb22eb-5c4e-4584-ab0f-843c43215f07","html_url":"https://github.com/TrueFiEng/Waffle","commit_stats":{"total_commits":556,"total_committers":77,"mean_commits":7.220779220779221,"dds":0.8651079136690647,"last_synced_commit":"0915e7274093f2a1fb1b2a8be0521470a9f8c2f4"},"previous_names":["ethworks/waffle"],"tags_count":241,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TrueFiEng%2FWaffle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TrueFiEng%2FWaffle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TrueFiEng%2FWaffle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TrueFiEng%2FWaffle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TrueFiEng","download_url":"https://codeload.github.com/TrueFiEng/Waffle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243718919,"owners_count":20336590,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T23:00:27.749Z","updated_at":"2025-03-15T10:31:17.236Z","avatar_url":"https://github.com/TrueFiEng.png","language":"TypeScript","funding_links":[],"categories":["Software Development","TypeScript"],"sub_categories":["Testing"],"readme":"![CI](https://github.com/EthWorks/Waffle/workflows/CI/badge.svg)\n[![](https://img.shields.io/npm/v/ethereum-waffle.svg)](https://www.npmjs.com/package/ethereum-waffle)\n[![Discord](https://badgen.net/badge/icon/discord?icon=discord\u0026label)](https://discord.gg/ppFxC3E44X)\n\n![Ethereum Waffle](https://raw.githubusercontent.com/EthWorks/Waffle/master/docs/source/logo.png)\n\nThe most advanced framework for testing smart contracts.\n\nSweeter, simpler and faster.\n\n## Links\n* Website - https://getwaffle.io/\n* Documentation - https://ethereum-waffle.readthedocs.io/\n\n## Philosophy\n* __Simpler__: Minimalistic, few dependencies.\n* __Sweeter__: Nice syntax, easy to extend.\n* __Faster__: Strong focus on the speed of test execution.\n\n## Features:\n* Sweet set of chai matchers, e.g.:\n  * `expect(...).to.be.revertedWith('Error message')`\n  * `expect(...).to.emit(contract, 'EventName').withArgs(...)`)\n* Importing contracts from npm modules working out of the box, e.g.:\n  * `import \"openzeppelin-solidity/contracts/token/ERC20/ERC20.sol\";`\n* Fixtures that help write fast and maintainable test suites, e.g.:\n  * `const {token} = await loadFixture(standardTokenWithBalance);`\n* Customizable compilation options with native solc, dockerized solc and any version of solc-js loaded remotely at compiled time\n* Mocking smart contracts, e.g.:\n  * `const mockToken = await deployMockContract(wallet, IERC20.abi);`\n* Support for promise-based configuration, e.g.:\n  * use native solc binary for fast compilation in CI environment\n  * use solc-js based on contract versions detected (async)\n* Support for TypeScript\n* Type-safe contract deployment and interactions with TypeChain\n* [Documentation](https://ethereum-waffle.readthedocs.io/en/latest/)\n\n## Documentation\nDocumentation is available [here](https://ethereum-waffle.readthedocs.io/en/latest/).\n\n## Installation:\n\nTo get started install `ethereum-waffle` with yarn:\n```\nyarn add --dev ethereum-waffle\n```\n\nOr if you prefer using npm:\n```\nnpm install --save-dev ethereum-waffle\n```\n\n## Step by step guide\n\n### Add external dependency:\nTo add an external library install it using npm:\n\n```sh\nnpm install @openzeppelin/contracts -D\n```\n\nor with yarn:\n\n```sh\nyarn add @openzeppelin/contracts -D\n```\n\n### Note\n\nFind this example in `examples/basic` and use it.\n\n### Example contract\nBelow is an example contract written in Solidity. Place it in `contracts/BasicToken.sol` file of your project:\n\n```solidity\npragma solidity ^0.6.0;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\n\n// Example class - a mock class using delivering from ERC20\ncontract BasicToken is ERC20 {\n    constructor(uint256 initialBalance) ERC20(\"Basic\", \"BSC\") public {\n        _mint(msg.sender, initialBalance);\n    }\n}\n\n```\n\n### Example test\nBelow is an example test written for the contract above compiled with Waffle. Place it under `test/BasicToken.test.ts` file in your project directory:\n\n```ts\nimport {expect, use} from 'chai';\nimport {Contract} from 'ethers';\nimport {deployContract, MockProvider, solidity} from 'ethereum-waffle';\nimport BasicToken from '../build/BasicToken.json';\n\nuse(solidity);\n\ndescribe('BasicToken', () =\u003e {\n  const [wallet, walletTo] = new MockProvider().getWallets();\n  let token: Contract;\n\n  beforeEach(async () =\u003e {\n    token = await deployContract(wallet, BasicToken, [1000]);\n  });\n\n  it('Assigns initial balance', async () =\u003e {\n    expect(await token.balanceOf(wallet.address)).to.equal(1000);\n  });\n\n  it('Transfer adds amount to destination account', async () =\u003e {\n    await token.transfer(walletTo.address, 7);\n    expect(await token.balanceOf(walletTo.address)).to.equal(7);\n  });\n\n  it('Transfer emits event', async () =\u003e {\n    await expect(token.transfer(walletTo.address, 7))\n      .to.emit(token, 'Transfer')\n      .withArgs(wallet.address, walletTo.address, 7);\n  });\n\n  it('Can not transfer above the amount', async () =\u003e {\n    await expect(token.transfer(walletTo.address, 1007)).to.be.reverted;\n  });\n\n  it('Can not transfer from empty account', async () =\u003e {\n    const tokenFromOtherWallet = token.connect(walletTo);\n    await expect(tokenFromOtherWallet.transfer(wallet.address, 1))\n      .to.be.reverted;\n  });\n\n  it('Calls totalSupply on BasicToken contract', async () =\u003e {\n    await token.totalSupply();\n    expect('totalSupply').to.be.calledOnContract(token);\n  });\n\n  it('Calls balanceOf with sender address on BasicToken contract', async () =\u003e {\n    await token.balanceOf(wallet.address);\n    expect('balanceOf').to.be.calledOnContractWith(token, [wallet.address]);\n  });\n});\n```\n\nNote: You will also need to install the following dependencies to run the example above:\n\n```sh\nyarn add mocha -D\nyarn add chai -D\n```\n\nOr with npm:\n\n```\nnpm i chai -D\nnpm i mocha -D\n```\n\n### Compiling\nTo compile your smart contracts run:\n\n```sh\nnpx waffle\n```\n\nTo compile using a custom configuration file run:\n\n```sh\nnpx waffle config.json\n```\n\nExample configuration file looks like this (all fields optional):\n```json\n{\n  \"sourceDirectory\": \"./custom_contracts\",\n  \"outputDirectory\": \"./custom_build\",\n  \"nodeModulesDirectory\": \"./custom_node_modules\"\n}\n```\n\nTo enable generation of [typechain](https://github.com/ethereum-ts/TypeChain) artifacts:\n```json\n{\n  \"typechainEnabled\": true\n}\n```\n\n### Flattener\nTo flat your smart contracts run:\n\n```sh\nnpx waffle flatten\n```\n\nIn configuration file you can add optional field with path to flatten files:\n```json\n{\n  \"flattenOutputDirectory\": \"./custom_flatten\"\n}\n```\n\n\n\n### Running tests\nTo run the tests run the following command:\n\n```sh\nnpx mocha\n```\n\n### Adding an npm script\nFor convenience, you can add the following to your `package.json`:\n```\n{\n  ...,\n  \"scripts\": {\n    \"test\": \"waffle \u0026\u0026 mocha\"\n  }\n}\n```\n\nNow you can build and test your contracts with one command:\n\n```sh\nnpm test\n```\n\n## Documentation\nFor detailed feature walkthrough checkout [documentation](https://ethereum-waffle.readthedocs.io/en/latest/).\n\n## Contributing\n\nContributions are always welcome, no matter how large or small. Before contributing, please read the [code of conduct](https://github.com/EthWorks/Waffle/blob/master/CODE_OF_CONDUCT.md) and [contribution policy](https://github.com/EthWorks/Waffle/blob/master/CONTRIBUTION.md).\n\nBefore you issue pull request:\n\nMake sure all tests and linters pass.\nMake sure you have test coverage for any new features.\n\n### Running tests\nNote: To make end-to-end test pass, you need to:\n* have Docker installed, up and running\n* have Ethereum stable docker image pulled, if not run `docker pull ethereum/solc:stable`\n* have native solidity 0.5.* installed\n\nTo run tests type:\n```sh\nyarn test\n```\n\nTo run linter type:\n```sh\nyarn lint\n```\n\n### Building documentation\n\n[Install Sphinx](https://www.sphinx-doc.org/en/master/usage/installation.html) to build documentation:\n\n```sh\ncd docs\nmake html\n```\n\nBefore building documentation for the first time you may have to install required python packages:\n```sh\npip3 install -r docs/requirements.txt\n```\n\n## Roadmap\n\nSee https://github.com/EthWorks/Waffle/issues/155\n\n## License\n\nWaffle is released under the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTrueFiEng%2FWaffle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTrueFiEng%2FWaffle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTrueFiEng%2FWaffle/lists"}