Errors when writing tests #867
Replies: 4 comments 6 replies
-
This is my test write up const { ethers } = require("hardhat")
const { expect, assert } = require("chai")
describe("EtherWallet", function () {
let etherWallet
let etherWalletFactory
//let etherWallet, etherWalletFactory
beforeEach(async function () {
const etherWalletFactory = await ethers.getContractFactory(
"etherWallet"
)
const etherWallet = await etherWalletFactory.deploy()
})
it("should start with a deposit", async function () {
const currentValue = await etherWallet.deposit()
//assert
//expect
assert.equal(currentValue.toString(), expectedValue)
// expect(currentValue.toString()).to.equal(expectedValue)
})
it("Should update when we call getBalance", async function () {
const expectedValue = 0
const transactionResponse = await etherWallet.getBalance(expectedValue)
await transactionResponse.wait(1)
const currentValue = await etherWallet.deposit()
assert.equal(currentValue.toString(), expectedValue)
})
}) |
Beta Was this translation helpful? Give feedback.
-
And my contract //SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract etherWallet {
event Deposit(address from, uint256 amount, uint256 balance);
event Withdrawal(uint256 amount, uint256 balance);
event Transfer(address from, address to, uint256 balance);
address public owner;
constructor() payable {
owner = msg.sender;
}
function deposit() public payable {
emit Deposit(msg.sender, msg.value, address(this).balance);
}
modifier onlyOwner() {
require(msg.sender == owner, "Not owner");
_;
}
bool internal locked;
modifier reentrancyGuard() {
require(!locked, "Non reentrant");
locked = true;
_;
locked = false;
}
function withdraw() public payable onlyOwner reentrancyGuard {
uint256 amount = address(this).balance;
(bool success, ) = owner.call{value: amount}(" ");
require(success, "ETHER TRANSACTION FAILED!");
emit Withdrawal(amount, address(this).balance);
}
function transfer(address to) public payable onlyOwner {
(bool success, ) = to.call{value: msg.value}(" ");
require(success, "ETHER TRANSACTION FAILED");
emit Transfer(msg.sender, to, address(this).balance);
}
function getBalance() public view returns (uint256) {
return address(this).balance;
}
} |
Beta Was this translation helpful? Give feedback.
-
Obvious errors, I have explained how you can fix them below: First error: You are incorrectly incorporating logic: rather, you should rather use Second error: You are incorrectly using here too. Good luck with the course! (And read more documentations - to correctly implement functions provided to us) |
Beta Was this translation helpful? Give feedback.
-
You are not saving it to global variables that's why it's showing undefined, remove |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I get this error when writing my test, please how do i fix this?
Beta Was this translation helpful? Give feedback.
All reactions