From 5f1ec06b9f64425f5f10581aaa9916e890647504 Mon Sep 17 00:00:00 2001 From: elv-preethi <39742400+elv-preethi@users.noreply.github.com> Date: Mon, 6 Mar 2023 12:05:25 -0800 Subject: [PATCH] add erc20 with configurable decimals --- src/tradable/ElvToken.sol | 9 ++++++++- test/elvToken/ElvToken.t.sol | 26 ++++++++++++++++++++++++++ test/payments/ERC20Payments.t.sol | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 test/elvToken/ElvToken.t.sol diff --git a/src/tradable/ElvToken.sol b/src/tradable/ElvToken.sol index 0441915..c705d25 100644 --- a/src/tradable/ElvToken.sol +++ b/src/tradable/ElvToken.sol @@ -8,13 +8,20 @@ import "@openzeppelin/contracts/access/AccessControlEnumerable.sol"; import "./cmn/Roles.sol"; contract ElvToken is ERC20, ERC20Burnable, Pausable, AccessControlEnumerable { - constructor(string memory name, string memory symbol, uint256 amount) ERC20(name, symbol) { + + uint8 private tokenDecimal; + constructor(string memory name, string memory symbol, uint8 decimal, uint256 amount) ERC20(name, symbol) { _grantRole(DEFAULT_ADMIN_ROLE, msg.sender); _grantRole(ElvCmnRoles.PAUSER_ROLE, msg.sender); + tokenDecimal = decimal; _mint(msg.sender, amount * 10 ** decimals()); _grantRole(ElvCmnRoles.MINTER_ROLE, msg.sender); } + function decimals() public view virtual override returns (uint8) { + return tokenDecimal; + } + function pause() public onlyRole(ElvCmnRoles.PAUSER_ROLE) { _pause(); } diff --git a/test/elvToken/ElvToken.t.sol b/test/elvToken/ElvToken.t.sol new file mode 100644 index 0000000..94d717f --- /dev/null +++ b/test/elvToken/ElvToken.t.sol @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; + +import {console} from "forge-std/console.sol"; +import {Test} from "forge-std/Test.sol"; +import "src/tradable/ElvToken.sol"; + + +contract ERC20PaymentsTest is Test { + ElvToken internal token; + address public deployer; + + function setUp() public virtual { + vm.prank(msg.sender, msg.sender); + deployer = msg.sender; + token = new ElvToken("ElvToken","ELV",6,20000); + } + + function testDecimals() public{ + assertEq(token.decimals(), 6); + } + + function testTokenMinted() public { + assertEq(token.balanceOf(deployer), 20000 * 10 ** token.decimals()); + } +} \ No newline at end of file diff --git a/test/payments/ERC20Payments.t.sol b/test/payments/ERC20Payments.t.sol index 2b53a3a..7409c34 100644 --- a/test/payments/ERC20Payments.t.sol +++ b/test/payments/ERC20Payments.t.sol @@ -29,7 +29,7 @@ contract ERC20PaymentsTest is Test { carol = users[2]; vm.label(carol, "Carol"); - token = new ElvToken("ElvToken","ELV",20000000); + token = new ElvToken("ElvToken","ELV",18, 20000000); erc20Payments = new ERC20Payments(); }