Skip to content

Commit 7f3b28d

Browse files
authored
Coverage 3.3.0 - Phase 1 (#1083)
1 parent 5c48f60 commit 7f3b28d

File tree

17 files changed

+476
-190
lines changed

17 files changed

+476
-190
lines changed

contracts/libraries/Allowance.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ library AllowanceLib {
2323

2424
// 1. Set initial allowance to 0
2525
token.approve(spender, 0);
26+
// untestable:
27+
// allowance should always be 0 if token behaves correctly
2628
require(token.allowance(address(this), spender) == 0, "allowance not 0");
2729

2830
if (value == 0) return;
@@ -37,6 +39,8 @@ library AllowanceLib {
3739
// 3. Fall-back to setting a maximum allowance
3840
if (!success) {
3941
token.approve(spender, type(uint256).max);
42+
// untestable:
43+
// allowance should always be max value if token behaves correctly
4044
require(token.allowance(address(this), spender) >= value, "allowance missing");
4145
}
4246
}

contracts/p1/Broker.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ contract BrokerP1 is ComponentP1, IBroker {
158158
dutchTradeDisabled[buy] = true;
159159
}
160160
} else {
161+
// untestable: trade kind is either BATCH or DUTCH
161162
revert("unrecognized trade kind");
162163
}
163164
}

