wighawag / hardhat-deploy

hardhat deployment plugin
MIT License
1.2k stars 296 forks source link

How do I test my contract's constructor? #330

Open colinsteidtmann opened 2 years ago

colinsteidtmann commented 2 years ago

I want to test that state variables are changed after creating a new contract with constructor arguments and setting state variables inside the constructor. I want to do something like openzeppelin's ERC20Mock.new(args..). (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/test/token/ERC20/ERC20.test.js#L23) inside of a test file. However, deployments.fixture doesn't accept deployment arguments I can pass in. What should I do?

dcamps-hacken commented 2 years ago

Hi!

I don't know why you want to use that specific method... I would suggest you do it like this:

wighawag commented 2 years ago

you can create a specific fixture that deploy a specifically configured contract instance.

the deploy fixture are meant to be used to test the deployment itself, so you would not want to configure it

Sceat commented 2 years ago

Also stated in https://github.com/wighawag/hardhat-deploy/issues/289, it would be really useful to be able to pass constructor arguments when loading fixtures, sometime we may need to test the contract with specific arguments.

await deployments.fixture()
await deployments.fixture({ 'myContract': [...args] })

Imagine you have a addresses Leaderboard contract and to test it you need real signers as players. It would be preferable to deploy it with a length of 2 for the tests so that you need 2 signers, and with a length of 100 in production.

for now we have to write a deploy script for each testing case when it comes to arguments

wighawag commented 2 years ago

@Sceat for the case you mention you could read the number of signers from a different file for test network, You can also add tags to network so you can differentiate between test network and real network programmatically.