Skip to content

Commit a8c58f1

Browse files
committed
tests: VaultFactory: fix failing fuzzing
1 parent 6875372 commit a8c58f1

File tree

1 file changed

+41
-35
lines changed

1 file changed

+41
-35
lines changed

test/unit/vault-factory/get-vtoken-premium-1155/getVTokenPremium1155.t.sol

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ contract getVTokenPremium1155_Unit_Test is NFTXVaultFactory_Unit_Test {
103103
}
104104

105105
function test_WhenTheAmountIsLessThanOrEqualToTheQuantityOfNftsInTheVault(
106-
uint256[1000] memory values,
106+
uint256[100] memory values,
107107
uint256 depositCount,
108108
uint256 _amount
109109
)
@@ -148,53 +148,59 @@ contract getVTokenPremium1155_Unit_Test is NFTXVaultFactory_Unit_Test {
148148

149149
totalDeposited += depositAmounts[i];
150150
}
151-
vm.assume(totalDeposited >= amount);
151+
// vm.assume doesn't work
152+
// vm.assume(totalDeposited >= amount);
153+
if (totalDeposited < amount) {
154+
vm.expectRevert(INFTXVaultFactoryV3.NFTInventoryExceeded.selector);
155+
}
152156

153157
// putting in a separate external call to avoid "EvmError: MemoryLimitOOG"
154158
// using storage instead to pass values
155159
// source: https://github.com/foundry-rs/foundry/issues/3971#issuecomment-1698653788
156160
this.getVTokenPremium1155();
157161

158-
// it should return the total premium
159-
assertGt(totalPremium, 0);
160-
assertEq(
161-
totalPremium,
162-
ExponentialPremium.getPremium(
163-
block.timestamp,
164-
vaultFactory.premiumMax(),
165-
vaultFactory.premiumDuration()
166-
) * amount
167-
);
168-
169-
// it should return the premiums array
170-
// it should return the depositors array
171-
172-
assertEq(premiums.length, depositors.length);
173-
174-
uint256 netDepositAmountUsed;
175-
for (uint256 i; i < depositors.length; i++) {
176-
uint256 depositAmountUsed;
177-
if (netDepositAmountUsed + depositAmounts[i] >= amount) {
178-
depositAmountUsed = amount - netDepositAmountUsed;
179-
} else {
180-
depositAmountUsed = depositAmounts[i];
181-
}
182-
netDepositAmountUsed += depositAmountUsed;
183-
162+
if (totalDeposited >= amount) {
163+
// it should return the total premium
164+
assertGt(totalPremium, 0);
184165
assertEq(
185-
premiums[i],
166+
totalPremium,
186167
ExponentialPremium.getPremium(
187168
block.timestamp,
188169
vaultFactory.premiumMax(),
189170
vaultFactory.premiumDuration()
190-
) * depositAmountUsed
191-
);
192-
assertEq(
193-
depositors[i],
194-
makeAddr(string.concat("depositor", Strings.toString(i)))
171+
) * amount
195172
);
173+
174+
// it should return the premiums array
175+
// it should return the depositors array
176+
177+
assertEq(premiums.length, depositors.length);
178+
179+
uint256 netDepositAmountUsed;
180+
for (uint256 i; i < depositors.length; i++) {
181+
uint256 depositAmountUsed;
182+
if (netDepositAmountUsed + depositAmounts[i] >= amount) {
183+
depositAmountUsed = amount - netDepositAmountUsed;
184+
} else {
185+
depositAmountUsed = depositAmounts[i];
186+
}
187+
netDepositAmountUsed += depositAmountUsed;
188+
189+
assertEq(
190+
premiums[i],
191+
ExponentialPremium.getPremium(
192+
block.timestamp,
193+
vaultFactory.premiumMax(),
194+
vaultFactory.premiumDuration()
195+
) * depositAmountUsed
196+
);
197+
assertEq(
198+
depositors[i],
199+
makeAddr(string.concat("depositor", Strings.toString(i)))
200+
);
201+
}
202+
assertEq(netDepositAmountUsed, amount);
196203
}
197-
assertEq(netDepositAmountUsed, amount);
198204
}
199205

200206
// helpers

0 commit comments

Comments
 (0)