contracts/p1/Distributor.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ contract DistributorP1 is ComponentP1, IDistributor {
124124

125125
if (addrTo == FURNACE) {
126126
addrTo = furnaceAddr;
127-
if (transferAmt > 0) accountRewards = true;
127+
accountRewards = true;
128128
} else if (addrTo == ST_RSR) {
129129
addrTo = stRSRAddr;
130-
if (transferAmt > 0) accountRewards = true;
130+
accountRewards = true;
131131
}
132132

133133
transfers[numTransfers] = Transfer({ addrTo: addrTo, amount: transferAmt });

contracts/p1/RevenueTrader.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ contract RevenueTraderP1 is TradingP1, IRevenueTrader {
5656

5757
// solhint-disable-next-line no-empty-blocks
5858
try this.distributeTokenToBuy() {} catch (bytes memory errData) {
59+
// untested:
60+
// OOG pattern tested in other contracts, cost to test here is high
5961
// see: docs/solidity-style.md#Catching-Empty-Data
6062
if (errData.length == 0) revert(); // solhint-disable-line reason-string
6163
}

contracts/p1/mixins/BasketLib.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ library BasketLibP1 {
363363
ICollateral coll = assetRegistry.toColl(erc20s[i]); // reverts if unregistered
364364

365365
(uint192 low, uint192 high) = coll.price(); // {UoA/tok}
366+
// untestable:
367+
// this function is only called if basket is SOUND
366368
require(low > 0 && high < FIX_MAX, "invalid price");
367369

368370
// {UoA/BU} += {target/BU} * {UoA/tok} / ({target/ref} * {ref/tok})

contracts/plugins/assets/EURFiatCollateral.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ contract EURFiatCollateral is FiatCollateral {
5555
uint192 pricePerTarget = targetUnitChainlinkFeed.price(targetUnitOracleTimeout);
5656

5757
// div-by-zero later
58+
// untestable:
59+
// calls to price() on the feed never return zero if using OracleLib
5860
if (pricePerTarget == 0) {
5961
return (0, FIX_MAX, 0);
6062
}

contracts/plugins/assets/RTokenAsset.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ contract RTokenAsset is IAsset, VersionedAsset, IRTokenOracle {
150150
/// @return updatedAt {s} The timestamp of the cache update
151151
function latestPrice() external returns (uint192 rTokenPrice, uint256 updatedAt) {
152152
// Situations that require an update, from most common to least common.
153+
// untestable:
154+
// basket and trade nonce checks, as first condition will always be true in these cases
153155
if (
154156
cachedOracleData.cachedAtTime + ORACLE_TIMEOUT <= block.timestamp || // Cache Timeout
155157
cachedOracleData.cachedAtNonce != basketHandler.nonce() || // Basket nonce was updated

contracts/plugins/assets/compoundv2/CTokenNonFiatCollateral.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ contract CTokenNonFiatCollateral is CTokenFiatCollateral {
3131
) CTokenFiatCollateral(config, revenueHiding) {
3232
require(address(targetUnitChainlinkFeed_) != address(0), "missing targetUnit feed");
3333
require(targetUnitOracleTimeout_ > 0, "targetUnitOracleTimeout zero");
34-
require(config.defaultThreshold > 0, "defaultThreshold zero");
3534
targetUnitChainlinkFeed = targetUnitChainlinkFeed_;
3635
targetUnitOracleTimeout = targetUnitOracleTimeout_;
3736
maxOracleTimeout = uint48(Math.max(maxOracleTimeout, targetUnitOracleTimeout_));

contracts/plugins/mocks/CTokenMock.sol

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ contract CTokenMock is ERC20Mock {
1212

1313
uint256 internal _exchangeRate;
1414

15-
bool public revertExchangeRate;
15+
bool public revertExchangeRateCurrent;
16+
bool public revertExchangeRateStored;
1617

1718
IComptroller public immutable comptroller;
1819

@@ -32,14 +33,17 @@ contract CTokenMock is ERC20Mock {
3233
}
3334

3435
function exchangeRateCurrent() external returns (uint256) {
35-
if (revertExchangeRate) {
36+
if (revertExchangeRateCurrent) {
3637
revert("reverting exchange rate current");
3738
}
3839
_exchangeRate = _exchangeRate; // just to avoid sol warning
3940
return _exchangeRate;
4041
}
4142

4243
function exchangeRateStored() external view returns (uint256) {
44+
if (revertExchangeRateStored) {
45+
revert("reverting exchange rate stored");
46+
}
4347
return _exchangeRate;
4448
}
4549

@@ -59,7 +63,11 @@ contract CTokenMock is ERC20Mock {
5963
return fiatcoinRedemptionRate.shiftl(leftShift).mul_toUint(start);
6064
}
6165

62-
function setRevertExchangeRate(bool newVal) external {
63-
revertExchangeRate = newVal;
66+
function setRevertExchangeRateCurrent(bool newVal) external {
67+
revertExchangeRateCurrent = newVal;
68+
}
69+
70+
function setRevertExchangeRateStored(bool newVal) external {
71+
revertExchangeRateStored = newVal;
6472
}
6573
}

contracts/plugins/mocks/InvalidChainlinkMock.sol

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import "./ChainlinkMock.sol";
1111
*/
1212
contract InvalidMockV3Aggregator is MockV3Aggregator {
1313
bool public simplyRevert;
14+
bool public revertWithExplicitError;
1415

15-
constructor(uint8 _decimals, int256 _initialAnswer)
16-
MockV3Aggregator(_decimals, _initialAnswer)
17-
{}
16+
constructor(
17+
uint8 _decimals,
18+
int256 _initialAnswer
19+
) MockV3Aggregator(_decimals, _initialAnswer) {}
1820

1921
function latestRoundData()
2022
external
@@ -30,6 +32,8 @@ contract InvalidMockV3Aggregator is MockV3Aggregator {
3032
{
3133
if (simplyRevert) {
3234
revert(); // Revert with no reason
35+
} else if (revertWithExplicitError) {
36+
revert("oracle explicit error"); // Revert with explicit reason
3337
} else {
3438
// Run out of gas
3539
this.infiniteLoop{ gas: 10 }();
@@ -47,6 +51,10 @@ contract InvalidMockV3Aggregator is MockV3Aggregator {
4751
simplyRevert = on;
4852
}
4953

54+
function setRevertWithExplicitError(bool on) external {
55+
revertWithExplicitError = on;
56+
}
57+
5058
function infiniteLoop() external pure {
5159
uint256 i = 0;
5260
uint256[1] memory array;

0 commit comments

Comments
 (0)