Created
May 6, 2021 16:53
-
-
Save kmbarry1/cace8e744b135833c182601b5a0158bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add these tests into DssVest.t.sol | |
uint256 constant WAD = 10**18; | |
function add(uint256 x, uint256 y) internal pure returns (uint256 z) { | |
require((z = x + y) >= x); | |
} | |
function testFuzzFail_1() public { | |
// derived from echidna failure: | |
// test_init_ids(115792089237316195423570985008687907853269984665640564039457584007913129639935,100242773934347682338375481833561433633362664707040856359631189992494487309630,10,39080061795132864699069909921915714851660400468839437511646123280429906730201,1524785992,0x20000) | |
uint256 _amt = 115792089237316195423570985008687907853269984665640564039457584007913129639935; | |
uint256 _bgn = 100242773934347682338375481833561433633362664707040856359631189992494487309630; | |
uint256 _tau = 10; | |
uint256 _clf = 39080061795132864699069909921915714851660400468839437511646123280429906730201; | |
uint256 _pmt = 1524785992; | |
address _mgr = address(0x20000); | |
_amt = _amt < WAD ? _amt *= WAD : _amt % uint128(-1); | |
_bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); | |
_tau = 1 + _tau % vest.MAX_VEST_PERIOD(); | |
_clf = _clf % _tau; | |
// added to confirm hypothesis | |
// assertTrue(_amt > 0); | |
_pmt = _pmt % _amt; | |
uint256 prevId = vest.ids(); | |
uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); | |
assert(vest.ids() == add(prevId, id)); | |
assert(vest.valid(id)); | |
} | |
function sub(uint256 x, uint256 y) internal pure returns (uint256 z) { | |
require((z = x - y) <= x); | |
} | |
function testFuzzFail_2() public { | |
// derived from echidna failure: | |
// test_vest(0,0,1,1,0,0x0) | |
// test_init_ids(0,0,0,0,0,0x0) | |
uint256 _amt = 0; | |
uint256 _bgn = 0; | |
uint256 _tau = 1; | |
uint256 _clf = 1; | |
uint256 _pmt = 0; | |
address _mgr = address(0); | |
_amt = _amt % uint128(-1); | |
if (_amt < WAD) _amt = (1 + _amt) * WAD; | |
_bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); | |
_tau = 1 + _tau % vest.MAX_VEST_PERIOD(); | |
_clf = _clf % _tau; | |
_pmt = _pmt % _amt; | |
uint256 id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); | |
assert(vest.valid(id)); | |
{ | |
uint256 ids = vest.ids(); | |
vest.vest(id); | |
(address usr, uint48 bgn, uint48 clf, uint48 fin, uint128 amt, uint128 rxd, address mgr) = vest.awards(id); | |
if (block.timestamp >= fin) { | |
assert (vest.ids() == sub(ids, 1)); | |
} else if (block.timestamp >= clf) { | |
uint256 t = (block.timestamp - bgn) * WAD / (fin - bgn); | |
assert(t >= 0); | |
assert(t < WAD); | |
uint256 mkr = (amt * t) / WAD; | |
assert(mkr >= 0); | |
assert(mkr < amt); | |
assert(rxd == uint128(mkr)); | |
} | |
} | |
_amt = 0; | |
_bgn = 0; | |
_tau = 0; | |
_clf = 0; | |
_pmt = 0; | |
_mgr = address(0); | |
_amt = _amt % uint128(-1); | |
if (_amt < WAD) _amt = (1 + _amt) * WAD; | |
_bgn = block.timestamp + _bgn % vest.MAX_VEST_PERIOD(); | |
_tau = 1 + _tau % vest.MAX_VEST_PERIOD(); | |
_clf = _clf % _tau; | |
_pmt = _pmt % _amt; | |
uint256 prevId = vest.ids(); | |
id = vest.init(address(this), _amt, _bgn, _tau, _clf, _pmt, _mgr); | |
// added to confirm hypothesis | |
/* | |
assertEq(vest.ids(), 2); | |
assertEq(prevId, 1); | |
assertEq(id, 2); | |
*/ | |
assert(vest.ids() == add(prevId, id)); | |
assert(vest.valid(id)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment