-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(invariant): more invariant testing work
- Loading branch information
1 parent
c57f6e3
commit 000d65d
Showing
13 changed files
with
216 additions
and
298 deletions.
There are no files selected for viewing
This file contains 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
Empty file.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
pragma solidity ^0.8.0; | ||
|
||
import "./setup/InvariantTargetContract.sol"; | ||
|
||
bytes32 constant SLOT_LOCKED = bytes32(uint(5)); | ||
|
||
contract InvariantGlobal is InvariantTargetContract { | ||
constructor(address hyper_, address asset_, address quote_) InvariantTargetContract(hyper_, asset_, quote_) {} | ||
|
||
function invariant_global() public { | ||
bytes32 locked = vm.load(address(__hyper__), SLOT_LOCKED); | ||
assertEq(uint(locked), 1, "invariant-locked"); | ||
|
||
(bool prepared, bool settled) = __hyper__.__account__(); | ||
assertTrue(!prepared, "invariant-prepared"); | ||
assertTrue(settled, "invariant-settled"); | ||
|
||
uint balance = address(__hyper__).balance; | ||
assertEq(balance, 0, "invariant-ether"); | ||
|
||
(uint reserve, uint physical, uint balances) = getBalances(address(__asset__)); | ||
assertTrue(physical >= reserve + balances, "invariant-asset-physical-balance"); | ||
|
||
(reserve, physical, balances) = getBalances(address(__quote__)); | ||
assertTrue(physical >= reserve + balances, "invariant-quite-physical-balance"); | ||
} | ||
|
||
function getBalances(address token) internal view returns (uint reserve, uint physical, uint balances) { | ||
reserve = getReserve(address(__hyper__), token); | ||
physical = getPhysicalBalance(address(__hyper__), token); | ||
balances = getBalanceSum(address(__hyper__), token, ctx.users()); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,25 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
pragma solidity ^0.8.0; | ||
|
||
import {InvariantAllocate} from "./InvariantAllocate.sol"; | ||
import "./setup/TestE2ESetup.sol"; | ||
import "./setup/TestInvariantSetup.sol"; | ||
|
||
contract InvariantBreaker { | ||
bool public flag0 = true; | ||
bool public flag1 = true; | ||
|
||
function set0(int val) public returns (bool) { | ||
if (val % 100 == 0) flag0 = false; | ||
return flag0; | ||
} | ||
|
||
function set1(int val) public returns (bool) { | ||
if (val % 10 == 0 && !flag0) flag1 = false; | ||
return flag1; | ||
} | ||
} | ||
import {InvariantAllocate} from "./InvariantAllocate.sol"; | ||
|
||
contract TestE2EInvariant is TestInvariantSetup, TestE2ESetup { | ||
InvariantAllocate internal _allocate; | ||
InvariantBreaker inv; | ||
|
||
function setUp() public override { | ||
super.setUp(); | ||
|
||
inv = new InvariantBreaker(); | ||
_allocate = new InvariantAllocate(address(__hyper__), address(__asset__), address(__quote__)); | ||
|
||
addTargetContract(address(_allocate)); | ||
addTargetContract(address(inv)); | ||
} | ||
|
||
function invariant_global() public withGlobalInvariants { | ||
console.log("Woooo"); | ||
} | ||
|
||
function invariant_neverFalse() public { | ||
require(inv.flag1()); | ||
function invariant_global_account() public { | ||
(bool prepared, bool settled) = __hyper__.__account__(); | ||
assertTrue(!prepared, "invariant-prepared"); | ||
assertTrue(settled, "invariant-settled"); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.