Skip to content

Instantly share code, notes, and snippets.

@socarrandinn
Created February 25, 2024 19:33
Show Gist options
  • Save socarrandinn/f5c70298261b8c4a9c48785021aae401 to your computer and use it in GitHub Desktop.
Save socarrandinn/f5c70298261b8c4a9c48785021aae401 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.24+commit.e11b9ed9.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.22 <0.9.0;
library TestsAccounts {
function getAccount(uint index) pure public returns (address) {
address[15] memory accounts;
accounts[0] = 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4;
accounts[1] = 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2;
accounts[2] = 0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db;
accounts[3] = 0x78731D3Ca6b7E34aC0F824c42a7cC18A495cabaB;
accounts[4] = 0x617F2E2fD72FD9D5503197092aC168c91465E7f2;
accounts[5] = 0x17F6AD8Ef982297579C203069C1DbfFE4348c372;
accounts[6] = 0x5c6B0f7Bf3E7ce046039Bd8FABdfD3f9F5021678;
accounts[7] = 0x03C6FcED478cBbC9a4FAB34eF9f40767739D1Ff7;
accounts[8] = 0x1aE0EA34a72D944a8C7603FfB3eC30a6669E454C;
accounts[9] = 0x0A098Eda01Ce92ff4A4CCb7A4fFFb5A43EBC70DC;
accounts[10] = 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c;
accounts[11] = 0x14723A09ACff6D2A60DcdF7aA4AFf308FDDC160C;
accounts[12] = 0x4B0897b0513fdC7C541B6d9D7E929C4e5364D2dB;
accounts[13] = 0x583031D1113aD414F02576BD6afaBfb302140225;
accounts[14] = 0xdD870fA1b7C4700F2BD7f44238821C26f7392148;
return accounts[index];
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.22 <0.9.0;
library Assert {
event AssertionEvent(
bool passed,
string message,
string methodName
);
event AssertionEventUint(
bool passed,
string message,
string methodName,
uint256 returned,
uint256 expected
);
event AssertionEventInt(
bool passed,
string message,
string methodName,
int256 returned,
int256 expected
);
event AssertionEventBool(
bool passed,
string message,
string methodName,
bool returned,
bool expected
);
event AssertionEventAddress(
bool passed,
string message,
string methodName,
address returned,
address expected
);
event AssertionEventBytes32(
bool passed,
string message,
string methodName,
bytes32 returned,
bytes32 expected
);
event AssertionEventString(
bool passed,
string message,
string methodName,
string returned,
string expected
);
event AssertionEventUintInt(
bool passed,
string message,
string methodName,
uint256 returned,
int256 expected
);
event AssertionEventIntUint(
bool passed,
string message,
string methodName,
int256 returned,
uint256 expected
);
function ok(bool a, string memory message) public returns (bool result) {
result = a;
emit AssertionEvent(result, message, "ok");
}
function equal(uint256 a, uint256 b, string memory message) public returns (bool result) {
result = (a == b);
emit AssertionEventUint(result, message, "equal", a, b);
}
function equal(int256 a, int256 b, string memory message) public returns (bool result) {
result = (a == b);
emit AssertionEventInt(result, message, "equal", a, b);
}
function equal(bool a, bool b, string memory message) public returns (bool result) {
result = (a == b);
emit AssertionEventBool(result, message, "equal", a, b);
}
// TODO: only for certain versions of solc
//function equal(fixed a, fixed b, string message) public returns (bool result) {
// result = (a == b);
// emit AssertionEvent(result, message);
//}
// TODO: only for certain versions of solc
//function equal(ufixed a, ufixed b, string message) public returns (bool result) {
// result = (a == b);
// emit AssertionEvent(result, message);
//}
function equal(address a, address b, string memory message) public returns (bool result) {
result = (a == b);
emit AssertionEventAddress(result, message, "equal", a, b);
}
function equal(bytes32 a, bytes32 b, string memory message) public returns (bool result) {
result = (a == b);
emit AssertionEventBytes32(result, message, "equal", a, b);
}
function equal(string memory a, string memory b, string memory message) public returns (bool result) {
result = (keccak256(abi.encodePacked(a)) == keccak256(abi.encodePacked(b)));
emit AssertionEventString(result, message, "equal", a, b);
}
function notEqual(uint256 a, uint256 b, string memory message) public returns (bool result) {
result = (a != b);
emit AssertionEventUint(result, message, "notEqual", a, b);
}
function notEqual(int256 a, int256 b, string memory message) public returns (bool result) {
result = (a != b);
emit AssertionEventInt(result, message, "notEqual", a, b);
}
function notEqual(bool a, bool b, string memory message) public returns (bool result) {
result = (a != b);
emit AssertionEventBool(result, message, "notEqual", a, b);
}
// TODO: only for certain versions of solc
//function notEqual(fixed a, fixed b, string message) public returns (bool result) {
// result = (a != b);
// emit AssertionEvent(result, message);
//}
// TODO: only for certain versions of solc
//function notEqual(ufixed a, ufixed b, string message) public returns (bool result) {
// result = (a != b);
// emit AssertionEvent(result, message);
//}
function notEqual(address a, address b, string memory message) public returns (bool result) {
result = (a != b);
emit AssertionEventAddress(result, message, "notEqual", a, b);
}
function notEqual(bytes32 a, bytes32 b, string memory message) public returns (bool result) {
result = (a != b);
emit AssertionEventBytes32(result, message, "notEqual", a, b);
}
function notEqual(string memory a, string memory b, string memory message) public returns (bool result) {
result = (keccak256(abi.encodePacked(a)) != keccak256(abi.encodePacked(b)));
emit AssertionEventString(result, message, "notEqual", a, b);
}
/*----------------- Greater than --------------------*/
function greaterThan(uint256 a, uint256 b, string memory message) public returns (bool result) {
result = (a > b);
emit AssertionEventUint(result, message, "greaterThan", a, b);
}
function greaterThan(int256 a, int256 b, string memory message) public returns (bool result) {
result = (a > b);
emit AssertionEventInt(result, message, "greaterThan", a, b);
}
// TODO: safely compare between uint and int
function greaterThan(uint256 a, int256 b, string memory message) public returns (bool result) {
if(b < int(0)) {
// int is negative uint "a" always greater
result = true;
} else {
result = (a > uint(b));
}
emit AssertionEventUintInt(result, message, "greaterThan", a, b);
}
function greaterThan(int256 a, uint256 b, string memory message) public returns (bool result) {
if(a < int(0)) {
// int is negative uint "b" always greater
result = false;
} else {
result = (uint(a) > b);
}
emit AssertionEventIntUint(result, message, "greaterThan", a, b);
}
/*----------------- Lesser than --------------------*/
function lesserThan(uint256 a, uint256 b, string memory message) public returns (bool result) {
result = (a < b);
emit AssertionEventUint(result, message, "lesserThan", a, b);
}
function lesserThan(int256 a, int256 b, string memory message) public returns (bool result) {
result = (a < b);
emit AssertionEventInt(result, message, "lesserThan", a, b);
}
// TODO: safely compare between uint and int
function lesserThan(uint256 a, int256 b, string memory message) public returns (bool result) {
if(b < int(0)) {
// int is negative int "b" always lesser
result = false;
} else {
result = (a < uint(b));
}
emit AssertionEventUintInt(result, message, "lesserThan", a, b);
}
function lesserThan(int256 a, uint256 b, string memory message) public returns (bool result) {
if(a < int(0)) {
// int is negative int "a" always lesser
result = true;
} else {
result = (uint(a) < b);
}
emit AssertionEventIntUint(result, message, "lesserThan", a, b);
}
}
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
ref: refs/heads/main
DIRC eە��eە������-�k�����uw����,�&$.deps/remix-tests/remix_accounts.soleە �.�eە �.��������b 2�H"��(���,�Dz!.deps/remix-tests/remix_tests.soleە,Eeە,E�����o#q{K���Sc��X�W�n.prettierrc.jsoneە�eە���;���9|�>�Xߌy��˷'contracts/MyToken.soleە�Q@eە�Q@���cS?���5?,���7��'�|scripts/deploy_with_ethers.tseەe��eەe��������.��E�r���NH-��Wscripts/deploy_with_web3.tseە���eە������'S��Н��M�%5�s<��wscripts/ethers-lib.tseە�<eە�<��%�~P9���WrV���ߒ�~�scripts/web3-lib.tseە��eە��
��!K�*����8��w'���tests/MyToken_test.sol�x7�1jfs"����bg��
x��U]o�0�9�⪼�R��6�1�"4�شI�����Z8v�F���Q�ڴIg���ڷ��s�=%��g� ǁ��_'W���SH��+J��x{5�ٮe��#J0R��w���v�k���E�XH I"���&J+[ 68�A���.m���k��V��6?/J����( T�_�ѲPJ� �]���J-J�5���;:?��j'��ɬv��Ď�s>P�`I@ H�TS�@<p"�B,��2�Z��l��v�O9�*�XS�aIVB�c��ɒQ �YE��^�F��X�N�j�������a��V������Ȕ� ��XBT�ʅRDj��Lr��h �·�:�z! � �x3��y���R�&����� AB�i��Ja��;���E ��]�l���^�3P��0ݧ?D�A��הk�ם6.C��U�wU��ꈹ�c��J�(��<�u�S*ktYu��Ѳf��:�9�gֈ�.�;�/�a����;�i�( �fpO��^
��I��?O�I���߈���lR�wZ��:�Z�@"�V}�����.�R�1�{8z675��yc�K[�47zCd��L���� EWݝf`�ߛ�4�4߾oj�������?���,���B�`���\I{���y�\ı�� F����6�R���
�r�
ڼϖ��h������y������x�we�s� �:Һ�"z�z�Qݒ˔r�g!4
�_ �����P�����ٍqJ ��T-v ���X-a��N����#Sm��s�dY��T�
x�+)JMU0�`01000P(J�ͬ�-I-.)fh����v�ß��w"[Z��Z[~��:�
x�M�A
�0D]����FQWB��;w"4i�ZL�K)���b��j`x��:�جw��j�G�(�q�a��s�D�Z�ۥ+m"�4��sH��^�wc9�!�Sx���5e�\29v'~P�,p��Ύ���LQx
a�y���7= 71�C��;��IW��ш�AI��B�
x�+)JMU01a040031Q� ��N͋/I-.�+��a`R�~���_��ۯ����)����
x�]S]k�@��<$s�%�Ӧ)���kV�Z�T�{�8���}�J_�ݝ���K+�����_�ٺ�؃�d 8`-�F���,9;�� ?���Z2
���w*�i[�ސP�}P��8k+����u7:�y�8������$E@e����wAe���]3+K�ή6u�re��8�u9����� kY�k��c��֍8�����S�ɬ�� -X���e����ѻ�褜�$n��s������k��7ߌ\.���f3t�}Ŧ�E��3�����t��i>�+� -I;�!�(s�W?n�-mV��XH9?Y������$jה���_F���VmZs]~� �� BO�{�K<�ⷁ%CrlI�h��wO-��\ъ�k/��z��Nѐ��㶚�rR���V�! Ӗ�B���&�������79*X�����V-�ҝG[N?݋�9K�Z@=�ʧT��RZ1|��m��{9[8,;�o�4Z0&��t�|n
ևn:��i~��R���s�=f�/ƣ)�R�8Zd�O�S�|Φg��NVo~���a��sc��χ�& ˷yY�=�^ڎ�+��z�Ʃ�`��ں.;��Č�q{!�3>>��?}�V
x�+)JMU04�`01000P�KI-(fR� �Z���˿8�`��W�?G���(����d�%�e��1lZ��\X�=���Jp�����A�J��+)JL.)fx�qFp�� ����\K��>3�KDMqrQfAI1�_��Mr��T5?�ۯx��o��]%��%� J��鱟�8�lG[I�h-o�q�J�
x�+)JMU047c040031QHI-�ɯ�/�,ɈO-�H-*�+)fH���u����N��^��w�`�P��d R.�j�t���]o�<���C�m�x8T9�Lݜ�$�B���{.�}���`����b�gʡ
Af��� �\��-�(l��g��'u���I5
x�M��
�0���7I@�88� ��Dh���Ŵ)IDB黋������w�uv���i{�#��[�0��] �6k�am��3&tH���Ȏ}�0� ���Fd�O���&�)�ݝ:���*�����D���S,��@�͘��FGSC��;��I���hB�(�|��C�
x���9�0����ȎB�<c�l��d �z$h�)��j�$����tf��'��=9���HޭHau�9�H�"�E�C��ý��uI�������)凞�C���z�Z��*���N5I� �� �Kz�p�e���N�Vo-�H
x�+)JMU��d040031Q(J�ͬ�OLN�/�+)�+��a8xD�d��7��ͻ_Z��_�}�_j(�KR��Jw�Ɯ�`��C��Q�o�<?� w�*�
x���Oo�0�9�S�rJ�4Y�*���s�`Պ���̖����.K�8YZU��C���{�ql7�6�rq��E]����o�_H#<>m�����-�O7���S���d��I�\���:g�@��:�?��Z[���Z�O���������5��I>�-ȁ,���>zV��g�:W1<!Ji�!�g�g��HRP6y`���&����; O�S�%����
7���G-��m=��$��َ� �~ �"O켄|�����x�=����m6�����ep*,���Ɛ�f?����q�4��r? ��D̪�C:b���"�,_�����x�`�MI|Qװ��������� �<��F��E��B���t��{m^F�*��ӭ�] �}�L�Î zVf.L���35��U�8D����#����i���_��]�
x����
�0 �=�)B�2ă��[����n٬�f�� c�.+l0cB{J�� ��ɪ�����e)\}�{�Py���l���X<N�r�t���|X��E���RH��/����D\[<s�� �,NV�R�&�3�0<{�;U<������6^p��k���xH�����%�pυ._ݢ6��̢�
x�͖�N�@�{��re���j!A�!$T��Ro��8��즻k B�{�>��؉q��$�l�ߌg�?��m8�68���������=u�I�ܹ��(�s�}��|�� c&�xJ@r��T��r��t��߻� ��-��Õ�(|�"Sq�rv�/M��܇��v�JP6�)JIƘ����$S4���Ŀh��Q8�L N�@�
K$Q|�����
r��L�2?8��c��]�C��\W���)H�(�D��c�P~�#Q�tS�h!��0s}�8�N ���˴foMɥ����_/`�f>1û��2�yrO f��S'N,��WC���#�Mt# �5N��EgڋZ��'-K��\�?����5�{!4 �F`[����؄ �Zm d�R/��|W9y����pC�.��������9p�����P�($�L��A;��Ty}GWg�>�X��^/�6�E�I��`QM����K���u��J���.���
�=W_G���ZE�T1A�!���Il�E�p�3A�$��K�r¶������ J�ϸ�i�)��8EBV��9��N��%��q���9��K]UkE6�G��;��҄}ԩh�I�>]�Rf-��ˑ�#%�t��frT�L�xI�Fw�/�H
P/���םN縷ڽqt����F�貂���?���3����~�K����x�����6�7Dvsu�>���i�P�2���?�&�,T�1Q�#�i���\&P�MS"��c����E����lz-��&�t�w��^f�z&)�7{W�<��]� �F����m�]���֕{�y�ʊ�n\U�Te��/*+��i�V��a�c�.)�갊�Z���^�����q`=I�pv�
�p"&�:b�״O�/}��
x�]�M�7�\ݿBG��㒪��2�A-�B�C|0,{P��4��,�^�����c2���xT�xk~��BJ-�x�V��1~�����;��j۝���ß���p��|�_��8����^��w���R�/ظ l��q���">����Kٟw���6!D?��i��ėvZ�^���I,�ھ���C���q)��N���(^�Z�x|���s�G�R?����?���V��^�����N�W=���dY���t ������u�fn������l�b2T]0UN%�ْ��0׈(�E]fu��Ө�9 Y)�[��vͲ��'�]S*���5� f�(#�lf��r�dR�K�֓�%�y��t�FrR��U�.j (�S9Hc��d����m}�����N�Y�kvA�qAƹ���lA��f��bF�<v��4 ��j�k��]Ҡ�a{����Ie�Ķ�sp���Zr�� 3�(S�kl׶��Gʬ�#�6�L}��1�M�)\c�V���T3�М�<�0���Ҭ=�4�x����Q�\�Ԥ�4A�̀�55��&�3#��fL+��|��D� �RgO>u�b ��m��!�x-���A�Mu�'�\���PT�&'rM��(��s$I �f3F�{���$�R�F�1��2t/g�I��;�Bk� �tF�$��p���sz�k���f���}�v�=�
x�mT]k�@�~�<$GN� �iK!�|@�P
^Ik�R��ܭ�[���$�j�@�������*�L�˫ˏ�T�2V���+,��n8�
���_�K�L�_/�����S<�D�Ќ��Y���A0;; p�����R2
��H��"K5vN��E3��f��a�>����8��Z�^���4 [8T�I���Į316���u����2�ւ�㼥r�s�/����u=N��:e۠ ��Jժ3fY�Vc�w��Us>�? �����C0�������:�-O���#� w���6I�lM�_�Jn0��.Г�G�94o�4D��gk�T�vңL�qe�h�)T����X]�h���0�$�]s�U+�fΝq���Re%�C��- �]�c�W��V(ȊZR&qW��~3�ڎfA�>�s�· �|,?X��$%�X��l�١�� ���Wg��ض��r��_��Y�mH ,��O�QUE�RU�@�
��a��MUN�3�+�3��9����Yʸ`���(�3V����@t�S�N�hw<9������h@[+��G��LαI_9���-�5kq��hF��7�{�tƃ����]Ȟ�����~��ϋ_aA.�;�����E{u�@��'Hc���_��p
x�+)JMU0�d040031Q� ��N��+��a�}�ٲ��N�o����s/NoWnf
767622adf17b0d960fabfb6286b47d0a758806f0
{
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false
}
},
{
"files": "*.yml",
"options": {}
},
{
"files": "*.yaml",
"options": {}
},
{
"files": "*.toml",
"options": {}
},
{
"files": "*.json",
"options": {}
},
{
"files": "*.js",
"options": {}
},
{
"files": "*.ts",
"options": {}
}
]
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
contract MyToken is ERC20, ERC20Burnable, ERC20Pausable, Ownable, ERC20Permit {
constructor(address initialOwner)
ERC20("MyToken", "MTK")
Ownable(initialOwner)
ERC20Permit("MyToken")
{}
function pause() public onlyOwner {
_pause();
}
function unpause() public onlyOwner {
_unpause();
}
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
// The following functions are overrides required by Solidity.
function _update(address from, address to, uint256 value)
internal
override(ERC20, ERC20Pausable)
{
super._update(from, to, value);
}
}
// this line is added to create a gist. Empty file is not allowed.
import { deploy } from './ethers-lib'
(async () => {
try {
const result = await deploy('MyToken', [])
console.log(`address: ${result.address}`)
} catch (e) {
console.log(e.message)
}
})()
import { deploy } from './web3-lib'
(async () => {
try {
const result = await deploy('MyToken', [])
console.log(`address: ${result.address}`)
} catch (e) {
console.log(e.message)
}
})()
import { ethers } from 'ethers'
/**
* Deploy the given contract
* @param {string} contractName name of the contract to deploy
* @param {Array<any>} args list of constructor' parameters
* @param {Number} accountIndex account index from the exposed account
* @return {Contract} deployed contract
*/
export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => {
console.log(`deploying ${contractName}`)
// Note that the script needs the ABI which is generated from the compilation artifact.
// Make sure contract is compiled and artifacts are generated
const artifactsPath = `browser/contracts/artifacts/${contractName}.json` // Change this for different path
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
// 'web3Provider' is a remix global variable object
const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex)
const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer)
const contract = await factory.deploy(...args)
// The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed()
return contract
}
import Web3 from 'web3'
import { Contract, ContractSendMethod, Options } from 'web3-eth-contract'
/**
* Deploy the given contract
* @param {string} contractName name of the contract to deploy
* @param {Array<any>} args list of constructor' parameters
* @param {string} from account used to send the transaction
* @param {number} gas gas limit
* @return {Options} deployed contract
*/
export const deploy = async (contractName: string, args: Array<any>, from?: string, gas?: number): Promise<Options> => {
const web3 = new Web3(web3Provider)
console.log(`deploying ${contractName}`)
// Note that the script needs the ABI which is generated from the compilation artifact.
// Make sure contract is compiled and artifacts are generated
const artifactsPath = `browser/contracts/artifacts/${contractName}.json`
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
const accounts = await web3.eth.getAccounts()
const contract: Contract = new web3.eth.Contract(metadata.abi)
const contractSend: ContractSendMethod = contract.deploy({
data: metadata.data.bytecode.object,
arguments: args
})
const newContractInstance = await contractSend.send({
from: from || accounts[0],
gas: gas || 1500000
})
return newContractInstance.options
}
// 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 = TestsAccounts.getAccount(0);
address acc1;
address acc2;
address acc3;
address acc4;
// acc0 will be set as initial owner
constructor() MyToken(acc0) {}
function beforeAll() public {
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), 400, "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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment