-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTestERC20.sol
75 lines (60 loc) · 1.71 KB
/
TestERC20.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.20;
contract TestERC20 {
mapping(address => uint256) internal balances;
event Transfer(address indexed from, address indexed to, uint256 value);
// Not used in testing
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
constructor() public {
address sender = msg.sender;
balances[sender] = 10000;
}
function addBalanceToAddress(uint256 balance, address to) public {
if (balances[to] > 0) {
balances[to] = balances[to] + balance;
} else {
balances[to] = balance;
}
}
function balanceOf(address account) external view returns (uint256) {
return balances[account];
}
// Not used in testing
function approve(address spender, uint256 amount) external returns (bool) {
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool) {
return true;
}
// Not used in testing
function totalSupply() external view returns (uint256) {
return 1000;
}
function transfer(address recipient, uint256 amount)
external
returns (bool)
{
address from = msg.sender;
require(balances[from] > 0, "no balance");
balances[from] = balances[from] - amount;
addBalanceToAddress(amount, recipient);
emit Transfer(from, recipient, amount);
return true;
}
// Not used in testing
function allowance(address owner, address spender)
external
view
returns (uint256)
{
return 10000;
}
}