{"_rev":"2-0fdb3b468b52ce7f810d6bc18e11f8c2","time":{"created":"2022-07-27T15:34:10.014Z","1.0.0":"2022-07-27T15:13:52.925Z","modified":"2022-07-27T15:34:10.498Z","1.0.1":"2022-07-27T15:34:10.314Z"},"_id":"@antandrieux/hardhat-test-generator","name":"@antandrieux/hardhat-test-generator","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.1":{"name":"@antandrieux/hardhat-test-generator","author":{"name":"Antoine Andrieux","email":"antoine@avelee.io"},"version":"1.0.1","description":"A unit test generator for the Hardhat framework","bin":{"htg":"generate.js"},"keywords":["solidity","hardhat","test","generator","blockchain","ethereum","polygon"],"homepage":"https://www.linkedin.com/in/antoine-andrieux/","repository":{"type":"git","url":"git+https://github.com/antandrieux/hardhat-test-generator.git"},"license":"MIT","dependencies":{"fs":"0.0.1-security","commander":"^9.2.0","hardhat":"^2.10.1","chai":"^4.3.6"},"bugs":{"url":"https://github.com/antandrieux/hardhat-test-generator/issues"},"main":"generate.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"gitHead":"1df12173d7646de8ff181460aef9c565cdb62a83","_id":"@antandrieux/hardhat-test-generator@1.0.1","_nodeVersion":"16.14.2","_npmVersion":"8.5.0","dist":{"integrity":"sha512-5vnWb0xgKrYPsu2skiRcGGS2nKL6PiNP4NVcSLhodi9jFrRcJJGYclJ1giMofOtFunSVc0rVa816KO2MKAyZUA==","shasum":"1fa70dc2ec16beb31a04f67d995b44a81924c2b6","tarball":"https://registry.npmjs.org/@antandrieux/hardhat-test-generator/-/hardhat-test-generator-1.0.1.tgz","fileCount":4,"unpackedSize":11470,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDIJzdBgXxA8xr6whjuAyGZkxFYHfOJ7WCpLkPH/LcX+AIgdjibl8rAS091qO3M7uk3GGlp9KWyHSdhAQ++k7SP5a4="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi4VryACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpQ5Q//TBIl0kWG5PHz0MLcyhvnxgKI4V5XyfUubafbfFU3vEPYp+l4\r\nVH3FZP6IIQW0XYUYdJq7elhoWjaRSF+8/jvla2HEB2XY2oev8ekRJhPLOPNj\r\nmnC5NsgZ+YKE29dVcegu5PY51R8/Vk952yfqwH6/6ek4XYKMve5kpebY2QTW\r\nMBHyN2dOYRhVZdW3xCATQG0XPMg5qyBKMqDxwSBirOizH3uuDA7zsX8DJMfT\r\nnb3diGnc3AdNBZpYQX63CLJSTYzIhNOqUH31dgCQ31ssVVv4ebDH0snJNMji\r\nZYSxpSPROHn3ZOzRIaTTnpu4/jLhY8T1AupR7hXI7/dSCwnskMDeWKkrs9Wo\r\nbNxvkRDnmOD2OZst3X8X4UE7HQU4QHp4Au61lCpUJUvBRNxPnbw4OawVWDhg\r\nVWHumc/PZIVzSH1b23C3z42Ord2JG39Ha3QW97HSs1zX3kQSlvq/RjFKjXcP\r\nK+LBlV0L6nGl/2HOu1zxBaMWUwvONRqhnOfBrcT147wGr6jiFBs6Bdv04MNc\r\ngLhQUUlUHBviOn+B2yMD62ZJ1nOKldkRoqPPdKgt8uQWxb/3CtAgQq0Yc+Xj\r\ncgG9dP+2W8GSfedsO07aXtzW2QG379Qi/CCRQSKkUgWZon40/FQV9njLbuF2\r\nXWC8rV28DqvC53Q22gjMZMHzEHSMW3abYiU=\r\n=/12x\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"antandrieux","email":"antoine_andrieux@hotmail.com"},"directories":{},"maintainers":[{"name":"antandrieux","email":"antoine_andrieux@hotmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hardhat-test-generator_1.0.1_1658936050134_0.07261765755200877"},"_hasShrinkwrap":false}},"maintainers":[{"name":"antandrieux","email":"antoine_andrieux@hotmail.com"}],"description":"A unit test generator for the Hardhat framework","homepage":"https://www.linkedin.com/in/antoine-andrieux/","keywords":["solidity","hardhat","test","generator","blockchain","ethereum","polygon"],"repository":{"type":"git","url":"git+https://github.com/antandrieux/hardhat-test-generator.git"},"author":{"name":"Antoine Andrieux","email":"antoine@avelee.io"},"bugs":{"url":"https://github.com/antandrieux/hardhat-test-generator/issues"},"license":"MIT","readme":"# Hardhat Test Generator\n\nA utility to create new unit tests files in a Hardhat project.\n\nThis provides a baseline for writing your own unit tests by listing all public (or external) functions with all their arguments. The goal is to speed up the initialization process of unit tests and not to miss any function in smart contracts.\n\n## Install\n\n```\nnpm i @antandrieux/hardhat-test-generator --save-dev\n```\n\n## Usage\n\nFirst use Hardhart to compile your contracts.\n\n```\nhardhat compile\n```\n\nGenerate tests for all contracts in your contract folder.\n\n```\nnpx htg\n```\n\nGenerate tests for a specific contract named MyContract from the file.\n\n```\nnpx htg -c MyContract\n```\n\n_Replace MyContract with the name of the contract for which you want to create tests._\n\n## How It Works\n\nThe test generator will look at the json files located in the `./build/contracts` directory for the given contract name. As long as that contract exists and has been compiled, a test file will be created for it.\n\nEach test will include a standard template for the beginning of the file, which includes the test declaration of the contract and the definition of some common account variables.\n\n```javascript\ndescribe('MyContract', (accounts) => {\n  const CONTRACT_NAME = 'MyContract';\n```\n\nBy reading the contract json file, it will also import the contract, generate input parameters for your builder. However, it will be up to you to update the values as your contract requires.\n\n```javascript\nbeforeEach(async () => {\n\t[owner, account1, account2, account3] = await ethers.getSigners();\n\n\tconst MyContract = await ethers.getContractFactory(CONTRACT_NAME);\n\n\t// To change\n\tconst _constructorParam_1 = 'example_value_respecting_type';\n\tconst _constructorParam_2 = 'example_value_respecting_type';\n\n\tmyContract = await MyContract.deploy(\n\t\t_constructorParam_1,\n\t\t_constructorParam_2\n\t);\n\tawait myContract.deployed();\n});\n```\n\nAll inherited contracts with external or public functions will have a test feature (as a `describe` block) created for it, with all their arguments.\n\n```javascript\ndescribe('Test setValue', async () => {\n\tit('Should test setValue', async () => {\n\t\tlet _firstParam = 'example_value_respecting_type';\n\t\tlet _secondParam = 'example_value_respecting_type';\n\t\tawait myContract.connect(owner).setValue(_firstParam, _secondParam);\n\t});\n});\n```\n\nThis allows you to easily have a structure for your tests and to make sure that every external/public method will be tested, provided you write a test for it.\n\nThe test file will be placed in the `test` directory of your Hardhat project and named `MyContract.test.js`, where MyContract is the name of the contract. To prevent a user from accidentally deleting an existing file, you can use the `--new` option to add a new version of the test file. Otherwise the file will be overwritten.\n\n## FYI\n\n1. The library ignores files that start with _I_, we consider them as interfaces and we don't want to test them.\n2. The library needs the file names to have the same name as the contract names.\n\n## Contributions & future\n\nAny improvement is welcome. Anyone can create a issue and propose something.\n\nIn the future, we would like to improve this library with more intelligent testing by getting information and typical vulnerabilities from another library that does static analysis (e.g. Slither).\n\nIf you are interested, please contact us, and we will discuss about it.\n\nContact to:\n\n- [My LinkedIn](https://www.linkedin.com/in/antoine-andrieux/)\n- My Discord: AntoineAdx#1429\n","readmeFilename":"README.md"}