im trying to test a constructor method of a exchange developed in solidity but i given the following error:
Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="VM Exception while processing transaction: reverted with reason string 'Invalid address _tokenVault'", method="estimateGas", transaction={"from":"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266","data":"0x60806040523480156200001157600080fd5b5060405162001dba38038062001dba833981810160405281019062000037919062000239565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1603620000a9576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401620000a090620002f6565b60405180910390fd5b33600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555082600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555081600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508060058190555060126000819055506003600181905550600060068190555050505062000318565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000620001c68262000199565b9050919050565b620001d881620001b9565b8114620001e457600080fd5b50565b600081519050620001f881620001cd565b92915050565b6000819050919050565b6200021381620001fe565b81146200021f57600080fd5b50565b600081519050620002338162000208565b92915050565b60008060006060848603121562000255576200025462000194565b5b60006200026586828701620001e7565b93505060206200027886828701620001e7565b92505060406200028b8682870162000222565b9150509250925092565b600082825260208201905092915050565b7f496e76616c69642061646472657373205f746f6b656e5661756c740000000000600082015250565b6000620002de601b8362000295565b9150620002eb82620002a6565b602082019050919050565b600060208201905081810360008301526200031181620002cf565b9050919050565b611a9280620003286000396000f3fe608060405234801561001057600080fd5b50600436106100f55760003560e01c8063a8f6c91311610097578063d0e30db011610066578063d0e30db01461028c578063e4828367146102aa578063e6aa216c146102da578063f071db5a146102f8576100f5565b8063a8f6c913146101f0578063ae06c1b71461020e578063b03a9a051461023e578063bda6606c1461025c576100f5565b80636497a8a0116100d35780636497a8a0146101665780638da5cb5b146101965780639902084b146101b4578063a001ecdd146101d2576100f5565b80632d296bf1146100fa578063313ce5671461012a5780635bc789d914610148575b600080fd5b610114600480360381019061010f9190611254565b610316565b6040516101219190611290565b60405180910390f35b6101326105ec565b60405161013f9190611290565b60405180910390f35b6101506105f2565b60405161015d91906112ec565b60405180910390f35b610180600480360381019061017b9190611333565b610618565b60405161018d9190611290565b60405180910390f35b61019e61089a565b6040516101ab91906112ec565b60405180910390f35b6101bc6108c0565b6040516101c99190611290565b60405180910390f35b6101da6109f8565b6040516101e79190611290565b60405180910390f35b6101f86109fe565b60405161020591906112ec565b60405180910390f35b61022860048036038101906102239190611254565b610a24565b6040516102359190611290565b60405180910390f35b610246610b09565b6040516102539190611290565b60405180910390f35b61027660048036038101906102719190611254565b610b0f565b6040516102839190611290565b60405180910390f35b610294610b81565b6040516102a19190611290565b60405180910390f35b6102c460048036038101906102bf9190611254565b610e46565b6040516102d19190611290565b60405180910390f35b6102e26111d6565b6040516102ef9190611290565b60405180910390f35b61030061120b565b60405161030d9190611290565b60405180910390f35b600080821161035a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610351906113bd565b60405180910390fd5b3073ffffffffffffffffffffffffffffffffffffffff1663bda6606c836040518263ffffffff1660e01b81526004016103939190611290565b6020604051808303816000875af11580156103b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103d691906113f2565b6103de611211565b101561041f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104169061146b565b60405180910390fd5b600060646001548461043191906114ba565b61043b919061152b565b90506000818461044b919061155c565b9050816006600082825461045f9190611590565b9250508190555080600560008282546104789190611590565b92505081905550600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb33836040518363ffffffff1660e01b81526004016104dc9291906115c4565b600060405180830381600087803b1580156104f657600080fd5b505af115801561050a573d6000803e3d6000fd5b505050503373ffffffffffffffffffffffffffffffffffffffff166108fc3073ffffffffffffffffffffffffffffffffffffffff1663bda6606c876040518263ffffffff1660e01b81526004016105619190611290565b6020604051808303816000875af1158015610580573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105a491906113f2565b6105ac611211565b6105b6919061155c565b9081150290604051600060405180830381858888f193505050501580156105e1573d6000803e3d6000fd5b508092505050919050565b60005481565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610688576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161067f90611639565b60405180910390fd5b60008273ffffffffffffffffffffffffffffffffffffffff163b146106e2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106d9906116a5565b60405180910390fd5b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610772576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161076990611711565b60405180910390fd5b6000600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f8b2cb4f846040518263ffffffff1660e01b81526004016107cf91906112ec565b602060405180830381865afa1580156107ec573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061081091906113f2565b11610850576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108479061177d565b60405180910390fd5b81600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060019050919050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610952576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161094990611711565b60405180910390fd5b6706f05b59d3b20000600654101561099f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610996906117e9565b60405180910390fd5b60006006819055503373ffffffffffffffffffffffffffffffffffffffff166108fc6006549081150290604051600060405180830381858888f193505050501580156109ef573d6000803e3d6000fd5b50600654905090565b60015481565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000808211610a68576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a5f90611855565b60405180910390fd5b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610af8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610aef90611711565b60405180910390fd5b816001819055506001549050919050565b60055481565b6000808211610b53576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b4a906118c1565b60405180910390fd5b6000600554670de0b6b3a764000084610b6c91906114ba565b610b76919061152b565b905080915050919050565b6000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610c13576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c0a90611711565b60405180910390fd5b6000600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f8b2cb4f336040518263ffffffff1660e01b8152600401610c7091906112ec565b602060405180830381865afa158015610c8d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cb191906113f2565b03610cf1576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ce89061192d565b60405180910390fd5b60003073ffffffffffffffffffffffffffffffffffffffff1663bda6606c610d17611211565b6040518263ffffffff1660e01b8152600401610d339190611290565b6020604051808303816000875af1158015610d52573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d7691906113f2565b90508060056000828254610d8a9190611590565b92505081905550600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16836040518363ffffffff1660e01b8152600401610e109291906115c4565b600060405180830381600087803b158015610e2a57600080fd5b505af1158015610e3e573d6000803e3d6000fd5b505050505090565b6000808211610e8a576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e8190611999565b60405180910390fd5b81600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663f8b2cb4f336040518263ffffffff1660e01b8152600401610ee691906112ec565b602060405180830381865afa158015610f03573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f2791906113f2565b1015610f68576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f5f90611a05565b60405180910390fd5b6000606460015484610f7a91906114ba565b610f84919061152b565b905060008184610f94919061155c565b9050600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663095ea7b333836040518363ffffffff1660e01b8152600401610ff39291906115c4565b600060405180830381600087803b15801561100d57600080fd5b505af1158015611021573d6000803e3d6000fd5b50505050600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166323b872dd33600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16846040518463ffffffff1660e01b81526004016110a693929190611a25565b600060405180830381600087803b1580156110c057600080fd5b505af11580156110d4573d6000803e3d6000fd5b5050505081600660008282546110ea9190611590565b925050819055508060056000828254611103919061155c565b925050819055503373ffffffffffffffffffffffffffffffffffffffff166108fc3073ffffffffffffffffffffffffffffffffffffffff1663bda6606c846040518263ffffffff1660e01b815260040161115d9190611290565b6020604051808303816000875af115801561117c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111a091906113f2565b9081150290604051600060405180830381858888f193505050501580156111cb573d6000803e3d6000fd5b508092505050919050565b600080670de0b6b3a7640000600554670de0b6b3a76400006111f891906114ba565b611202919061152b565b90508091505090565b60065481565b600034905090565b600080fd5b6000819050919050565b6112318161121e565b811461123c57600080fd5b50565b60008135905061124e81611228565b92915050565b60006020828403121561126a57611269611219565b5b60006112788482850161123f565b91505092915050565b61128a8161121e565b82525050565b60006020820190506112a56000830184611281565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006112d6826112ab565b9050919050565b6112e6816112cb565b82525050565b600060208201905061130160008301846112dd565b92915050565b611310816112cb565b811461131b57600080fd5b50565b60008135905061132d81611307565b92915050565b60006020828403121561134957611348611219565b5b60006113578482850161131e565b91505092915050565b600082825260208201905092915050565b7f496e76616c6964205f616d6f756e74546f4275792076616c7565000000000000600082015250565b60006113a7601a83611360565b91506113b282611371565b602082019050919050565b600060208201905081810360008301526113d68161139a565b9050919050565b6000815190506113ec81611228565b92915050565b60006020828403121561140857611407611219565b5b6000611416848285016113dd565b91505092915050565b7f496e73756666696369656e742065746865727300000000000000000000000000600082015250565b6000611455601383611360565b91506114608261141f565b602082019050919050565b6000602082019050818103600083015261148481611448565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006114c58261121e565b91506114d08361121e565b92508282026114de8161121e565b915082820484148315176114f5576114f461148b565b5b5092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b60006115368261121e565b91506115418361121e565b925082611551576115506114fc565b5b828204905092915050565b60006115678261121e565b91506115728361121e565b925082820390508181111561158a5761158961148b565b5b92915050565b600061159b8261121e565b91506115a68361121e565b92508282019050808211156115be576115bd61148b565b5b92915050565b60006040820190506115d960008301856112dd565b6115e66020830184611281565b9392505050565b7f496e76616c69642061646472657373205f746f6b656e5661756c740000000000600082015250565b6000611623601b83611360565b915061162e826115ed565b602082019050919050565b6000602082019050818103600083015261165281611616565b9050919050565b7f5f746f6b656e5661756c742063616e6e6f74206265206120636f6e7472616374600082015250565b600061168f602083611360565b915061169a82611659565b602082019050919050565b600060208201905081810360008301526116be81611682565b9050919050565b7f4e6f74206175746f72697a656400000000000000000000000000000000000000600082015250565b60006116fb600d83611360565b9150611706826116c5565b602082019050919050565b6000602082019050818103600083015261172a816116ee565b9050919050565b7f5f746f6b656e5661756c7420686173206e6f2062616c616e6365000000000000600082015250565b6000611767601a83611360565b915061177282611731565b602082019050919050565b600060208201905081810360008301526117968161175a565b9050919050565b7f496e73756666696369656e7420616d6f756e74206f6620666565730000000000600082015250565b60006117d3601b83611360565b91506117de8261179d565b602082019050919050565b60006020820190508181036000830152611802816117c6565b9050919050565b7f496e76616c6964205f70657263656e746167652076616c756500000000000000600082015250565b600061183f601983611360565b915061184a82611809565b602082019050919050565b6000602082019050818103600083015261186e81611832565b9050919050565b7f496e76616c6964205f746f6b656e416d6f756e742076616c7565000000000000600082015250565b60006118ab601a83611360565b91506118b682611875565b602082019050919050565b600060208201905081810360008301526118da8161189e565b9050919050565b7f4e6f20657468657273206465706f736974656400000000000000000000000000600082015250565b6000611917601383611360565b9150611922826118e1565b602082019050919050565b600060208201905081810360008301526119468161190a565b9050919050565b7f496e76616c6964205f616d6f756e74546f457863686167652076616c75650000600082015250565b6000611983601e83611360565b915061198e8261194d565b602082019050919050565b600060208201905081810360008301526119b281611976565b9050919050565b7f496e73756666696369656e742062616c616e6365000000000000000000000000600082015250565b60006119ef601483611360565b91506119fa826119b9565b602082019050919050565b60006020820190508181036000830152611a1e816119e2565b9050919050565b6000606082019050611a3a60008301866112dd565b611a4760208301856112dd565b611a546040830184611281565b94935050505056fea2646970667358221220ffad1a9439d9834abe467db3f1382023c0dc5f0f1296ff9a6bd076af0f22edd464736f6c6343000811003300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a","accessList":null}, error={"stackTrace":[{"type":4,"sourceReference":{"function":"constructor","contract":"Exchange","sourceName":"contracts/Exchange.sol","sourceContent":"//SPDX-License-Identifier: MIT\npragma solidity 0.8.17;\nimport "./interface/IExchange.sol";\nimport "./interface/IERC20.sol";\n\ncontract Exchange is IExchange {\n\n uint256 public decimals;\n uint256 public feePercentage;\n address public owner;\n address public tokenVault;\n address public erc20Contract;\n uint256 public invariant;\n uint256 public feesCollected;\n\n/\n* @notice Constructor\n* @dev Throw if '_tokenVault' is zero address\n* @dev Throw if '_tokenVault' is a contract\n* @dev Throw if '_erc20Contract' is zero address\n* @dev Throw if '_erc20Contract' is not a contract\n* @dev Throw if '_tokenAmount' is zero\n* @dev Throw if '_tokenVault' doesn't have enough balance\n* @param _tokenVault Address of the token vault\n* @param _erc20Contract Address of the ERC20 contract\n* @param _tokenAmount Amount of tokens to be deposited in the vault\n */\nconstructor(address _tokenVault, address _erc20Contract,uint256 _tokenAmount ){\n require(_tokenVault != address(0), "Invalid address _tokenVault");\n // require(_tokenVault.code.length==0, "_tokenVault cannot be a contract");\n //require(_erc20Contract != address(0), "_erc20Contract cannot be zero address");\n // require(_erc20Contract.code.length>0, "_erc20Contract is not a contract");\n // require(_tokenAmount > 0, "Invalid _tokenAmount value");\n // require(IERC20(_erc20Contract).getBalance(_tokenVault) >= _tokenAmount, "Insufficient tokens in the vault");\n owner = msg.sender;\n tokenVault = _tokenVault;\n erc20Contract = _erc20Contract;\n invariant = _tokenAmount;\n decimals = 18;\n feePercentage = 3;\n feesCollected = 0;\n}\n\n\n //auxiliaries\n function getValue() internal view returns (uint256) {\n return msg.value;\n }\n\n \n /\n * @notice calculate Ether Amount \n * @dev Throw if '_tokenAmount' is zero\n * @param _tokenAmount Amount of tokens to be exchanged\n */\n function calculateEtherAmount(uint256 _tokenAmount) external override returns (uint256)\n { \n require(_tokenAmount > 0, "Invalid _tokenAmount value");\n uint256 etherAmount = (_tokenAmount * 1 ether) / invariant;\n return etherAmount; \n }\n\n /\n * @notice returns the quantity of tokens that can be obtained for an ether at the moment of the query\n */\n function getExchangeRate() external override returns (uint256) {\n uint256 tokenAmount = (1 ether * invariant) / 1 ether;\n return tokenAmount;\n }\n\n /\n * @notice Buy tokens\n * @dev Throw if '_amountToBuy' is zero \n * @dev Thorw if 'msg.value' is less than '_amountToBuy'\n * @param _amountToBuy Amount of tokens to be bought\n */\n function buyToken(uint256 _amountToBuy) external override returns (uint256)\n {\n require(_amountToBuy > 0, "Invalid _amountToBuy value");\n require(getValue()>=this.calculateEtherAmount(_amountToBuy),"Insufficient ethers");\n uint256 fee = (_amountToBuy * feePercentage) / 100;\n uint256 amountToTransfer = _amountToBuy - fee;\n feesCollected = fee;\n invariant = amountToTransfer;\n IERC20(erc20Contract).transfer(msg.sender, amountToTransfer);\n payable(msg.sender).transfer(getValue()-this.calculateEtherAmount(_amountToBuy));\n return amountToTransfer;\n }\n\n /\n * @notice Buy ethers\n * @dev Throw if '_amountToExchange' is zero\n * @param _amountToExchange Amount of tokens to be exchanged\n */\n function buyEther(uint256 _amountToExchange) external override returns (uint256)\n {\n require(_amountToExchange > 0, "Invalid _amountToExchage value");\n require(IERC20(erc20Contract).getBalance(msg.sender) >=_amountToExchange,"Insufficient balance");\n uint256 fee = (_amountToExchange * feePercentage) / 100;\n uint256 amountToTransfer = _amountToExchange - fee;\n IERC20(erc20Contract).approve(msg.sender, amountToTransfer);\n IERC20(erc20Contract).transferFrom(msg.sender,tokenVault,amountToTransfer);\n feesCollected = fee;\n invariant -= amountToTransfer;\n\n payable(msg.sender).transfer(this.calculateEtherAmount(amountToTransfer));\n return amountToTransfer;\n }\n\n /\n * @notice Set fee percentage\n * @dev Throw if '_percentage' is zero\n * @dev Throw if 'msg.sender' is not the owner\n * @param _percentage Percentage of fee\n */\n function setFeePercentage(uint256 _percentage) external override returns (uint256)\n {\n require(_percentage > 0, "Invalid _percentage value");\n require(msg.sender == owner, "Not autorized");\n feePercentage = _percentage;\n return feePercentage;\n }\n\n /\n * @notice Deposit ethers\n * @dev Throw if 'msg.value' is zero\n * @dev Throw if 'msg.sender' is not the owner\n */\n\n function deposit() external override returns (uint256) {\n require(msg.sender == owner, "Not autorized");\n require (IERC20(erc20Contract).getBalance(msg.sender)!=0, "No ethers deposited");\n uint256 amountToTransfer = this.calculateEtherAmount(getValue());\n invariant = amountToTransfer;\n IERC20(erc20Contract).transfer(tokenVault, amountToTransfer);\n }\n\n\n /\n * @notice Set token vault\n * @dev Throw if '_tokenVault' is zero\n * @dev Throw if '_tokenVault' is a contract\n * @dev Throw if 'msg.sender' is not the owner\n * @dev Throw if '_tokenVault' has no balance\n * @dev Throw if '_tokenVault' has no authorization\n * @param _tokenVault Address of the token vault\n */\n function setTokenVault(address _tokenVault) external override returns (uint256)\n {\n require(_tokenVault != address(0), "Invalid address _tokenVault");\n require (_tokenVault.code.length==0, "_tokenVault cannot be a contract");\n require(msg.sender == owner, "Not autorized");\n require(IERC20(erc20Contract).getBalance(_tokenVault) > 0, "_tokenVault has no balance");\n tokenVault = _tokenVault;\n return 1;\n }\n\n /**\n * @notice Withdraw fees\n * @dev Throw if 'msg.sender' is not the owner\n * @dev Throw if 'feesCollected' is less than 0.5 ethers\n */\n function withdrawFeesAmount() external override returns (uint256) {\n require(msg.sender == owner, "Not autorized");\n require(feesCollected >= 0.5 ether, "Insufficient amount of fees");\n feesCollected = 0;\n payable(msg.sender).transfer(feesCollected);\n return feesCollected;\n }\n}\n","line":29,"range":[950,1015]},"message":{"value":{"type":"Buffer","data":[8,195,121,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,27,73,110,118,97,108,105,100,32,97,100,100,114,101,115,115,32,95,116,111,107,101,110,86,97,117,108,116,0,0,0,0,0]},"_selector":"08c379a0"},"isInvalidOpcodeError":false}],"data":"0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001b496e76616c69642061646472657373205f746f6b656e5661756c740000000000"}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.6.8) at Logger.makeError (node_modules/@ethersproject/logger/src.ts/index.ts:261:28) at Logger.throwError (node_modules/@ethersproject/logger/src.ts/index.ts:273:20) at checkError (node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:78:20) at EthersProviderWrapper. (node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:603:20) at step (node_modules/@ethersproject/providers/lib/json-rpc-provider.js:48:23) at Object.throw (node_modules/@ethersproject/providers/lib/json-rpc-provider.js:29:53) at rejected (node_modules/@ethersproject/providers/lib/json-rpc-provider.js:21:65) at processTicksAndRejections (internal/process/task_queues.js:95:5) at runNextTicks (internal/process/task_queues.js:64:3) at listOnTimeout (internal/timers.js:526:9)
the test code:
const { ethers } = require("hardhat");
const chai = require("chai");
const { solidity } = require( "ethereum-waffle");
const { ConstructorFragment } = require("ethers/lib/utils");
chai.use(solidity);
const { expect } = chai;
const EchangePath = "contracts/Exchange.sol:Exchange";
const confirmations_number = 1;
const zeroAddress = '0x0000000000000000000000000000000000000000';
let contractInstance;
// Constructor parameters
const decimals = 18 ;
const feePercentage = 1 ;
const owner = '0x0000000000000000000000000000000000000000';
const tokenVault = '0x0000000000000000000000000000000000000000';
const erc20Contract = '0x0000000000000000000000000000000000000000';
const invariant = 1 ;
const feesCollected = 0 ;
const tokenAmount = 10;
describe("Echange tests", () => {
beforeEach(async () => {
console.log("-----------------------------------------------------------------------------------");
console.log(" -- Exchange tests start");
console.log("-----------------------------------------------------------------------------------");
[signer, account1, account2, account3] = await ethers.getSigners();
provider = ethers.provider;
// Deploy Exchange contract
const Exchange = await ethers.getContractFactory(EchangePath, signer);
contractInstance = await Exchange.deploy(
tokenVault,
erc20Contract,
tokenAmount
);
});
describe("Constructor tests", () => {
it("Try send invalid tokenValue address", async () => {
const Exchange = await ethers.getContractFactory(EchangePath, signer);
await expect(
Exchange.deploy(
zeroAddress,
erc20Contract,
tokenAmount,
{ gas: 1000000, gasPrice: 1000000000,gasLimit:1000000 , from: owner}
)
).to.be.revertedWith("Invalid token address");
});
});
the exchange code:
//SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
import "./interface/IExchange.sol";
import "./interface/IERC20.sol";
contract Exchange is IExchange {
uint256 public decimals;
uint256 public feePercentage;
address public owner;
address public tokenVault;
address public erc20Contract;
uint256 public invariant;
uint256 public feesCollected;
constructor(address _tokenVault, address _erc20Contract,uint256 _tokenAmount ){
require(_tokenVault != address(0), "Invalid address _tokenVault");
require(_tokenVault.code.length==0, "_tokenVault cannot be a contract");
require(_erc20Contract != address(0), "_erc20Contract cannot be zero address");
require(_erc20Contract.code.length>0, "_erc20Contract is not a contract");
require(_tokenAmount > 0, "Invalid _tokenAmount value");
require(IERC20(_erc20Contract).getBalance(_tokenVault) >= _tokenAmount, "Insufficient tokens in the vault");
owner = msg.sender;
tokenVault = _tokenVault;
erc20Contract = _erc20Contract;
invariant = _tokenAmount;
decimals = 18;
feePercentage = 3;
feesCollected = 0;
}
I tried commenting the requires and it did not return the error.Also i tried deploy without the line :
{ gas: 1000000, gasPrice: 1000000000,gasLimit:1000000 , from: owner}
CodePudding user response:
If you look closely the error is more like "Invalid address _tokenVault".
If you look into your tests, the error is coming from the beforeEach() under the comment // Deploy Exchange contract There you are trying to invoke the deploy method which is outside the test. Here is the updated test method.
describe("Echange tests", () => {
beforeEach(async () => {
console.log("-----------------------------------------------------------------------------------");
console.log(" -- Exchange tests start");
console.log("-----------------------------------------------------------------------------------");
[signer, account1, account2, account3] = await ethers.getSigners();
provider = ethers.provider;
});
describe("Constructor tests", () => {
it("Try send invalid tokenValue address", async () => {
const Exchange = await ethers.getContractFactory(EchangePath, signer);
const transactionPromise = Exchange.deploy(
zeroAddress,
erc20Contract,
tokenAmount
)
await expect(
transactionPromise
).to.be.revertedWith("Invalid address _tokenVault");
});
})
});