Skip to content

Commit 295ac1a

Browse files
committed
fix: BI04
1 parent 29b8b76 commit 295ac1a

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

test/recon/CryticToFoundry.sol

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pragma solidity ^0.8.0;
44
import {Test} from "forge-std/Test.sol";
55
import {TargetFunctions} from "./TargetFunctions.sol";
66
import {FoundryAsserts} from "@chimera/FoundryAsserts.sol";
7+
import {IBribeInitiative} from "src/interfaces/IBribeInitiative.sol";
78

89
import {console} from "forge-std/console.sol";
910

@@ -35,6 +36,41 @@ contract CryticToFoundry is Test, TargetFunctions, FoundryAsserts {
3536
property_BI04();
3637
}
3738

39+
// forge test --match-test test_property_BI04_0 -vv
40+
function test_property_BI04_0() public {
41+
42+
governance_depositLQTY(2);
43+
44+
vm.roll(block.number + 1);
45+
vm.warp(block.timestamp + 794178);
46+
check_skip_consistecy(0);
47+
48+
IBribeInitiative initiative = IBribeInitiative(_getDeployedInitiative(0));
49+
50+
(uint88 totalLQTYAllocatedAtEpochPrev, ) = initiative.totalLQTYAllocatedByEpoch(governance.epoch());
51+
vm.roll(block.number + 1);
52+
vm.warp(block.timestamp + 1022610);
53+
54+
governance_allocateLQTY_clamped_single_initiative(0,1,0);
55+
56+
(uint88 totalLQTYAllocatedAtEpoch, ) = initiative.totalLQTYAllocatedByEpoch(governance.epoch());
57+
(
58+
uint88 voteLQTY,
59+
,
60+
,
61+
,
62+
63+
) = governance.initiativeStates(_getDeployedInitiative(0));
64+
65+
check_unregisterable_consistecy(0);
66+
67+
console.log("totalLQTYAllocatedAtEpochPrev", totalLQTYAllocatedAtEpochPrev);
68+
console.log("totalLQTYAllocatedAtEpoch", totalLQTYAllocatedAtEpoch);
69+
console.log("voteLQTY", voteLQTY);
70+
71+
property_BI04();
72+
}
73+
3874
// forge test --match-test test_property_BI11_3 -vv
3975
function test_property_BI11_3() public {
4076

test/recon/properties/BribeInitiativeProperties.sol

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ function property_BI04() public {
6767
for(uint8 i; i < deployedInitiatives.length; i++) {
6868
IBribeInitiative initiative = IBribeInitiative(deployedInitiatives[i]);
6969

70-
// NOTE: This can revert if no changes happen in an epoch | That's ok
71-
(uint88 totalLQTYAllocatedAtEpoch, ) = initiative.totalLQTYAllocatedByEpoch(currentEpoch);
70+
// NOTE: This doesn't revert in the future!
71+
uint88 lastKnownLQTYAlloc = _getLastLQTYAllocationKnown(initiative, currentEpoch);
7272

7373
// We compare when we don't get a revert (a change happened this epoch)
7474

@@ -82,10 +82,23 @@ function property_BI04() public {
8282

8383

8484

85-
eq(totalLQTYAllocatedAtEpoch, voteLQTY, "BI-04: Initiative Account matches governace");
85+
eq(lastKnownLQTYAlloc, voteLQTY, "BI-04: Initiative Account matches governace");
8686
}
8787
}
8888

89+
function _getLastLQTYAllocationKnown(IBribeInitiative initiative, uint16 targetEpoch) internal returns (uint88) {
90+
uint16 currenEpoch;
91+
uint88 found;
92+
while(currenEpoch <= targetEpoch) {
93+
(uint88 totalLQTYAllocatedAtEpoch, uint32 ts) = initiative.totalLQTYAllocatedByEpoch(currenEpoch++);
94+
if(ts != 0) {
95+
found = totalLQTYAllocatedAtEpoch;
96+
}
97+
}
98+
99+
return found;
100+
}
101+
89102
function property_BI05() public {
90103
// users can't claim for current epoch so checking for previous
91104
uint16 checkEpoch = governance.epoch() - 1;

0 commit comments

Comments
 (0)