Commit b0a54509 authored by smartcontracts's avatar smartcontracts Committed by GitHub

maint(ct): simplify test helpers (#2523)

Simplifies test helpers slightly by cutting out unnecessary code.
parent 2e0b6330
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity >=0.8.9; pragma solidity >=0.8.9;
/**
* @title FailingReceiver
*/
contract FailingReceiver { contract FailingReceiver {
/**
* @notice Receiver that always reverts upon receiving ether.
*/
receive() external payable { receive() external payable {
require(false, "FailingReceiver"); require(false, "FailingReceiver");
} }
......
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.9; pragma solidity ^0.8.9;
// a test ERC20 token with an open mint function import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract TestERC20 {
string public constant name = "Test";
string public constant symbol = "TST";
uint8 public constant decimals = 18;
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
event Approval(address indexed owner, address indexed spender, uint256 value); contract TestERC20 is ERC20 {
event Transfer(address indexed from, address indexed to, uint256 value); constructor() ERC20("TEST", "TST") {}
constructor() {}
function mint(address to, uint256 value) public { function mint(address to, uint256 value) public {
totalSupply = totalSupply + value; _mint(to, value);
balanceOf[to] = balanceOf[to] + value;
emit Transfer(address(0), to, value);
}
function _approve(
address owner,
address spender,
uint256 value
) private {
allowance[owner][spender] = value;
emit Approval(owner, spender, value);
}
function _transfer(
address from,
address to,
uint256 value
) private {
balanceOf[from] = balanceOf[from] - value;
balanceOf[to] = balanceOf[to] + value;
emit Transfer(from, to, value);
}
function approve(address spender, uint256 value) external returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
function transfer(address to, uint256 value) external returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
function transferFrom(
address from,
address to,
uint256 value
) external returns (bool) {
if (allowance[from][msg.sender] != type(uint256).max) {
allowance[from][msg.sender] = allowance[from][msg.sender] - value;
}
_transfer(from, to, value);
return true;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment