the function in the contract is
function withdraw() external onlyOwner { payable(msg.sender).transfer(address(this).balance); }
the test I’ve started is
it('Should withdraw all funds', async () => { const balance = await provider.getBalance(owner.address); expect(ethers.utils.formatEther(await balance.toString())).to.equal( '9999.982579589843532242' ); const setWithdrawTx = await greeter.withdraw(); await setWithdrawTx.wait(); expect(ethers.utils.formatEther(await balance.toString())).to.equal( '19999.9651591797' ); });
and this is how I’m launching the contract
beforeEach(async () => { provider = ethers.provider; [owner, addr1, addr2, ...addresses] = await ethers.getSigners(); const baseFactory = (await ethers.getContractFactory( 'Greeter', owner )) as Greeter__factory; greeter = await baseFactory.deploy('hello'); await greeter.deployed(); });
The error is
AssertionError: expected '9999.982579589843532242' to equal '19999.9651591797'
Will the contract initially have no funds? hence the balance doesn’t change? If so I guess I need a way to send some funds then try to withdraw it? How do I get the address of the balance?