-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(erc20.sol): testing for events and completed testing #52
test(erc20.sol): testing for events and completed testing #52
Conversation
vm.expectRevert(ERC20.InvalidRecipient.selector); | ||
vm.prank(ownerAddress); | ||
erc20Contract.transfer(address(0), 500); | ||
assertEq(erc20Contract.balanceOf(ownerAddress), 1000, "Amount supposed to be 500"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change error message from "Amount supposed to be 500" to "Amount supposed to be 1000"
assertEq(erc20Contract.balanceOf(ownerAddress), 1000, "Amount supposed to be 1000"); | ||
vm.expectEmit(true, true, false, true); | ||
emit Transfer(ownerAddress, recipient, 500); | ||
vm.prank(ownerAddress); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to prank again since prank from line 69 is still effective
assertEq(erc20Contract.balanceOf(recipient), 0, "Amount supposed to be 0"); | ||
assertEq(erc20Contract.balanceOf(ownerAddress), 0, "Amount supposed to be 0"); | ||
vm.prank(ownerAddress); | ||
erc20Contract.mint(ownerAddress, 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use variables instead of literal values. e.g:
uint mintAmount = 1000;
uint tranferAmount = 500;
} | ||
|
||
function test_changeOwner() public { | ||
address newowner = address(0x2938); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check current value of ownerAddress
before calling changeOwner()
//check if they were minted succesfully | ||
assertEq(bwcErc20TokenContract.balanceOf(callingAddress), mintConst, "Balance is supposed to be 1000"); | ||
assertEq(receiptTokenContract.balanceOf(stakingContractAddress), mintConst, "Balance is supposed to be 1000"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also check for the balance change of reward tokens in the contract
PR Description: Testing ERC20 Contract Events
Summary
This PR introduces a series of tests to validate the ERC20 contract's behavior, specifically focusing on key events and functions, such as transfers, approvals, ownership changes, and burn functionality.
Tests Covered
Event Emissions:
Functionality Tests:
Changes Made
testRevert_transferRevertedIfZeroAddress
to verify that transfers from the zero address are reverted.test_Burn
to test the token burn functionality.testRevert_changeOwnerShouldRevertIfUnauthorized
to ensure unauthorized ownership changes are reverted.test_changeOwner
to test successful ownership changes.test_transfer
to validate the transfer function.Checklist