Skip to content

Commit

Permalink
expose parameters to ERC20 constructor and change the directory name …
Browse files Browse the repository at this point in the history
…to mock
  • Loading branch information
arbazkiraak committed Nov 20, 2023
1 parent d929445 commit fd3b2ab
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
15 changes: 9 additions & 6 deletions src/weird-erc20/ERC20-bool.sol → src/mocks/ERC20-bool.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
pragma solidity ^0.8.0;

import "forge-std/interfaces/IERC20.sol";
import {ERC20Token} from "./ERC20-base.sol";
import {ERC20Base} from "./base/ERC20Base.sol";

contract ERC20Bool is ERC20Token {
constructor(uint256 initialSupply) {
totalSupply = initialSupply;
balanceOf[msg.sender] = initialSupply;
contract ERC20Bool is ERC20Base {
constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _initialSupply) {
name = _name;
symbol = _symbol;
decimals = _decimals;
totalSupply = _initialSupply;
balanceOf[msg.sender] = _initialSupply;

emit Transfer(address(0),msg.sender,initialSupply);
emit Transfer(address(0),msg.sender,_initialSupply);
}

function transfer(address to,uint256 amount) public override returns (bool) {
Expand Down
21 changes: 5 additions & 16 deletions src/weird-erc20/ERC20-base.sol → src/mocks/base/ERC20Base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,16 @@ pragma solidity ^0.8.0;

import "forge-std/interfaces/IERC20.sol";

contract ERC20Token is IERC20 {
string private _name = "ERC20Token";
string private _symbol = "ERC";
uint8 private _decimals = 18;
contract ERC20Base is IERC20 {
string public name = "ERC20Token";
string public symbol = "ERC";
uint8 public decimals = 18;


uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;

function name() public view returns (string memory) {
return _name;
}

function symbol() public view returns (string memory) {
return _symbol;
}

function decimals() public view returns (uint8) {
return _decimals;
}

function approve(address spender, uint256 amount) public returns (bool) {
_approve(msg.sender,spender,amount);
return true;
Expand Down
5 changes: 3 additions & 2 deletions test/examples/ERC20Example.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ pragma solidity ^0.8.13;

import "forge-std/Test.sol";
import "forge-std/interfaces/IERC20.sol";
import "../../src/weird-erc20/ERC20-bool.sol";
import "../../src/mocks/ERC20-bool.sol";

contract ERC20Test is Test {
IERC20 public boolToken;
uint256 immutable initialSupply = 1000000000;

address alice = vm.addr(1);
address bob = vm.addr(2);

function setUp() public {
boolToken = new ERC20Bool(initialSupply);
boolToken = new ERC20Bool("BoolToken","Btoken",18,initialSupply);
assertEq(boolToken.balanceOf(address(this)),initialSupply);
}

Expand Down

0 comments on commit fd3b2ab

Please sign in to comment.