1+ pragma solidity 0.4.24 ;
2+
3+ import "zeppelin-solidity/contracts/math/SafeMath.sol " ;
4+
5+ // mock class using BasicToken
6+ contract MockTokenInvalidReturn {
7+
8+ using SafeMath for uint ;
9+ mapping (address => uint256 ) balances;
10+ mapping (address => mapping (address => uint256 )) internal allowed;
11+
12+ uint256 public decimals;
13+ string public name;
14+ string public symbol;
15+ uint256 public totalSupply;
16+
17+ event Transfer (
18+ address indexed from ,
19+ address indexed to ,
20+ uint256 value
21+ );
22+
23+ event Approval (
24+ address indexed owner ,
25+ address indexed spender ,
26+ uint256 value
27+ );
28+
29+ constructor (
30+ address initialAccount ,
31+ uint256 initialBalance ,
32+ string _name ,
33+ string _symbol ,
34+ uint256 _decimals )
35+ public
36+ {
37+ balances[initialAccount] = initialBalance;
38+ totalSupply = initialBalance;
39+ name = _name;
40+ symbol = _symbol;
41+ decimals = _decimals;
42+ }
43+
44+ /**
45+ * @dev Total number of tokens in existence
46+ */
47+ function totalSupply () public view returns (uint256 ) {
48+ return totalSupply;
49+ }
50+
51+ /**
52+ * @dev Transfer token for a specified address
53+ * @param _to The address to transfer to.
54+ * @param _value The amount to be transferred.
55+ */
56+ function transfer (
57+ address _to ,
58+ uint256 _value
59+ )
60+ public
61+ returns (uint256 )
62+ {
63+ require (_to != address (0 ));
64+ require (_value <= balances[msg .sender ]);
65+
66+ balances[msg .sender ] = balances[msg .sender ].sub (_value);
67+ balances[_to] = balances[_to].add (_value);
68+ emit Transfer (msg .sender , _to, _value);
69+ return 4 ;
70+ }
71+
72+ /**
73+ * @dev Gets the balance of the specified address.
74+ * @param _owner The address to query the the balance of.
75+ * @return An uint256 representing the amount owned by the passed address.
76+ */
77+ function balanceOf (address _owner ) public view returns (uint256 ) {
78+ return balances[_owner];
79+ }
80+
81+ /**
82+ * @dev Transfer tokens from one address to another
83+ * @param _from address The address which you want to send tokens from
84+ * @param _to address The address which you want to transfer to
85+ * @param _value uint256 the amount of tokens to be transferred
86+ */
87+ function transferFrom (
88+ address _from ,
89+ address _to ,
90+ uint256 _value
91+ )
92+ public
93+ returns (uint256 )
94+ {
95+ require (_to != address (0 ));
96+ require (_value <= balances[_from]);
97+ require (_value <= allowed[_from][msg .sender ]);
98+
99+ balances[_from] = balances[_from].sub (_value);
100+ balances[_to] = balances[_to].add (_value);
101+ allowed[_from][msg .sender ] = allowed[_from][msg .sender ].sub (_value);
102+ emit Transfer (_from, _to, _value);
103+ return 4 ;
104+ }
105+
106+ /**
107+ * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
108+ * Beware that changing an allowance with this method brings the risk that someone may use both the old
109+ * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
110+ * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
111+ * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
112+ * @param _spender The address which will spend the funds.
113+ * @param _value The amount of tokens to be spent.
114+ */
115+ function approve (
116+ address _spender ,
117+ uint256 _value
118+ )
119+ public
120+ returns (uint256 )
121+ {
122+ allowed[msg .sender ][_spender] = _value;
123+ emit Approval (msg .sender , _spender, _value);
124+ return 4 ;
125+ }
126+
127+ /**
128+ * @dev Function to check the amount of tokens that an owner allowed to a spender.
129+ * @param _owner address The address which owns the funds.
130+ * @param _spender address The address which will spend the funds.
131+ * @return A uint256 specifying the amount of tokens still available for the spender.
132+ */
133+ function allowance (
134+ address _owner ,
135+ address _spender
136+ )
137+ public
138+ view
139+ returns (uint256 )
140+ {
141+ return allowed[_owner][_spender];
142+ }
143+
144+ /**
145+ * @dev Increase the amount of tokens that an owner allowed to a spender.
146+ * approve should be called when allowed[_spender] == 0. To increment
147+ * allowed value is better to use this function to avoid 2 calls (and wait until
148+ * the first transaction is mined)
149+ * From MonolithDAO Token.sol
150+ * @param _spender The address which will spend the funds.
151+ * @param _addedValue The amount of tokens to increase the allowance by.
152+ */
153+ function increaseApproval (
154+ address _spender ,
155+ uint256 _addedValue
156+ )
157+ public
158+ returns (uint256 )
159+ {
160+ allowed[msg .sender ][_spender] = (
161+ allowed[msg .sender ][_spender].add (_addedValue));
162+ emit Approval (msg .sender , _spender, allowed[msg .sender ][_spender]);
163+ return 4 ;
164+ }
165+
166+ /**
167+ * @dev Decrease the amount of tokens that an owner allowed to a spender.
168+ * approve should be called when allowed[_spender] == 0. To decrement
169+ * allowed value is better to use this function to avoid 2 calls (and wait until
170+ * the first transaction is mined)
171+ * From MonolithDAO Token.sol
172+ * @param _spender The address which will spend the funds.
173+ * @param _subtractedValue The amount of tokens to decrease the allowance by.
174+ */
175+ function decreaseApproval (
176+ address _spender ,
177+ uint256 _subtractedValue
178+ )
179+ public
180+ returns (uint256 )
181+ {
182+ uint256 oldValue = allowed[msg .sender ][_spender];
183+ if (_subtractedValue > oldValue) {
184+ allowed[msg .sender ][_spender] = 0 ;
185+ } else {
186+ allowed[msg .sender ][_spender] = oldValue.sub (_subtractedValue);
187+ }
188+ emit Approval (msg .sender , _spender, allowed[msg .sender ][_spender]);
189+ return 4 ;
190+ }
191+ }
0 commit comments