Skip to content

Commit

Permalink
Merge pull request #42 from ebtc-protocol/fix-tests
Browse files Browse the repository at this point in the history
Adapted tests to work for Mainnet fork
  • Loading branch information
sajanrajdev authored Apr 4, 2024
2 parents f78aa6b + 2c2923c commit 92413cf
Show file tree
Hide file tree
Showing 8 changed files with 627 additions and 136 deletions.
83 changes: 83 additions & 0 deletions contracts/mock/MockFallbackCaller.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// SPDX-License-Identifier: MIT
// File: Interfaces/IFallbackCaller.sol

pragma solidity 0.8.17;

interface IFallbackCaller {
// --- Events ---
event FallbackTimeOutChanged(uint256 _oldTimeOut, uint256 _newTimeOut);

// --- Function External View ---

// NOTE: The fallback oracle must always return its answer scaled to 18 decimals where applicable
// The system will assume an 18 decimal response for efficiency.
function getFallbackResponse() external view returns (uint256, uint256, bool);

// NOTE: this returns the timeout window interval for the fallback oracle instead
// of storing in the `PriceFeed` contract is retrieve for the `FallbackCaller`
function fallbackTimeout() external view returns (uint256);

// --- Function External Setter ---

function setFallbackTimeout(uint256 newFallbackTimeout) external;
}
// File: contracts/MockFallbackCaller.sol

pragma solidity 0.8.17;

contract MockFallbackCaller is IFallbackCaller {
uint256 public _answer;
uint256 public _timestampRetrieved;
uint256 public _fallbackTimeout = 90000; // NOTE: MAYBE BEST TO CUSTOMIZE
bool public _success;
uint256 public _initAnswer;

bool public getFallbackResponseRevert;
bool public fallbackTimeoutRevert;

constructor(uint256 answer) {
_initAnswer = answer;
}

function setGetFallbackResponseRevert() external {
getFallbackResponseRevert = !getFallbackResponseRevert;
}

function setFallbackTimeoutRevert() external {
fallbackTimeoutRevert = !fallbackTimeoutRevert;
}

function setFallbackResponse(
uint256 answer,
uint256 timestampRetrieved,
bool success
) external {
_answer = answer;
_timestampRetrieved = timestampRetrieved;
_success = success;
}

function setFallbackTimeout(uint256 newFallbackTimeout) external {
uint256 oldTimeOut = _fallbackTimeout;
_fallbackTimeout = newFallbackTimeout;
emit FallbackTimeOutChanged(oldTimeOut, newFallbackTimeout);
}

function getFallbackResponse()
external
view
returns (uint256, uint256, bool)
{
if (getFallbackResponseRevert) {
require(1 == 0, "getFallbackResponse reverted");
}
return (_answer, _timestampRetrieved, _success);
}

function fallbackTimeout() external view returns (uint256) {
if (fallbackTimeoutRevert) {
require(1 == 0, "fallbackTimeout reverted");
}
return _fallbackTimeout;
}
}
Loading

0 comments on commit 92413cf

Please sign in to comment.