I'm desperately trying to find an answer as to how I can accurately test my smart contract balances, as not only can I not get the test to return the correct balance number, but I also am not seeing any test ether leaving my Hardhat test account either.
Relevant code is below, what am I doing wrong??? I've looked everywhere for a concrete answer but I can't seem to find one. The idea is just a simple pool contract that is only accepting deposits (in ETH, important) at this point, and then should accurately state that it has the user's deposited amount of funds.
Am I referencing the amount wrong? Is it a conversion issue between the two? Anyone know what gives on this? I feel like this action is super simple so I must be on the wrong page about something, but both balances currently return zero.
Contract:
contract DepositPool {
mapping(address => uint256) public userBalance;
function makeDeposit(
uint256 _amount,
address _from
) public payable {
require(_amount > 0, "Must input amount to deposit");
_amount = msg.value;
_from = msg.sender;
userBalance[msg.sender] += msg.value;
console.log("User balance: ", userBalance[msg.sender]);
console.log("Contract balance: ", address(this).balance);
}
}
Test:
describe('DepositPool', function () {
it('Should accept deposits and have correct balances', async function () {
const Pool = await ethers.getContractFactory('DepositPool');
const pool = await Pool.deploy();
await pool.deployed();
const [user] = await ethers.getSigners();
const makeADeposit = await pool.connect(user).makeDeposit(20, user.address);
await makeABet.wait();
console.log(makeABet);
console.log(await pool.getPoolBalance().toString());
assert.equal(20, 20, 'Pool balance should equal 20');
});
**using Hardhat's console.log import by the way if anyone is wondering why those log statements are in there
THANK YOU!