-
Notifications
You must be signed in to change notification settings - Fork 21
/
ERC20Test.sol
55 lines (39 loc) · 1.66 KB
/
ERC20Test.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
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "../src/ExampleToken.sol";
import "./util/Constants.sol";
contract ERC20Test is ExampleToken, Constants {
constructor() {
_mint(USER1, INITIAL_BALANCE);
_mint(USER2, INITIAL_BALANCE);
_mint(USER3, INITIAL_BALANCE);
}
// User balance must never exceed total supply
function echidna_userBalanceNotHigherThanSupply() public returns (bool) {
return totalSupply() >= balanceOf(msg.sender);
}
// User balances must never exceed total supply
function echidna_userBalancesNotHigherThanSupply() public returns (bool) {
uint256 balance = balanceOf(USER1) + balanceOf(USER2) + balanceOf(USER3);
return totalSupply() >= balance;
}
// Zero address does never have balance
function echidna_zeroAddressDoesNotHaveBalance() public returns (bool) {
return balanceOf(address(0)) == 0;
}
// User cannot transfer more than balance
function test_transferMoreThanBalance(address target) public returns (bool) {
uint256 balanceSender = balanceOf(msg.sender);
uint256 balanceReceiver = balanceOf(target);
uint256 currentAllowance = allowance(msg.sender, address(this));
require(balanceSender > 0 && currentAllowance > balanceSender);
bool success = transferFrom(msg.sender, target, balanceSender + 1);
assert(!success);
assert(balanceSender == balanceOf(msg.sender));
assert(balanceReceiver == balanceOf(target));
}
}
// INTERNAL TESTING
//ASSERT
//tx -> check -> tx -> check
//echidna --config echidna.yaml echidna/ERC20Test.sol --contract ERC20Test