watcher-ts/packages/uni-watcher/test/contracts/TestERC20.sol
Ashwin Phatak 9a3ac28a5d
uni-watcher smoke test (#172)
* Created a smoke test for uni-watcher.

* Added test for createPool.

* Added more pool tests.

* Using ethers instead of hardhat-ethers in smoke test.

Co-authored-by: prathamesh0 <prathamesh.musale0@gmail.com>
2021-07-30 19:50:56 +05:30

61 lines
2.1 KiB
Solidity

// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.7.6;
import '@uniswap/v3-core/contracts/interfaces/IERC20Minimal.sol';
contract TestERC20 is IERC20Minimal {
mapping(address => uint256) public override balanceOf;
mapping(address => mapping(address => uint256)) public override allowance;
constructor(uint256 amountToMint) {
mint(msg.sender, amountToMint);
}
function mint(address to, uint256 amount) public {
uint256 balanceNext = balanceOf[to] + amount;
require(balanceNext >= amount, 'overflow balance');
balanceOf[to] = balanceNext;
}
function transfer(address recipient, uint256 amount) external override returns (bool) {
uint256 balanceBefore = balanceOf[msg.sender];
require(balanceBefore >= amount, 'insufficient balance');
balanceOf[msg.sender] = balanceBefore - amount;
uint256 balanceRecipient = balanceOf[recipient];
require(balanceRecipient + amount >= balanceRecipient, 'recipient balance overflow');
balanceOf[recipient] = balanceRecipient + amount;
emit Transfer(msg.sender, recipient, amount);
return true;
}
function approve(address spender, uint256 amount) external override returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) external override returns (bool) {
uint256 allowanceBefore = allowance[sender][msg.sender];
require(allowanceBefore >= amount, 'allowance insufficient');
allowance[sender][msg.sender] = allowanceBefore - amount;
uint256 balanceRecipient = balanceOf[recipient];
require(balanceRecipient + amount >= balanceRecipient, 'overflow balance recipient');
balanceOf[recipient] = balanceRecipient + amount;
uint256 balanceSender = balanceOf[sender];
require(balanceSender >= amount, 'underflow balance sender');
balanceOf[sender] = balanceSender - amount;
emit Transfer(sender, recipient, amount);
return true;
}
}