Skip to content
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

Conversation

Akshola00
Copy link

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:

  • Transfer event
  • Approval event
  • Ownership events (change of ownership)

Functionality Tests:

  • Transfer function
  • Attempt to transfer from the zero address
  • Burn functionality
  • Change of ownership
  • Unauthorized ownership attempts

Changes Made

  • Added testRevert_transferRevertedIfZeroAddress to verify that transfers from the zero address are reverted.
  • Added test_Burn to test the token burn functionality.
  • Added testRevert_changeOwnerShouldRevertIfUnauthorized to ensure unauthorized ownership changes are reverted.
  • Added test_changeOwner to test successful ownership changes.
  • Added test_transfer to validate the transfer function.

Checklist

  • Test.

vm.expectRevert(ERC20.InvalidRecipient.selector);
vm.prank(ownerAddress);
erc20Contract.transfer(address(0), 500);
assertEq(erc20Contract.balanceOf(ownerAddress), 1000, "Amount supposed to be 500");
Copy link
Collaborator

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);
Copy link
Collaborator

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);
Copy link
Collaborator

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);
Copy link
Collaborator

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");

Copy link
Collaborator

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

@Akshola00 Akshola00 closed this Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants