'confusing contract's balance with externalContract's balance
The total code is here in my gist https://gist.github.com/supersuperrookie/0cd4584c691c88af9aaa43d67fb730cd
I created a smart contract which has the below function,
function execute() public checkExternalStatus checkDeadline(false) {
uint256 balanceAmount = address(this).balance;
require(balanceAmount > threshold, "threshold is not reached");
(bool sent, ) = address(exampleExternalContract).call{
value: balanceAmount
}(abi.encodeWithSignature("complete()"));
require(sent, "exampleExternalContract.complete failed");
}
and when I test this method like this, i do not know why stakerContractbalance is 0 (★)
it('external contract sucessfully completed', async() => {
const amount = ethers.utils.parseEther('1.1');
await stakerContract.connect(addr1).stake({
value :amount,
});
await stakerContract.connect(addr1).execute();
const competed = await exampleExternalContract.completed();
expect(competed).to.equal(true);
const externalBalance = await ethers.provider.getBalance(exampleExternalContract.address);
expect(externalBalance).to.equal(amount);
const stakerContractbalance = await ethers.provider.getBalance(stakerContract.address);
--(★)confuing witch this line(why stakerContractbalance is 0?)
expect(stakerContractbalance).to.equal(0);
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
