more tests for ERC20 template

pull/5370/head
Aniket-Engg 2 years ago committed by Aniket
parent 2b99728be8
commit 0e3f3153ff
  1. 10
      libs/remix-ws-templates/src/templates/ozerc20/index.ts
  2. 104
      libs/remix-ws-templates/src/templates/ozerc20/tests/MyToken_mintable_test.sol
  3. 15
      libs/remix-ws-templates/src/templates/ozerc20/tests/MyToken_test.sol

@ -23,7 +23,13 @@ export default async (opts) => {
// If no options is selected, opts.upgradeable will be undefined
// We do not show test file for upgradeable contract
// @ts-ignore
if (!opts || opts.upgradeable === undefined || !opts.upgradeable) filesObj['tests/MyToken_test.sol'] = (await import('raw-loader!./tests/MyToken_test.sol')).default
if (!opts || opts.upgradeable === undefined || !opts.upgradeable) {
// @ts-ignore
if(opts.mintable) filesObj['tests/MyToken_test.sol'] = (await import('raw-loader!./tests/MyToken_mintable_test.sol')).default
// @ts-ignore
else filesObj['tests/MyToken_test.sol'] = (await import('raw-loader!./tests/MyToken_test.sol')).default
}
return filesObj
}

@ -0,0 +1,104 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "remix_tests.sol";
import "remix_accounts.sol";
import "../contracts/MyToken.sol";
contract MyTokenTest is MyToken {
address acc0;
address acc1;
address acc2;
address acc3;
address acc4;
function beforeAll() public {
acc0 = TestsAccounts.getAccount(0);
acc1 = TestsAccounts.getAccount(1);
acc2 = TestsAccounts.getAccount(2);
acc3 = TestsAccounts.getAccount(3);
acc4 = TestsAccounts.getAccount(4);
}
function testTokenInitialValues() public {
Assert.equal(name(), "MyToken", "token name did not match");
Assert.equal(symbol(), "MTK", "token symbol did not match");
Assert.equal(decimals(), 18, "token decimals did not match");
Assert.equal(totalSupply(), 0, "token supply should be zero");
}
function testTokenMinting() public {
Assert.equal(balanceOf(acc0), 0, "token balance should be zero initially");
mint(acc0, 10000);
Assert.equal(balanceOf(acc0), 10000, "token balance did not match");
}
function testTotalSupply() public {
Assert.equal(totalSupply(), 10000, "total supply did not match");
}
/// #sender: account-1
function failTestTokenMintingWithWrongOwner() public {
Assert.equal(balanceOf(acc0), 0, "token balance should be zero initially");
mint(acc0, 10000);
Assert.equal(balanceOf(acc0), 10000, "token balance did not match");
}
function failTestTokenMintingForZeroAddress() public {
mint(address(0), 10000);
}
function testTokenTransfer() public {
Assert.equal(balanceOf(acc1), 0, "token balance should be zero initially");
transfer(acc1, 500);
Assert.equal(balanceOf(acc0), 9500, "token balance did not match");
Assert.equal(balanceOf(acc1), 500, "token balance did not match");
}
/// #sender: account-1
function testTokenTransferToOtherAddress() public {
Assert.equal(balanceOf(acc1), 500, "acc1 token balance did not match");
transfer(acc2, 100);
Assert.equal(balanceOf(acc1), 400, "acc1 token balance did not match");
Assert.equal(balanceOf(acc2), 100, "acc2 token balance did not match");
}
function failTestTokenTransferToZeroAddress() public {
transfer(address(0), 100);
}
/// #sender: account-2
function failTestTokenTransferMoreThanBalance() public {
transfer(acc3, 110);
}
function testTokenApprove() public {
Assert.equal(allowance(acc0, acc3), 0, "token allowance should be zero initially");
approve(acc3, 500);
Assert.equal(allowance(acc0, acc3), 500, "token allowance did not match");
}
function failTestTokenApproveForZeroSpenderAddress() public {
approve(address(0), 500);
}
/// #sender: account-3
function testTokenTransferfrom() public {
Assert.equal(allowance(acc0, acc3), 500, "token allowance did not match");
transferFrom(acc0, acc4, 400);
Assert.equal(balanceOf(acc4), 500, "acc4 token balance did not match");
Assert.equal(allowance(acc0, acc3), 100, "token allowance did not match");
}
/// #sender: account-3
function failTestTokenTransferfromForMoreThanAllowance() public {
transferFrom(acc0, acc4, 110);
}
/// #sender: account-3
function failTestTokenTransferfromForZeroToAddress() public {
transferFrom(acc0, address(0), 100);
}
}

@ -4,15 +4,12 @@ pragma solidity >=0.7.0 <0.9.0;
import "remix_tests.sol";
import "../contracts/MyToken.sol";
contract MyTokenTest {
contract MyTokenTest is MyToken {
MyToken s;
function beforeAll () public {
s = new MyToken();
}
function testTokenNameAndSymbol () public {
Assert.equal(s.name(), "MyToken", "token name did not match");
Assert.equal(s.symbol(), "MTK", "token symbol did not match");
function testTokenInitialValues() public {
Assert.equal(name(), "MyToken", "token name did not match");
Assert.equal(symbol(), "MTK", "token symbol did not match");
Assert.equal(decimals(), 18, "token decimals did not match");
Assert.equal(totalSupply(), 0, "token supply should be zero");
}
}
Loading…
Cancel
Save